Expand description
HLSL AST.
Minimal AST that covers what MD2 user comp shaders use. Not a faithful HLSL AST — only the constructs the regex pipeline already targets, plus the ones blocking the long-tail residual failures.
A future WGSL emitter will consume this AST and gradually retire the
string-driven rewrites in crate::translate_shader. Currently the AST
exists, can be constructed by crate::parse, and is exercised by
tests — but no emitter consumes it yet.
Structs§
- Assign
Expr - Assign
Stmt - Binary
Expr - Block
{ stmt; stmt; ... }— a sequence of statements with its own scope.- Call
Expr - ForStmt
- Function
Def <type> <name>(<params>) { <body> }- Global
Var - IfStmt
- Index
Expr - Init
List Expr - Lit
- Local
Decl - Member
Expr - Param
- One function parameter: optional storage class qualifier, type, name.
- Sampler
Decl sampler <name>;— minimal sampler declaration. MD2 user shaders usesampler sampler_<name>for disk-loaded textures andsampler_main/sampler_blur1..3for built-ins.- Swizzle
Expr - Ternary
Expr - Translation
Unit - A whole HLSL translation unit: top-level items (functions, samplers,
static constdeclarations) plus an optionalshader_body { ... }block at the end. MD2 always wraps the main code inshader_body; standalone fragments (test fixtures, function-only inputs) omit it. - TypeRef
- Reference to a (possibly compound) HLSL type —
float,float2,float2x2,int,bool,void, or a struct name. Kept as a raw identifier plus span so the emitter can map to WGSL on its own table. - Unary
Expr - While
Stmt
Enums§
- Assign
Op - Binary
Op - Expr
- 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.
- Item
- Top-level item in the translation unit.
- LitValue
- Param
Qualifier - HLSL
in,out,inoutparameter direction. - Sampler
Tag - Stmt
- One statement. Statements that contain expressions own the
Exprdirectly — noRc/Boxindirection at the top level. - UnaryOp