naga::front::glsl::context

Struct Context

source
pub struct Context<'a> {
Show 16 fields pub expressions: Arena<Expression>, pub locals: Arena<LocalVariable>, pub arguments: Vec<FunctionArgument>, pub parameters: Vec<Handle<Type>>, pub parameters_info: Vec<ParameterInfo>, pub symbol_table: SymbolTable<String, VariableReference>, pub samplers: FastHashMap<Handle<Expression>, Handle<Expression>>, pub const_typifier: Typifier, pub typifier: Typifier, emitter: Emitter, stmt_ctx: Option<StmtContext>, pub body: Block, pub module: &'a mut Module, pub is_const: bool, pub local_expression_kind_tracker: ExpressionKindTracker, pub global_expression_kind_tracker: &'a mut ExpressionKindTracker,
}

Fields§

§expressions: Arena<Expression>§locals: Arena<LocalVariable>§arguments: Vec<FunctionArgument>

The FunctionArguments for the final crate::Function.

Parameters with the out and inout qualifiers have Pointer types here. For example, an inout vec2 a argument would be a Pointer to a Vector.

§parameters: Vec<Handle<Type>>

The parameter types given in the source code.

The out and inout qualifiers don’t affect the types that appear here. For example, an inout vec2 a argument would simply be a Vector, not a pointer to one.

§parameters_info: Vec<ParameterInfo>§symbol_table: SymbolTable<String, VariableReference>§samplers: FastHashMap<Handle<Expression>, Handle<Expression>>§const_typifier: Typifier§typifier: Typifier§emitter: Emitter§stmt_ctx: Option<StmtContext>§body: Block§module: &'a mut Module§is_const: bool§local_expression_kind_tracker: ExpressionKindTracker

Tracks the expression kind of Expressions residing in self.expressions

§global_expression_kind_tracker: &'a mut ExpressionKindTracker

Tracks the expression kind of Expressions residing in self.module.global_expressions

Implementations§

source§

impl<'a> Context<'a>

source

pub fn new( frontend: &Frontend, module: &'a mut Module, is_const: bool, global_expression_kind_tracker: &'a mut ExpressionKindTracker, ) -> Result<Self, Error>

source

pub fn new_body<F>(&mut self, cb: F) -> Result<Block, Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

source

pub fn new_body_with_ret<F, R>(&mut self, cb: F) -> Result<(Block, R), Error>
where F: FnOnce(&mut Self) -> Result<R, Error>,

source

pub fn with_body<F>(&mut self, body: Block, cb: F) -> Result<Block, Error>
where F: FnOnce(&mut Self) -> Result<(), Error>,

source

pub fn add_global(&mut self, name: &str, _: GlobalLookup) -> Result<(), Error>

source

pub fn emit_start(&mut self)

Starts the expression emitter

§Panics
  • If called twice in a row without calling emit_end.
source

pub fn emit_end(&mut self)

Emits all the expressions captured by the emitter to the current body

§Panics
source

pub fn emit_restart(&mut self)

Emits all the expressions captured by the emitter to the current body and starts the emitter again

§Panics
source

pub fn add_expression( &mut self, expr: Expression, meta: Span, ) -> Result<Handle<Expression>, Error>

source

pub fn add_local_var( &mut self, name: String, expr: Handle<Expression>, mutable: bool, ) -> Option<VariableReference>

Add variable to current scope

Returns a variable if a variable with the same name was already defined, otherwise returns None

source

pub fn add_function_arg( &mut self, name_meta: Option<(String, Span)>, ty: Handle<Type>, qualifier: ParameterQualifier, ) -> Result<(), Error>

Add function argument to current scope

source

pub fn stmt_ctx(&mut self) -> StmtContext

Returns a StmtContext to be used in parsing and lowering

§Panics
  • If more than one StmtContext are active at the same time or if the previous call didn’t use it in lowering.
source

pub fn lower( &mut self, stmt: StmtContext, frontend: &mut Frontend, expr: Handle<HirExpr>, pos: ExprPos, ) -> Result<(Option<Handle<Expression>>, Span), Error>

Lowers a HirExpr which might produce a Expression.

consumes a StmtContext returning it to the context so that it can be used again later.

source

pub fn lower_expect( &mut self, stmt: StmtContext, frontend: &mut Frontend, expr: Handle<HirExpr>, pos: ExprPos, ) -> Result<(Handle<Expression>, Span), Error>

