@galacean/engine-shader-compiler 2.0.0-alpha.31

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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -0
  3. package/dist/browser.js +8720 -0
  4. package/dist/browser.js.map +1 -0
  5. package/dist/browser.min.js +2 -0
  6. package/dist/browser.min.js.map +1 -0
  7. package/dist/browser.verbose.js +9385 -0
  8. package/dist/browser.verbose.js.map +1 -0
  9. package/dist/browser.verbose.min.js +2 -0
  10. package/dist/browser.verbose.min.js.map +1 -0
  11. package/dist/bundler/cli.js +339 -0
  12. package/dist/bundler/rollup.cjs.js +366 -0
  13. package/dist/bundler/rollup.js +339 -0
  14. package/dist/main.js +8717 -0
  15. package/dist/main.js.map +1 -0
  16. package/dist/main.verbose.js +9382 -0
  17. package/dist/main.verbose.js.map +1 -0
  18. package/dist/module.js +8710 -0
  19. package/dist/module.js.map +1 -0
  20. package/dist/module.verbose.js +9375 -0
  21. package/dist/module.verbose.js.map +1 -0
  22. package/package.json +63 -0
  23. package/types/GSError.d.ts +16 -0
  24. package/types/ParserUtils.d.ts +26 -0
  25. package/types/Preprocessor.d.ts +33 -0
  26. package/types/ShaderCompiler.d.ts +21 -0
  27. package/types/ShaderCompilerUtils.d.ts +10 -0
  28. package/types/ShaderInstructionEncoder.d.ts +1 -0
  29. package/types/TempArray.d.ts +5 -0
  30. package/types/bundler/cli.d.ts +1 -0
  31. package/types/bundler/precompile.d.ts +25 -0
  32. package/types/bundler/rollup.d.ts +41 -0
  33. package/types/codeGen/CodeGenVisitor.d.ts +1 -0
  34. package/types/codeGen/GLES100.d.ts +12 -0
  35. package/types/codeGen/GLES300.d.ts +20 -0
  36. package/types/codeGen/GLESVisitor.d.ts +1 -0
  37. package/types/codeGen/VisitorContext.d.ts +2 -0
  38. package/types/codeGen/index.d.ts +3 -0
  39. package/types/codeGen/types.d.ts +12 -0
  40. package/types/common/BaseLexer.d.ts +2 -0
  41. package/types/common/BaseToken.d.ts +35 -0
  42. package/types/common/IBaseSymbol.d.ts +5 -0
  43. package/types/common/ShaderPosition.d.ts +8 -0
  44. package/types/common/ShaderRange.d.ts +8 -0
  45. package/types/common/SymbolTable.d.ts +9 -0
  46. package/types/common/SymbolTableStack.d.ts +13 -0
  47. package/types/common/enums/Keyword.d.ts +124 -0
  48. package/types/common/enums/ShaderStage.d.ts +5 -0
  49. package/types/common/index.d.ts +5 -0
  50. package/types/common/types.d.ts +101 -0
  51. package/types/index.d.ts +3 -0
  52. package/types/lalr/CFG.d.ts +5 -0
  53. package/types/lalr/LALR1.d.ts +26 -0
  54. package/types/lalr/Production.d.ts +9 -0
  55. package/types/lalr/State.d.ts +20 -0
  56. package/types/lalr/StateItem.d.ts +20 -0
  57. package/types/lalr/Utils.d.ts +22 -0
  58. package/types/lalr/index.d.ts +2 -0
  59. package/types/lalr/types.d.ts +14 -0
  60. package/types/lexer/Lexer.d.ts +111 -0
  61. package/types/lexer/index.d.ts +1 -0
  62. package/types/parser/AST.d.ts +482 -0
  63. package/types/parser/Grammar.d.ts +11 -0
  64. package/types/parser/GrammarSymbol.d.ts +128 -0
  65. package/types/parser/SemanticAnalyzer.d.ts +2 -0
  66. package/types/parser/ShaderInfo.d.ts +10 -0
  67. package/types/parser/ShaderTargetParser.d.ts +24 -0
  68. package/types/parser/builtin/functions.d.ts +34 -0
  69. package/types/parser/builtin/index.d.ts +2 -0
  70. package/types/parser/builtin/variables.d.ts +11 -0
  71. package/types/parser/index.d.ts +2 -0
  72. package/types/parser/symbolTable/FnSymbol.d.ts +6 -0
  73. package/types/parser/symbolTable/StructSymbol.d.ts +6 -0
  74. package/types/parser/symbolTable/SymbolDataType.d.ts +8 -0
  75. package/types/parser/symbolTable/SymbolInfo.d.ts +22 -0
  76. package/types/parser/symbolTable/VarSymbol.d.ts +8 -0
  77. package/types/parser/symbolTable/index.d.ts +6 -0
  78. package/types/parser/types.d.ts +24 -0
  79. package/types/sourceParser/ShaderSourceFactory.d.ts +8 -0
  80. package/types/sourceParser/ShaderSourceParser.d.ts +1 -0
  81. package/types/sourceParser/ShaderSourceSymbol.d.ts +10 -0
  82. package/types/sourceParser/SourceLexer.d.ts +19 -0
  83. package/types/sourceParser/index.d.ts +1 -0
  84. package/verbose/package.json +11 -0
