@galacean/engine-shader-parser 0.0.0-stage → 2.0.0-alpha.54
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/dist/main.analyzer.js +2 -0
- package/dist/main.analyzer.js.map +1 -0
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -0
- package/dist/main.shared.js +2 -0
- package/dist/main.shared.js.map +1 -0
- package/dist/module.analyzer.js +2 -0
- package/dist/module.analyzer.js.map +1 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/module.shared.js +2 -0
- package/dist/module.shared.js.map +1 -0
- package/dist/shared/GLESShaderInfo.main.js +2 -0
- package/dist/shared/GLESShaderInfo.main.js.map +1 -0
- package/dist/shared/GLESShaderInfo.module.js +2 -0
- package/dist/shared/GLESShaderInfo.module.js.map +1 -0
- package/internal/analyzer/package.json +5 -0
- package/internal/package.json +5 -0
- package/package.json +42 -3
- package/shared/package.json +5 -0
- package/types/GSError.d.ts +31 -0
- package/types/ParsedShaderPass.d.ts +11 -0
- package/types/ParserObjectPool.d.ts +51 -0
- package/types/ParserUtils.d.ts +91 -0
- package/types/Preprocessor.d.ts +71 -0
- package/types/PreprocessorExpression.d.ts +1 -0
- package/types/ShaderCompilerUtils.d.ts +9 -0
- package/types/backends/GLESShaderInfo.d.ts +39 -0
- package/types/common/BaseLexer.d.ts +61 -0
- package/types/common/BaseToken.d.ts +105 -0
- package/types/common/BranchAnalysis.d.ts +84 -0
- package/types/common/BranchIdentity.d.ts +58 -0
- package/types/common/BranchSemantics.d.ts +54 -0
- package/types/common/IBaseSymbol.d.ts +9 -0
- package/types/common/PreprocessorCondition.d.ts +39 -0
- package/types/common/ShaderPosition.d.ts +20 -0
- package/types/common/ShaderRange.d.ts +18 -0
- package/types/common/SymbolTable.d.ts +43 -0
- package/types/common/SymbolTableStack.d.ts +53 -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/formatDiagnostic.d.ts +18 -0
- package/types/index.d.ts +37 -0
- package/types/ir/ShaderBuiltinSemantic.d.ts +13 -0
- package/types/ir/ShaderClueIR.d.ts +48 -0
- package/types/ir/ShaderCoreInfo.d.ts +85 -0
- package/types/ir/ShaderDeclarationOwnership.d.ts +36 -0
- package/types/ir/ShaderStructOwnership.d.ts +18 -0
- package/types/ir/index.d.ts +4 -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 +29 -0
- package/types/lalr/index.d.ts +2 -0
- package/types/lalr/types.d.ts +14 -0
- package/types/lexer/AnalyzerLexer.d.ts +56 -0
- package/types/lexer/Lexer.d.ts +122 -0
- package/types/lexer/index.d.ts +1 -0
- package/types/parser/AST.d.ts +625 -0
- package/types/parser/AnalyzerSemanticDiagnostics.d.ts +15 -0
- package/types/parser/Grammar.d.ts +11 -0
- package/types/parser/GrammarSymbol.d.ts +128 -0
- package/types/parser/ICodeGenVisitor.d.ts +29 -0
- package/types/parser/MacroExpansionFacts.d.ts +25 -0
- package/types/parser/ParsedShaderPass.d.ts +71 -0
- package/types/parser/ParsedShaderPassHandle.d.ts +29 -0
- package/types/parser/ParserSemanticValidation.d.ts +110 -0
- package/types/parser/PassParser.d.ts +15 -0
- package/types/parser/RuntimePassParser.d.ts +24 -0
- package/types/parser/SemanticAnalyzer.d.ts +174 -0
- package/types/parser/SemanticDiagnostics.d.ts +93 -0
- package/types/parser/ShaderIncludePath.d.ts +23 -0
- package/types/parser/ShaderInfo.d.ts +56 -0
- package/types/parser/ShaderTargetParser.d.ts +65 -0
- package/types/parser/TypeSystem.d.ts +104 -0
- package/types/parser/ValidatedPassParser.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 +13 -0
- package/types/parser/index.d.ts +7 -0
- package/types/parser/symbolTable/FnSymbol.d.ts +9 -0
- package/types/parser/symbolTable/StructSymbol.d.ts +6 -0
- package/types/parser/symbolTable/SymbolDataType.d.ts +12 -0
- package/types/parser/symbolTable/SymbolInfo.d.ts +33 -0
- package/types/parser/symbolTable/VarSymbol.d.ts +16 -0
- package/types/parser/symbolTable/index.d.ts +6 -0
- package/types/parser/types.d.ts +49 -0
- package/types/preprocessor/PreprocessorCondition.d.ts +56 -0
- package/types/preprocessor/PreprocessorConditionDiagram.d.ts +11 -0
- package/types/preprocessor/PreprocessorConditionNormalization.d.ts +18 -0
- package/types/preprocessor/PreprocessorMacroState.d.ts +84 -0
- package/types/runtime.d.ts +36 -0
- package/types/shared.d.ts +1 -0
- package/types/sourceParser/ShaderSourceFactory.d.ts +8 -0
- package/types/sourceParser/ShaderSourceParser.d.ts +36 -0
- package/types/sourceParser/ShaderSourceSymbol.d.ts +12 -0
- package/types/sourceParser/SourceLexer.d.ts +20 -0
- package/types/sourceParser/index.d.ts +1 -0
- package/README.md +0 -3
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BranchCondition, BranchCoverage, BranchSignature, DeclarationCoexistence } from "./BaseToken";
|
|
2
|
+
/**
|
|
3
|
+
* Whether two signatures express the same macro conditions. Lexical group/arm identity is
|
|
4
|
+
* intentionally ignored: repeated include-guard blocks have different lexical identities but
|
|
5
|
+
* the same condition, and macro-definition deduplication relies on that equivalence.
|
|
6
|
+
* @param a - First branch signature.
|
|
7
|
+
* @param b - Second branch signature.
|
|
8
|
+
* @returns Whether both signatures contain the same ordered macro conditions.
|
|
9
|
+
*/
|
|
10
|
+
export declare function sameBranch(a: BranchSignature, b: BranchSignature): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Determines whether enclosing arms and known preprocessor truth prove a declaration active at a reference.
|
|
13
|
+
* @param declaration - Branch signature at the declaration.
|
|
14
|
+
* @param reference - Branch signature at the reference.
|
|
15
|
+
* @returns Whether every declaration arm is certain or lexically encloses the reference.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare function isLexicalBranchVisibleFrom(declaration: BranchSignature, reference: BranchSignature): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Proves coverage using enclosing arms, known arm truth, and complete lexical conditional chains.
|
|
21
|
+
* Macro names and expressions do not establish relationships between independent groups.
|
|
22
|
+
* @param candidates - Branches containing matching declarations or members.
|
|
23
|
+
* @param reference - Branch containing their use.
|
|
24
|
+
* @returns Proven lexical coverage, or unknown when the available facts cannot establish it.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare function getLexicalBranchCoverage(candidates: readonly BranchSignature[], reference: BranchSignature): BranchCoverage;
|
|
28
|
+
/**
|
|
29
|
+
* Classifies only coexistence facts encoded directly in lexical branch identities.
|
|
30
|
+
*
|
|
31
|
+
* This intentionally does not evaluate `#if` expressions. The runtime compiler uses it to avoid
|
|
32
|
+
* bundling the analyzer's bounded macro solver; offline validation supplies the full proof function.
|
|
33
|
+
* @param earlier - Earlier declaration branch.
|
|
34
|
+
* @param later - Later declaration branch.
|
|
35
|
+
* @returns Proven coexistence, proven lexical exclusivity, or an unresolved relation.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export declare function getLexicalDeclarationCoexistence(earlier: BranchSignature, later: BranchSignature): DeclarationCoexistence;
|
|
39
|
+
/**
|
|
40
|
+
* Compares two optional branch conditions structurally.
|
|
41
|
+
* @param left - First condition, or no condition.
|
|
42
|
+
* @param right - Second condition, or no condition.
|
|
43
|
+
* @returns Whether both conditions encode the same predicate.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export declare function sameCondition(left?: BranchCondition, right?: BranchCondition): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Compares the normalized expression and macro-version dependencies of two expression conditions.
|
|
49
|
+
* @param left - First expression condition.
|
|
50
|
+
* @param right - Second expression condition.
|
|
51
|
+
* @returns Whether both expression conditions have identical inputs.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export declare function sameExpression(left: Extract<BranchCondition, {
|
|
55
|
+
kind: "expression";
|
|
56
|
+
}>, right: Extract<BranchCondition, {
|
|
57
|
+
kind: "expression";
|
|
58
|
+
}>): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { BranchCoverage, BranchSignature, DeclarationCoexistence } from "./BaseToken";
|
|
2
|
+
/**
|
|
3
|
+
* Branch-reasoning operations supplied only to analyzer parser instances.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export interface BranchSemantics {
|
|
7
|
+
/**
|
|
8
|
+
* Determines whether two branches may coexist.
|
|
9
|
+
* @param left - First branch signature.
|
|
10
|
+
* @param right - Second branch signature.
|
|
11
|
+
* @returns Whether the branches overlap.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
canBranchesOverlap(left: BranchSignature, right: BranchSignature): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Determines whether two declarations may coexist.
|
|
17
|
+
* @param earlier - Earlier declaration branch.
|
|
18
|
+
* @param later - Later declaration branch.
|
|
19
|
+
* @returns Whether coexistence has not been disproven.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
canDeclarationsCoexist(earlier: BranchSignature, later: BranchSignature): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Classifies declaration coverage at a reference.
|
|
25
|
+
* @param candidates - Declaration branches.
|
|
26
|
+
* @param callSiteBranch - Reference branch.
|
|
27
|
+
* @returns Proven coverage, proven absence, or unknown coverage.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
getBranchCoverage(candidates: readonly BranchSignature[], callSiteBranch: BranchSignature): BranchCoverage;
|
|
31
|
+
/**
|
|
32
|
+
* Classifies whether two declarations can coexist.
|
|
33
|
+
* @param earlier - Earlier declaration branch.
|
|
34
|
+
* @param later - Later declaration branch.
|
|
35
|
+
* @returns Proven coexistence, proven exclusivity, or an unknown relation.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
getDeclarationCoexistence(earlier: BranchSignature, later: BranchSignature): DeclarationCoexistence;
|
|
39
|
+
/**
|
|
40
|
+
* Determines whether a branch has a satisfying macro configuration.
|
|
41
|
+
* @param branch - Branch signature to test.
|
|
42
|
+
* @returns Whether the branch is reachable.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
isBranchReachable(branch: BranchSignature): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Determines whether a declaration is guaranteed at a reference.
|
|
48
|
+
* @param defBranch - Declaration branch.
|
|
49
|
+
* @param callSiteBranch - Reference branch.
|
|
50
|
+
* @returns Whether every reachable call-site configuration includes the declaration.
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
isBranchVisibleFrom(defBranch: BranchSignature, callSiteBranch: BranchSignature): boolean;
|
|
54
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BranchSignature } from "./BaseToken";
|
|
2
|
+
export interface IBaseSymbol {
|
|
3
|
+
isInMacroBranch: boolean;
|
|
4
|
+
branchSignature: BranchSignature;
|
|
5
|
+
/** ShaderLab inheritance layer owning the declaration. */
|
|
6
|
+
sourceScope?: number;
|
|
7
|
+
readonly ident: string;
|
|
8
|
+
equal(other: IBaseSymbol): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Condition, type PreprocessorExpressionParseResult } from "@galacean/engine-design";
|
|
2
|
+
import type { BoolCondition, CompareCondition, DefinedCondition } from "@galacean/engine-design";
|
|
3
|
+
/**
|
|
4
|
+
* Parsed condition subset used for static branch reasoning and compact runtime instructions.
|
|
5
|
+
*/
|
|
6
|
+
export type PreprocessorCondition = BoolCondition | CompareCondition | DefinedCondition | {
|
|
7
|
+
t: "and";
|
|
8
|
+
l: PreprocessorCondition;
|
|
9
|
+
r: PreprocessorCondition;
|
|
10
|
+
} | {
|
|
11
|
+
t: "or";
|
|
12
|
+
l: PreprocessorCondition;
|
|
13
|
+
r: PreprocessorCondition;
|
|
14
|
+
} | {
|
|
15
|
+
t: "not";
|
|
16
|
+
c: PreprocessorCondition;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Parses a condition that can be represented by the branch-reasoning model.
|
|
20
|
+
* @param expression - Text following an `#if` or `#elif` directive.
|
|
21
|
+
* @returns Parsed branch condition.
|
|
22
|
+
* @throws Error when the complete expression is malformed or exceeds the reasoning subset.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parsePreprocessorCondition(expression: string): PreprocessorCondition;
|
|
25
|
+
/**
|
|
26
|
+
* Parses a condition without throwing when static branch reasoning cannot represent it.
|
|
27
|
+
* @param expression - Text following an `#if` or `#elif` directive.
|
|
28
|
+
* @param parsedExpression - Complete parser result already produced while lexing.
|
|
29
|
+
* @returns Parsed branch condition, or `undefined` for malformed or richer expressions.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare function tryParsePreprocessorCondition(expression: string, parsedExpression?: PreprocessorExpressionParseResult): PreprocessorCondition | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Projects a complete expression tree into the static branch-reasoning subset.
|
|
35
|
+
* @param condition - Complete parsed expression tree.
|
|
36
|
+
* @returns Compact branch condition, or `undefined` when the subset cannot represent it.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export declare function toPreprocessorCondition(condition: Condition): PreprocessorCondition | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutable zero-based source position used by the parser.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare class ShaderPosition {
|
|
6
|
+
/** Zero-based UTF-16 source offset. */
|
|
7
|
+
index: number;
|
|
8
|
+
/** Zero-based source line. */
|
|
9
|
+
line: number;
|
|
10
|
+
/** Zero-based source column. */
|
|
11
|
+
column: number;
|
|
12
|
+
/**
|
|
13
|
+
* Replaces the position coordinates.
|
|
14
|
+
* @param index - Zero-based UTF-16 source offset.
|
|
15
|
+
* @param line - Zero-based source line.
|
|
16
|
+
* @param column - Zero-based source column.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
set(index: number, line: number, column: number): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ShaderPosition } from "./ShaderPosition";
|
|
2
|
+
/**
|
|
3
|
+
* Mutable half-open source range used by the parser.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare class ShaderRange {
|
|
7
|
+
/** Inclusive range start. */
|
|
8
|
+
start: ShaderPosition;
|
|
9
|
+
/** Exclusive range end. */
|
|
10
|
+
end: ShaderPosition;
|
|
11
|
+
/**
|
|
12
|
+
* Replaces the range boundaries.
|
|
13
|
+
* @param start - Inclusive range start.
|
|
14
|
+
* @param end - Exclusive range end.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
set(start: ShaderPosition, end: ShaderPosition): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BranchSignature, DeclarationCoexistence } from "./BaseToken";
|
|
2
|
+
import type { BranchSemantics } from "./BranchSemantics";
|
|
3
|
+
import { IBaseSymbol } from "./IBaseSymbol";
|
|
4
|
+
export declare class SymbolTable<T extends IBaseSymbol> {
|
|
5
|
+
private _table;
|
|
6
|
+
/**
|
|
7
|
+
* Insert a symbol and report whether it conflicts with an existing declaration.
|
|
8
|
+
* Branch declarations are retained even on conflict because codegen needs every arm.
|
|
9
|
+
* @param symbol - Symbol to insert.
|
|
10
|
+
* @param isInMacroBranch - Whether the declaration is inside a macro branch.
|
|
11
|
+
* @param branchSignature - Macro conditions at the declaration site.
|
|
12
|
+
* @returns Whether an equal declaration conflicts, is exclusive, or has unresolved branch overlap.
|
|
13
|
+
*/
|
|
14
|
+
insert(symbol: T, isInMacroBranch?: boolean, branchSignature?: BranchSignature, branchSemantics?: BranchSemantics): Exclude<DeclarationCoexistence, "exclusive"> | "none";
|
|
15
|
+
private _insertWithoutBranchAnalysis;
|
|
16
|
+
/**
|
|
17
|
+
* Classifies remaining inherited conflicts after all narrower declarations have been inserted.
|
|
18
|
+
* @param symbol - Narrower declaration whose deferred diagnostic is being resolved.
|
|
19
|
+
* @param branchSemantics - Analyzer-owned coexistence classification.
|
|
20
|
+
* @param isDeferred - Whether a particular cross-scope pair is resolved during variant selection.
|
|
21
|
+
* @returns The conflict remaining after collective inheritance coverage has been applied.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
getInheritedConflict(symbol: T, branchSemantics: BranchSemantics, isDeferred?: (earlier: T, later: T) => boolean): Exclude<DeclarationCoexistence, "exclusive"> | "none";
|
|
25
|
+
/**
|
|
26
|
+
* Look up a symbol visible from `callsiteBranch`. A candidate `item` is visible when
|
|
27
|
+
* `isBranchVisibleFrom(item.branchSignature, callsiteBranch)` — same or nested branch, or item is
|
|
28
|
+
* unconditional. Without a callsite branch, `includeMacro` controls whether macro-branch entries
|
|
29
|
+
* are eligible. Iterates from latest inserted to first visible match.
|
|
30
|
+
*/
|
|
31
|
+
getSymbol(symbol: T, includeMacro?: boolean, callsiteBranch?: BranchSignature, branchSemantics?: BranchSemantics): T | undefined;
|
|
32
|
+
getSymbols(symbol: T, includeMacro: boolean, out: T[]): T[];
|
|
33
|
+
/** Whether this scope contains an equal symbol without applying macro-branch visibility rules. */
|
|
34
|
+
hasSymbol(symbol: T): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
* Collect every matching declaration that can coexist with the callsite. Consumers combine this
|
|
38
|
+
* candidate set with `canBranchesCoverCallsite` before accepting an unconditional reference.
|
|
39
|
+
*/
|
|
40
|
+
_getSymbols(symbol: T, includeMacro: boolean, out: T[], callsiteBranch?: BranchSignature, branchSemantics?: BranchSemantics): T[];
|
|
41
|
+
/** Iterate every registered symbol. Order within a name bucket is insertion order. */
|
|
42
|
+
forEach(callback: (symbol: T) => void): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BranchSignature, DeclarationCoexistence } from "./BaseToken";
|
|
2
|
+
import type { BranchSemantics } from "./BranchSemantics";
|
|
3
|
+
import { IBaseSymbol } from "./IBaseSymbol";
|
|
4
|
+
import { SymbolTable } from "./SymbolTable";
|
|
5
|
+
export declare class SymbolTableStack<S extends IBaseSymbol, T extends SymbolTable<S>> {
|
|
6
|
+
stack: T[];
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
_macroLevel: number;
|
|
11
|
+
/**
|
|
12
|
+
* Branch signature stamped on declarations at the current parser position. Lookups receive their
|
|
13
|
+
* callsite branch explicitly.
|
|
14
|
+
*/
|
|
15
|
+
_currentBranch: BranchSignature;
|
|
16
|
+
/** Analyzer-only branch operations; absent on the runtime compiler path. */
|
|
17
|
+
branchSemantics?: BranchSemantics;
|
|
18
|
+
get scope(): T;
|
|
19
|
+
get isInMacroBranch(): boolean;
|
|
20
|
+
pushScope(scope: T): void;
|
|
21
|
+
clear(): void;
|
|
22
|
+
popScope(): T | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Insert a symbol into the current lexical scope.
|
|
25
|
+
* @param symbol - Symbol to insert.
|
|
26
|
+
* @param branchSignature - Macro branch at the declaration token.
|
|
27
|
+
* @returns Whether the declaration conflicts, is exclusive, or has unresolved branch overlap.
|
|
28
|
+
*/
|
|
29
|
+
insert(symbol: S, branchSignature?: BranchSignature): Exclude<DeclarationCoexistence, "exclusive"> | "none";
|
|
30
|
+
lookup(symbol: S, includeMacro?: boolean, callsiteBranch?: BranchSignature): S | undefined;
|
|
31
|
+
/** Whether any lexical scope contains an equal symbol, regardless of macro-branch visibility. */
|
|
32
|
+
hasSymbol(symbol: S): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Collect every matching symbol from the nearest lexical scope.
|
|
35
|
+
* @param symbol - Symbol shape used for name and kind matching.
|
|
36
|
+
* @param includeMacro - Whether lookups include declarations from macro branches without a callsite branch.
|
|
37
|
+
* @param out - Reusable output array.
|
|
38
|
+
* @param callsiteBranch - Branch signature used for branch-aware visibility filtering.
|
|
39
|
+
* @returns The supplied output array containing visible matches.
|
|
40
|
+
*/
|
|
41
|
+
lookupAll(symbol: S, includeMacro: boolean, out: S[], callsiteBranch?: BranchSignature): S[];
|
|
42
|
+
/**
|
|
43
|
+
* Collects semantic candidates from the nearest scope and runtime-owner candidates from outer fallback scopes.
|
|
44
|
+
* @param symbol - Symbol shape used for name and kind matching.
|
|
45
|
+
* @param includeMacro - Whether lookups include declarations from macro branches without a callsite branch.
|
|
46
|
+
* @param out - Reusable output array receiving candidates from the nearest matching scope.
|
|
47
|
+
* @param runtimeFallbacks - Reusable output array receiving outer declarations that may own a runtime reference.
|
|
48
|
+
* @param callsiteBranch - Branch signature used for branch-aware visibility filtering.
|
|
49
|
+
* @returns The supplied `out` array containing semantic candidates from the nearest matching scope.
|
|
50
|
+
*/
|
|
51
|
+
lookupAllWithRuntimeFallbacks(symbol: S, includeMacro: boolean, out: S[], runtimeFallbacks: S[], callsiteBranch?: BranchSignature): S[];
|
|
52
|
+
private _runtimeCandidatesCoverCallsite;
|
|
53
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export declare enum Keyword {
|
|
2
|
+
CONST = 0,
|
|
3
|
+
BOOL = 1,
|
|
4
|
+
FLOAT = 2,
|
|
5
|
+
DOUBLE = 3,
|
|
6
|
+
INT = 4,
|
|
7
|
+
UINT = 5,
|
|
8
|
+
BREAK = 6,
|
|
9
|
+
CONTINUE = 7,
|
|
10
|
+
DO = 8,
|
|
11
|
+
ELSE = 9,
|
|
12
|
+
FOR = 10,
|
|
13
|
+
IF = 11,
|
|
14
|
+
WHILE = 12,
|
|
15
|
+
DISCARD = 13,
|
|
16
|
+
RETURN = 14,
|
|
17
|
+
BVEC2 = 15,
|
|
18
|
+
BVEC3 = 16,
|
|
19
|
+
BVEC4 = 17,
|
|
20
|
+
IVEC2 = 18,
|
|
21
|
+
IVEC3 = 19,
|
|
22
|
+
IVEC4 = 20,
|
|
23
|
+
UVEC2 = 21,
|
|
24
|
+
UVEC3 = 22,
|
|
25
|
+
UVEC4 = 23,
|
|
26
|
+
VEC2 = 24,
|
|
27
|
+
VEC3 = 25,
|
|
28
|
+
VEC4 = 26,
|
|
29
|
+
VEC4_ARRAY = 27,
|
|
30
|
+
MAT2 = 28,
|
|
31
|
+
MAT3 = 29,
|
|
32
|
+
MAT4 = 30,
|
|
33
|
+
MAT2X3 = 31,
|
|
34
|
+
MAT2X4 = 32,
|
|
35
|
+
MAT3X2 = 33,
|
|
36
|
+
MAT3X4 = 34,
|
|
37
|
+
MAT4X2 = 35,
|
|
38
|
+
MAT4X3 = 36,
|
|
39
|
+
IN = 37,
|
|
40
|
+
OUT = 38,
|
|
41
|
+
INOUT = 39,
|
|
42
|
+
CENTROID = 40,
|
|
43
|
+
SAMPLER2D = 41,
|
|
44
|
+
SAMPLER3D = 42,
|
|
45
|
+
SAMPLER_CUBE = 43,
|
|
46
|
+
SAMPLER2D_SHADOW = 44,
|
|
47
|
+
SAMPLER_CUBE_SHADOW = 45,
|
|
48
|
+
SAMPLER2D_ARRAY = 46,
|
|
49
|
+
SAMPLER2D_ARRAY_SHADOW = 47,
|
|
50
|
+
I_SAMPLER2D = 48,
|
|
51
|
+
I_SAMPLER3D = 49,
|
|
52
|
+
I_SAMPLER_CUBE = 50,
|
|
53
|
+
I_SAMPLER2D_ARRAY = 51,
|
|
54
|
+
U_SAMPLER2D = 52,
|
|
55
|
+
U_SAMPLER3D = 53,
|
|
56
|
+
U_SAMPLER_CUBE = 54,
|
|
57
|
+
U_SAMPLER2D_ARRAY = 55,
|
|
58
|
+
STRUCT = 56,
|
|
59
|
+
LAYOUT = 57,
|
|
60
|
+
LOCATION = 58,
|
|
61
|
+
VOID = 59,
|
|
62
|
+
PRECISION = 60,
|
|
63
|
+
PRECISE = 61,
|
|
64
|
+
HIGHP = 62,
|
|
65
|
+
MEDIUMP = 63,
|
|
66
|
+
LOWP = 64,
|
|
67
|
+
INVARIANT = 65,
|
|
68
|
+
SMOOTH = 66,
|
|
69
|
+
FLAT = 67,
|
|
70
|
+
NOPERSPECTIVE = 68,
|
|
71
|
+
True = 69,
|
|
72
|
+
False = 70,
|
|
73
|
+
LeftBrace = 71,
|
|
74
|
+
RightBrace = 72,
|
|
75
|
+
Equal = 73,
|
|
76
|
+
BitwiseOr = 74,
|
|
77
|
+
GSRenderQueueType = 75,
|
|
78
|
+
GSBlendState = 76,
|
|
79
|
+
GSDepthState = 77,
|
|
80
|
+
GSStencilState = 78,
|
|
81
|
+
GSRasterState = 79,
|
|
82
|
+
GSEditorProperties = 80,
|
|
83
|
+
GSEditorMacros = 81,
|
|
84
|
+
GSEditor = 82,
|
|
85
|
+
GSTags = 83,
|
|
86
|
+
GSVertexShader = 84,
|
|
87
|
+
GSFragmentShader = 85,
|
|
88
|
+
GSSubShader = 86,
|
|
89
|
+
GSPass = 87,
|
|
90
|
+
GSBlendFactor = 88,
|
|
91
|
+
GSBlendOperation = 89,
|
|
92
|
+
GSBool = 90,
|
|
93
|
+
GSNumber = 91,
|
|
94
|
+
GSColor = 92,
|
|
95
|
+
GSCompareFunction = 93,
|
|
96
|
+
GSStencilOperation = 94,
|
|
97
|
+
GSCullMode = 95,
|
|
98
|
+
GSColorWriteMask = 96,
|
|
99
|
+
GSUsePass = 97,
|
|
100
|
+
MACRO_IF = 98,
|
|
101
|
+
MACRO_IFDEF = 99,
|
|
102
|
+
MACRO_IFNDEF = 100,
|
|
103
|
+
MACRO_ELSE = 101,
|
|
104
|
+
MACRO_ELIF = 102,
|
|
105
|
+
MACRO_ENDIF = 103,
|
|
106
|
+
MACRO_UNDEF = 104,
|
|
107
|
+
/** Legacy opaque `#define` token — whole directive packed into one lexeme. Retained
|
|
108
|
+
* for macros whose value can't be parsed as a GLSL expression (type aliases,
|
|
109
|
+
* qualifier aliases, partial-syntax macros). Expression-style macros instead emit
|
|
110
|
+
* `MACRO_DEFINE` + ID + value tokens + `MACRO_DEFINE_END`. */
|
|
111
|
+
MACRO_DEFINE_EXPRESSION = 105,
|
|
112
|
+
MACRO_CONDITIONAL_EXPRESSION = 106,
|
|
113
|
+
MACRO_CALL = 107,
|
|
114
|
+
/** `#define` directive head for expression-style macros. */
|
|
115
|
+
MACRO_DEFINE = 108,
|
|
116
|
+
/** Terminates a `MACRO_DEFINE` directive at end-of-line. */
|
|
117
|
+
MACRO_DEFINE_END = 109,
|
|
118
|
+
/** `(params)` block for a function-like `#define`. The lexer captures the entire
|
|
119
|
+
* parenthesized parameter list as one opaque token so the macro-define CFG rule
|
|
120
|
+
* doesn't need its own parameter-list production (which would conflict with
|
|
121
|
+
* function_call_parameter_list under LALR(1)). The AST consumer parses the
|
|
122
|
+
* lexeme to recover the individual parameter names. */
|
|
123
|
+
MACRO_DEFINE_PARAMS = 110
|
|
124
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Keyword } from "./enums/Keyword";
|
|
2
|
+
export declare enum ETokenType {
|
|
3
|
+
ID = 1000,
|
|
4
|
+
FLOAT_CONSTANT = 1001,
|
|
5
|
+
INT_CONSTANT = 1002,
|
|
6
|
+
STRING_CONST = 1003,
|
|
7
|
+
/** << */
|
|
8
|
+
LEFT_OP = 1004,
|
|
9
|
+
/** \>> */
|
|
10
|
+
RIGHT_OP = 1005,
|
|
11
|
+
/** ++ */
|
|
12
|
+
INC_OP = 1006,
|
|
13
|
+
/** -- */
|
|
14
|
+
DEC_OP = 1007,
|
|
15
|
+
/** <= */
|
|
16
|
+
LE_OP = 1008,
|
|
17
|
+
/** \>= */
|
|
18
|
+
GE_OP = 1009,
|
|
19
|
+
/** == */
|
|
20
|
+
EQ_OP = 1010,
|
|
21
|
+
/** != */
|
|
22
|
+
NE_OP = 1011,
|
|
23
|
+
/** && */
|
|
24
|
+
AND_OP = 1012,
|
|
25
|
+
/** || */
|
|
26
|
+
OR_OP = 1013,
|
|
27
|
+
/** ^^ */
|
|
28
|
+
XOR_OP = 1014,
|
|
29
|
+
/** *= */
|
|
30
|
+
MUL_ASSIGN = 1015,
|
|
31
|
+
/** /= */
|
|
32
|
+
DIV_ASSIGN = 1016,
|
|
33
|
+
/** += */
|
|
34
|
+
ADD_ASSIGN = 1017,
|
|
35
|
+
/** -= */
|
|
36
|
+
SUB_ASSIGN = 1018,
|
|
37
|
+
/** %= */
|
|
38
|
+
MOD_ASSIGN = 1019,
|
|
39
|
+
/** <<= */
|
|
40
|
+
LEFT_ASSIGN = 1020,
|
|
41
|
+
/** >>= */
|
|
42
|
+
RIGHT_ASSIGN = 1021,
|
|
43
|
+
/** &= */
|
|
44
|
+
AND_ASSIGN = 1022,
|
|
45
|
+
/** ^= */
|
|
46
|
+
XOR_ASSIGN = 1023,
|
|
47
|
+
/** |= */
|
|
48
|
+
OR_ASSIGN = 1024,
|
|
49
|
+
/** ( */
|
|
50
|
+
LEFT_PAREN = 1025,
|
|
51
|
+
/** ) */
|
|
52
|
+
RIGHT_PAREN = 1026,
|
|
53
|
+
/** [ */
|
|
54
|
+
LEFT_BRACKET = 1027,
|
|
55
|
+
/** ] */
|
|
56
|
+
RIGHT_BRACKET = 1028,
|
|
57
|
+
/** { */
|
|
58
|
+
LEFT_BRACE = 1029,
|
|
59
|
+
/** } */
|
|
60
|
+
RIGHT_BRACE = 1030,
|
|
61
|
+
/** . */
|
|
62
|
+
DOT = 1031,
|
|
63
|
+
/** , */
|
|
64
|
+
COMMA = 1032,
|
|
65
|
+
COLON = 1033,
|
|
66
|
+
/** = */
|
|
67
|
+
EQUAL = 1034,
|
|
68
|
+
/** ; */
|
|
69
|
+
SEMICOLON = 1035,
|
|
70
|
+
/** ! */
|
|
71
|
+
BANG = 1036,
|
|
72
|
+
/** \- */
|
|
73
|
+
DASH = 1037,
|
|
74
|
+
/** ~ */
|
|
75
|
+
TILDE = 1038,
|
|
76
|
+
PLUS = 1039,
|
|
77
|
+
/** \* */
|
|
78
|
+
STAR = 1040,
|
|
79
|
+
/** / */
|
|
80
|
+
SLASH = 1041,
|
|
81
|
+
/** % */
|
|
82
|
+
PERCENT = 1042,
|
|
83
|
+
/** < */
|
|
84
|
+
LEFT_ANGLE = 1043,
|
|
85
|
+
/** \> */
|
|
86
|
+
RIGHT_ANGLE = 1044,
|
|
87
|
+
VERTICAL_BAR = 1045,
|
|
88
|
+
/** ^ */
|
|
89
|
+
CARET = 1046,
|
|
90
|
+
/** & */
|
|
91
|
+
AMPERSAND = 1047,
|
|
92
|
+
/** ? */
|
|
93
|
+
QUESTION = 1048,
|
|
94
|
+
NotWord = 1049,
|
|
95
|
+
/** ε */
|
|
96
|
+
EPSILON = 1998,
|
|
97
|
+
EOF = 1999
|
|
98
|
+
}
|
|
99
|
+
export declare const TypeAny = 3000;
|
|
100
|
+
export type GalaceanDataType = Keyword.VOID | Keyword.FLOAT | Keyword.BOOL | Keyword.INT | Keyword.UINT | Keyword.VEC2 | Keyword.VEC3 | Keyword.VEC4 | Keyword.BVEC2 | Keyword.BVEC3 | Keyword.BVEC4 | Keyword.IVEC2 | Keyword.IVEC3 | Keyword.IVEC4 | Keyword.UVEC2 | Keyword.UVEC3 | Keyword.UVEC4 | Keyword.MAT2 | Keyword.MAT3 | Keyword.MAT4 | Keyword.MAT2X3 | Keyword.MAT2X4 | Keyword.MAT3X2 | Keyword.MAT3X4 | Keyword.MAT4X2 | Keyword.MAT4X3 | Keyword.SAMPLER2D | Keyword.SAMPLER3D | Keyword.SAMPLER_CUBE | Keyword.SAMPLER2D_SHADOW | Keyword.SAMPLER_CUBE_SHADOW | Keyword.SAMPLER2D_ARRAY | Keyword.SAMPLER2D_ARRAY_SHADOW | Keyword.I_SAMPLER2D | Keyword.I_SAMPLER3D | Keyword.I_SAMPLER_CUBE | Keyword.I_SAMPLER2D_ARRAY | Keyword.U_SAMPLER2D | Keyword.U_SAMPLER3D | Keyword.U_SAMPLER_CUBE | Keyword.U_SAMPLER2D_ARRAY | Keyword.VEC4_ARRAY | typeof TypeAny | string;
|
|
101
|
+
export type TokenType = ETokenType | Keyword;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a diagnostic with a source excerpt and caret markers.
|
|
3
|
+
* @param source - Source text containing the diagnostic.
|
|
4
|
+
* @param range - Zero-based source range containing the diagnostic.
|
|
5
|
+
* @param header - Text displayed before the source excerpt.
|
|
6
|
+
* @param contextLines - Number of context lines shown on either side of the range.
|
|
7
|
+
* @returns Formatted diagnostic text.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatDiagnosticSource(source: string | undefined, range: {
|
|
10
|
+
start: {
|
|
11
|
+
line: number;
|
|
12
|
+
column: number;
|
|
13
|
+
};
|
|
14
|
+
end: {
|
|
15
|
+
line: number;
|
|
16
|
+
column: number;
|
|
17
|
+
};
|
|
18
|
+
}, header: string, contextLines?: number): string;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export * from "./common";
|
|
2
|
+
export * from "./common/BaseToken";
|
|
3
|
+
export * from "./common/BranchAnalysis";
|
|
4
|
+
export * from "./common/BranchSemantics";
|
|
5
|
+
export * from "./common/BaseLexer";
|
|
6
|
+
export * from "./common/PreprocessorCondition";
|
|
7
|
+
export * from "./common/SymbolTable";
|
|
8
|
+
export * from "./common/SymbolTableStack";
|
|
9
|
+
export * from "./common/IBaseSymbol";
|
|
10
|
+
export * from "./common/enums/ShaderStage";
|
|
11
|
+
export * from "./lexer";
|
|
12
|
+
export * from "./lexer/AnalyzerLexer";
|
|
13
|
+
export * from "./lalr";
|
|
14
|
+
export * from "./parser";
|
|
15
|
+
export * from "./parser/AST";
|
|
16
|
+
export * from "./parser/types";
|
|
17
|
+
export * from "./parser/GrammarSymbol";
|
|
18
|
+
export * from "./parser/ShaderInfo";
|
|
19
|
+
export * from "./parser/PassParser";
|
|
20
|
+
export * from "./parser/AnalyzerSemanticDiagnostics";
|
|
21
|
+
export * from "./parser/SemanticDiagnostics";
|
|
22
|
+
export * from "./parser/ICodeGenVisitor";
|
|
23
|
+
export * from "./parser/symbolTable";
|
|
24
|
+
export * from "./parser/builtin";
|
|
25
|
+
export * from "./parser/TypeSystem";
|
|
26
|
+
export * from "./parser/ParserSemanticValidation";
|
|
27
|
+
export * from "./ir";
|
|
28
|
+
export * from "./sourceParser";
|
|
29
|
+
export * from "./sourceParser/ShaderSourceFactory";
|
|
30
|
+
export * from "./Preprocessor";
|
|
31
|
+
export * from "./PreprocessorExpression";
|
|
32
|
+
export * from "./ParserObjectPool";
|
|
33
|
+
export * from "./ParserUtils";
|
|
34
|
+
export * from "./GSError";
|
|
35
|
+
export * from "./formatDiagnostic";
|
|
36
|
+
export * from "./ShaderCompilerUtils";
|
|
37
|
+
export * from "./backends/GLESShaderInfo";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend-neutral meanings of stage IO builtins recognized by the parser.
|
|
3
|
+
*
|
|
4
|
+
* Source-language spellings remain on tokens for diagnostics and source reproduction; consumers
|
|
5
|
+
* use these values when behavior depends on the builtin's meaning.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare enum ShaderBuiltinSemantic {
|
|
9
|
+
VertexPosition = "vertex-position",
|
|
10
|
+
FragmentOutput0 = "fragment-output-0",
|
|
11
|
+
FragmentOutputArray = "fragment-output-array",
|
|
12
|
+
FragmentDepth = "fragment-depth"
|
|
13
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ASTNode } from "../parser/AST";
|
|
2
|
+
import type { ShaderData } from "../parser/ShaderInfo";
|
|
3
|
+
/**
|
|
4
|
+
* Identifies the ShaderLab inheritance layer of an expanded source range.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface ShaderSourceScope {
|
|
8
|
+
/** Start offset in the preprocessed pass. */
|
|
9
|
+
readonly generatedStart: number;
|
|
10
|
+
/** Exclusive end offset in the preprocessed pass. */
|
|
11
|
+
readonly generatedEnd: number;
|
|
12
|
+
/** ShaderLab inheritance layer that contributed this source. */
|
|
13
|
+
readonly sourceScope?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Maps an expanded shader range back to its original source chunk.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export interface ShaderSourceMapSegment extends ShaderSourceScope {
|
|
20
|
+
/** Start offset in the original source chunk. */
|
|
21
|
+
readonly sourceStart: number;
|
|
22
|
+
/** Original source chunk. */
|
|
23
|
+
readonly source: string;
|
|
24
|
+
/** Canonical source path represented by this segment. */
|
|
25
|
+
readonly sourceFile?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Read-only, backend-neutral view of a parsed shader pass.
|
|
29
|
+
*
|
|
30
|
+
* The existing typed AST and symbol table are the backing store; creating this view does not clone
|
|
31
|
+
* the syntax tree. Backends and analysis passes consume this object instead of depending on each
|
|
32
|
+
* other.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare class ShaderClueIR {
|
|
36
|
+
readonly program: ASTNode.GLShaderProgram;
|
|
37
|
+
readonly source: string;
|
|
38
|
+
readonly sourceMap: readonly ShaderSourceMapSegment[];
|
|
39
|
+
/** Semantic facts collected while parsing the pass. */
|
|
40
|
+
readonly shaderData: ShaderData;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a neutral view over a parsed shader program.
|
|
43
|
+
* @param program - Existing typed AST used as the IR backing store.
|
|
44
|
+
* @param source - Preprocessed pass source represented by the AST.
|
|
45
|
+
* @param sourceMap - Mapping from preprocessed offsets to original source chunks.
|
|
46
|
+
*/
|
|
47
|
+
constructor(program: ASTNode.GLShaderProgram, source: string, sourceMap?: readonly ShaderSourceMapSegment[]);
|
|
48
|
+
}
|