@galacean/engine-shader-parser 0.0.0-stage → 2.0.0-alpha.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/dist/main.analyzer.js +2 -0
  3. package/dist/main.analyzer.js.map +1 -0
  4. package/dist/main.js +2 -0
  5. package/dist/main.js.map +1 -0
  6. package/dist/main.shared.js +2 -0
  7. package/dist/main.shared.js.map +1 -0
  8. package/dist/module.analyzer.js +2 -0
  9. package/dist/module.analyzer.js.map +1 -0
  10. package/dist/module.js +2 -0
  11. package/dist/module.js.map +1 -0
  12. package/dist/module.shared.js +2 -0
  13. package/dist/module.shared.js.map +1 -0
  14. package/dist/shared/GLESShaderInfo.main.js +2 -0
  15. package/dist/shared/GLESShaderInfo.main.js.map +1 -0
  16. package/dist/shared/GLESShaderInfo.module.js +2 -0
  17. package/dist/shared/GLESShaderInfo.module.js.map +1 -0
  18. package/internal/analyzer/package.json +5 -0
  19. package/internal/package.json +5 -0
  20. package/package.json +42 -3
  21. package/shared/package.json +5 -0
  22. package/types/GSError.d.ts +31 -0
  23. package/types/ParsedShaderPass.d.ts +11 -0
  24. package/types/ParserObjectPool.d.ts +51 -0
  25. package/types/ParserUtils.d.ts +91 -0
  26. package/types/Preprocessor.d.ts +71 -0
  27. package/types/PreprocessorExpression.d.ts +1 -0
  28. package/types/ShaderCompilerUtils.d.ts +9 -0
  29. package/types/backends/GLESShaderInfo.d.ts +39 -0
  30. package/types/common/BaseLexer.d.ts +61 -0
  31. package/types/common/BaseToken.d.ts +105 -0
  32. package/types/common/BranchAnalysis.d.ts +84 -0
  33. package/types/common/BranchIdentity.d.ts +58 -0
  34. package/types/common/BranchSemantics.d.ts +54 -0
  35. package/types/common/IBaseSymbol.d.ts +9 -0
  36. package/types/common/PreprocessorCondition.d.ts +39 -0
  37. package/types/common/ShaderPosition.d.ts +20 -0
  38. package/types/common/ShaderRange.d.ts +18 -0
  39. package/types/common/SymbolTable.d.ts +43 -0
  40. package/types/common/SymbolTableStack.d.ts +53 -0
  41. package/types/common/enums/Keyword.d.ts +124 -0
  42. package/types/common/enums/ShaderStage.d.ts +5 -0
  43. package/types/common/index.d.ts +5 -0
  44. package/types/common/types.d.ts +101 -0
  45. package/types/formatDiagnostic.d.ts +18 -0
  46. package/types/index.d.ts +37 -0
  47. package/types/ir/ShaderBuiltinSemantic.d.ts +13 -0
  48. package/types/ir/ShaderClueIR.d.ts +48 -0
  49. package/types/ir/ShaderCoreInfo.d.ts +85 -0
  50. package/types/ir/ShaderDeclarationOwnership.d.ts +36 -0
  51. package/types/ir/ShaderStructOwnership.d.ts +18 -0
  52. package/types/ir/index.d.ts +4 -0
  53. package/types/lalr/CFG.d.ts +5 -0
  54. package/types/lalr/LALR1.d.ts +27 -0
  55. package/types/lalr/Production.d.ts +9 -0
  56. package/types/lalr/State.d.ts +20 -0
  57. package/types/lalr/StateItem.d.ts +20 -0
  58. package/types/lalr/Utils.d.ts +29 -0
  59. package/types/lalr/index.d.ts +2 -0
  60. package/types/lalr/types.d.ts +14 -0
  61. package/types/lexer/AnalyzerLexer.d.ts +56 -0
  62. package/types/lexer/Lexer.d.ts +122 -0
  63. package/types/lexer/index.d.ts +1 -0
  64. package/types/parser/AST.d.ts +625 -0
  65. package/types/parser/AnalyzerSemanticDiagnostics.d.ts +15 -0
  66. package/types/parser/Grammar.d.ts +11 -0
  67. package/types/parser/GrammarSymbol.d.ts +128 -0
  68. package/types/parser/ICodeGenVisitor.d.ts +29 -0
  69. package/types/parser/MacroExpansionFacts.d.ts +25 -0
  70. package/types/parser/ParsedShaderPass.d.ts +71 -0
  71. package/types/parser/ParsedShaderPassHandle.d.ts +29 -0
  72. package/types/parser/ParserSemanticValidation.d.ts +110 -0
  73. package/types/parser/PassParser.d.ts +15 -0
  74. package/types/parser/RuntimePassParser.d.ts +24 -0
  75. package/types/parser/SemanticAnalyzer.d.ts +174 -0
  76. package/types/parser/SemanticDiagnostics.d.ts +93 -0
  77. package/types/parser/ShaderIncludePath.d.ts +23 -0
  78. package/types/parser/ShaderInfo.d.ts +56 -0
  79. package/types/parser/ShaderTargetParser.d.ts +65 -0
  80. package/types/parser/TypeSystem.d.ts +104 -0
  81. package/types/parser/ValidatedPassParser.d.ts +24 -0
  82. package/types/parser/builtin/functions.d.ts +34 -0
  83. package/types/parser/builtin/index.d.ts +2 -0
  84. package/types/parser/builtin/variables.d.ts +13 -0
  85. package/types/parser/index.d.ts +7 -0
  86. package/types/parser/symbolTable/FnSymbol.d.ts +9 -0
  87. package/types/parser/symbolTable/StructSymbol.d.ts +6 -0
  88. package/types/parser/symbolTable/SymbolDataType.d.ts +12 -0
  89. package/types/parser/symbolTable/SymbolInfo.d.ts +33 -0
  90. package/types/parser/symbolTable/VarSymbol.d.ts +16 -0
  91. package/types/parser/symbolTable/index.d.ts +6 -0
  92. package/types/parser/types.d.ts +49 -0
  93. package/types/preprocessor/PreprocessorCondition.d.ts +56 -0
  94. package/types/preprocessor/PreprocessorConditionDiagram.d.ts +11 -0
  95. package/types/preprocessor/PreprocessorConditionNormalization.d.ts +18 -0
  96. package/types/preprocessor/PreprocessorMacroState.d.ts +84 -0
  97. package/types/runtime.d.ts +36 -0
  98. package/types/shared.d.ts +1 -0
  99. package/types/sourceParser/ShaderSourceFactory.d.ts +8 -0
  100. package/types/sourceParser/ShaderSourceParser.d.ts +36 -0
  101. package/types/sourceParser/ShaderSourceSymbol.d.ts +12 -0
  102. package/types/sourceParser/SourceLexer.d.ts +20 -0
  103. package/types/sourceParser/index.d.ts +1 -0
  104. package/README.md +0 -3
