@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,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,29 @@
|
|
|
1
|
+
import type { ASTNode, TreeNode } from "./AST";
|
|
2
|
+
import type { NodeChild } from "./types";
|
|
3
|
+
/** AST nodes call back into the code generator through this interface, so AST stays decoupled from the concrete `CodeGenVisitor`. */
|
|
4
|
+
export interface ICodeGenVisitor {
|
|
5
|
+
cache(node: TreeNode, code: string): string;
|
|
6
|
+
getCachedCode(node: TreeNode): string | undefined;
|
|
7
|
+
defaultCodeGen(children: NodeChild[]): string;
|
|
8
|
+
visitPostfixExpression(node: ASTNode.PostfixExpression): string;
|
|
9
|
+
visitVariableIdentifier(node: ASTNode.VariableIdentifier): string;
|
|
10
|
+
visitFunctionCall(node: ASTNode.FunctionCall): string;
|
|
11
|
+
visitMacroCallFunction(node: ASTNode.MacroCallFunction): string;
|
|
12
|
+
visitStatementList(node: ASTNode.StatementList): string;
|
|
13
|
+
visitMacroDefine(node: ASTNode.MacroDefine): string;
|
|
14
|
+
visitSingleDeclaration(node: ASTNode.SingleDeclaration): string;
|
|
15
|
+
visitGlobalVariableDeclaration(node: ASTNode.VariableDeclaration): string;
|
|
16
|
+
visitDeclaration(node: ASTNode.Declaration): string;
|
|
17
|
+
visitFunctionParameterList(node: ASTNode.FunctionParameterList): string;
|
|
18
|
+
visitFunctionHeader(node: ASTNode.FunctionHeader): string;
|
|
19
|
+
visitJumpStatement(node: ASTNode.JumpStatement): string;
|
|
20
|
+
visitFunctionIdentifier(node: ASTNode.FunctionIdentifier): string;
|
|
21
|
+
/**
|
|
22
|
+
* Emits a type occurrence using the backend's declaration rules.
|
|
23
|
+
* @param node - Type occurrence with its captured declarations.
|
|
24
|
+
* @returns Generated type source.
|
|
25
|
+
*/
|
|
26
|
+
visitTypeSpecifier(node: ASTNode.TypeSpecifier): string;
|
|
27
|
+
visitStructSpecifier(node: ASTNode.StructSpecifier): string;
|
|
28
|
+
visitFunctionDefinition(node: ASTNode.FunctionDefinition): string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type BranchSignature } from "../common/BaseToken";
|
|
2
|
+
import type { MacroDefineList } from "../Preprocessor";
|
|
3
|
+
import { ASTNode } from "./AST";
|
|
4
|
+
import type SemanticAnalyzer from "./SemanticAnalyzer";
|
|
5
|
+
import type { MacroExpansionSyntax } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Retains source-ordered macro mutations separately from the codegen definition catalog.
|
|
8
|
+
* @param definitions - Analyzer request's macro catalog, used only as a lifetime identity.
|
|
9
|
+
* @param name - Macro being changed.
|
|
10
|
+
* @param offset - Mutation offset in preprocessed source.
|
|
11
|
+
* @param branch - Conditional constraints at the mutation.
|
|
12
|
+
* @param body - Replacement text, or undefined for an undefinition.
|
|
13
|
+
* @param parameters - Formal names for a function-like macro.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function recordMacroSyntaxEvent(definitions: MacroDefineList, name: string, offset: number, branch: BranchSignature, body?: string, parameters?: readonly string[]): void;
|
|
17
|
+
/**
|
|
18
|
+
* Captures expanded lexical references and arguments without parsing a second shader program.
|
|
19
|
+
* @param node - Macro invocation whose effective syntax is requested.
|
|
20
|
+
* @param analyzer - Binding and macro state for this analysis request.
|
|
21
|
+
* @param source - Preprocessed source used to choose collision-free argument markers.
|
|
22
|
+
* @returns Proven expansion alternatives; unresolved replacements remain unreported.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function captureMacroExpansion(node: ASTNode.MacroCallSymbol | ASTNode.MacroCallFunction, analyzer: SemanticAnalyzer, source: string): readonly MacroExpansionSyntax[];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PreprocessorConditionalArm } from "../preprocessor/PreprocessorCondition";
|
|
2
|
+
import type { BaseToken } from "../common/BaseToken";
|
|
3
|
+
import type { PreprocessorExpressionParseResult } from "@galacean/engine-design";
|
|
4
|
+
import { ShaderPosition } from "../common/ShaderPosition";
|
|
5
|
+
import type { MacroDefineList } from "../Preprocessor";
|
|
6
|
+
import { type ChunkOutputCache, type IncludeMap } from "../Preprocessor";
|
|
7
|
+
import { ShaderClueIR, type ShaderSourceMapSegment } from "../ir";
|
|
8
|
+
import type { ShaderTargetParser } from "./ShaderTargetParser";
|
|
9
|
+
import type { ParserObjectPool } from "../ParserObjectPool";
|
|
10
|
+
/**
|
|
11
|
+
* Request-owned parser output shared read-only by analysis and backend generation.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export interface ParsedShaderPassData {
|
|
15
|
+
/** Neutral typed IR, or `null` when parsing could not produce a program. */
|
|
16
|
+
readonly ir: ShaderClueIR | null;
|
|
17
|
+
/** Source after recursive `#include` expansion. */
|
|
18
|
+
readonly expandedSource: string;
|
|
19
|
+
/** Mapping from expanded offsets to original Shader and ShaderChunk sources. */
|
|
20
|
+
readonly sourceMap: readonly ShaderSourceMapSegment[];
|
|
21
|
+
/** Preprocessor, syntax, and parser-semantic errors. */
|
|
22
|
+
readonly errors: readonly Error[];
|
|
23
|
+
/** Complete preprocessor expression trees keyed by normalized directive text. */
|
|
24
|
+
readonly preprocessorExpressions: ReadonlyMap<string, PreprocessorExpressionParseResult>;
|
|
25
|
+
/** Preprocessor, syntax, and parser-proven semantic errors that prevent backend generation. */
|
|
26
|
+
readonly blockingErrors: readonly Error[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Original source and range resolved from an expanded shader-pass range.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export interface MappedShaderSourceRange {
|
|
33
|
+
readonly source: string;
|
|
34
|
+
readonly sourceFile?: string;
|
|
35
|
+
readonly start: ShaderPosition;
|
|
36
|
+
readonly end: ShaderPosition;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Maps one expanded pass range to the Shader or ShaderChunk that produced it.
|
|
40
|
+
* @param startOffset - Zero-based start offset in expanded source.
|
|
41
|
+
* @param endOffset - Zero-based exclusive end offset in expanded source.
|
|
42
|
+
* @param segments - Parser-owned include source map.
|
|
43
|
+
* @returns Original source and local range, or `undefined` outside mapped text.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export declare function mapExpandedShaderRange(startOffset: number, endOffset: number, segments: readonly ShaderSourceMapSegment[]): MappedShaderSourceRange | undefined;
|
|
47
|
+
export declare function mapExpandedShaderError(error: Error, expandedSource: string, segments: readonly ShaderSourceMapSegment[]): Error;
|
|
48
|
+
/**
|
|
49
|
+
* Minimal token source consumed by the shared pass parser.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export interface ShaderPassLexer {
|
|
53
|
+
readonly preprocessorExpressions: ReadonlyMap<string, PreprocessorExpressionParseResult>;
|
|
54
|
+
tokenize(): Generator<BaseToken, BaseToken>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Runs the shared preprocessing and parser pipeline with a caller-selected lexer/parser policy.
|
|
58
|
+
* @param source - GLSL source for one ShaderLab pass.
|
|
59
|
+
* @param includeMap - Canonical include paths mapped to chunk sources.
|
|
60
|
+
* @param cache - Request-owned cache of expanded chunks.
|
|
61
|
+
* @param basePathForIncludeKey - Internal base URL for resolving relative includes.
|
|
62
|
+
* @param createLexer - Creates the runtime or analyzer lexer for the expanded source.
|
|
63
|
+
* @param createParser - Creates a request-owned parser backed by shared immutable grammar tables.
|
|
64
|
+
* @param sourceFile - Optional canonical root location for relative includes and attribution.
|
|
65
|
+
* @param objectPool - Optional pool for a synchronous consumer that does not retain parsed passes.
|
|
66
|
+
* @param trackSourceMap - Whether to retain include-source mapping for this parse.
|
|
67
|
+
* @param sourceScopeStarts - Start offsets of inherited ShaderLab content layers.
|
|
68
|
+
* @returns Request-owned parsed-pass data whose public containers are read-only.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export declare function parseShaderPassWith(source: string, includeMap: IncludeMap, cache: ChunkOutputCache, basePathForIncludeKey: string, createLexer: (expandedSource: string, macroDefineList: MacroDefineList, objectPool?: ParserObjectPool, conditionalArms?: ReadonlyMap<number, PreprocessorConditionalArm>) => ShaderPassLexer, createParser: (expandedSource: string, objectPool?: ParserObjectPool) => ShaderTargetParser, sourceFile?: string, objectPool?: ParserObjectPool, trackSourceMap?: boolean, sourceScopeStarts?: readonly number[]): ParsedShaderPassData;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ShaderCoreInfo } from "../ir/ShaderCoreInfo";
|
|
2
|
+
import type { ParsedShaderPassData } from "./ParsedShaderPass";
|
|
3
|
+
import type { ParsedShaderPass } from "../ParsedShaderPass";
|
|
4
|
+
export type { ParsedShaderPass } from "../ParsedShaderPass";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export interface ParsedShaderPassPayload {
|
|
7
|
+
readonly data: ParsedShaderPassData;
|
|
8
|
+
readonly vertexEntry: string;
|
|
9
|
+
readonly fragmentEntry: string;
|
|
10
|
+
readonly coreInfo?: ShaderCoreInfo;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates the opaque public handle for a request-owned parsed pass.
|
|
14
|
+
* @param data - Internal parser output.
|
|
15
|
+
* @param vertexEntry - Vertex entry function name declared by the ShaderLab pass.
|
|
16
|
+
* @param fragmentEntry - Fragment entry function name declared by the ShaderLab pass.
|
|
17
|
+
* @param coreInfo - Optional parser-owned stage facts already derived by the analyzer.
|
|
18
|
+
* @returns Immutable handle accepted by backend generation.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export declare function createParsedShaderPass(data: ParsedShaderPassData, vertexEntry: string, fragmentEntry: string, coreInfo?: ShaderCoreInfo): ParsedShaderPass;
|
|
22
|
+
/**
|
|
23
|
+
* Reads the parser-owned payload behind a public pass handle.
|
|
24
|
+
* @param pass - Handle returned by `createParsedShaderPass`.
|
|
25
|
+
* @returns Internal parser data, ShaderLab entries, and any reusable stage facts.
|
|
26
|
+
* @throws TypeError when the value was not created by this parser package instance.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function getParsedShaderPassPayload(pass: ParsedShaderPass): ParsedShaderPassPayload;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ShaderRange } from "../common";
|
|
2
|
+
import { type BranchSignature } from "../common/BaseToken";
|
|
3
|
+
import { ASTNode, TreeNode } from "./AST";
|
|
4
|
+
/**
|
|
5
|
+
* A semantic failure proven from parser-owned AST and symbol facts.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface ParserSemanticIssue {
|
|
9
|
+
/** Stable diagnostic identifier shared by authoring and offline validation. */
|
|
10
|
+
readonly code: string;
|
|
11
|
+
/** Human-readable description of the proven failure. */
|
|
12
|
+
readonly message: string;
|
|
13
|
+
/** Source range that should be highlighted for the failure. */
|
|
14
|
+
readonly location: ShaderRange;
|
|
15
|
+
/** Configuration proving a conditional failure; absent for unconditional semantic rules. */
|
|
16
|
+
readonly branch?: BranchSignature;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parser-owned semantic rules shared by Analyzer and offline admission.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare class ParserSemanticValidation {
|
|
23
|
+
/**
|
|
24
|
+
* Collects proven semantic failures from a complete parser IR.
|
|
25
|
+
* @param root - Parsed translation-unit root.
|
|
26
|
+
* @returns Failures from reachable source branches in source order.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
static collect(root: TreeNode): ParserSemanticIssue[];
|
|
30
|
+
/**
|
|
31
|
+
* Describes why an expression cannot be modified.
|
|
32
|
+
* @param node - Candidate assignment or increment target.
|
|
33
|
+
* @returns A concrete reason only when every resolved symbol candidate is non-modifiable.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
static nonAssignableReason(node: TreeNode): string | undefined;
|
|
37
|
+
private static _vectorComponentCount;
|
|
38
|
+
/**
|
|
39
|
+
* Validates output arguments separately for each provably reachable function declaration.
|
|
40
|
+
* @param node - Function call with captured overload candidates.
|
|
41
|
+
* @returns Invalid targets with their candidate's effective branch; unknown bindings remain unchecked.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
static outputArgumentIssues(node: ASTNode.FunctionCallGeneric): ParserSemanticIssue[];
|
|
45
|
+
/**
|
|
46
|
+
* Validates an assignment target from parser-owned symbol identities.
|
|
47
|
+
* @param node - Assignment expression to inspect.
|
|
48
|
+
* @returns A proven invalid-target issue, or `undefined` for valid or unresolved targets.
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
static assignmentTargetIssue(node: ASTNode.AssignmentExpression): ParserSemanticIssue | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Validates the target of a prefix or postfix increment operation.
|
|
54
|
+
* @param node - Unary or postfix expression to inspect.
|
|
55
|
+
* @returns A proven invalid-target issue, or `undefined` for other operators and modifiable targets.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
static incrementTargetIssue(node: ASTNode.UnaryExpression | ASTNode.PostfixExpression): ParserSemanticIssue | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Validates assignment operand compatibility.
|
|
61
|
+
* @param node - Assignment expression to inspect.
|
|
62
|
+
* @returns A proven type issue, or `undefined` when compatible or unresolved.
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
static assignmentTypeIssue(node: ASTNode.AssignmentExpression): ParserSemanticIssue | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Validates a condition that must be a scalar boolean.
|
|
68
|
+
* @param condition - Typed condition expression.
|
|
69
|
+
* @param label - User-facing construct name such as `if condition`.
|
|
70
|
+
* @returns A proven non-boolean issue, or `undefined` when valid or unresolved.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
static nonBoolConditionIssue(condition: ASTNode.ExpressionAstNode, label: string): ParserSemanticIssue | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Resolves and validates an `if` condition.
|
|
76
|
+
* @param node - Selection statement.
|
|
77
|
+
* @returns A proven condition issue, or `undefined`.
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
static selectionConditionIssue(node: ASTNode.SelectionStatement): ParserSemanticIssue | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Resolves and validates a loop condition.
|
|
83
|
+
* @param node - Iteration statement.
|
|
84
|
+
* @returns A proven condition issue, or `undefined`.
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
static iterationConditionIssue(node: ASTNode.IterationStatement): ParserSemanticIssue | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Validates a ternary condition.
|
|
90
|
+
* @param node - Conditional expression.
|
|
91
|
+
* @returns A proven condition issue, or `undefined`.
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
static ternaryConditionIssue(node: ASTNode.ConditionalExpression): ParserSemanticIssue | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Validates the component contract of a builtin constructor.
|
|
97
|
+
* @param node - Function-call node representing a possible constructor.
|
|
98
|
+
* @returns A proven constructor issue, or `undefined` when valid or unresolved.
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
static constructorIssue(node: ASTNode.FunctionCallGeneric): ParserSemanticIssue | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Validates that a function return type can be passed by value.
|
|
104
|
+
* @param node - Function declarator with its exact parser-resolved return type.
|
|
105
|
+
* @returns A proven opaque-return issue, or `undefined` when constructible or unresolved.
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
static functionReturnTypeIssue(node: ASTNode.FunctionDeclarator): ParserSemanticIssue | undefined;
|
|
109
|
+
private static _structContainsSampler;
|
|
110
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChunkOutputCache, IncludeMap } from "../Preprocessor";
|
|
2
|
+
import type { ShaderSourceMapSegment } from "../ir";
|
|
3
|
+
import { type ParsedShaderPassData } from "./ParsedShaderPass";
|
|
4
|
+
/** Maps a range in expanded pass text back to its source chunk. */
|
|
5
|
+
export type PreprocessSourceMapSegment = ShaderSourceMapSegment;
|
|
6
|
+
/**
|
|
7
|
+
* Parses one shader pass into neutral IR and parse-stage diagnostics.
|
|
8
|
+
* @param source - GLSL source for the shader pass.
|
|
9
|
+
* @param includeMap - Include-path lookup table.
|
|
10
|
+
* @param cache - Cache for expanded include chunks.
|
|
11
|
+
* @param sourceFile - Canonical path of the root Shader source.
|
|
12
|
+
* @param sourceScopeStarts - Start offsets of inherited ShaderLab content layers.
|
|
13
|
+
* @returns Neutral IR, diagnostics, and preprocessed pass text.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseShaderPass(source: string, includeMap: IncludeMap, cache: ChunkOutputCache, sourceFile?: string, sourceScopeStarts?: readonly number[]): ParsedShaderPassData;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ChunkOutputCache, type IncludeMap } from "../Preprocessor";
|
|
2
|
+
import type { ParsedShaderPassData } from "./ParsedShaderPass";
|
|
3
|
+
import { ShaderTargetParser } from "./ShaderTargetParser";
|
|
4
|
+
import type { ParserObjectPool } from "../ParserObjectPool";
|
|
5
|
+
/**
|
|
6
|
+
* Creates the lean parser used by runtime shader compilation.
|
|
7
|
+
* @param objectPool - Compiler-owned allocator for synchronous parser requests.
|
|
8
|
+
* @returns Reusable runtime parser without authoring diagnostics.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function createRuntimeShaderTargetParser(objectPool?: ParserObjectPool): ShaderTargetParser;
|
|
12
|
+
/**
|
|
13
|
+
* Parses one shader pass using the lean runtime lexer.
|
|
14
|
+
* @param source - GLSL source for one ShaderLab pass.
|
|
15
|
+
* @param includeMap - Canonical include paths mapped to chunk sources.
|
|
16
|
+
* @param cache - Request-owned expanded-include cache.
|
|
17
|
+
* @param sourceFile - Canonical root source path used for relative includes and error attribution.
|
|
18
|
+
* @param objectPool - Compiler-owned pool used only while synchronously consuming this pass.
|
|
19
|
+
* @param runtimeParser - Compiler-owned parser whose source is replaced for each pass.
|
|
20
|
+
* @param sourceScopeStarts - ShaderLab inheritance boundaries supplied by the source parser.
|
|
21
|
+
* @returns Request-owned parser output suitable for GLES generation.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseRuntimeShaderPass(source: string, includeMap: IncludeMap, cache: ChunkOutputCache, sourceFile?: string, objectPool?: ParserObjectPool, runtimeParser?: ShaderTargetParser, sourceScopeStarts?: readonly number[]): ParsedShaderPassData;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { GalaceanDataType, ShaderRange } from "../common";
|
|
2
|
+
import type { BranchCoverage, BranchSignature, DeclarationCoexistence } from "../common/BaseToken";
|
|
3
|
+
import type { BranchSemantics } from "../common/BranchSemantics";
|
|
4
|
+
import { SymbolTable } from "../common/SymbolTable";
|
|
5
|
+
import { SymbolTableStack } from "../common/SymbolTableStack";
|
|
6
|
+
import { FnSymbol, SymbolInfo, VarSymbol } from "../parser/symbolTable";
|
|
7
|
+
import { ASTNode, TreeNode } from "./AST";
|
|
8
|
+
import { ShaderData } from "./ShaderInfo";
|
|
9
|
+
import type { SemanticAmbiguityKind, SemanticDiagnostics } from "./SemanticDiagnostics";
|
|
10
|
+
import { NodeChild } from "./types";
|
|
11
|
+
import { MacroDefineList } from "../Preprocessor";
|
|
12
|
+
import type { ParserObjectPool } from "../ParserObjectPool";
|
|
13
|
+
import type { ShaderSourceScope } from "../ir";
|
|
14
|
+
export type TranslationRule<T = unknown> = (sa: SemanticAnalyzer, ...tokens: NodeChild[]) => T;
|
|
15
|
+
type RedefinitionConflict = Exclude<DeclarationCoexistence, "exclusive"> | "none";
|
|
16
|
+
interface FunctionCapture {
|
|
17
|
+
readonly header: ASTNode.FunctionDeclarator;
|
|
18
|
+
readonly localVariables: VarSymbol[];
|
|
19
|
+
readonly calledFunctions: FnSymbol[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
* The semantic analyzer of `ShaderCompiler` compiler.
|
|
24
|
+
* - Build symbol table
|
|
25
|
+
* - Static analysis
|
|
26
|
+
*/
|
|
27
|
+
export default class SemanticAnalyzer {
|
|
28
|
+
readonly branchSemantics?: BranchSemantics;
|
|
29
|
+
readonly semanticDiagnostics?: SemanticDiagnostics;
|
|
30
|
+
/**
|
|
31
|
+
* Request allocator used only by synchronous compiler-owned parses.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
readonly objectPool?: ParserObjectPool;
|
|
35
|
+
/** Request-owned lookup key reused during this parser session. @internal */
|
|
36
|
+
readonly lookupSymbol: SymbolInfo;
|
|
37
|
+
/** Request-owned scratch output for array-size symbol resolution. @internal */
|
|
38
|
+
readonly arraySymbolScratch: SymbolInfo[];
|
|
39
|
+
/** Request-owned scratch output for overload resolution. @internal */
|
|
40
|
+
readonly overloadScratch: SymbolInfo[];
|
|
41
|
+
/** Request-owned scratch output for struct resolution. @internal */
|
|
42
|
+
readonly structScratch: SymbolInfo[];
|
|
43
|
+
/**
|
|
44
|
+
* Request-owned nearest-scope output for secondary runtime-reference probes.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
readonly runtimeLookupScratch: SymbolInfo[];
|
|
48
|
+
/**
|
|
49
|
+
* Request-owned runtime-owner candidates, including conditional outer-scope fallbacks.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
readonly runtimeFallbackScratch: SymbolInfo[];
|
|
53
|
+
semanticStack: TreeNode[];
|
|
54
|
+
acceptRule?: TranslationRule;
|
|
55
|
+
symbolTableStack: SymbolTableStack<SymbolInfo, SymbolTable<SymbolInfo>>;
|
|
56
|
+
private readonly _functionCaptures;
|
|
57
|
+
private _shaderData;
|
|
58
|
+
private _translationRules;
|
|
59
|
+
private _sourceScopes;
|
|
60
|
+
private readonly _inheritedDeclarations;
|
|
61
|
+
private _macroDefineList;
|
|
62
|
+
readonly errors: Error[];
|
|
63
|
+
readonly diagnosticsEnabled: boolean;
|
|
64
|
+
inMacroDefinition: boolean;
|
|
65
|
+
/** Ambiguity diagnostic keys already emitted in this pass. Reset in `reset()`. */
|
|
66
|
+
readonly _ambiguousReported: Set<string>;
|
|
67
|
+
get shaderData(): ShaderData;
|
|
68
|
+
get macroDefineList(): MacroDefineList;
|
|
69
|
+
/**
|
|
70
|
+
* Function identity whose body is currently being parsed, if a declarator is active.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
get currentFunctionHeader(): ASTNode.FunctionDeclarator | undefined;
|
|
74
|
+
constructor(branchSemantics?: BranchSemantics, semanticDiagnostics?: SemanticDiagnostics,
|
|
75
|
+
/**
|
|
76
|
+
* Request allocator used only by synchronous compiler-owned parses.
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
objectPool?: ParserObjectPool, diagnosticsEnabled?: boolean);
|
|
80
|
+
reset(macroDefineList: MacroDefineList): void;
|
|
81
|
+
pushScope(): void;
|
|
82
|
+
popScope(): SymbolTable<SymbolInfo>;
|
|
83
|
+
/**
|
|
84
|
+
* Binds the immutable grammar translation table shared by parser sessions.
|
|
85
|
+
* @param rules - Translation callbacks indexed by production ID.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
setTranslationRules(rules: readonly (TranslationRule | undefined)[]): void;
|
|
89
|
+
/**
|
|
90
|
+
* Replaces the inheritance ranges for the next semantic-analysis request.
|
|
91
|
+
* @param sourceScopes - Ordered expanded source ranges carrying ShaderLab inheritance scopes.
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
setSourceScopes(sourceScopes: readonly ShaderSourceScope[]): void;
|
|
95
|
+
/**
|
|
96
|
+
* Assigns the ShaderLab inheritance scope containing a declaration.
|
|
97
|
+
* @param symbol - Symbol created for the declaration.
|
|
98
|
+
* @param location - Declaration range in expanded pass source.
|
|
99
|
+
* @returns The same symbol with its source scope assigned.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
assignSourceScope<T extends SymbolInfo>(symbol: T, location: ShaderRange): T;
|
|
103
|
+
getTranslationRule(pid: number): TranslationRule | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Opens a declarator's capture without overwriting an enclosing function's facts.
|
|
106
|
+
* @param header - Declarator that owns references until its prototype or definition ends.
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
beginFunction(header: ASTNode.FunctionDeclarator): void;
|
|
110
|
+
/**
|
|
111
|
+
* Closes the active declarator and restores the enclosing function's capture.
|
|
112
|
+
* @returns Facts owned by the completed prototype or definition.
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
endFunction(): FunctionCapture;
|
|
116
|
+
/**
|
|
117
|
+
* Records a local variable in the active function capture.
|
|
118
|
+
* @param variable - Variable declared in the current body.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
recordFunctionVariable(variable: VarSymbol): void;
|
|
122
|
+
/**
|
|
123
|
+
* Records a resolved call in the active function capture.
|
|
124
|
+
* @param fn - Exact function declaration selected by parser lookup.
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
recordFunctionCall(fn: FnSymbol): void;
|
|
128
|
+
/**
|
|
129
|
+
* Reports a declaration conflict only when branch coexistence is proven.
|
|
130
|
+
* @param loc - Conflicting declaration range.
|
|
131
|
+
* @param symbol - Declaration whose remaining inherited conflicts are checked after its scope is complete.
|
|
132
|
+
* @param conflict - Proven or unresolved coexistence state.
|
|
133
|
+
*/
|
|
134
|
+
reportRedefinition(loc: ShaderRange, symbol: SymbolInfo, conflict: RedefinitionConflict): void;
|
|
135
|
+
/** Resolves inherited diagnostics after every declaration in the pass is available. @internal */
|
|
136
|
+
finalizeInheritance(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Reports a missing declaration only when a reachable uncovered configuration is proven.
|
|
139
|
+
* @param loc - Reference range.
|
|
140
|
+
* @param subjectKind - Referenced symbol category.
|
|
141
|
+
* @param name - Referenced symbol name.
|
|
142
|
+
* @param coverage - Branch coverage result.
|
|
143
|
+
*/
|
|
144
|
+
reportBranchAvailability(loc: ShaderRange, subjectKind: "Function" | "Struct" | "Identifier", name: string, coverage: BranchCoverage): void;
|
|
145
|
+
/**
|
|
146
|
+
* Emit one macro-branch ambiguity diagnostic per semantic projection and pass.
|
|
147
|
+
* @param loc - Source range of the ambiguous reference.
|
|
148
|
+
* @param key - Stable projection key, such as a variable name or `Struct.member`.
|
|
149
|
+
* @param kind - Structured ambiguity category.
|
|
150
|
+
* @param name - Symbol or member name.
|
|
151
|
+
* @param owner - Struct owner for member ambiguities.
|
|
152
|
+
*/
|
|
153
|
+
reportBranchAmbiguity(loc: ShaderRange, key: string, kind: SemanticAmbiguityKind, name: string, owner?: string): void;
|
|
154
|
+
/** @internal */
|
|
155
|
+
reportNonConstArraySize(loc: ShaderRange): void;
|
|
156
|
+
/** @internal */
|
|
157
|
+
reportExpectedSampler(loc: ShaderRange, functionName: string, actualType: GalaceanDataType): void;
|
|
158
|
+
/** @internal */
|
|
159
|
+
reportNoMatchingOverload(loc: ShaderRange, functionName: string): void;
|
|
160
|
+
/** @internal */
|
|
161
|
+
reportUndeclaredStructMember(loc: ShaderRange, structName: string, memberName: string): void;
|
|
162
|
+
/** @internal */
|
|
163
|
+
canBranchesOverlap(left: BranchSignature, right: BranchSignature): boolean;
|
|
164
|
+
/** @internal */
|
|
165
|
+
canDeclarationsCoexist(earlier: BranchSignature, later: BranchSignature): boolean;
|
|
166
|
+
/** @internal */
|
|
167
|
+
getBranchCoverage(candidates: readonly BranchSignature[], callSiteBranch: BranchSignature): BranchCoverage;
|
|
168
|
+
/** @internal */
|
|
169
|
+
isBranchVisibleFrom(defBranch: BranchSignature, callSiteBranch: BranchSignature): boolean;
|
|
170
|
+
private _report;
|
|
171
|
+
/** Suppress diagnostics from paths the lexer has proven cannot reach the generated shader. */
|
|
172
|
+
private _isCurrentBranchReachable;
|
|
173
|
+
}
|
|
174
|
+
export {};
|