Struct TypeInfo

Source
pub struct TypeInfo {
    pub types: HashMap<NodeId, TypeAndValue>,
    pub defs: HashMap<IdentKey, Option<ObjKey>>,
    pub uses: HashMap<IdentKey, ObjKey>,
    pub implicits: HashMap<NodeId, ObjKey>,
    pub selections: HashMap<NodeId, Selection>,
    pub scopes: HashMap<NodeId, ScopeKey>,
    pub init_order: Vec<Initializer>,
    pub ast_files: Vec<File>,
}
Expand description

Types info holds the results of Type Checking

Fields§

§types: HashMap<NodeId, TypeAndValue>

‘types’ maps expressions to their types, and for constant expressions, also their values. Invalid expressions are omitted.

For (possibly parenthesized) identifiers denoting built-in functions, the recorded signatures are call-site specific: if the call result is not a constant, the recorded type is an argument-specific signature. Otherwise, the recorded type is invalid.

‘types’ does not record the type of every identifier, only those that appear where an arbitrary expression is permitted. For instance, the identifier f in a selector expression x.f is found only in the Selections map, the identifier z in a variable declaration ‘var z int’ is found only in the Defs map, and identifiers denoting packages in qualified identifiers are collected in the Uses map.

§defs: HashMap<IdentKey, Option<ObjKey>>

‘defs’ maps identifiers to the objects they define (including package names, dots “.” of dot-imports, and blank “_” identifiers). For identifiers that do not denote objects (e.g., the package name in package clauses, or symbolic variables t in t := x.(type) of type switch headers), the corresponding objects are None.

For an embedded field, Defs returns the field it defines.

Invariant: defs[id] == None || defs[id].pos() == id.pos()

§uses: HashMap<IdentKey, ObjKey>

‘uses’ maps identifiers to the objects they denote.

For an embedded field, ‘uses’ returns the TypeName it denotes.

Invariant: uses[id].pos() != id.pos()

§implicits: HashMap<NodeId, ObjKey>

‘implicits’ maps nodes to their implicitly declared objects, if any. The following node and object types may appear: node declared object ImportSpec PkgName for imports without renames CaseClause type-specific Object::Var for each type switch case clause (incl. default) Field anonymous parameter Object::Var

§selections: HashMap<NodeId, Selection>

‘selections’ maps selector expressions (excluding qualified identifiers) to their corresponding selections.

§scopes: HashMap<NodeId, ScopeKey>

‘scopes’ maps ast::Nodes to the scopes they define. Package scopes are not associated with a specific node but with all files belonging to a package. Thus, the package scope can be found in the type-checked Package object. Scopes nest, with the Universe scope being the outermost scope, enclosing the package scope, which contains (one or more) files scopes, which enclose function scopes which in turn enclose statement and function literal scopes. Note that even though package-level functions are declared in the package scope, the function scopes are embedded in the file scope of the file containing the function declaration.

The following node types may appear in Scopes: File FuncType BlockStmt IfStmt SwitchStmt TypeSwitchStmt CaseClause CommClause ForStmt RangeStmt

§init_order: Vec<Initializer>

‘init_order’ is the list of package-level initializers in the order in which they must be executed. Initializers referring to variables related by an initialization dependency appear in topological order, the others appear in source order. Variables without an initialization expression do not appear in this list.

§ast_files: Vec<File>

oxfeeefeee: parse result of the package, to be used by code gen

Implementations§

Source§

impl TypeInfo

Source

pub fn new() -> TypeInfo

Source§

impl TypeInfo

Source

pub fn record_type_and_value( &mut self, e: &Expr, mode: OperandMode, typ: TypeKey, )

Source

pub fn record_type_and_value_with_id( &mut self, id: NodeId, mode: OperandMode, typ: TypeKey, )

Source

pub fn record_builtin_type( &mut self, mode: &OperandMode, e: &Expr, sig: TypeKey, )

Source

pub fn record_comma_ok_types( &mut self, e: &Expr, t: &[TypeKey; 2], tc_objs: &mut TCObjects, ast_objs: &AstObjects, pkg: PackageKey, )

Source

pub fn record_def(&mut self, id: IdentKey, obj: Option<ObjKey>)

Source

pub fn record_use(&mut self, id: IdentKey, obj: ObjKey)

Source

pub fn record_implicit(&mut self, node: &impl Node, obj: ObjKey)

Source

pub fn record_selection(&mut self, expr: &SelectorExpr, sel: Selection)

Source

pub fn record_scope(&mut self, node: &impl Node, scope: ScopeKey)

Source

pub fn record_init_order(&mut self, init_order: Vec<Initializer>)

Trait Implementations§

Source§

impl Debug for TypeInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.