ShaderCompiler/GlslAst.h file

Shared GLSL expression AST and stage tokenizer for the AST-based ShaderCompiler lowerings.

Both AST-based emitters — the GLSL-to-HLSL emitter (Hlsl.h) and the GLSL-to-C++ software transpiler (GlslToCpp.h) — grow a per-statement/expression tree from the same reusable lexer (GlslExprTokenizer) and preprocessor (Preprocessor). This header holds the parts of that tree that carry no type information and are therefore identical for every target: the expression node (Expr / ExprKind), its factory (MakeExpr) and the stage-source tokenizer (TokenizeStage). Each emitter keeps its OWN statement/declaration model and type system, because those diverge per target (HLSL keeps uint/uvec/matrices/user structs distinct, the software path folds them away), so they are NOT shared here.

ExprKind is the UNION of what the targets need: it carries ExprKind::UIntLit for the HLSL emitter (which keeps unsigned literals distinct); the software transpiler folds 2u to a signed ExprKind::IntLit while tokenizing, so it never produces a ExprKind::UIntLit node.

Namespaces

namespace ShaderCompiler

Classes

struct ShaderCompiler::Expr
One expression-tree node; the type-free shape shared by the AST-based lowerings.

Enums

enum class ExprKind { IntLit, UIntLit, FloatLit, BoolLit, Ident, Member, Index, Call, Unary, Binary, Assign, Conditional }
Kind of an Expr node (the union across the AST-based targets).

Typedefs

using ExprPtr = std::unique_ptr<Expr>

Functions

auto IsQualifier(StringView k) -> bool
True for a type-qualifier keyword the AST parsers skip (precision / interpolation / const).
auto BinPrec(StringView op) -> std::int32_t
auto MakeExpr(ExprKind kind, String text = {}) -> ExprPtr
Allocates an Expr of the given kind, optionally carrying literal/identifier/operator text.
auto TokenizeStage(StringView glsl, std::vector<GlslToken>& tokens, String& reason) -> bool

Function documentation

std::int32_t BinPrec(StringView op)

Precedence of a binary/assignment operator, mirroring ConstFold's model (assignment = 1, ternary handled separately at 2). Returns -1 for anything that is not a binary operator.

bool TokenizeStage(StringView glsl, std::vector<GlslToken>& tokens, String& reason)

Splits, strips comments from, preprocesses and tokenizes a GLSL stage source, appending a trailing GlslTokenType::End token. Returns false (with a reason) only if preprocessing fails.