Struct naga::front::wgsl::parse::ExpressionContext

source ·
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.

Implementations§

source§

impl<'a> ExpressionContext<'a, '_, '_>

source

fn parse_binary_op( &mut self, lexer: &mut Lexer<'a>, classifier: impl Fn(Token<'a>) -> Option<BinaryOperator>, parser: impl FnMut(&mut Lexer<'a>, &mut Self) -> Result<Handle<Expression<'a>>, Error<'a>>, ) -> Result<Handle<Expression<'a>>, Error<'a>>

source

fn declare_local(&mut self, name: Ident<'a>) -> Result<Handle<Local>, Error<'a>>

source

fn new_scalar(&mut self, scalar: Scalar) -> Handle<Type<'a>>

Auto Trait Implementations§

§

impl<'input, 'temp, 'out> Freeze for ExpressionContext<'input, 'temp, 'out>

§

impl<'input, 'temp, 'out> RefUnwindSafe for ExpressionContext<'input, 'temp, 'out>

§

impl<'input, 'temp, 'out> Send for ExpressionContext<'input, 'temp, 'out>

§

impl<'input, 'temp, 'out> Sync for ExpressionContext<'input, 'temp, 'out>

§

impl<'input, 'temp, 'out> Unpin for ExpressionContext<'input, 'temp, 'out>

§

impl<'input, 'temp, 'out> !UnwindSafe for ExpressionContext<'input, 'temp, 'out>

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.