Similar to lower but returns an error if the expression returns void (ie. doesn’t produce a Expression).

consumes a StmtContext returning it to the context so that it can be used again later.

source

pub fn lower_expect_inner( &mut self, stmt: &StmtContext, frontend: &mut Frontend, expr: Handle<HirExpr>, pos: ExprPos, ) -> Result<(Handle<Expression>, Span), Error>

internal implementation of lower_expect

this method is only public because it’s used in function_call, unless you know what you’re doing use lower_expect

source

fn lower_store( &mut self, pointer: Handle<Expression>, value: Handle<Expression>, meta: Span, ) -> Result<(), Error>

source

fn lower_inner( &mut self, stmt: &StmtContext, frontend: &mut Frontend, expr: Handle<HirExpr>, pos: ExprPos, ) -> Result<(Option<Handle<Expression>>, Span), Error>

Internal implementation of lower

source

pub fn expr_scalar_components( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<Option<Scalar>, Error>

source

pub fn expr_power( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<Option<u32>, Error>

source

pub fn conversion( &mut self, expr: &mut Handle<Expression>, meta: Span, scalar: Scalar, ) -> Result<(), Error>

source

pub fn implicit_conversion( &mut self, expr: &mut Handle<Expression>, meta: Span, scalar: Scalar, ) -> Result<(), Error>

source

pub fn forced_conversion( &mut self, expr: &mut Handle<Expression>, meta: Span, scalar: Scalar, ) -> Result<(), Error>

source

pub fn binary_implicit_conversion( &mut self, left: &mut Handle<Expression>, left_meta: Span, right: &mut Handle<Expression>, right_meta: Span, ) -> Result<(), Error>

source

pub fn implicit_splat( &mut self, expr: &mut Handle<Expression>, meta: Span, vector_size: Option<VectorSize>, ) -> Result<(), Error>

source

pub fn vector_resize( &mut self, size: VectorSize, vector: Handle<Expression>, meta: Span, ) -> Result<Handle<Expression>, Error>

source§

impl Context<'_>

source

fn arg_type_walker( &mut self, name: Option<String>, binding: Binding, pointer: Handle<Expression>, ty: Handle<Type>, f: &mut impl FnMut(&mut Context<'_>, Option<String>, Handle<Expression>, Handle<Type>, Binding), ) -> Result<(), Error>

Helper function for building the input/output interface of the entry point

Calls f with the data of the entry point argument, flattening composite types recursively

The passed arguments to the callback are:

  • The ctx
  • The name
  • The pointer expression to the global storage
  • The handle to the type of the entry point argument
  • The binding of the entry point argument
source§

impl Context<'_>

source

pub(crate) fn typifier_grow( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<(), Error>

Resolves the types of the expressions until expr (inclusive)

This needs to be done before the typifier can be queried for the types of the expressions in the range between the last grow and expr.

§Note

The resolve_type* methods (like resolve_type) automatically grow the typifier so calling this method is not necessary when using them.

source

pub(crate) fn get_type(&self, expr: Handle<Expression>) -> &TypeInner

source

pub(crate) fn resolve_type( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<&TypeInner, Error>

Gets the type for the result of the expr expression

Automatically grows the typifier to expr so calling typifier_grow is not necessary

source

pub(crate) fn resolve_type_handle( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<Handle<Type>, Error>

Gets the type handle for the result of the expr expression

Automatically grows the typifier to expr so calling typifier_grow is not necessary

§Note

Consider using resolve_type whenever possible since it doesn’t require adding each type to the types arena and it doesn’t need to mutably borrow the Parser

source

pub(crate) fn invalidate_expression( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<(), Error>

Invalidates the cached type resolution for expr forcing a recomputation

source

pub(crate) fn lift_up_const_expression( &mut self, expr: Handle<Expression>, ) -> Result<Handle<Expression>, Error>

Trait Implementations§

source§

impl<'a> Debug for Context<'a>

source§

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

Formats the value using the given formatter. Read more
source§

impl Index<Handle<Expression>> for Context<'_>

source§

type Output = Expression

The returned type after indexing.
source§

fn index(&self, index: Handle<Expression>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Context<'a>

§

impl<'a> RefUnwindSafe for Context<'a>

§

impl<'a> Send for Context<'a>

§

impl<'a> Sync for Context<'a>

§

impl<'a> Unpin for Context<'a>

§

impl<'a> !UnwindSafe for Context<'a>

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.