struct ExpressionContext<'input, 'temp, 'out> {
expressions: &'out mut Arena<Expression<'input>>,
types: &'out mut Arena<Type<'input>>,
local_table: &'temp mut SymbolTable<&'input str, Handle<Local>>,
locals: &'out mut Arena<Local>,
unresolved: &'out mut FastIndexSet<Dependency<'input>>,
}
Expand description
State for constructing an AST expression.
Not to be confused with lower::ExpressionContext
, which is for producing
Naga IR from the AST we produce here.
Fields§
§expressions: &'out mut Arena<Expression<'input>>
The TranslationUnit::expressions
arena to which we should contribute
expressions.
types: &'out mut Arena<Type<'input>>
The TranslationUnit::types
arena to which we should contribute new
types.
local_table: &'temp mut SymbolTable<&'input str, Handle<Local>>
A map from identifiers in scope to the locals/arguments they represent.
The handles refer to the locals
arena; see that field’s
documentation for details.
locals: &'out mut Arena<Local>
Local variable and function argument arena for the function we’re building.
Note that the ast::Local
here is actually a zero-sized type. This
Arena
’s only role is to assign a unique Handle
to each local
identifier, and track its definition’s span for use in diagnostics. All
the detailed information about locals - names, types, etc. - is kept in
the LocalDecl
statements we parsed from their declarations. For
arguments, that information is kept in arguments
.
In the AST, when an Ident
expression refers to a local variable or
argument, its IdentExpr
holds the referent’s Handle<Local>
in this
arena.
During lowering, LocalDecl
statements add entries to a per-function
table that maps Handle<Local>
values to their Naga representations,
accessed via StatementContext::local_table
and
LocalExpressionContext::local_table
. This table is then consulted when
lowering subsequent Ident
expressions.
unresolved: &'out mut FastIndexSet<Dependency<'input>>
Identifiers used by the current global declaration that have no local definition.
This becomes the GlobalDecl
’s dependencies
set.
Note that we don’t know at parse time what kind of GlobalDecl
the
name refers to. We can’t look up names until we’ve seen the entire
translation unit.