@galacean/engine-shader-compiler 0.0.0-experimental-2.0-spine.0
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.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/bundler/cli.js +341 -0
- package/bundler/precompile.cjs.js +324 -0
- package/bundler/precompile.js +294 -0
- package/bundler/rollup.cjs.js +368 -0
- package/bundler/rollup.js +341 -0
- package/dist/browser.js +8938 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.min.js +2 -0
- package/dist/browser.min.js.map +1 -0
- package/dist/browser.verbose.js +9601 -0
- package/dist/browser.verbose.js.map +1 -0
- package/dist/browser.verbose.min.js +2 -0
- package/dist/browser.verbose.min.js.map +1 -0
- package/dist/main.js +8935 -0
- package/dist/main.js.map +1 -0
- package/dist/main.verbose.js +9598 -0
- package/dist/main.verbose.js.map +1 -0
- package/dist/module.js +8928 -0
- package/dist/module.js.map +1 -0
- package/dist/module.verbose.js +9591 -0
- package/dist/module.verbose.js.map +1 -0
- package/package.json +69 -0
- package/types/GSError.d.ts +16 -0
- package/types/ParserUtils.d.ts +39 -0
- package/types/Preprocessor.d.ts +30 -0
- package/types/ShaderCompiler.d.ts +21 -0
- package/types/ShaderCompilerUtils.d.ts +10 -0
- package/types/ShaderInstructionEncoder.d.ts +1 -0
- package/types/TempArray.d.ts +5 -0
- package/types/bundler/cli.d.ts +1 -0
- package/types/bundler/precompile.d.ts +25 -0
- package/types/bundler/rollup.d.ts +41 -0
- package/types/codeGen/CodeGenVisitor.d.ts +1 -0
- package/types/codeGen/GLES100.d.ts +12 -0
- package/types/codeGen/GLES300.d.ts +20 -0
- package/types/codeGen/GLESVisitor.d.ts +1 -0
- package/types/codeGen/VisitorContext.d.ts +2 -0
- package/types/codeGen/index.d.ts +3 -0
- package/types/codeGen/types.d.ts +12 -0
- package/types/common/BaseLexer.d.ts +2 -0
- package/types/common/BaseToken.d.ts +35 -0
- package/types/common/IBaseSymbol.d.ts +5 -0
- package/types/common/ShaderPosition.d.ts +8 -0
- package/types/common/ShaderRange.d.ts +8 -0
- package/types/common/SymbolTable.d.ts +9 -0
- package/types/common/SymbolTableStack.d.ts +13 -0
- package/types/common/enums/Keyword.d.ts +124 -0
- package/types/common/enums/ShaderStage.d.ts +5 -0
- package/types/common/index.d.ts +5 -0
- package/types/common/types.d.ts +101 -0
- package/types/index.d.ts +3 -0
- package/types/lalr/CFG.d.ts +5 -0
- package/types/lalr/LALR1.d.ts +27 -0
- package/types/lalr/Production.d.ts +9 -0
- package/types/lalr/State.d.ts +20 -0
- package/types/lalr/StateItem.d.ts +20 -0
- package/types/lalr/Utils.d.ts +22 -0
- package/types/lalr/index.d.ts +2 -0
- package/types/lalr/types.d.ts +14 -0
- package/types/lexer/Lexer.d.ts +143 -0
- package/types/lexer/index.d.ts +1 -0
- package/types/parser/AST.d.ts +502 -0
- package/types/parser/Grammar.d.ts +11 -0
- package/types/parser/GrammarSymbol.d.ts +128 -0
- package/types/parser/SemanticAnalyzer.d.ts +2 -0
- package/types/parser/ShaderInfo.d.ts +10 -0
- package/types/parser/ShaderTargetParser.d.ts +24 -0
- package/types/parser/builtin/functions.d.ts +34 -0
- package/types/parser/builtin/index.d.ts +2 -0
- package/types/parser/builtin/variables.d.ts +11 -0
- package/types/parser/index.d.ts +2 -0
- package/types/parser/symbolTable/FnSymbol.d.ts +6 -0
- package/types/parser/symbolTable/StructSymbol.d.ts +6 -0
- package/types/parser/symbolTable/SymbolDataType.d.ts +8 -0
- package/types/parser/symbolTable/SymbolInfo.d.ts +22 -0
- package/types/parser/symbolTable/VarSymbol.d.ts +8 -0
- package/types/parser/symbolTable/index.d.ts +6 -0
- package/types/parser/types.d.ts +24 -0
- package/types/sourceParser/ShaderSourceFactory.d.ts +8 -0
- package/types/sourceParser/ShaderSourceParser.d.ts +1 -0
- package/types/sourceParser/ShaderSourceSymbol.d.ts +10 -0
- package/types/sourceParser/SourceLexer.d.ts +19 -0
- package/types/sourceParser/index.d.ts +1 -0
- package/verbose/package.json +11 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { ClearableObjectPool, type IPoolElement } from "@galacean/engine-core";
|
|
2
|
+
import { CodeGenVisitor } from "../codeGen";
|
|
3
|
+
import { GalaceanDataType, ShaderRange, TokenType } from "../common";
|
|
4
|
+
import { BaseToken } from "../common/BaseToken";
|
|
5
|
+
import { Keyword } from "../common/enums/Keyword";
|
|
6
|
+
import { NoneTerminal } from "./GrammarSymbol";
|
|
7
|
+
import SemanticAnalyzer from "./SemanticAnalyzer";
|
|
8
|
+
import { ShaderData } from "./ShaderInfo";
|
|
9
|
+
import { FnSymbol, StructSymbol } from "./symbolTable";
|
|
10
|
+
import { IParamInfo, NodeChild, StructProp, SymbolType } from "./types";
|
|
11
|
+
export declare abstract class TreeNode implements IPoolElement {
|
|
12
|
+
static pool: ClearableObjectPool<TreeNode & {
|
|
13
|
+
set: (loc: ShaderRange, children: NodeChild[]) => void;
|
|
14
|
+
}>;
|
|
15
|
+
/** The non-terminal in grammar. */
|
|
16
|
+
nt: NoneTerminal;
|
|
17
|
+
private _children;
|
|
18
|
+
private _parent;
|
|
19
|
+
private _location;
|
|
20
|
+
private _codeCache;
|
|
21
|
+
/**
|
|
22
|
+
* Parent pointer for AST traversal.
|
|
23
|
+
* @remarks
|
|
24
|
+
* The parent pointer is only reliable after the entire AST has been constructed.
|
|
25
|
+
* DO NOT rely on `parent` during the `semanticAnalyze` phase, as the AST may still be under construction.
|
|
26
|
+
* It is safe to use `parent` during code generation or any phase after AST construction.
|
|
27
|
+
*/
|
|
28
|
+
get parent(): TreeNode;
|
|
29
|
+
get children(): NodeChild[];
|
|
30
|
+
get location(): ShaderRange;
|
|
31
|
+
set(loc: ShaderRange, children: NodeChild[]): void;
|
|
32
|
+
init(): void;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
setCache(code: string): string;
|
|
35
|
+
getCache(): string;
|
|
36
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
37
|
+
/**
|
|
38
|
+
* Do semantic analyze right after the ast node is generated.
|
|
39
|
+
*/
|
|
40
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
41
|
+
}
|
|
42
|
+
export declare namespace ASTNode {
|
|
43
|
+
type MacroExpression = MacroPushContext | MacroPopContext | MacroElseExpression | MacroElifExpression | MacroUndef | MacroDefine | BaseToken;
|
|
44
|
+
export type ASTNodePool = ClearableObjectPool<{
|
|
45
|
+
set: (loc: ShaderRange, children: NodeChild[]) => void;
|
|
46
|
+
} & IPoolElement & TreeNode>;
|
|
47
|
+
export function _unwrapToken(node: NodeChild): BaseToken<number>;
|
|
48
|
+
export function get(pool: ASTNodePool, sa: SemanticAnalyzer, loc: ShaderRange, children: NodeChild[]): void;
|
|
49
|
+
export class TrivialNode extends TreeNode {
|
|
50
|
+
}
|
|
51
|
+
export class ScopeBrace extends TreeNode {
|
|
52
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
53
|
+
}
|
|
54
|
+
export class ScopeEndBrace extends TreeNode {
|
|
55
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
56
|
+
}
|
|
57
|
+
export class JumpStatement extends TreeNode {
|
|
58
|
+
isFragReturnStatement: boolean;
|
|
59
|
+
init(): void;
|
|
60
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
61
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
62
|
+
}
|
|
63
|
+
export class ConditionOpt extends TreeNode {
|
|
64
|
+
}
|
|
65
|
+
export class ForRestStatement extends TreeNode {
|
|
66
|
+
}
|
|
67
|
+
export class Condition extends TreeNode {
|
|
68
|
+
}
|
|
69
|
+
export class ForInitStatement extends TreeNode {
|
|
70
|
+
}
|
|
71
|
+
export class IterationStatement extends TreeNode {
|
|
72
|
+
}
|
|
73
|
+
export class SelectionStatement extends TreeNode {
|
|
74
|
+
}
|
|
75
|
+
export class ExpressionStatement extends TreeNode {
|
|
76
|
+
}
|
|
77
|
+
export abstract class ExpressionAstNode extends TreeNode {
|
|
78
|
+
protected _type?: GalaceanDataType;
|
|
79
|
+
set type(t: GalaceanDataType | undefined);
|
|
80
|
+
get type(): GalaceanDataType | undefined;
|
|
81
|
+
init(): void;
|
|
82
|
+
}
|
|
83
|
+
export class InitializerList extends ExpressionAstNode {
|
|
84
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
85
|
+
}
|
|
86
|
+
export class Initializer extends ExpressionAstNode {
|
|
87
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
88
|
+
}
|
|
89
|
+
export class SingleDeclaration extends TreeNode {
|
|
90
|
+
typeSpecifier: TypeSpecifier;
|
|
91
|
+
arraySpecifier?: ArraySpecifier;
|
|
92
|
+
init(): void;
|
|
93
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
94
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
95
|
+
}
|
|
96
|
+
export class FullySpecifiedType extends TreeNode {
|
|
97
|
+
typeSpecifier: TypeSpecifier;
|
|
98
|
+
type: GalaceanDataType;
|
|
99
|
+
semanticAnalyze(_: SemanticAnalyzer): void;
|
|
100
|
+
}
|
|
101
|
+
export class TypeQualifier extends TreeNode {
|
|
102
|
+
}
|
|
103
|
+
export class SingleTypeQualifier extends TreeNode {
|
|
104
|
+
qualifier: Keyword;
|
|
105
|
+
lexeme: string;
|
|
106
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
107
|
+
}
|
|
108
|
+
abstract class BasicTypeQualifier extends TreeNode {
|
|
109
|
+
qualifier: Keyword;
|
|
110
|
+
lexeme: string;
|
|
111
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
112
|
+
}
|
|
113
|
+
export class StorageQualifier extends BasicTypeQualifier {
|
|
114
|
+
}
|
|
115
|
+
export class PrecisionQualifier extends BasicTypeQualifier {
|
|
116
|
+
}
|
|
117
|
+
export class InterpolationQualifier extends BasicTypeQualifier {
|
|
118
|
+
}
|
|
119
|
+
export class InvariantQualifier extends BasicTypeQualifier {
|
|
120
|
+
}
|
|
121
|
+
export class TypeSpecifier extends TreeNode {
|
|
122
|
+
type: GalaceanDataType;
|
|
123
|
+
lexeme: string;
|
|
124
|
+
arraySize?: number;
|
|
125
|
+
isCustom: boolean;
|
|
126
|
+
init(): void;
|
|
127
|
+
get arraySpecifier(): ArraySpecifier;
|
|
128
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
129
|
+
}
|
|
130
|
+
export class ArraySpecifier extends TreeNode {
|
|
131
|
+
size: number | undefined;
|
|
132
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
133
|
+
}
|
|
134
|
+
export class IntegerConstantExpressionOperator extends TreeNode {
|
|
135
|
+
compute: (a: number, b: number) => number;
|
|
136
|
+
lexeme: string;
|
|
137
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
138
|
+
}
|
|
139
|
+
export class IntegerConstantExpression extends TreeNode {
|
|
140
|
+
value?: number;
|
|
141
|
+
init(): void;
|
|
142
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
143
|
+
}
|
|
144
|
+
export class TypeSpecifierNonArray extends TreeNode {
|
|
145
|
+
type: GalaceanDataType;
|
|
146
|
+
lexeme: string;
|
|
147
|
+
init(): void;
|
|
148
|
+
}
|
|
149
|
+
export class ExtBuiltinTypeSpecifierNonArray extends TreeNode {
|
|
150
|
+
type: TokenType;
|
|
151
|
+
lexeme: string;
|
|
152
|
+
init(): void;
|
|
153
|
+
}
|
|
154
|
+
export class InitDeclaratorList extends TreeNode {
|
|
155
|
+
typeInfo: SymbolType;
|
|
156
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
157
|
+
}
|
|
158
|
+
export class IdentifierList extends TreeNode {
|
|
159
|
+
idList: BaseToken[];
|
|
160
|
+
init(): void;
|
|
161
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
162
|
+
}
|
|
163
|
+
export class Declaration extends TreeNode {
|
|
164
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
165
|
+
}
|
|
166
|
+
export class FunctionProtoType extends TreeNode {
|
|
167
|
+
ident: BaseToken;
|
|
168
|
+
returnType: FullySpecifiedType;
|
|
169
|
+
parameterList: IParamInfo[];
|
|
170
|
+
paramSig: GalaceanDataType[] | undefined;
|
|
171
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
172
|
+
}
|
|
173
|
+
export class FunctionDeclarator extends TreeNode {
|
|
174
|
+
ident: BaseToken;
|
|
175
|
+
returnType: FullySpecifiedType;
|
|
176
|
+
parameterInfoList: IParamInfo[] | undefined;
|
|
177
|
+
paramSig: GalaceanDataType[] | undefined;
|
|
178
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
179
|
+
}
|
|
180
|
+
export class FunctionHeader extends TreeNode {
|
|
181
|
+
ident: BaseToken;
|
|
182
|
+
returnType: FullySpecifiedType;
|
|
183
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
184
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
185
|
+
}
|
|
186
|
+
export class FunctionParameterList extends TreeNode {
|
|
187
|
+
parameterInfoList: IParamInfo[];
|
|
188
|
+
paramSig: GalaceanDataType[];
|
|
189
|
+
init(): void;
|
|
190
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
191
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
192
|
+
}
|
|
193
|
+
export class MacroParamCaseList extends TreeNode {
|
|
194
|
+
}
|
|
195
|
+
export class MacroParamBlock extends TreeNode {
|
|
196
|
+
}
|
|
197
|
+
export class MacroParameterBranch extends TreeNode {
|
|
198
|
+
}
|
|
199
|
+
export class ParameterDeclaration extends TreeNode {
|
|
200
|
+
typeInfo?: SymbolType;
|
|
201
|
+
ident?: BaseToken;
|
|
202
|
+
init(): void;
|
|
203
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
204
|
+
}
|
|
205
|
+
export class ParameterDeclarator extends TreeNode {
|
|
206
|
+
ident: BaseToken;
|
|
207
|
+
typeInfo: SymbolType;
|
|
208
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
209
|
+
}
|
|
210
|
+
export class SimpleStatement extends TreeNode {
|
|
211
|
+
}
|
|
212
|
+
export class CompoundStatement extends TreeNode {
|
|
213
|
+
}
|
|
214
|
+
export class CompoundStatementNoScope extends TreeNode {
|
|
215
|
+
}
|
|
216
|
+
export class Statement extends TreeNode {
|
|
217
|
+
}
|
|
218
|
+
export class StatementList extends TreeNode {
|
|
219
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
220
|
+
}
|
|
221
|
+
export class FunctionDefinition extends TreeNode {
|
|
222
|
+
returnStatement?: ASTNode.JumpStatement;
|
|
223
|
+
protoType: FunctionProtoType;
|
|
224
|
+
statements: CompoundStatementNoScope;
|
|
225
|
+
isInMacroBranch: boolean;
|
|
226
|
+
init(): void;
|
|
227
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
228
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
229
|
+
}
|
|
230
|
+
export class FunctionCall extends ExpressionAstNode {
|
|
231
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
232
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
233
|
+
}
|
|
234
|
+
export class FunctionCallGeneric extends ExpressionAstNode {
|
|
235
|
+
fnSymbol: FnSymbol | StructSymbol | undefined;
|
|
236
|
+
init(): void;
|
|
237
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
238
|
+
}
|
|
239
|
+
export class FunctionCallParameterList extends TreeNode {
|
|
240
|
+
paramSig: GalaceanDataType[];
|
|
241
|
+
paramNodes: Array<AssignmentExpression | MacroCallArgBlock>;
|
|
242
|
+
init(): void;
|
|
243
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
244
|
+
}
|
|
245
|
+
export class MacroCallArgCaseList extends TreeNode {
|
|
246
|
+
}
|
|
247
|
+
export class MacroCallArgBlock extends TreeNode {
|
|
248
|
+
}
|
|
249
|
+
export class MacroCallArgBranch extends TreeNode {
|
|
250
|
+
}
|
|
251
|
+
export class PrecisionSpecifier extends TreeNode {
|
|
252
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
253
|
+
}
|
|
254
|
+
export class FunctionIdentifier extends TreeNode {
|
|
255
|
+
ident: GalaceanDataType;
|
|
256
|
+
lexeme: string;
|
|
257
|
+
isBuiltin: boolean;
|
|
258
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
259
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
260
|
+
}
|
|
261
|
+
export class AssignmentExpression extends ExpressionAstNode {
|
|
262
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
263
|
+
}
|
|
264
|
+
export class AssignmentOperator extends TreeNode {
|
|
265
|
+
}
|
|
266
|
+
export class Expression extends ExpressionAstNode {
|
|
267
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
268
|
+
}
|
|
269
|
+
export class PrimaryExpression extends ExpressionAstNode {
|
|
270
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
271
|
+
}
|
|
272
|
+
export class PostfixExpression extends ExpressionAstNode {
|
|
273
|
+
init(): void;
|
|
274
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
275
|
+
}
|
|
276
|
+
export class UnaryOperator extends TreeNode {
|
|
277
|
+
}
|
|
278
|
+
export class UnaryExpression extends ExpressionAstNode {
|
|
279
|
+
init(): void;
|
|
280
|
+
}
|
|
281
|
+
export class MultiplicativeExpression extends ExpressionAstNode {
|
|
282
|
+
init(): void;
|
|
283
|
+
}
|
|
284
|
+
export class AdditiveExpression extends ExpressionAstNode {
|
|
285
|
+
init(): void;
|
|
286
|
+
}
|
|
287
|
+
export class ShiftExpression extends ExpressionAstNode {
|
|
288
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
289
|
+
}
|
|
290
|
+
export class RelationalExpression extends ExpressionAstNode {
|
|
291
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
292
|
+
}
|
|
293
|
+
export class EqualityExpression extends ExpressionAstNode {
|
|
294
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
295
|
+
}
|
|
296
|
+
export class AndExpression extends ExpressionAstNode {
|
|
297
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
298
|
+
}
|
|
299
|
+
export class ExclusiveOrExpression extends ExpressionAstNode {
|
|
300
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
301
|
+
}
|
|
302
|
+
export class InclusiveOrExpression extends ExpressionAstNode {
|
|
303
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
304
|
+
}
|
|
305
|
+
export class LogicalAndExpression extends ExpressionAstNode {
|
|
306
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
307
|
+
}
|
|
308
|
+
export class LogicalXorExpression extends ExpressionAstNode {
|
|
309
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
310
|
+
}
|
|
311
|
+
export class LogicalOrExpression extends ExpressionAstNode {
|
|
312
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
313
|
+
}
|
|
314
|
+
export class ConditionalExpression extends ExpressionAstNode {
|
|
315
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
316
|
+
}
|
|
317
|
+
export class StructSpecifier extends TreeNode {
|
|
318
|
+
ident?: BaseToken;
|
|
319
|
+
propList: StructProp[];
|
|
320
|
+
macroExpressions: MacroExpression[];
|
|
321
|
+
isInMacroBranch: boolean;
|
|
322
|
+
init(): void;
|
|
323
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
324
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
325
|
+
}
|
|
326
|
+
export class StructDeclarationList extends TreeNode {
|
|
327
|
+
propList: StructProp[];
|
|
328
|
+
macroExpressions: MacroExpression[];
|
|
329
|
+
init(): void;
|
|
330
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
331
|
+
}
|
|
332
|
+
export class StructDeclaration extends TreeNode {
|
|
333
|
+
props: StructProp[];
|
|
334
|
+
macroExpressions: MacroExpression[];
|
|
335
|
+
private _typeSpecifier?;
|
|
336
|
+
private _declaratorList?;
|
|
337
|
+
init(): void;
|
|
338
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
339
|
+
}
|
|
340
|
+
export class MacroStructDeclaration extends TreeNode {
|
|
341
|
+
props: StructProp[];
|
|
342
|
+
macroExpressions: MacroExpression[];
|
|
343
|
+
init(): void;
|
|
344
|
+
semanticAnalyze(): void;
|
|
345
|
+
}
|
|
346
|
+
export class MacroStructBranch extends TreeNode {
|
|
347
|
+
props: StructProp[];
|
|
348
|
+
macroExpressions: MacroExpression[];
|
|
349
|
+
init(): void;
|
|
350
|
+
semanticAnalyze(): void;
|
|
351
|
+
}
|
|
352
|
+
export class LayoutQualifier extends TreeNode {
|
|
353
|
+
index: number;
|
|
354
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
355
|
+
}
|
|
356
|
+
export class StructDeclaratorList extends TreeNode {
|
|
357
|
+
declaratorList: StructDeclarator[];
|
|
358
|
+
init(): void;
|
|
359
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
360
|
+
}
|
|
361
|
+
export class StructDeclarator extends TreeNode {
|
|
362
|
+
ident: BaseToken;
|
|
363
|
+
arraySpecifier: ArraySpecifier | undefined;
|
|
364
|
+
init(): void;
|
|
365
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
366
|
+
}
|
|
367
|
+
export class VariableDeclaration extends TreeNode {
|
|
368
|
+
type: FullySpecifiedType;
|
|
369
|
+
isStatic: boolean;
|
|
370
|
+
init(): void;
|
|
371
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
372
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
373
|
+
}
|
|
374
|
+
export class VariableDeclarationList extends TreeNode {
|
|
375
|
+
type: FullySpecifiedType;
|
|
376
|
+
variableDeclarations: VariableDeclaration[];
|
|
377
|
+
init(): void;
|
|
378
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
379
|
+
}
|
|
380
|
+
export class VariableIdentifier extends TreeNode {
|
|
381
|
+
typeInfo: GalaceanDataType;
|
|
382
|
+
referenceGlobalSymbolNames: string[];
|
|
383
|
+
private _symbols;
|
|
384
|
+
init(): void;
|
|
385
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
386
|
+
/** Run the cross-arm shadowing probe for a MACRO_CALL site. No-op when the
|
|
387
|
+
* probe isn't meaningful: no macro name, name already resolved as a real
|
|
388
|
+
* reference, or name is a builtin (builtins can't be shadowed by a
|
|
389
|
+
* sibling-arm decl). */
|
|
390
|
+
private static _probeCrossArmShadowing;
|
|
391
|
+
/** Look up `name` in the symbol stack and, if a global var/fn declaration
|
|
392
|
+
* exists, push it into `referenceGlobalSymbolNames`. Returns `true` iff
|
|
393
|
+
* the lookup hit (caller can then derive type info). When `missWarnLoc`
|
|
394
|
+
* is non-null, a miss reports a "declared before used" warning; pass
|
|
395
|
+
* `null` for silent probes (e.g. FXAA-style cross-arm shadowing).
|
|
396
|
+
*
|
|
397
|
+
* Mutation contract: `symbols` is used as scratch storage — `lookupAll`
|
|
398
|
+
* clears and refills it. On hit, the caller may read `symbols[0]` for
|
|
399
|
+
* type info before the next call overwrites the contents. */
|
|
400
|
+
private static _lookupAndMarkGlobalReference;
|
|
401
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
402
|
+
getLexeme(visitor: CodeGenVisitor): string;
|
|
403
|
+
}
|
|
404
|
+
export class GLShaderProgram extends TreeNode {
|
|
405
|
+
shaderData: ShaderData;
|
|
406
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
407
|
+
}
|
|
408
|
+
export class GlobalDeclaration extends TreeNode {
|
|
409
|
+
macroExpressions: Array<MacroExpression | MacroUndef | BaseToken>;
|
|
410
|
+
init(): void;
|
|
411
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
412
|
+
}
|
|
413
|
+
export class MacroUndef extends TreeNode {
|
|
414
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
415
|
+
}
|
|
416
|
+
export class MacroPushContext extends TreeNode {
|
|
417
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
418
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
419
|
+
}
|
|
420
|
+
export class MacroPopContext extends TreeNode {
|
|
421
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
422
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
423
|
+
}
|
|
424
|
+
export class MacroElifExpression extends TreeNode {
|
|
425
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
426
|
+
}
|
|
427
|
+
export class MacroElseExpression extends TreeNode {
|
|
428
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
429
|
+
}
|
|
430
|
+
export class GlobalMacroDeclaration extends TreeNode {
|
|
431
|
+
macroExpressions: MacroExpression[];
|
|
432
|
+
init(): void;
|
|
433
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
434
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
435
|
+
}
|
|
436
|
+
export class GlobalMacroIfStatement extends TreeNode {
|
|
437
|
+
macroExpressions: MacroExpression[];
|
|
438
|
+
init(): void;
|
|
439
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
440
|
+
}
|
|
441
|
+
export class GlobalMacroBranch extends TreeNode {
|
|
442
|
+
macroExpressions: MacroExpression[];
|
|
443
|
+
init(): void;
|
|
444
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
445
|
+
}
|
|
446
|
+
export class MacroIfStatement extends TreeNode {
|
|
447
|
+
}
|
|
448
|
+
export class MacroBranch extends TreeNode {
|
|
449
|
+
}
|
|
450
|
+
export class MacroCallSymbol extends TreeNode {
|
|
451
|
+
referenceSymbolNames: string[];
|
|
452
|
+
macroName: string;
|
|
453
|
+
/** True iff every `MacroDefineInfo` visible from this call site's branch
|
|
454
|
+
* has a `valueAst` (i.e. was parsed via the `macro_define` CFG rule).
|
|
455
|
+
* Call sites use this to skip naive type inference: an AST-form macro
|
|
456
|
+
* drives the call site's type through its own value subtree, not through
|
|
457
|
+
* a root of `referenceSymbolNames`. Mixed forms across branches → false,
|
|
458
|
+
* fall back to legacy inference. */
|
|
459
|
+
hasAstValue: boolean;
|
|
460
|
+
/** `#define NAME(params) …` form — drives function-like vs object-like codegen. */
|
|
461
|
+
isFunctionLikeMacro: boolean;
|
|
462
|
+
/** Every visible replacement is a non-builtin identifier — assume user fn alias. */
|
|
463
|
+
aliasesNonBuiltinIdent: boolean;
|
|
464
|
+
init(): void;
|
|
465
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
466
|
+
/** Push every leaf `VariableIdentifier`'s lexeme into `out`, skipping
|
|
467
|
+
* function-like parameter names (local to the macro, not call-site refs)
|
|
468
|
+
* and duplicates. */
|
|
469
|
+
private static _collectIdentifierRefs;
|
|
470
|
+
}
|
|
471
|
+
export class MacroCallFunction extends TreeNode {
|
|
472
|
+
referenceSymbolNames: string[];
|
|
473
|
+
macroName: string;
|
|
474
|
+
hasAstValue: boolean;
|
|
475
|
+
isFunctionLikeMacro: boolean;
|
|
476
|
+
aliasesNonBuiltinIdent: boolean;
|
|
477
|
+
init(): void;
|
|
478
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
479
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* `#define NAME [(params)] [value]` — expression-style macro.
|
|
483
|
+
*
|
|
484
|
+
* Expression-form macros are parsed into AST rather than kept as raw lexemes. The
|
|
485
|
+
* optional `valueExpression` is an `AssignmentExpression` subtree that participates
|
|
486
|
+
* in normal codegen — so `v.v_normal.xyz` inside a `#define` flows through
|
|
487
|
+
* `visitPostfixExpression` just like an inline expression would, and varying
|
|
488
|
+
* flattening/type inference/reference tracking all come for free.
|
|
489
|
+
*
|
|
490
|
+
* Semantic analysis does not resolve symbols inside the value (the definition-site
|
|
491
|
+
* scope is not the call-site scope). Lookup happens lazily during codegen.
|
|
492
|
+
*/
|
|
493
|
+
export class MacroDefine extends TreeNode {
|
|
494
|
+
macroName: string;
|
|
495
|
+
isFunction: boolean;
|
|
496
|
+
valueExpression?: Expression;
|
|
497
|
+
init(): void;
|
|
498
|
+
semanticAnalyze(sa: SemanticAnalyzer): void;
|
|
499
|
+
codeGen(visitor: CodeGenVisitor): string;
|
|
500
|
+
}
|
|
501
|
+
export {};
|
|
502
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { TokenType } from "../common";
|
|
2
|
+
export type Terminal = TokenType;
|
|
3
|
+
export declare enum NoneTerminal {
|
|
4
|
+
START = 2000,
|
|
5
|
+
gs_shader_program = 2001,
|
|
6
|
+
global_declaration = 2002,
|
|
7
|
+
variable_declaration = 2003,
|
|
8
|
+
variable_declaration_list = 2004,
|
|
9
|
+
variable_declaration_statement = 2005,
|
|
10
|
+
array_specifier_list = 2006,
|
|
11
|
+
array_specifier = 2007,
|
|
12
|
+
ext_builtin_type_specifier_nonarray = 2008,
|
|
13
|
+
precision_specifier = 2009,
|
|
14
|
+
variable_identifier = 2010,
|
|
15
|
+
variable_identifier_node = 2011,
|
|
16
|
+
primary_expression = 2012,
|
|
17
|
+
postfix_expression = 2013,
|
|
18
|
+
integer_expression = 2014,
|
|
19
|
+
function_call = 2015,
|
|
20
|
+
function_call_generic = 2016,
|
|
21
|
+
function_call_header_no_parameters = 2017,
|
|
22
|
+
function_call_header_with_parameters = 2018,
|
|
23
|
+
function_call_parameter_list = 2019,
|
|
24
|
+
function_call_header = 2020,
|
|
25
|
+
function_identifier = 2021,
|
|
26
|
+
constructor_identifier = 2022,
|
|
27
|
+
unary_expression = 2023,
|
|
28
|
+
unary_operator = 2024,
|
|
29
|
+
multiplicative_expression = 2025,
|
|
30
|
+
additive_expression = 2026,
|
|
31
|
+
shift_expression = 2027,
|
|
32
|
+
relational_expression = 2028,
|
|
33
|
+
equality_expression = 2029,
|
|
34
|
+
and_expression = 2030,
|
|
35
|
+
inclusive_or_expression = 2031,
|
|
36
|
+
exclusive_or_expression = 2032,
|
|
37
|
+
logical_and_expression = 2033,
|
|
38
|
+
logical_xor_expression = 2034,
|
|
39
|
+
logical_or_expression = 2035,
|
|
40
|
+
conditional_expression = 2036,
|
|
41
|
+
assignment_expression = 2037,
|
|
42
|
+
assignment_operator = 2038,
|
|
43
|
+
expression = 2039,
|
|
44
|
+
integer_constant_expression = 2040,
|
|
45
|
+
integer_constant_expression_operator = 2041,
|
|
46
|
+
declaration = 2042,
|
|
47
|
+
function_prototype = 2043,
|
|
48
|
+
function_declarator = 2044,
|
|
49
|
+
function_header_with_parameters = 2045,
|
|
50
|
+
function_header = 2046,
|
|
51
|
+
function_parameter_list = 2047,
|
|
52
|
+
parameter_declarator = 2048,
|
|
53
|
+
parameter_declaration = 2049,
|
|
54
|
+
parameter_qualifier = 2050,
|
|
55
|
+
parameter_type_specifier = 2051,
|
|
56
|
+
init_declarator_list = 2052,
|
|
57
|
+
single_declaration = 2053,
|
|
58
|
+
fully_specified_type = 2054,
|
|
59
|
+
type_qualifier = 2055,
|
|
60
|
+
single_type_qualifier = 2056,
|
|
61
|
+
storage_qualifier = 2057,
|
|
62
|
+
precision_qualifier = 2058,
|
|
63
|
+
interpolation_qualifier = 2059,
|
|
64
|
+
invariant_qualifier = 2060,
|
|
65
|
+
type_specifier = 2061,
|
|
66
|
+
type_specifier_nonarray = 2062,
|
|
67
|
+
type_specifier_no_prec = 2063,
|
|
68
|
+
basic_type = 2064,
|
|
69
|
+
struct_specifier = 2065,
|
|
70
|
+
struct_declaration_list = 2066,
|
|
71
|
+
struct_declaration = 2067,
|
|
72
|
+
layout_qualifier = 2068,
|
|
73
|
+
struct_declarator_list = 2069,
|
|
74
|
+
struct_declarator = 2070,
|
|
75
|
+
identifier_list = 2071,
|
|
76
|
+
decl_identifier = 2072,
|
|
77
|
+
initializer = 2073,
|
|
78
|
+
initializer_list = 2074,
|
|
79
|
+
declaration_statement = 2075,
|
|
80
|
+
simple_statement = 2076,
|
|
81
|
+
compound_statement_no_scope = 2077,
|
|
82
|
+
statement_with_scope = 2078,
|
|
83
|
+
compound_statement = 2079,
|
|
84
|
+
statement = 2080,
|
|
85
|
+
statement_list = 2081,
|
|
86
|
+
iteration_statement_no_new_scope = 2082,
|
|
87
|
+
expression_statement = 2083,
|
|
88
|
+
selection_statement = 2084,
|
|
89
|
+
selection_rest_statement = 2085,
|
|
90
|
+
condition = 2086,
|
|
91
|
+
conditionopt = 2087,
|
|
92
|
+
iteration_statement = 2088,
|
|
93
|
+
for_init_statement = 2089,
|
|
94
|
+
for_rest_statement = 2090,
|
|
95
|
+
jump_statement = 2091,
|
|
96
|
+
external_declaration = 2092,
|
|
97
|
+
function_definition = 2093,
|
|
98
|
+
field_selection = 2094,
|
|
99
|
+
bool_constant = 2095,
|
|
100
|
+
function_identifier_node = 2096,
|
|
101
|
+
typename_identifier_node = 2097,
|
|
102
|
+
scope_brace = 2098,
|
|
103
|
+
scope_end_brace = 2099,
|
|
104
|
+
macro_undef = 2100,
|
|
105
|
+
macro_push_context = 2101,
|
|
106
|
+
macro_pop_context = 2102,
|
|
107
|
+
macro_elif_expression = 2103,
|
|
108
|
+
macro_else_expression = 2104,
|
|
109
|
+
global_macro_if_statement = 2105,
|
|
110
|
+
global_macro_declaration = 2106,
|
|
111
|
+
global_macro_branch = 2107,
|
|
112
|
+
macro_struct_declaration = 2108,
|
|
113
|
+
macro_struct_branch = 2109,
|
|
114
|
+
macro_if_statement = 2110,
|
|
115
|
+
macro_branch = 2111,
|
|
116
|
+
macro_param_case_list = 2112,
|
|
117
|
+
macro_param_block = 2113,
|
|
118
|
+
macro_parameter_branch = 2114,
|
|
119
|
+
macro_call_arg_case_list = 2115,
|
|
120
|
+
macro_call_arg_block = 2116,
|
|
121
|
+
macro_call_arg_branch = 2117,
|
|
122
|
+
macro_call_symbol = 2118,
|
|
123
|
+
macro_call_function = 2119,
|
|
124
|
+
macro_define = 2120,
|
|
125
|
+
_ignore = 2121
|
|
126
|
+
}
|
|
127
|
+
export type GrammarSymbol = Terminal | NoneTerminal;
|
|
128
|
+
export type Derivation = GrammarSymbol[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SymbolInfo, SymbolTable } from "../parser/symbolTable";
|
|
2
|
+
import { ASTNode } from "./AST";
|
|
3
|
+
export declare class ShaderData {
|
|
4
|
+
symbolTable: SymbolTable<SymbolInfo>;
|
|
5
|
+
vertexMain: ASTNode.FunctionDefinition;
|
|
6
|
+
fragmentMain: ASTNode.FunctionDefinition;
|
|
7
|
+
globalPrecisions: ASTNode.PrecisionSpecifier[];
|
|
8
|
+
globalMacroDeclarations: ASTNode.GlobalDeclaration[];
|
|
9
|
+
getOuterGlobalMacroDeclarations(): ASTNode.GlobalDeclaration[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseToken } from "../common/BaseToken";
|
|
2
|
+
import { StateActionTable, StateGotoTable } from "../lalr/types";
|
|
3
|
+
import { MacroDefineList } from "../Preprocessor";
|
|
4
|
+
import { ASTNode } from "./AST";
|
|
5
|
+
import { Grammar } from "./Grammar";
|
|
6
|
+
import SematicAnalyzer from "./SemanticAnalyzer";
|
|
7
|
+
/**
|
|
8
|
+
* The syntax parser and sematic analyzer of `ShaderCompiler` compiler
|
|
9
|
+
*/
|
|
10
|
+
export declare class ShaderTargetParser {
|
|
11
|
+
readonly actionTable: StateActionTable;
|
|
12
|
+
readonly gotoTable: StateGotoTable;
|
|
13
|
+
readonly grammar: Grammar;
|
|
14
|
+
readonly sematicAnalyzer: SematicAnalyzer;
|
|
15
|
+
private _traceBackStack;
|
|
16
|
+
private get curState();
|
|
17
|
+
private get stateActionTable();
|
|
18
|
+
private get stateGotoTable();
|
|
19
|
+
static _singleton: ShaderTargetParser;
|
|
20
|
+
static create(): ShaderTargetParser;
|
|
21
|
+
private constructor();
|
|
22
|
+
parse(tokens: Generator<BaseToken, BaseToken>, macroDefineList: MacroDefineList): ASTNode.GLShaderProgram | null;
|
|
23
|
+
private _printStack;
|
|
24
|
+
}
|