Module ast

Module ast 

Source
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§

AssignExpr
AssignStmt
BinaryExpr
Block
{ stmt; stmt; ... } — a sequence of statements with its own scope.
CallExpr
ForStmt
FunctionDef
<type> <name>(<params>) { <body> }
GlobalVar
IfStmt
IndexExpr
InitListExpr
Lit
LocalDecl
MemberExpr
Param
One function parameter: optional storage class qualifier, type, name.
SamplerDecl
sampler <name>; — minimal sampler declaration. MD2 user shaders use sampler sampler_<name> for disk-loaded textures and sampler_main / sampler_blur1..3 for built-ins.
SwizzleExpr
TernaryExpr
TranslationUnit
A whole HLSL translation unit: top-level items (functions, samplers, static const declarations) plus an optional shader_body { ... } block at the end. MD2 always wraps the main code in shader_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.
UnaryExpr
WhileStmt

Enums§

AssignOp
BinaryOp
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
ParamQualifier
HLSL in, out, inout parameter direction.
SamplerTag
Stmt
One statement. Statements that contain expressions own the Expr directly — no Rc/Box indirection at the top level.
UnaryOp