@@ -0,0 +1,26 @@
1
+ import { Grammar } from "../parser/Grammar";
2
+ import { NoneTerminal, Terminal } from "../parser/GrammarSymbol";
3
+ import { StateActionTable, StateGotoTable } from "./types";
4
+ /**
5
+ * The [LALR1](https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/handouts/140%20LALR%20Parsing.pdf) Parser generator
6
+ */
7
+ export declare class LALR1 {
8
+ readonly firstSetMap: Map<NoneTerminal, Set<Terminal>>;
9
+ readonly followSetMap: Map<NoneTerminal, Set<Terminal>>;
10
+ readonly actionTable: StateActionTable;
11
+ readonly gotoTable: StateGotoTable;
12
+ private grammar;
13
+ /** For circle detect */
14
+ private _firstSetNTStack;
15
+ constructor(grammar: Grammar);
16
+ generate(): void;
17
+ private buildStateTable;
18
+ private _extendState;
19
+ private _closure;
20
+ private _extendStateItem;
21
+ private _inferNextState;
22
+ /** Resolve shift-reduce/reduce-reduce conflict detect */
23
+ private _addAction;
24
+ private computeFirstSet;
25
+ private _computeFirstSetForNT;
26
+ }
@@ -0,0 +1,9 @@
1
+ import { NoneTerminal, GrammarSymbol } from "../parser/GrammarSymbol";
2
+ export default class Production {
3
+ private static _id;
4
+ static pool: Map<number, Production>;
5
+ readonly goal: NoneTerminal;
6
+ readonly derivation: GrammarSymbol[];
7
+ readonly id: number;
8
+ constructor(goal: NoneTerminal, derivation: GrammarSymbol[]);
9
+ }
@@ -0,0 +1,20 @@
1
+ import { Terminal } from "../parser/GrammarSymbol";
2
+ import Production from "./Production";
3
+ import StateItem from "./StateItem";
4
+ export default class State {
5
+ static closureMap: Map<string /** state mapKey */, State>;
6
+ static pool: Map<number, State>;
7
+ static _id: number;
8
+ readonly id: number;
9
+ readonly cores: Set<StateItem>;
10
+ private _items;
11
+ get items(): Set<StateItem>;
12
+ closured: boolean;
13
+ get needReInfer(): boolean;
14
+ private _stateItemPool;
15
+ static create(cores: StateItem[]): State;
16
+ static getMapKey(cores: StateItem[]): string;
17
+ private constructor();
18
+ getStateItemMapKey(production: Production, position: number): string;
19
+ createStateItem(production: Production, position: number, lookaheadSet?: Iterable<Terminal>): StateItem;
20
+ }
@@ -0,0 +1,20 @@
1
+ import { Terminal } from "../parser/GrammarSymbol";
2
+ import Production from "./Production";
3
+ export default class StateItem {
4
+ static _id: number;
5
+ readonly production: Production;
6
+ readonly position: number;
7
+ readonly lookaheadSet: Set<Terminal>;
8
+ readonly id: number;
9
+ _needReInfer: boolean;
10
+ get needReInfer(): boolean;
11
+ set needReInfer(v: boolean);
12
+ get curSymbol(): import("../parser/GrammarSymbol").GrammarSymbol;
13
+ get nextSymbol(): import("../parser/GrammarSymbol").GrammarSymbol;
14
+ constructor(production: Production, position: number, lookahead: Iterable<Terminal>);
15
+ addLookahead(ts: Iterable<Terminal>): void;
16
+ symbolByOffset(offset: number): import("../parser/GrammarSymbol").GrammarSymbol;
17
+ canReduce(): boolean;
18
+ advance(): StateItem;
19
+ toString(): string;
20
+ }
@@ -0,0 +1,22 @@
1
+ import { ShaderRange } from "../common";
2
+ import { TreeNode } from "../parser/AST";
3
+ import { TranslationRule } from "../parser/SemanticAnalyzer";
4
+ import { NoneTerminal, GrammarSymbol } from "../parser/GrammarSymbol";
5
+ import Production from "./Production";
6
+ import { ActionInfo } from "./types";
7
+ import { ClearableObjectPool, type IPoolElement } from "@galacean/engine-core";
8
+ import { NodeChild } from "../parser/types";
9
+ export default class GrammarUtils {
10
+ static isTerminal(sm: GrammarSymbol): boolean;
11
+ static toString(sm: GrammarSymbol): string;
12
+ static createProductionWithOptions(goal: NoneTerminal, options: GrammarSymbol[][],
13
+ /** the ast node */
14
+ astTypePool?: ClearableObjectPool<{
15
+ set: (loc: ShaderRange, children: NodeChild[]) => void;
16
+ } & IPoolElement & TreeNode>): [GrammarSymbol[], TranslationRule][];
17
+ static addMapSetItem<K, T>(map: Map<K, Set<T>>, k: K, v: T): void;
18
+ static isSubSet<T>(sa: Set<T>, sb: Set<T>): boolean;
19
+ static isActionEqual(a: ActionInfo, b: ActionInfo): boolean;
20
+ static printAction(actionInfo: ActionInfo): string;
21
+ static printProduction(production: Production): string;
22
+ }
@@ -0,0 +1,2 @@
1
+ export { LALR1 } from "./LALR1";
2
+ export * from "./CFG";
@@ -0,0 +1,14 @@
1
+ import { NoneTerminal, Terminal } from "../parser/GrammarSymbol";
2
+ export type StateActionTable = Map<number /** state ID */, ActionTable>;
3
+ export type ActionTable = Map<Terminal, ActionInfo>;
4
+ export type StateGotoTable = Map<number /** state ID */, GotoTable>;
5
+ export type GotoTable = Map<NoneTerminal, number /** state ID */>;
6
+ export declare enum EAction {
7
+ Shift = 0,
8
+ Reduce = 1,
9
+ Accept = 2
10
+ }
11
+ export interface ActionInfo {
12
+ action: EAction;
13
+ target?: number;
14
+ }
@@ -0,0 +1,111 @@
1
+ import { BaseLexer } from "../common/BaseLexer";
2
+ import { BaseToken, BranchSignature } from "../common/BaseToken";
3
+ import { MacroDefineList } from "../Preprocessor";
4
+ /**
5
+ * The Lexer of Shader Compiler
6
+ */
7
+ export declare class Lexer extends BaseLexer {
8
+ macroDefineList: MacroDefineList;
9
+ private static _lexemeTable;
10
+ private static readonly _defineDirectiveReg;
11
+ private static readonly _referenceReg;
12
+ private static readonly _lineContinuationReg;
13
+ private static _ifCounter;
14
+ /** Two branch signatures are equal iff they have the same constraints in the
15
+ * same order with the same polarity. Used by `#define` dedup and AST upgrade
16
+ * matching. */
17
+ static sameBranch(a: BranchSignature, b: BranchSignature): boolean;
18
+ /**
19
+ * Returns true if a `#define` registered under `defBranch` is reachable from
20
+ * a call site under `callSiteBranch`. Two signatures are mutually exclusive
21
+ * iff some flag appears in both with opposite `defined` polarity. Anything
22
+ * else is compatible — the same flag with the same polarity, or flags that
23
+ * simply don't intersect.
24
+ *
25
+ * Conservative for `#if expr` (not modeled — `tokenize` pushes a sentinel
26
+ * with `name === ""` to keep the `#endif` stack depth correct; that
27
+ * sentinel never matches a real flag in the polarity check below, so it
28
+ * stays visible from everywhere). Exact for the common `#ifdef` /
29
+ * `#ifndef` / `#else` cases that drive real shader code.
30
+ */
31
+ static isVisibleFrom(defBranch: BranchSignature, callSiteBranch: BranchSignature): boolean;
32
+ private _needScanMacroConditionExpression;
33
+ private _inMacroDefineValue;
34
+ private _macroDefineExpectsNameToken;
35
+ private _macroDefineExpectsParamsToken;
36
+ private _macroDefineDirectiveStart;
37
+ private _branchStack;
38
+ private _pendingBranchPushDefined;
39
+ tokenize(): Generator<BaseToken<number>, BaseToken<number>, unknown>;
40
+ constructor(source: string, macroDefineList: MacroDefineList);
41
+ scanToken(): BaseToken;
42
+ private _scanStringConst;
43
+ private _scanNumAfterDot;
44
+ private _scanUtilBreakLine;
45
+ private _scanDirectives;
46
+ /** True if the current char is an unescaped line break (ignoring `\` continuation). */
47
+ private _isAtLineBreak;
48
+ /**
49
+ * Peek forward from `#define` and decide whether this directive should use the
50
+ * expression-AST path or the legacy opaque path.
51
+ *
52
+ * The AST path's only purpose is to enable the shader compiler's structural rewrites
53
+ * (varying flatten, struct-property reference tracking) on macro values that
54
+ * mention struct members. Every other shape — bare identifiers, numeric
55
+ * literals, type-alias keywords (`#define FxaaFloat2 vec2`), constructor
56
+ * calls, qualifier fragments, `#define COMMA ,` etc. — is correctly handled
57
+ * by the GLSL driver via textual substitution and needs no AST.
58
+ *
59
+ * So the routing rule is positive and information-driven: **AST iff the
60
+ * replacement list contains a `.` member-access operator**. This is robust
61
+ * against new GLSL keywords / extensions and incidentally moves all simple
62
+ * constants and type aliases off the 18-layer expression precedence chain.
63
+ */
64
+ private _defineHasValue;
65
+ /**
66
+ * If `i` points at a `\` immediately followed by a newline (`\n`, `\r`, or
67
+ * `\r\n`), return the index just past the pair (a single atom in the C/GLSL
68
+ * preprocessor view). Otherwise return `i` unchanged. This is the single
69
+ * source of truth for line-continuation detection — callers along the
70
+ * directive-scanning path (`_skipNonSemantic`, `_scanUtilBreakLine`,
71
+ * `_scanMacroDefineParams`) all delegate here so the rule stays in one
72
+ * place. The string-level `_lineContinuationReg` covers the regex path
73
+ * used by `_registerMacroDefine` for one-shot folding.
74
+ */
75
+ private static _skipLineContinuation;
76
+ /**
77
+ * Pure positional version of "skip non-semantic characters within a single
78
+ * `#define` directive": spaces, tabs, `\` + newline line-continuation, block
79
+ * comments, line comments. A real `\n` (without preceding `\`) is *not*
80
+ * consumed — it terminates the directive — so callers can detect
81
+ * end-of-directive after this returns. Shared by `_defineHasValue` (peek
82
+ * path) and `_skipInlineSpaceAndComments` (consuming path) so both honor
83
+ * the same lexical view.
84
+ */
85
+ private static _skipNonSemantic;
86
+ /** Consuming wrapper around `_skipNonSemantic` operating on the lexer's
87
+ * current position. Used by the `#define`-value scan state machine. Goes
88
+ * through `advance(diff)` so verbose builds keep their line/column counters
89
+ * in sync (advance walks the consumed slice and bumps `_line` on `\n`). */
90
+ private _skipInlineSpaceAndComments;
91
+ /**
92
+ * Capture a `(param1, param2, …)` block immediately after the macro name in a
93
+ * `#define` directive, producing a single `MACRO_DEFINE_PARAMS` token whose lexeme
94
+ * is the complete `(…)` text (including parens). Balanced parentheses are honored
95
+ * so the scanner doesn't terminate early on inner `()`. Newlines inside the
96
+ * parameter list are tolerated (rare; appears when the directive uses `\` line
97
+ * continuation), but any newline raises no special error here — it simply stops
98
+ * capture and parser handles the resulting token however it can.
99
+ */
100
+ private _scanMacroDefineParams;
101
+ /** Emit `MACRO_DEFINE_END` at the end of a `#define` value, consuming the newline. */
102
+ private _emitMacroDefineEnd;
103
+ private _registerMacroDefine;
104
+ private _scanMacroConditionExpression;
105
+ private _scanWord;
106
+ /** True iff at least one `#define <word>` is reachable from the current branch. */
107
+ private _isVisibleMacro;
108
+ private _scanNum;
109
+ private _scanFloatSuffix;
110
+ private _scanIntegerSuffix;
111
+ }
@@ -0,0 +1 @@
1
+ export * from "./Lexer";