@@ -0,0 +1,625 @@
1
+ import type { ICodeGenVisitor } from "./ICodeGenVisitor";
2
+ import { GalaceanDataType, ShaderRange, TokenType } from "../common";
3
+ import { BaseToken, BranchSignature } from "../common/BaseToken";
4
+ import { Keyword } from "../common/enums/Keyword";
5
+ import { NoneTerminal } from "./GrammarSymbol";
6
+ import SemanticAnalyzer from "./SemanticAnalyzer";
7
+ import { ShaderData } from "./ShaderInfo";
8
+ import { ShaderBuiltinSemantic } from "../ir/ShaderBuiltinSemantic";
9
+ import { FnSymbol, StructSymbol, VarSymbol } from "./symbolTable";
10
+ import { IParamInfo, NodeChild, StructProp, SymbolType, type MacroExpansionSyntax } from "./types";
11
+ export declare abstract class TreeNode {
12
+ /** The non-terminal in grammar. */
13
+ nt: NoneTerminal;
14
+ private _children;
15
+ private _parent;
16
+ private _location;
17
+ /**
18
+ * Snapshot of the `#ifdef` stack at this node's source position, inherited from its first
19
+ * terminal descendant (tokens carry `.branch` from the Lexer). Empty = unconditional. Used as
20
+ * the callsite branch for `symbolTableStack.lookup/insert` so a reference inside `#ifdef X`
21
+ * resolves against declarations visible from that branch, and a declaration inside `#ifdef X`
22
+ * is stamped with that branch. Mirrors codegen's per-branch visibility model.
23
+ */
24
+ _branch: BranchSignature;
25
+ _inMacroDefinition: boolean;
26
+ /**
27
+ * Parent pointer for AST traversal.
28
+ * @remarks
29
+ * The parent pointer is only reliable after the entire AST has been constructed.
30
+ * DO NOT rely on `parent` during the `semanticAnalyze` phase, as the AST may still be under construction.
31
+ * It is safe to use `parent` during code generation or any phase after AST construction.
32
+ */
33
+ get parent(): TreeNode | undefined;
34
+ get children(): NodeChild[];
35
+ get location(): ShaderRange;
36
+ set(loc: ShaderRange, children: NodeChild[]): void;
37
+ init(): void;
38
+ codeGen(visitor: ICodeGenVisitor): string;
39
+ /**
40
+ * Do semantic analyze right after the ast node is generated.
41
+ */
42
+ semanticAnalyze(sa: SemanticAnalyzer): void;
43
+ }
44
+ declare namespace ASTNodes {
45
+ interface MacroReferenceBase {
46
+ branch: BranchSignature;
47
+ isValueIdentity?: boolean;
48
+ replacementMemberOwner?: VariableIdentifier;
49
+ requiresRuntimeOwnerExpansion?: boolean;
50
+ }
51
+ type MacroReference = MacroReferenceBase & ({
52
+ name: string;
53
+ formalParameterIndex?: never;
54
+ unresolved?: never;
55
+ } | {
56
+ name?: never;
57
+ formalParameterIndex: number;
58
+ unresolved?: never;
59
+ } | {
60
+ name?: never;
61
+ formalParameterIndex?: never;
62
+ unresolved: true;
63
+ });
64
+ type MacroExpression = MacroPushContext | MacroPopContext | MacroElseExpression | MacroElifExpression | MacroUndef | MacroDefine | BaseToken;
65
+ export type ASTNodeConstructor = new () => TreeNode;
66
+ export function _unwrapToken(node: NodeChild): BaseToken<number>;
67
+ export function get(type: ASTNodeConstructor, sa: SemanticAnalyzer, loc: ShaderRange, children: NodeChild[]): void;
68
+ export class TrivialNode extends TreeNode {
69
+ }
70
+ export class ScopeBrace extends TreeNode {
71
+ semanticAnalyze(sa: SemanticAnalyzer): void;
72
+ }
73
+ export class ScopeEndBrace extends TreeNode {
74
+ semanticAnalyze(sa: SemanticAnalyzer): void;
75
+ }
76
+ export class JumpStatement extends TreeNode {
77
+ codeGen(visitor: ICodeGenVisitor): string;
78
+ }
79
+ export class ConditionOpt extends TreeNode {
80
+ }
81
+ export class ForRestStatement extends TreeNode {
82
+ }
83
+ export class Condition extends TreeNode {
84
+ }
85
+ export class ForInitStatement extends TreeNode {
86
+ }
87
+ export class IterationStatement extends TreeNode {
88
+ semanticAnalyze(sa: SemanticAnalyzer): void;
89
+ }
90
+ export class SelectionStatement extends TreeNode {
91
+ }
92
+ export class ExpressionStatement extends TreeNode {
93
+ }
94
+ export abstract class ExpressionAstNode extends TreeNode {
95
+ protected _type?: GalaceanDataType;
96
+ set type(t: GalaceanDataType | undefined);
97
+ get type(): GalaceanDataType | undefined;
98
+ init(): void;
99
+ }
100
+ export class InitializerList extends ExpressionAstNode {
101
+ semanticAnalyze(sa: SemanticAnalyzer): void;
102
+ }
103
+ export class Initializer extends ExpressionAstNode {
104
+ semanticAnalyze(sa: SemanticAnalyzer): void;
105
+ }
106
+ /**
107
+ * Canonical semantic description of one variable declarator.
108
+ *
109
+ * A comma-separated declaration owns one instance per identifier so array and initializer state
110
+ * cannot leak between siblings. Parser symbol registration and analyzer validation consume this
111
+ * same description instead of decoding grammar child counts independently.
112
+ */
113
+ export interface VariableDeclaratorInfo {
114
+ /** Identifier introduced by this declarator. */
115
+ identifier: BaseToken;
116
+ /** Fully resolved base and array type for this identifier. */
117
+ typeInfo: SymbolType;
118
+ /** Initializer attached to this identifier, when present. */
119
+ initializer?: Initializer;
120
+ /** Whether the shared declaration type is `const`-qualified. */
121
+ isConst: boolean;
122
+ /** Whether the declaration belongs to shader-global scope. */
123
+ isGlobal: boolean;
124
+ /** Exact variable symbol inserted for this declarator. @internal */
125
+ symbol: VarSymbol;
126
+ }
127
+ export class SingleDeclaration extends TreeNode {
128
+ typeSpecifier: TypeSpecifier;
129
+ arraySpecifier?: ArraySpecifier;
130
+ isConst: boolean;
131
+ /** Canonical information for the first declarator in a declaration list. */
132
+ declarator: VariableDeclaratorInfo;
133
+ init(): void;
134
+ semanticAnalyze(sa: SemanticAnalyzer): void;
135
+ codeGen(visitor: ICodeGenVisitor): string;
136
+ }
137
+ export class FullySpecifiedType extends TreeNode {
138
+ typeSpecifier: TypeSpecifier;
139
+ type: GalaceanDataType;
140
+ /** Whether the declaration is `const`-qualified — drives the const-initializer / array-size checks. */
141
+ isConst: boolean;
142
+ semanticAnalyze(_: SemanticAnalyzer): void;
143
+ }
144
+ export class TypeQualifier extends TreeNode {
145
+ }
146
+ export class SingleTypeQualifier extends TreeNode {
147
+ qualifier: Keyword;
148
+ lexeme: string;
149
+ semanticAnalyze(sa: SemanticAnalyzer): void;
150
+ }
151
+ abstract class BasicTypeQualifier extends TreeNode {
152
+ qualifier: Keyword;
153
+ lexeme: string;
154
+ semanticAnalyze(sa: SemanticAnalyzer): void;
155
+ }
156
+ export class StorageQualifier extends BasicTypeQualifier {
157
+ }
158
+ export class PrecisionQualifier extends BasicTypeQualifier {
159
+ }
160
+ export class InterpolationQualifier extends BasicTypeQualifier {
161
+ }
162
+ export class InvariantQualifier extends BasicTypeQualifier {
163
+ }
164
+ export class TypeSpecifier extends TreeNode {
165
+ type: GalaceanDataType;
166
+ lexeme: string;
167
+ arraySize?: number;
168
+ isCustom: boolean;
169
+ /** Exact custom-struct declarations visible at this type occurrence. @internal */
170
+ structDeclarations: readonly StructSpecifier[];
171
+ /** Emission dependencies, including possible macro types without asserting their semantic type. @internal */
172
+ structDependencies: readonly StructSpecifier[];
173
+ init(): void;
174
+ get arraySpecifier(): ArraySpecifier;
175
+ semanticAnalyze(sa: SemanticAnalyzer): void;
176
+ codeGen(visitor: ICodeGenVisitor): string;
177
+ }
178
+ export class ArraySpecifier extends TreeNode {
179
+ size: number | undefined;
180
+ init(): void;
181
+ semanticAnalyze(sa: SemanticAnalyzer): void;
182
+ }
183
+ export class IntegerConstantExpressionOperator extends TreeNode {
184
+ compute?: (a: number, b: number) => number;
185
+ lexeme: string;
186
+ semanticAnalyze(sa: SemanticAnalyzer): void;
187
+ }
188
+ export class IntegerConstantExpression extends TreeNode {
189
+ value?: number;
190
+ init(): void;
191
+ semanticAnalyze(sa: SemanticAnalyzer): void;
192
+ }
193
+ export class TypeSpecifierNonArray extends TreeNode {
194
+ type: GalaceanDataType;
195
+ lexeme: string;
196
+ init(): void;
197
+ }
198
+ export class ExtBuiltinTypeSpecifierNonArray extends TreeNode {
199
+ type: TokenType;
200
+ lexeme: string;
201
+ init(): void;
202
+ }
203
+ export class InitDeclaratorList extends TreeNode {
204
+ typeInfo: SymbolType;
205
+ isConst: boolean;
206
+ /** Canonical information for the declarator appended by this list node. */
207
+ declarator?: VariableDeclaratorInfo;
208
+ init(): void;
209
+ semanticAnalyze(sa: SemanticAnalyzer): void;
210
+ }
211
+ export class IdentifierList extends TreeNode {
212
+ idList: BaseToken[];
213
+ init(): void;
214
+ semanticAnalyze(sa: SemanticAnalyzer): void;
215
+ }
216
+ export class Declaration extends TreeNode {
217
+ /**
218
+ * Ends a prototype's parameter scope while retaining an enclosing function's captured facts.
219
+ * @param sa - Parser session owning the declaration scope.
220
+ * @internal
221
+ */
222
+ semanticAnalyze(sa: SemanticAnalyzer): void;
223
+ codeGen(visitor: ICodeGenVisitor): string;
224
+ }
225
+ export class FunctionProtoType extends TreeNode {
226
+ ident: BaseToken;
227
+ returnType: FullySpecifiedType;
228
+ parameterList: IParamInfo[];
229
+ paramSig: GalaceanDataType[] | undefined;
230
+ semanticAnalyze(sa: SemanticAnalyzer): void;
231
+ }
232
+ export class FunctionDeclarator extends TreeNode {
233
+ ident: BaseToken;
234
+ returnType: FullySpecifiedType;
235
+ parameterInfoList: IParamInfo[] | undefined;
236
+ paramSig: GalaceanDataType[] | undefined;
237
+ semanticAnalyze(sa: SemanticAnalyzer): void;
238
+ }
239
+ export class FunctionHeader extends TreeNode {
240
+ ident: BaseToken;
241
+ returnType: FullySpecifiedType;
242
+ semanticAnalyze(sa: SemanticAnalyzer): void;
243
+ codeGen(visitor: ICodeGenVisitor): string;
244
+ }
245
+ export class FunctionParameterList extends TreeNode {
246
+ parameterInfoList: IParamInfo[];
247
+ paramSig: GalaceanDataType[];
248
+ init(): void;
249
+ semanticAnalyze(sa: SemanticAnalyzer): void;
250
+ codeGen(visitor: ICodeGenVisitor): string;
251
+ }
252
+ export class MacroParamCaseList extends TreeNode {
253
+ }
254
+ export class MacroParamBlock extends TreeNode {
255
+ }
256
+ export class MacroParameterBranch extends TreeNode {
257
+ }
258
+ export class ParameterDeclaration extends TreeNode {
259
+ typeInfo?: SymbolType;
260
+ ident?: BaseToken;
261
+ /** Exact variable symbol inserted for this parameter. @internal */
262
+ symbol?: VarSymbol;
263
+ init(): void;
264
+ semanticAnalyze(sa: SemanticAnalyzer): void;
265
+ }
266
+ export class ParameterDeclarator extends TreeNode {
267
+ ident: BaseToken;
268
+ typeInfo: SymbolType;
269
+ semanticAnalyze(sa: SemanticAnalyzer): void;
270
+ }
271
+ export class SimpleStatement extends TreeNode {
272
+ }
273
+ export class CompoundStatement extends TreeNode {
274
+ }
275
+ export class CompoundStatementNoScope extends TreeNode {
276
+ }
277
+ export class Statement extends TreeNode {
278
+ }
279
+ export class StatementList extends TreeNode {
280
+ codeGen(visitor: ICodeGenVisitor): string;
281
+ }
282
+ export class FunctionDefinition extends TreeNode {
283
+ protoType: FunctionProtoType;
284
+ statements: CompoundStatementNoScope;
285
+ isInMacroBranch: boolean;
286
+ semanticAnalyze(sa: SemanticAnalyzer): void;
287
+ codeGen(visitor: ICodeGenVisitor): string;
288
+ }
289
+ export class FunctionCall extends ExpressionAstNode {
290
+ semanticAnalyze(sa: SemanticAnalyzer): void;
291
+ codeGen(visitor: ICodeGenVisitor): string;
292
+ }
293
+ export class FunctionCallGeneric extends ExpressionAstNode {
294
+ fnSymbol: FnSymbol | StructSymbol | undefined;
295
+ /**
296
+ * Matching user-function declarations retained across macro alternatives. An empty list means
297
+ * `TypeAny` matched different overload signatures, so no concrete call edge is proven.
298
+ * @internal
299
+ */
300
+ fnSymbols: readonly FnSymbol[] | undefined;
301
+ init(): void;
302
+ semanticAnalyze(sa: SemanticAnalyzer): void;
303
+ private static _hasConflictingBranches;
304
+ private static _hasSameParameterSignature;
305
+ }
306
+ export class FunctionCallParameterList extends TreeNode {
307
+ paramSig: GalaceanDataType[];
308
+ paramNodes: Array<AssignmentExpression | MacroCallArgBlock>;
309
+ init(): void;
310
+ semanticAnalyze(sa: SemanticAnalyzer): void;
311
+ }
312
+ export class MacroCallArgCaseList extends TreeNode {
313
+ }
314
+ export class MacroCallArgBlock extends TreeNode {
315
+ }
316
+ export class MacroCallArgBranch extends TreeNode {
317
+ }
318
+ export class PrecisionSpecifier extends TreeNode {
319
+ semanticAnalyze(sa: SemanticAnalyzer): void;
320
+ }
321
+ export class FunctionIdentifier extends TreeNode {
322
+ ident: GalaceanDataType;
323
+ lexeme: string;
324
+ isBuiltin: boolean;
325
+ semanticAnalyze(sa: SemanticAnalyzer): void;
326
+ codeGen(visitor: ICodeGenVisitor): string;
327
+ }
328
+ export class AssignmentExpression extends ExpressionAstNode {
329
+ semanticAnalyze(sa: SemanticAnalyzer): void;
330
+ }
331
+ /** Assignment operator syntax retained for post-parse validation. @internal */
332
+ export class AssignmentOperator extends TreeNode {
333
+ }
334
+ export class Expression extends ExpressionAstNode {
335
+ semanticAnalyze(sa: SemanticAnalyzer): void;
336
+ }
337
+ export class PrimaryExpression extends ExpressionAstNode {
338
+ semanticAnalyze(sa: SemanticAnalyzer): void;
339
+ }
340
+ export class PostfixExpression extends ExpressionAstNode {
341
+ init(): void;
342
+ semanticAnalyze(sa: SemanticAnalyzer): void;
343
+ /** A `struct.field` access where the struct type is resolvable: the field must be a declared member. */
344
+ private static _checkStructField;
345
+ codeGen(visitor: ICodeGenVisitor): string;
346
+ }
347
+ export class UnaryOperator extends TreeNode {
348
+ }
349
+ export class UnaryExpression extends ExpressionAstNode {
350
+ init(): void;
351
+ }
352
+ export class MultiplicativeExpression extends ExpressionAstNode {
353
+ init(): void;
354
+ }
355
+ export class AdditiveExpression extends ExpressionAstNode {
356
+ init(): void;
357
+ }
358
+ export class ShiftExpression extends ExpressionAstNode {
359
+ semanticAnalyze(sa: SemanticAnalyzer): void;
360
+ }
361
+ export class RelationalExpression extends ExpressionAstNode {
362
+ semanticAnalyze(sa: SemanticAnalyzer): void;
363
+ }
364
+ export class EqualityExpression extends ExpressionAstNode {
365
+ semanticAnalyze(sa: SemanticAnalyzer): void;
366
+ }
367
+ export class AndExpression extends ExpressionAstNode {
368
+ semanticAnalyze(sa: SemanticAnalyzer): void;
369
+ }
370
+ export class ExclusiveOrExpression extends ExpressionAstNode {
371
+ semanticAnalyze(sa: SemanticAnalyzer): void;
372
+ }
373
+ export class InclusiveOrExpression extends ExpressionAstNode {
374
+ semanticAnalyze(sa: SemanticAnalyzer): void;
375
+ }
376
+ export class LogicalAndExpression extends ExpressionAstNode {
377
+ semanticAnalyze(sa: SemanticAnalyzer): void;
378
+ }
379
+ export class LogicalXorExpression extends ExpressionAstNode {
380
+ semanticAnalyze(sa: SemanticAnalyzer): void;
381
+ }
382
+ export class LogicalOrExpression extends ExpressionAstNode {
383
+ semanticAnalyze(sa: SemanticAnalyzer): void;
384
+ }
385
+ export class ConditionalExpression extends ExpressionAstNode {
386
+ semanticAnalyze(sa: SemanticAnalyzer): void;
387
+ }
388
+ export class StructSpecifier extends TreeNode {
389
+ ident?: BaseToken;
390
+ propList: StructProp[];
391
+ macroExpressions: MacroExpression[];
392
+ isInMacroBranch: boolean;
393
+ init(): void;
394
+ semanticAnalyze(sa: SemanticAnalyzer): void;
395
+ codeGen(visitor: ICodeGenVisitor): string;
396
+ }
397
+ export class StructDeclarationList extends TreeNode {
398
+ propList: StructProp[];
399
+ macroExpressions: MacroExpression[];
400
+ init(): void;
401
+ semanticAnalyze(sa: SemanticAnalyzer): void;
402
+ }
403
+ export class StructDeclaration extends TreeNode {
404
+ props: StructProp[];
405
+ macroExpressions: MacroExpression[];
406
+ private _typeSpecifier?;
407
+ private _declaratorList?;
408
+ init(): void;
409
+ semanticAnalyze(sa: SemanticAnalyzer): void;
410
+ }
411
+ export class MacroStructDeclaration extends TreeNode {
412
+ props: StructProp[];
413
+ macroExpressions: MacroExpression[];
414
+ init(): void;
415
+ semanticAnalyze(): void;
416
+ }
417
+ export class MacroStructBranch extends TreeNode {
418
+ props: StructProp[];
419
+ macroExpressions: MacroExpression[];
420
+ init(): void;
421
+ semanticAnalyze(): void;
422
+ }
423
+ export class LayoutQualifier extends TreeNode {
424
+ index: number;
425
+ semanticAnalyze(sa: SemanticAnalyzer): void;
426
+ }
427
+ export class StructDeclaratorList extends TreeNode {
428
+ declaratorList: StructDeclarator[];
429
+ init(): void;
430
+ semanticAnalyze(sa: SemanticAnalyzer): void;
431
+ }
432
+ export class StructDeclarator extends TreeNode {
433
+ ident: BaseToken;
434
+ arraySpecifier: ArraySpecifier | undefined;
435
+ init(): void;
436
+ semanticAnalyze(sa: SemanticAnalyzer): void;
437
+ }
438
+ export class VariableDeclaration extends TreeNode {
439
+ type: FullySpecifiedType;
440
+ isStatic: boolean;
441
+ /** Canonical information for this shader-global declarator. */
442
+ declarator: VariableDeclaratorInfo;
443
+ init(): void;
444
+ semanticAnalyze(sa: SemanticAnalyzer): void;
445
+ codeGen(visitor: ICodeGenVisitor): string;
446
+ }
447
+ export class VariableDeclarationList extends TreeNode {
448
+ type: FullySpecifiedType;
449
+ variableDeclarations: VariableDeclaration[];
450
+ init(): void;
451
+ semanticAnalyze(sa: SemanticAnalyzer): void;
452
+ }
453
+ export class VariableIdentifier extends TreeNode {
454
+ typeInfo: GalaceanDataType;
455
+ /** Backend-neutral meaning when this is a direct stage-IO builtin reference. */
456
+ builtinSemantic?: ShaderBuiltinSemantic;
457
+ /** Whether the resolved symbol is an array — `typeInfo` alone drops array-ness, but indexing rules need it. */
458
+ isArray: boolean;
459
+ /** A fixed array's element count, for constant index bounds-checking; `undefined` if unsized/unknown. */
460
+ arraySize?: number;
461
+ referenceGlobalSymbolNames: string[];
462
+ private _symbols;
463
+ private _valueSymbols?;
464
+ /**
465
+ * Returns the symbols retained when this reference was resolved.
466
+ * @returns Branch-visible variable or function candidates for the reference.
467
+ * @internal
468
+ */
469
+ resolvedSymbols(): readonly (VarSymbol | FnSymbol)[];
470
+ /**
471
+ * Returns symbols that represent this expression's value identity.
472
+ *
473
+ * AST-backed macros contribute a value symbol only when their replacement is mechanically a
474
+ * bare identifier, including formal-argument substitution and nested identity macros.
475
+ * @returns Exact symbols that own this expression's value.
476
+ * @internal
477
+ */
478
+ resolvedValueSymbols(): readonly (VarSymbol | FnSymbol)[];
479
+ init(): void;
480
+ semanticAnalyze(sa: SemanticAnalyzer): void;
481
+ private _semanticAnalyzeForCodegen;
482
+ private _resolveCodegenReference;
483
+ private _appendCodegenRuntimeFallbacks;
484
+ private _appendValueSymbols;
485
+ private _markCodegenReference;
486
+ private _setCodegenType;
487
+ /** Run the cross-arm shadowing probe for a MACRO_CALL site. No-op when the
488
+ * probe isn't meaningful: no macro name, name already resolved as a real
489
+ * reference, or name is a builtin (builtins can't be shadowed by a
490
+ * sibling-arm decl). */
491
+ private static _probeCrossArmShadowing;
492
+ /** Look up `name` in the symbol stack and, if a global var/fn declaration
493
+ * exists, push it into `referenceGlobalSymbolNames`. Returns `true` iff
494
+ * the lookup hit (caller can then derive type info). When `missErrorLoc`
495
+ * is non-null, a miss reports an "undeclared identifier" error; pass
496
+ * `null` for silent probes (e.g. FXAA-style cross-arm shadowing).
497
+ * `retainPartialBranchCandidates` is reserved for codegen-only probes: they retain every
498
+ * branch-local declaration even though none is guaranteed at the probe's synthetic call site.
499
+ *
500
+ * Mutation contract: `symbols` is used as scratch storage — `lookupAll`
501
+ * clears and refills it. On hit, the caller may read `symbols[0]` for
502
+ * type info before the next call overwrites the contents. */
503
+ private static _lookupAndMarkGlobalReference;
504
+ private _registerReferenceResolution;
505
+ private _registerUnresolvedReferenceResolution;
506
+ private static _hasConflictingGlobalBranches;
507
+ private static _containsGlobalSymbol;
508
+ codeGen(visitor: ICodeGenVisitor): string;
509
+ getLexeme(visitor: ICodeGenVisitor): string;
510
+ }
511
+ export class GLShaderProgram extends TreeNode {
512
+ shaderData: ShaderData;
513
+ semanticAnalyze(sa: SemanticAnalyzer): void;
514
+ }
515
+ export class GlobalDeclaration extends TreeNode {
516
+ macroExpressions: Array<MacroExpression | MacroUndef | BaseToken>;
517
+ init(): void;
518
+ semanticAnalyze(sa: SemanticAnalyzer): void;
519
+ }
520
+ export class MacroUndef extends TreeNode {
521
+ codeGen(visitor: ICodeGenVisitor): string;
522
+ }
523
+ export class MacroPushContext extends TreeNode {
524
+ semanticAnalyze(sa: SemanticAnalyzer): void;
525
+ codeGen(visitor: ICodeGenVisitor): string;
526
+ }
527
+ export class MacroPopContext extends TreeNode {
528
+ semanticAnalyze(sa: SemanticAnalyzer): void;
529
+ codeGen(visitor: ICodeGenVisitor): string;
530
+ }
531
+ export class MacroElifExpression extends TreeNode {
532
+ codeGen(visitor: ICodeGenVisitor): string;
533
+ }
534
+ export class MacroElseExpression extends TreeNode {
535
+ codeGen(visitor: ICodeGenVisitor): string;
536
+ }
537
+ export class GlobalMacroDeclaration extends TreeNode {
538
+ macroExpressions: MacroExpression[];
539
+ init(): void;
540
+ semanticAnalyze(sa: SemanticAnalyzer): void;
541
+ codeGen(visitor: ICodeGenVisitor): string;
542
+ }
543
+ export class GlobalMacroIfStatement extends TreeNode {
544
+ macroExpressions: MacroExpression[];
545
+ init(): void;
546
+ semanticAnalyze(sa: SemanticAnalyzer): void;
547
+ }
548
+ export class GlobalMacroBranch extends TreeNode {
549
+ macroExpressions: MacroExpression[];
550
+ init(): void;
551
+ semanticAnalyze(sa: SemanticAnalyzer): void;
552
+ }
553
+ export class MacroIfStatement extends TreeNode {
554
+ }
555
+ export class MacroBranch extends TreeNode {
556
+ }
557
+ export class MacroCallSymbol extends TreeNode {
558
+ /**
559
+ * Analyzer-requested syntax projection; absent from ordinary runtime parsing.
560
+ * @internal
561
+ */
562
+ expandedSyntax?: readonly MacroExpansionSyntax[];
563
+ referenceSymbolNames: string[];
564
+ referenceSymbols: MacroReference[];
565
+ macroName: string;
566
+ /** True iff every `MacroDefineInfo` visible from this call site's branch
567
+ * has a `valueAst` (i.e. was parsed via the `macro_define` CFG rule).
568
+ * Call sites use this to skip naive type inference: an AST-form macro
569
+ * drives the call site's type through its own value subtree, not through
570
+ * a root of `referenceSymbolNames`. Mixed forms across branches → false,
571
+ * fall back to legacy inference. */
572
+ hasAstValue: boolean;
573
+ /** Whether every branch-visible replacement has an expression AST. */
574
+ visibleHasAstValue: boolean;
575
+ /** `#define NAME(params) …` form — drives function-like vs object-like codegen. */
576
+ isFunctionLikeMacro: boolean;
577
+ /** Every visible replacement is a non-builtin identifier — assume user fn alias. */
578
+ aliasesNonBuiltinIdent: boolean;
579
+ init(): void;
580
+ semanticAnalyze(sa: SemanticAnalyzer): void;
581
+ private _analyzeForCodegen;
582
+ /** Collect replacement identifiers and member-owner occurrences at the call site. */
583
+ private static _collectIdentifierRefs;
584
+ }
585
+ export class MacroCallFunction extends TreeNode {
586
+ /**
587
+ * Analyzer-requested syntax projection; absent from ordinary runtime parsing.
588
+ * @internal
589
+ */
590
+ expandedSyntax?: readonly MacroExpansionSyntax[];
591
+ referenceSymbolNames: string[];
592
+ referenceSymbols: MacroReference[];
593
+ macroName: string;
594
+ hasAstValue: boolean;
595
+ visibleHasAstValue: boolean;
596
+ isFunctionLikeMacro: boolean;
597
+ aliasesNonBuiltinIdent: boolean;
598
+ init(): void;
599
+ semanticAnalyze(sa: SemanticAnalyzer): void;
600
+ codeGen(visitor: ICodeGenVisitor): string;
601
+ }
602
+ /**
603
+ * `#define NAME [(params)] [value]` — expression-style macro.
604
+ *
605
+ * Expression-form macros are parsed into AST rather than kept as raw lexemes. The
606
+ * optional `valueExpression` is an `AssignmentExpression` subtree that participates
607
+ * in normal codegen — so `v.v_normal.xyz` inside a `#define` flows through
608
+ * `visitPostfixExpression` just like an inline expression would, and varying
609
+ * flattening/type inference/reference tracking all come for free.
610
+ *
611
+ * Semantic analysis does not resolve symbols inside the value (the definition-site
612
+ * scope is not the call-site scope). Lookup happens lazily during codegen.
613
+ */
614
+ export class MacroDefine extends TreeNode {
615
+ macroName: string;
616
+ isFunction: boolean;
617
+ valueExpression?: Expression;
618
+ init(): void;
619
+ semanticAnalyze(sa: SemanticAnalyzer): void;
620
+ codeGen(visitor: ICodeGenVisitor): string;
621
+ }
622
+ export {};
623
+ }
624
+ export import ASTNode = ASTNodes;
625
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { SemanticDiagnostics } from "./SemanticDiagnostics";
2
+ /**
3
+ * Creates a request-owned semantic diagnostic mapper.
4
+ * @param source - Expanded pass source attached to parser diagnostics.
5
+ * @returns Analyzer semantic diagnostic policy for one parser session.
6
+ * @internal
7
+ */
8
+ export declare function createAnalyzerSemanticDiagnostics(source: string): SemanticDiagnostics;
9
+ /**
10
+ * Creates proven macro-declaration diagnostics that are safe to block offline generation.
11
+ * @param source - Expanded pass source attached to parser diagnostics.
12
+ * @returns Compiler semantic diagnostics for one parser session.
13
+ * @internal
14
+ */
15
+ export declare function createCompilerSemanticDiagnostics(source: string): SemanticDiagnostics;
@@ -0,0 +1,11 @@
1
+ import { NoneTerminal, GrammarSymbol } from "./GrammarSymbol";
2
+ import Production from "../lalr/Production";
3
+ export declare class Grammar {
4
+ readonly productions: Production[];
5
+ readonly startSymbol: NoneTerminal;
6
+ static create(start: NoneTerminal, productions: GrammarSymbol[][]): Grammar;
7
+ constructor(start: NoneTerminal, productions: Production[]);
8
+ getProductionList(nonTerminal: NoneTerminal): Production[];
9
+ isNullableNT(NT: NoneTerminal): Production;
10
+ getProductionByID(pid: number): Production;
11
+ }