@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.
- 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,93 @@
|
|
|
1
|
+
import type { GalaceanDataType, ShaderRange } from "../common";
|
|
2
|
+
import type { BranchCoverage, BranchSignature, DeclarationCoexistence } from "../common/BaseToken";
|
|
3
|
+
import type { ASTNode } from "./AST";
|
|
4
|
+
import type SemanticAnalyzer from "./SemanticAnalyzer";
|
|
5
|
+
import type { MacroExpansionSyntax } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Analyzer-only ambiguity categories emitted while semantic facts are projected.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export type SemanticAmbiguityKind = "const-qualification" | "struct-member-presence";
|
|
11
|
+
/**
|
|
12
|
+
* Structured parser facts mapped to analyzer or offline-compiler diagnostics.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export interface SemanticDiagnostics {
|
|
16
|
+
/**
|
|
17
|
+
* Captures neutral effective macro syntax without coupling the runtime parser to analysis.
|
|
18
|
+
* @param node - Macro invocation to expand.
|
|
19
|
+
* @param analyzer - Binding state at the invocation.
|
|
20
|
+
* @returns Proven syntax alternatives, including any unresolved execution effects.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
macroExpansion?(node: ASTNode.MacroCallSymbol | ASTNode.MacroCallFunction, analyzer: SemanticAnalyzer): readonly MacroExpansionSyntax[];
|
|
24
|
+
/**
|
|
25
|
+
* Replaces the expanded source attached to subsequent diagnostics.
|
|
26
|
+
* @param source - Expanded shader-pass source for the current parser request.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
setSource?(source: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Maps a declaration conflict to a diagnostic.
|
|
32
|
+
* @param location - Declaration range.
|
|
33
|
+
* @param name - Declared symbol name.
|
|
34
|
+
* @param conflict - Proven or unresolved coexistence state.
|
|
35
|
+
* @param branch - Macro branch containing the later declaration.
|
|
36
|
+
* @returns A diagnostic when the conflict is reportable.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
redefinition(location: ShaderRange, name: string, conflict: Exclude<DeclarationCoexistence, "exclusive"> | "none", branch: BranchSignature): Error | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Maps declaration coverage to a reference diagnostic.
|
|
42
|
+
* @param location - Reference range.
|
|
43
|
+
* @param subjectKind - Referenced declaration category.
|
|
44
|
+
* @param name - Referenced symbol name.
|
|
45
|
+
* @param coverage - Proven or unresolved coverage state.
|
|
46
|
+
* @returns A diagnostic when absence is proven.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
branchAvailability(location: ShaderRange, subjectKind: "Function" | "Struct" | "Identifier", name: string, coverage: BranchCoverage): Error | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Creates an ambiguity diagnostic for one semantic projection.
|
|
52
|
+
* @param location - Ambiguous reference range.
|
|
53
|
+
* @param kind - Ambiguity category.
|
|
54
|
+
* @param name - Symbol or member name.
|
|
55
|
+
* @param owner - Optional owning struct name.
|
|
56
|
+
* @returns The mapped ambiguity diagnostic.
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
branchAmbiguity?(location: ShaderRange, kind: SemanticAmbiguityKind, name: string, owner?: string): Error | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a non-constant array-size diagnostic.
|
|
62
|
+
* @param location - Array-size range.
|
|
63
|
+
* @returns The mapped diagnostic.
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
nonConstArraySize?(location: ShaderRange): Error | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a sampler-argument diagnostic.
|
|
69
|
+
* @param location - Call range.
|
|
70
|
+
* @param functionName - Texture function name.
|
|
71
|
+
* @param actualType - First argument type.
|
|
72
|
+
* @returns The mapped diagnostic.
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
expectedSampler?(location: ShaderRange, functionName: string, actualType: GalaceanDataType): Error | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Creates an overload-resolution diagnostic.
|
|
78
|
+
* @param location - Call range.
|
|
79
|
+
* @param functionName - Called function name.
|
|
80
|
+
* @returns The mapped diagnostic.
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
noMatchingOverload?(location: ShaderRange, functionName: string): Error | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Creates an unknown-struct-member diagnostic.
|
|
86
|
+
* @param location - Member range.
|
|
87
|
+
* @param structName - Struct type name.
|
|
88
|
+
* @param memberName - Referenced member name.
|
|
89
|
+
* @returns The mapped diagnostic.
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
undeclaredStructMember?(location: ShaderRange, structName: string, memberName: string): Error | undefined;
|
|
93
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IncludeMap } from "../Preprocessor";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a caller-provided source location into the canonical form stored in source maps.
|
|
4
|
+
* @param sourceFile - Project-relative path, project-root path, or absolute URL.
|
|
5
|
+
* @returns Canonical source location, or `undefined` when no location was supplied.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeShaderSourceFile(sourceFile?: string): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Exposes an include registry through canonical lookup keys without copying its sources.
|
|
11
|
+
* @param includeMap - Caller-owned include registry.
|
|
12
|
+
* @returns Read-only canonical lookup view that preserves live updates to canonical keys.
|
|
13
|
+
* @throws Error when two input keys resolve to the same canonical key.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function normalizeShaderIncludeMap(includeMap?: IncludeMap): IncludeMap;
|
|
17
|
+
/**
|
|
18
|
+
* Creates the internal URL used to resolve relative includes from a canonical source location.
|
|
19
|
+
* @param sourceFile - Project path or absolute URL returned by `normalizeShaderSourceFile`.
|
|
20
|
+
* @returns Base URL for include resolution, or an empty string when no source location exists.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function shaderSourceBaseURL(sourceFile?: string): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { BranchSignature } from "../common/BaseToken";
|
|
2
|
+
import { SymbolInfo, SymbolTable, type FnSymbol, type VarSymbol } from "../parser/symbolTable";
|
|
3
|
+
import { ASTNode } from "./AST";
|
|
4
|
+
import type { ShaderDeclarationOwnershipInfo } from "../ir/ShaderDeclarationOwnership";
|
|
5
|
+
/**
|
|
6
|
+
* Immutable candidates retained for one reference lookup.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface ReferenceResolutionSnapshot {
|
|
10
|
+
/**
|
|
11
|
+
* Call-site reference resolved by this lookup.
|
|
12
|
+
*/
|
|
13
|
+
readonly reference: ASTNode.VariableIdentifier;
|
|
14
|
+
/**
|
|
15
|
+
* Exact candidates retained for this lookup, independent of later lookups on the same AST node.
|
|
16
|
+
*/
|
|
17
|
+
readonly symbols: readonly (VarSymbol | FnSymbol)[];
|
|
18
|
+
/**
|
|
19
|
+
* Index of the first outer owner used only when nearer conditional declarations are absent.
|
|
20
|
+
*/
|
|
21
|
+
readonly fallbackStart: number;
|
|
22
|
+
/**
|
|
23
|
+
* Effective branch of this lookup, including an expression-macro replacement branch.
|
|
24
|
+
*/
|
|
25
|
+
readonly callSiteBranch: BranchSignature;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this lookup identifies the enclosing macro expression's value.
|
|
28
|
+
*/
|
|
29
|
+
readonly isValueIdentity?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Definition-owned AST identity of a member owner inside a macro replacement.
|
|
32
|
+
*/
|
|
33
|
+
readonly replacementMemberOwner?: ASTNode.VariableIdentifier;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the owner is formed only after function-argument or nested-macro substitution.
|
|
36
|
+
*/
|
|
37
|
+
readonly requiresRuntimeOwnerExpansion?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare class ShaderData {
|
|
40
|
+
symbolTable: SymbolTable<SymbolInfo>;
|
|
41
|
+
/** Ownership facts populated after all pass declarations have been parsed. @internal */
|
|
42
|
+
declarationOwnership: ShaderDeclarationOwnershipInfo;
|
|
43
|
+
globalPrecisions: ASTNode.PrecisionSpecifier[];
|
|
44
|
+
globalMacroDeclarations: ASTNode.GlobalDeclaration[];
|
|
45
|
+
/**
|
|
46
|
+
* Direct member-owner references discovered while their postfix expressions are reduced.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
directMemberOwnerReferences: ASTNode.VariableIdentifier[];
|
|
50
|
+
/**
|
|
51
|
+
* Sparse lookup snapshots required when AST-local symbol state cannot represent every owner candidate.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
referenceResolutionSnapshots: ReferenceResolutionSnapshot[];
|
|
55
|
+
getOuterGlobalMacroDeclarations(): ASTNode.GlobalDeclaration[];
|
|
56
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BaseToken } from "../common/BaseToken";
|
|
2
|
+
import type { BranchSemantics } from "../common/BranchSemantics";
|
|
3
|
+
import { StateActionTable, StateGotoTable } from "../lalr/types";
|
|
4
|
+
import { MacroDefineList } from "../Preprocessor";
|
|
5
|
+
import { ASTNode } from "./AST";
|
|
6
|
+
import { Grammar } from "./Grammar";
|
|
7
|
+
import SemanticAnalyzer from "./SemanticAnalyzer";
|
|
8
|
+
import type { SemanticDiagnostics } from "./SemanticDiagnostics";
|
|
9
|
+
import type { ParserObjectPool } from "../ParserObjectPool";
|
|
10
|
+
import type { ShaderSourceScope } from "../ir";
|
|
11
|
+
/**
|
|
12
|
+
* Parses shader tokens and performs the parser-owned semantic pass.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare class ShaderTargetParser {
|
|
16
|
+
private _source?;
|
|
17
|
+
readonly semanticErrorsBlockCodegen: boolean;
|
|
18
|
+
readonly actionTable: StateActionTable;
|
|
19
|
+
readonly gotoTable: StateGotoTable;
|
|
20
|
+
readonly grammar: Grammar;
|
|
21
|
+
readonly semanticAnalyzer: SemanticAnalyzer;
|
|
22
|
+
readonly blockingErrors: Error[];
|
|
23
|
+
private _traceBackStack;
|
|
24
|
+
private get curState();
|
|
25
|
+
private get stateActionTable();
|
|
26
|
+
private get stateGotoTable();
|
|
27
|
+
/**
|
|
28
|
+
* Gets semantic errors collected for the current parse.
|
|
29
|
+
* @returns Mutable parser-owned error storage.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
get errors(): Error[];
|
|
33
|
+
private static _tables?;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a parser that reuses the immutable generated grammar tables.
|
|
36
|
+
* @param branchSemantics - Optional analyzer branch-proof implementation.
|
|
37
|
+
* @param semanticDiagnostics - Optional semantic diagnostic factory.
|
|
38
|
+
* @param source - Source attached to parser errors.
|
|
39
|
+
* @param objectPool - Optional high-water object pool for synchronous compilation.
|
|
40
|
+
* @param semanticErrorsBlockCodegen - Whether semantic errors enter the backend admission gate.
|
|
41
|
+
* @param authoringAnalysisEnabled - Whether analyzer-only semantic facts are collected.
|
|
42
|
+
* @returns Configured shader target parser.
|
|
43
|
+
*/
|
|
44
|
+
static create(branchSemantics?: BranchSemantics, semanticDiagnostics?: SemanticDiagnostics, source?: string, objectPool?: ParserObjectPool, semanticErrorsBlockCodegen?: boolean, authoringAnalysisEnabled?: boolean): ShaderTargetParser;
|
|
45
|
+
private constructor();
|
|
46
|
+
/**
|
|
47
|
+
* Replaces the source used to format errors for a reused parser.
|
|
48
|
+
* @param source - Expanded source for the next parse.
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
setSource(source: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Replaces the semantic inheritance ranges for the next parse.
|
|
54
|
+
* @param sourceScopes - Ordered expanded source ranges with ShaderLab scope identities.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
setSourceScopes(sourceScopes: readonly ShaderSourceScope[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* Parses one token stream and performs parser-owned semantic analysis.
|
|
60
|
+
* @param tokens - Token stream ending with an explicit EOF token.
|
|
61
|
+
* @param macroDefineList - Visible macro definitions collected by the lexer.
|
|
62
|
+
* @returns Parsed program, or `null` after a blocking syntax failure.
|
|
63
|
+
*/
|
|
64
|
+
parse(tokens: Generator<BaseToken, BaseToken>, macroDefineList: MacroDefineList): ASTNode.GLShaderProgram | null;
|
|
65
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { GalaceanDataType } from "../common";
|
|
2
|
+
export type { GalaceanDataType } from "../common/types";
|
|
3
|
+
/** Proven reason that a binary arithmetic operation is invalid. */
|
|
4
|
+
export type ArithmeticFailureReason = "non-arithmetic" | "family-mismatch" | "shape-mismatch" | "integer-required";
|
|
5
|
+
/**
|
|
6
|
+
* Shared result of arithmetic type inference and validation.
|
|
7
|
+
*
|
|
8
|
+
* `valid` is undefined when an operand type is unresolved. A false value is therefore proof of an
|
|
9
|
+
* invalid operation, while unresolved macro-provided types remain non-blocking.
|
|
10
|
+
*/
|
|
11
|
+
export interface ArithmeticTypeResult {
|
|
12
|
+
/** Inferred result type, or `TypeAny` when it cannot be determined. */
|
|
13
|
+
resultType: GalaceanDataType | undefined;
|
|
14
|
+
/** Whether the operation is proven valid, proven invalid, or unresolved. */
|
|
15
|
+
valid: boolean | undefined;
|
|
16
|
+
/** Invalidity reason when `valid` is false. */
|
|
17
|
+
reason?: ArithmeticFailureReason;
|
|
18
|
+
}
|
|
19
|
+
/** Utility functions for GLSL type classification and compatibility. */
|
|
20
|
+
export declare class TypeSystem {
|
|
21
|
+
/**
|
|
22
|
+
* Tests whether a value type can be assigned without an implicit conversion.
|
|
23
|
+
* @param target - Type of the assignment target.
|
|
24
|
+
* @param source - Type of the assigned value.
|
|
25
|
+
* @returns Whether the assignment is valid or cannot yet be resolved.
|
|
26
|
+
*/
|
|
27
|
+
static isAssignable(target: GalaceanDataType | undefined, source: GalaceanDataType | undefined): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a human-readable GLSL type name.
|
|
30
|
+
* @param type - Type to format.
|
|
31
|
+
* @returns GLSL name or `unknown` when the type is unresolved.
|
|
32
|
+
*/
|
|
33
|
+
static typeName(type: GalaceanDataType | undefined): string;
|
|
34
|
+
/**
|
|
35
|
+
* Tests whether a type is an opaque GLSL sampler.
|
|
36
|
+
* @param type - Type to classify.
|
|
37
|
+
* @returns Whether the type is a sampler.
|
|
38
|
+
*/
|
|
39
|
+
static isSamplerType(type: GalaceanDataType | undefined): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Tests whether a type is a boolean scalar or vector.
|
|
42
|
+
* @param type - Type to classify.
|
|
43
|
+
* @returns Whether the type belongs to the boolean family.
|
|
44
|
+
*/
|
|
45
|
+
static isBoolType(type: GalaceanDataType | undefined): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Tests whether a type is a signed or unsigned integer scalar or vector.
|
|
48
|
+
* @param type - Type to classify.
|
|
49
|
+
* @returns Whether the type belongs to an integer family.
|
|
50
|
+
*/
|
|
51
|
+
static isIntegerType(type: GalaceanDataType | undefined): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Tests whether a resolved type cannot participate in arithmetic.
|
|
54
|
+
* @param type - Type to classify.
|
|
55
|
+
* @returns Whether the type is a boolean, sampler, or struct. Unresolved types return false.
|
|
56
|
+
*/
|
|
57
|
+
static nonArithmeticOperand(type: GalaceanDataType | undefined): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Tests whether a type is a numeric or boolean scalar.
|
|
60
|
+
* @param type - Type to classify.
|
|
61
|
+
* @returns Whether the type is a scalar.
|
|
62
|
+
*/
|
|
63
|
+
static isScalarType(type: GalaceanDataType | undefined): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Infers and validates one GLSL arithmetic operation from a single rule table.
|
|
66
|
+
* @param left - Left operand type.
|
|
67
|
+
* @param right - Right operand type.
|
|
68
|
+
* @param operator - Arithmetic operator lexeme.
|
|
69
|
+
* @returns Shared inference and validity result.
|
|
70
|
+
*/
|
|
71
|
+
static arithmeticOperation(left: GalaceanDataType | undefined, right: GalaceanDataType | undefined, operator: string): ArithmeticTypeResult;
|
|
72
|
+
/**
|
|
73
|
+
* Result type compatibility wrapper for existing inference consumers.
|
|
74
|
+
* @param a - Left operand type.
|
|
75
|
+
* @param b - Right operand type.
|
|
76
|
+
* @param operator - Arithmetic operator lexeme.
|
|
77
|
+
* @returns Inferred type or `TypeAny` when invalid or unresolved.
|
|
78
|
+
*/
|
|
79
|
+
static arithmeticResultType(a: GalaceanDataType | undefined, b: GalaceanDataType | undefined, operator?: string): GalaceanDataType | undefined;
|
|
80
|
+
private static _arithmeticFamily;
|
|
81
|
+
private static _vectorType;
|
|
82
|
+
private static _matrixType;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the component count of a vector type.
|
|
85
|
+
* @param type - Type to inspect.
|
|
86
|
+
* @returns Two, three, or four for vectors; otherwise zero.
|
|
87
|
+
*/
|
|
88
|
+
static vectorComponentCount(type: GalaceanDataType | undefined): number;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the total component count of a matrix type.
|
|
91
|
+
* @param type - Type to inspect.
|
|
92
|
+
* @returns Row count multiplied by column count, or zero for non-matrix types.
|
|
93
|
+
*/
|
|
94
|
+
static matrixComponentCount(type: GalaceanDataType | undefined): number;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the dimensions of a matrix type.
|
|
97
|
+
* @param type - Type to inspect.
|
|
98
|
+
* @returns Column and row counts, or `undefined` for non-matrix types.
|
|
99
|
+
*/
|
|
100
|
+
static matrixDimensions(type: GalaceanDataType | undefined): {
|
|
101
|
+
columns: number;
|
|
102
|
+
rows: number;
|
|
103
|
+
} | undefined;
|
|
104
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ChunkOutputCache, IncludeMap } from "../Preprocessor";
|
|
2
|
+
import type { ParserObjectPool } from "../ParserObjectPool";
|
|
3
|
+
import { type ParsedShaderPassData } from "./ParsedShaderPass";
|
|
4
|
+
import { ShaderTargetParser } from "./ShaderTargetParser";
|
|
5
|
+
/**
|
|
6
|
+
* Creates the offline parser that admits only parser-proven valid semantic facts.
|
|
7
|
+
* @param objectPool - Precompiler-owned allocator for synchronous parser requests.
|
|
8
|
+
* @returns Reusable parser whose proven semantic failures block artifact generation.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function createValidatedShaderTargetParser(objectPool?: ParserObjectPool): ShaderTargetParser;
|
|
12
|
+
/**
|
|
13
|
+
* Parses one shader pass for offline export with proven macro-conflict validation.
|
|
14
|
+
* @param source - Shader pass source before include expansion.
|
|
15
|
+
* @param includeMap - Canonical include paths mapped to chunk sources.
|
|
16
|
+
* @param cache - Precompiler-owned expanded-include cache.
|
|
17
|
+
* @param sourceFile - Canonical root source path used for includes and attribution.
|
|
18
|
+
* @param objectPool - Precompiler-owned synchronous parse allocator.
|
|
19
|
+
* @param parser - Reusable validated parser.
|
|
20
|
+
* @param sourceScopeStarts - Start offsets of inherited ShaderLab content layers.
|
|
21
|
+
* @returns Parsed pass with source-mapped blocking errors.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseValidatedShaderPass(source: string, includeMap: IncludeMap, cache: ChunkOutputCache, sourceFile: string | undefined, objectPool: ParserObjectPool, parser: ShaderTargetParser, sourceScopeStarts?: readonly number[]): ParsedShaderPassData;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { GalaceanDataType } from "../../common";
|
|
2
|
+
import { EShaderStage } from "../../common/enums/ShaderStage";
|
|
3
|
+
export declare enum GenericType {
|
|
4
|
+
GenType = 200,
|
|
5
|
+
GenIntType = 201,
|
|
6
|
+
GenUintType = 202,
|
|
7
|
+
GenBoolType = 203,
|
|
8
|
+
Mat = 204,
|
|
9
|
+
BoolVec = 205,
|
|
10
|
+
IntVec = 206,
|
|
11
|
+
UintVec = 207,
|
|
12
|
+
Vec = 208,
|
|
13
|
+
GVec4 = 209,
|
|
14
|
+
GSampler2D = 210,
|
|
15
|
+
GSampler3D = 211,
|
|
16
|
+
GSamplerCube = 212,
|
|
17
|
+
GSampler2DArray = 213
|
|
18
|
+
}
|
|
19
|
+
export type NonGenericGalaceanType = Exclude<GalaceanDataType, string>;
|
|
20
|
+
type BuiltinType = NonGenericGalaceanType | GenericType;
|
|
21
|
+
export declare class BuiltinFunction {
|
|
22
|
+
ident: string;
|
|
23
|
+
readonly args: BuiltinType[];
|
|
24
|
+
readonly scope: EShaderStage;
|
|
25
|
+
private _returnType;
|
|
26
|
+
private _realReturnType;
|
|
27
|
+
get realReturnType(): NonGenericGalaceanType;
|
|
28
|
+
private constructor();
|
|
29
|
+
static _create(ident: string, returnType: BuiltinType, ...args: BuiltinType[]): void;
|
|
30
|
+
static _createWithScope(ident: string, returnType: BuiltinType, scope: EShaderStage, ...args: BuiltinType[]): void;
|
|
31
|
+
static resolveOverload(funcName: string, callArgTypes: NonGenericGalaceanType[] | undefined): BuiltinFunction | undefined;
|
|
32
|
+
static isExist(ident: string): boolean;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GalaceanDataType } from "../../common";
|
|
2
|
+
import { EShaderStage } from "../../common/enums/ShaderStage";
|
|
3
|
+
import { ShaderBuiltinSemantic } from "../../ir/ShaderBuiltinSemantic";
|
|
4
|
+
export declare const BuiltinVariableTable: Map<string, BuiltinVariable>;
|
|
5
|
+
export declare class BuiltinVariable {
|
|
6
|
+
type: GalaceanDataType;
|
|
7
|
+
lexeme: string;
|
|
8
|
+
scope: EShaderStage;
|
|
9
|
+
semantic?: ShaderBuiltinSemantic;
|
|
10
|
+
private constructor();
|
|
11
|
+
static createVariable(lexeme: string, type: GalaceanDataType, scope?: EShaderStage, semantic?: ShaderBuiltinSemantic): void;
|
|
12
|
+
static getVar(ident: string): BuiltinVariable | undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ShaderTargetParser } from "./ShaderTargetParser";
|
|
2
|
+
export { Grammar } from "./Grammar";
|
|
3
|
+
export * from "./ParsedShaderPass";
|
|
4
|
+
export * from "./ParsedShaderPassHandle";
|
|
5
|
+
export * from "./ShaderIncludePath";
|
|
6
|
+
export * from "./RuntimePassParser";
|
|
7
|
+
export * from "./ValidatedPassParser";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ASTNode } from "../AST";
|
|
2
|
+
import { SymbolInfo } from "./SymbolInfo";
|
|
3
|
+
import type { VarSymbol } from "./VarSymbol";
|
|
4
|
+
export declare class FnSymbol extends SymbolInfo {
|
|
5
|
+
astNode: ASTNode.FunctionDefinition;
|
|
6
|
+
readonly localVariables: readonly VarSymbol[];
|
|
7
|
+
readonly calledFunctions: readonly FnSymbol[];
|
|
8
|
+
constructor(lexeme: string, astNode: ASTNode.FunctionDefinition, localVariables?: readonly VarSymbol[], calledFunctions?: readonly FnSymbol[]);
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GalaceanDataType } from "../../common";
|
|
2
|
+
import type { ASTNode } from "../AST";
|
|
3
|
+
export declare class SymbolDataType {
|
|
4
|
+
type: GalaceanDataType;
|
|
5
|
+
typeLexeme: string;
|
|
6
|
+
arraySpecifier?: ASTNode.ArraySpecifier;
|
|
7
|
+
/** Exact custom-struct declarations visible where this type was resolved. @internal */
|
|
8
|
+
structDeclarations: readonly ASTNode.StructSpecifier[];
|
|
9
|
+
constructor(type: GalaceanDataType, typeLexeme: string, arraySpecifier?: ASTNode.ArraySpecifier,
|
|
10
|
+
/** Exact custom-struct declarations visible where this type was resolved. @internal */
|
|
11
|
+
structDeclarations?: readonly ASTNode.StructSpecifier[]);
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IBaseSymbol } from "../../common/IBaseSymbol";
|
|
2
|
+
import { BranchSignature } from "../../common/BaseToken";
|
|
3
|
+
import { GalaceanDataType } from "../../common/types";
|
|
4
|
+
import { ASTNode } from "../AST";
|
|
5
|
+
import { SymbolDataType } from "./SymbolDataType";
|
|
6
|
+
export declare enum ESymbolType {
|
|
7
|
+
VAR = 0,
|
|
8
|
+
FN = 1,
|
|
9
|
+
STRUCT = 2,
|
|
10
|
+
Any = 3
|
|
11
|
+
}
|
|
12
|
+
export type SymbolAstNode = ASTNode.Initializer | ASTNode.StructSpecifier | ASTNode.FunctionDefinition | ASTNode.ParameterDeclarator | ASTNode.InitDeclaratorList | ASTNode.VariableDeclaration;
|
|
13
|
+
export declare class SymbolInfo implements IBaseSymbol {
|
|
14
|
+
ident: string;
|
|
15
|
+
type: ESymbolType | null;
|
|
16
|
+
astNode?: SymbolAstNode;
|
|
17
|
+
dataType?: SymbolDataType;
|
|
18
|
+
paramSignature?: GalaceanDataType[];
|
|
19
|
+
isInMacroBranch: boolean;
|
|
20
|
+
sourceScope: number;
|
|
21
|
+
/**
|
|
22
|
+
* Snapshot of the `#ifdef` stack at the declaration site. Empty means the declaration is
|
|
23
|
+
* unconditional (top-level). Non-empty means the declaration is only active when every
|
|
24
|
+
* constraint holds. `SymbolTable.getSymbol` filters candidates by
|
|
25
|
+
* `isBranchVisibleFrom(this.branchSignature, callsiteBranch)` — a reference inside a mutually
|
|
26
|
+
* exclusive branch never sees this symbol; a reference inside the same or a nested branch
|
|
27
|
+
* does. Mirrors `codegen`'s per-branch symbol visibility.
|
|
28
|
+
*/
|
|
29
|
+
branchSignature: BranchSignature;
|
|
30
|
+
constructor(ident: string, type: ESymbolType | null, astNode?: SymbolAstNode, dataType?: SymbolDataType, paramSignature?: GalaceanDataType[], isInMacroBranch?: boolean);
|
|
31
|
+
set(ident: string, symbolType: ESymbolType, astNode?: SymbolAstNode, dataType?: SymbolDataType, paramSignature?: GalaceanDataType[]): void;
|
|
32
|
+
equal(symbol: SymbolInfo): boolean;
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ASTNode } from "../AST";
|
|
2
|
+
import { SymbolDataType } from "./SymbolDataType";
|
|
3
|
+
import { SymbolInfo } from "./SymbolInfo";
|
|
4
|
+
export declare class VarSymbol extends SymbolInfo {
|
|
5
|
+
astNode: ASTNode.Initializer | ASTNode.ParameterDeclarator | ASTNode.InitDeclaratorList | ASTNode.VariableDeclaration;
|
|
6
|
+
readonly isGlobalVariable: boolean;
|
|
7
|
+
/** `const`-qualified — lets a const-expression check resolve identifier references to constants. */
|
|
8
|
+
readonly isConst: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Global variable without an initializer — Galacean's implicit uniform. The material system
|
|
11
|
+
* binds it at runtime. Read-only from the shader's perspective, so writes must be flagged as
|
|
12
|
+
* `InvalidAssignmentTarget`.
|
|
13
|
+
*/
|
|
14
|
+
readonly isUniform: boolean;
|
|
15
|
+
constructor(ident: string, dataType: SymbolDataType, isGlobalVariable: boolean, initAst: ASTNode.Initializer | ASTNode.ParameterDeclarator | ASTNode.InitDeclaratorList | ASTNode.VariableDeclaration, isConst?: boolean, isUniform?: boolean);
|
|
16
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BaseToken } from "../common/BaseToken";
|
|
2
|
+
import { ASTNode, TreeNode } from "./AST";
|
|
3
|
+
import { NoneTerminal } from "./GrammarSymbol";
|
|
4
|
+
import { SymbolDataType } from "./symbolTable/SymbolDataType";
|
|
5
|
+
import type { BranchSignature } from "../common/BaseToken";
|
|
6
|
+
import type { FnSymbol } from "./symbolTable/FnSymbol";
|
|
7
|
+
import type { ShaderBuiltinSemantic } from "../ir/ShaderBuiltinSemantic";
|
|
8
|
+
/**
|
|
9
|
+
* Effective syntax of a macro invocation under one proven source-macro configuration.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export interface MacroExpansionSyntax {
|
|
13
|
+
/** Some expansion or binding could not be proven; its execution effects remain unknown. */
|
|
14
|
+
readonly hasUnknownEffects?: boolean;
|
|
15
|
+
readonly branch: BranchSignature;
|
|
16
|
+
readonly arguments: readonly TreeNode[];
|
|
17
|
+
readonly references: readonly {
|
|
18
|
+
name: string;
|
|
19
|
+
call: boolean;
|
|
20
|
+
functions: readonly FnSymbol[];
|
|
21
|
+
builtinSemantic?: ShaderBuiltinSemantic;
|
|
22
|
+
indexed?: boolean;
|
|
23
|
+
}[];
|
|
24
|
+
/** Explicit writes, expressed as source identifiers, builtin semantics or retained argument syntax. */
|
|
25
|
+
readonly writtenTargets?: readonly (string | TreeNode)[];
|
|
26
|
+
/** The replacement itself is one assignment target, for aliases used outside the macro body. */
|
|
27
|
+
readonly valueTarget?: string | TreeNode;
|
|
28
|
+
readonly keywords: readonly number[];
|
|
29
|
+
}
|
|
30
|
+
export type TraceStackItem = NoneTerminal | BaseToken;
|
|
31
|
+
export declare class SymbolType extends SymbolDataType {
|
|
32
|
+
}
|
|
33
|
+
export declare class StructProp implements IParamInfo {
|
|
34
|
+
typeInfo: SymbolType;
|
|
35
|
+
ident: BaseToken;
|
|
36
|
+
mrtIndex?: number;
|
|
37
|
+
isInMacroBranch: boolean;
|
|
38
|
+
/** Whether the member carries the `flat` interpolation qualifier — integer varyings require it. */
|
|
39
|
+
isFlat: boolean;
|
|
40
|
+
constructor(typeInfo: SymbolType, ident: BaseToken, mrtIndex?: number, isInMacroBranch?: boolean,
|
|
41
|
+
/** Whether the member carries the `flat` interpolation qualifier — integer varyings require it. */
|
|
42
|
+
isFlat?: boolean);
|
|
43
|
+
}
|
|
44
|
+
export type NodeChild = TreeNode | BaseToken;
|
|
45
|
+
export type IParamInfo = {
|
|
46
|
+
ident?: BaseToken;
|
|
47
|
+
typeInfo?: SymbolType;
|
|
48
|
+
astNode?: ASTNode.ParameterDeclaration | ASTNode.MacroParamBlock;
|
|
49
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Condition } from "@galacean/engine-design";
|
|
2
|
+
import type { BranchSignature } from "../common/BaseToken";
|
|
3
|
+
/**
|
|
4
|
+
* A source condition whose parsed meaning or complete opaque identity is fixed at its directive.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export type SourcePreprocessorCondition = {
|
|
8
|
+
readonly kind: "expression";
|
|
9
|
+
readonly expression: Condition;
|
|
10
|
+
readonly versions: Readonly<Record<string, number>>;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "opaque";
|
|
13
|
+
readonly identity: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* One required condition or its negation in a preprocessor arm.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export interface PreprocessorConditionTerm {
|
|
20
|
+
readonly condition: SourcePreprocessorCondition;
|
|
21
|
+
readonly negated: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Source-owned truth and conjunctive predicates for an entire arm, including earlier alternatives.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export interface PreprocessorConditionalArm {
|
|
28
|
+
/** Truth relative to the enclosing parent, when all macro configurations agree. */
|
|
29
|
+
readonly value?: boolean;
|
|
30
|
+
/** Required predicates; absent when the source condition cannot be represented safely. */
|
|
31
|
+
readonly predicates?: readonly PreprocessorConditionTerm[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Captures definition versions for a fully expanded expression without changing its numeric semantics.
|
|
35
|
+
* @param expression - Parsed expression containing only constants and definition checks.
|
|
36
|
+
* @param versions - Current source macro mutation versions.
|
|
37
|
+
* @returns The expression and an independent snapshot of its definition dependencies.
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare function capturePreprocessorCondition(expression: Condition, versions: Readonly<Record<string, number>>): SourcePreprocessorCondition;
|
|
41
|
+
/**
|
|
42
|
+
* Proves that a set of narrower declarations collectively covers an inherited declaration.
|
|
43
|
+
* @param declarations - Alternative guards from narrower ShaderLab scopes.
|
|
44
|
+
* @param reference - Guard of the inherited declaration.
|
|
45
|
+
* @returns Whether the inherited declaration can be removed in every macro configuration.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare function canInheritanceBranchesCover(declarations: readonly BranchSignature[], reference: BranchSignature): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Classifies inheritance coverage without confusing a failed proof with a counterexample.
|
|
51
|
+
* @param declarations - Alternative guards from narrower ShaderLab scopes.
|
|
52
|
+
* @param reference - Guard of the inherited declaration.
|
|
53
|
+
* @returns True for coverage, false for a definite uncovered configuration, or undefined for unknown coverage.
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export declare function proveInheritanceBranchesCover(declarations: readonly BranchSignature[], reference: BranchSignature): boolean | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PreprocessorConditionTerm } from "./PreprocessorCondition";
|
|
2
|
+
type Predicates = readonly PreprocessorConditionTerm[] | boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Proves union coverage using shared numeric decision nodes instead of enumerating macro assignments.
|
|
5
|
+
* @param declarations - Alternative declaration guards, each expressed as a conjunction.
|
|
6
|
+
* @param reference - Guard of the inherited declaration.
|
|
7
|
+
* @returns True for coverage, false for a definite uncovered configuration, or undefined for invalid or exhausted proofs.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function provePreprocessorConditionCoverage(declarations: readonly Predicates[], reference: Predicates): boolean | undefined;
|
|
11
|
+
export {};
|