WalkCtx

Struct WalkCtx 

Source
struct WalkCtx<'a> {
    src: &'a str,
    scopes: Vec<HashMap<String, WgslType>>,
    edits: Vec<TextEdit>,
}
Expand description

AST walker state: a small stacked symbol table plus a sink for text edits. Each walk_* consults and updates the table; walk_expr returns the inferred type of the expression so callers can decide whether to emit a fix-up edit.

Fields§

§src: &'a str§scopes: Vec<HashMap<String, WgslType>>§edits: Vec<TextEdit>

Implementations§

Source§

impl<'a> WalkCtx<'a>

Source

fn new(src: &'a str) -> Self

Source

fn seed_globals(&mut self, tu: &TranslationUnit)

Source

fn scope_push(&mut self)

Source

fn scope_pop(&mut self)

Source

fn declare(&mut self, name: &str, ty: WgslType)

Source

fn lookup(&self, name: &str) -> WgslType

Source

fn slice(&self, span: Span) -> &'a str

Slice of original source between span bounds.

Source

fn emit_truncation(&mut self, span: Span, target_size: usize)

Source

fn emit_pad_vec2_to_vec3(&mut self, span: Span)

Wrap a vec2 expression in vec3<f32>(<expr>, 0.0) so it satisfies a helper that demands a vec3 (real example: MD2 presets calling lum(roam_sin.yx) where the runtime padded implicitly). Emitted as two zero-length insertions instead of one replace-range edit so any inner edits inside the arg (e.g. a swizzle rewrite) don’t get dropped by apply_edits’s overlap guard.

Source

fn emit_scalar_to_vec2(&mut self, span: Span)

Wrap a scalar expression in vec2<f32>(<expr>) so it satisfies a 2D-texture coord parameter. MD2 presets occasionally pass a single channel (tex2D(sampler_noise_hq, uv.x)) where naga demands a vec2; HLSL silently broadcast in that situation. Emitted as two zero-length insertions, same overlap-safety rationale as Self::emit_pad_vec2_to_vec3.

Auto Trait Implementations§

§

impl<'a> Freeze for WalkCtx<'a>

§

impl<'a> RefUnwindSafe for WalkCtx<'a>

§

impl<'a> Send for WalkCtx<'a>

§

impl<'a> Sync for WalkCtx<'a>

§

impl<'a> Unpin for WalkCtx<'a>

§

impl<'a> UnwindSafe for WalkCtx<'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.