pub enum Expr {
Lit(Lit),
Ident(String, Span),
Binary(BinaryExpr),
Unary(UnaryExpr),
Ternary(TernaryExpr),
Call(CallExpr),
Member(MemberExpr),
Swizzle(SwizzleExpr),
Index(IndexExpr),
InitList(InitListExpr),
Assign(AssignExpr),
}Expand description
HLSL expression node. Members and swizzles are split because WGSL treats them slightly differently — keeping them separate at the AST level lets the emitter choose the right WGSL form.
Variants§
Lit(Lit)
42, 1.5, true
Ident(String, Span)
foo, aspect, texsize
Binary(BinaryExpr)
lhs + rhs, lhs * rhs, lhs && rhs, …
Unary(UnaryExpr)
-x, !x, +x, ~x
Ternary(TernaryExpr)
cond ? then : else_
Call(CallExpr)
f(arg, arg, …) — also covers vector/matrix constructors like
float2(x, y), since they share syntax.
Member(MemberExpr)
obj.member — struct field access. Swizzles use Expr::Swizzle.
Swizzle(SwizzleExpr)
vec.xy, color.rgba, m.r — sub-vector / component access.
HLSL spells RGBA swizzles equivalently to XYZW.
Index(IndexExpr)
arr[i]
InitList(InitListExpr)
{ 1, 2, 3 } — array initialiser used in float arr[3] = {…};
and matrix initialisers. Kept distinct from Call so the emitter
can target WGSL’s array<f32, 3>(…) form.
Assign(AssignExpr)
Assignment as an expression — i = i + 1, x += 2. HLSL allows
these inside for headers and other expression contexts. Statement
form (<stmt>;) is modelled separately as AssignStmt to keep
the common case (top-level statement) cheap to walk.