@galacean/engine-design 2.0.0-alpha.6 → 2.0.0-alpha.60
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/dist/main.js +1094 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +1081 -0
- package/dist/module.js.map +1 -0
- package/package.json +3 -2
- package/types/index.d.ts +2 -2
- package/types/physics/ICollider.d.ts +6 -3
- package/types/physics/ICollision.d.ts +6 -3
- package/types/physics/IDynamicCollider.d.ts +20 -8
- package/types/physics/IPhysics.d.ts +6 -16
- package/types/physics/IPhysicsEvents.d.ts +25 -0
- package/types/physics/IPhysicsMaterial.d.ts +10 -0
- package/types/physics/IPhysicsScene.d.ts +84 -23
- package/types/physics/IStaticCollider.d.ts +10 -0
- package/types/physics/index.d.ts +2 -1
- package/types/physics/joints/IJoint.d.ts +1 -1
- package/types/physics/shape/IColliderShape.d.ts +5 -0
- package/types/physics/shape/IMeshColliderShape.d.ts +4 -5
- package/types/shader-compiler/ICondition.d.ts +131 -0
- package/types/shader-compiler/IPrecompiledShader.d.ts +20 -0
- package/types/shader-compiler/IShaderCompiler.d.ts +33 -0
- package/types/shader-compiler/IShaderProgramSource.d.ts +14 -0
- package/types/shader-compiler/PreprocessorExpression.d.ts +174 -0
- package/types/shader-compiler/ShaderIncludePath.d.ts +7 -0
- package/types/shader-compiler/index.d.ts +12 -0
- package/types/shader-compiler/shaderSource/IShaderPassSource.d.ts +34 -0
- package/types/spine/ISpineAnimation.d.ts +4 -0
- package/types/spine/ISpineAnimationState.d.ts +17 -0
- package/types/spine/ISpineAnimationStateData.d.ts +5 -0
- package/types/spine/ISpineAnimationStateListener.d.ts +10 -0
- package/types/spine/ISpineBone.d.ts +21 -0
- package/types/spine/ISpineBoneData.d.ts +3 -0
- package/types/spine/ISpineConstraint.d.ts +5 -0
- package/types/spine/ISpineConstraintData.d.ts +3 -0
- package/types/spine/ISpineEvent.d.ts +9 -0
- package/types/spine/ISpineGeometry.d.ts +17 -0
- package/types/spine/ISpinePhysics.d.ts +7 -0
- package/types/spine/ISpinePhysicsConstraint.d.ts +11 -0
- package/types/spine/ISpineRuntime.d.ts +52 -0
- package/types/spine/ISpineSkeleton.d.ts +21 -0
- package/types/spine/ISpineSkeletonData.d.ts +15 -0
- package/types/spine/ISpineSkin.d.ts +5 -0
- package/types/spine/ISpineSlot.d.ts +9 -0
- package/types/spine/ISpineTextureAtlas.d.ts +6 -0
- package/types/spine/ISpineTrackEntry.d.ts +23 -0
- package/types/spine/SpineCapability.d.ts +8 -0
- package/types/spine/index.d.ts +21 -0
- package/types/xr/IXRDevice.d.ts +3 -4
- package/types/xr/IXRSession.d.ts +7 -7
- package/types/renderingHardwareInterface/IHardwareRenderer.d.ts +0 -6
- package/types/renderingHardwareInterface/IPlatformPrimitive.d.ts +0 -5
- package/types/renderingHardwareInterface/IPlatformShaderProgram.d.ts +0 -4
- package/types/renderingHardwareInterface/index.d.ts +0 -3
- package/types/shader-lab/IShaderLab.d.ts +0 -22
- package/types/shader-lab/IShaderProgramSource.d.ts +0 -4
- package/types/shader-lab/index.d.ts +0 -8
- package/types/shader-lab/shaderSource/IShaderPassSource.d.ts +0 -13
- /package/types/{shader-lab → shader-compiler}/shaderSource/IRenderStates.d.ts +0 -0
- /package/types/{shader-lab → shader-compiler}/shaderSource/IShaderPosition.d.ts +0 -0
- /package/types/{shader-lab → shader-compiler}/shaderSource/IShaderSource.d.ts +0 -0
- /package/types/{shader-lab → shader-compiler}/shaderSource/IStatement.d.ts +0 -0
- /package/types/{shader-lab → shader-compiler}/shaderSource/ISubShaderSource.d.ts +0 -0
package/dist/module.js
ADDED
|
@@ -0,0 +1,1081 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function assign(target) {
|
|
3
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return target;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
return _extends.apply(this, arguments);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function _type_of(obj) {
|
|
15
|
+
"@swc/helpers - typeof";
|
|
16
|
+
|
|
17
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _array_like_to_array(arr, len) {
|
|
21
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
22
|
+
|
|
23
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
24
|
+
|
|
25
|
+
return arr2;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
29
|
+
if (!o) return;
|
|
30
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
31
|
+
|
|
32
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
33
|
+
|
|
34
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
35
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
36
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
40
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
41
|
+
|
|
42
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
43
|
+
// Fallback for engines without symbol support
|
|
44
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
45
|
+
if (it) o = it;
|
|
46
|
+
|
|
47
|
+
var i = 0;
|
|
48
|
+
|
|
49
|
+
return function() {
|
|
50
|
+
if (i >= o.length) return { done: true };
|
|
51
|
+
|
|
52
|
+
return { done: false, value: o[i++] };
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var binaryPrecedence = {
|
|
60
|
+
"||": 1,
|
|
61
|
+
"&&": 2,
|
|
62
|
+
"|": 3,
|
|
63
|
+
"^": 4,
|
|
64
|
+
"&": 5,
|
|
65
|
+
"==": 6,
|
|
66
|
+
"!=": 6,
|
|
67
|
+
"<": 7,
|
|
68
|
+
"<=": 7,
|
|
69
|
+
">": 7,
|
|
70
|
+
">=": 7,
|
|
71
|
+
"<<": 8,
|
|
72
|
+
">>": 8,
|
|
73
|
+
"+": 9,
|
|
74
|
+
"-": 9,
|
|
75
|
+
"*": 10,
|
|
76
|
+
"/": 10,
|
|
77
|
+
"%": 10
|
|
78
|
+
};
|
|
79
|
+
var MAX_EXPRESSION_NESTING = 256;
|
|
80
|
+
var MAX_MACRO_EXPANSION_DEPTH = 256;
|
|
81
|
+
var MAX_MACRO_EXPANSION_TOKENS = 65536;
|
|
82
|
+
/**
|
|
83
|
+
* Parses the complete integer-expression grammar used by `#if` and `#elif`.
|
|
84
|
+
* @param expression - Text after the preprocessor directive.
|
|
85
|
+
* @returns A serializable tree or a structured parse failure.
|
|
86
|
+
*/ function parsePreprocessorExpression(expression) {
|
|
87
|
+
return new ExpressionParser(expression).parse();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Resolves `defined` operators and removes comments with the expression parser's tokenization rules.
|
|
91
|
+
* @param expression - Expression before ordinary macro replacement.
|
|
92
|
+
* @param isDefined - Resolves whether one macro name is defined, or returns `undefined` when external state decides.
|
|
93
|
+
* @returns Token-normalized expression with every known `defined` operator replaced by `0` or `1`.
|
|
94
|
+
*/ function resolvePreprocessorDefinedOperators(expression, isDefined) {
|
|
95
|
+
var tokens = tokenize(expression);
|
|
96
|
+
var parts = [];
|
|
97
|
+
for(var index = 0; index < tokens.length - 1; index++){
|
|
98
|
+
var token = tokens[index];
|
|
99
|
+
if (token.kind !== "identifier" || token.text !== "defined") {
|
|
100
|
+
parts.push(token.text);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
var next = tokens[index + 1];
|
|
104
|
+
var parenthesized = (next == null ? void 0 : next.text) === "(";
|
|
105
|
+
var name = tokens[index + (parenthesized ? 2 : 1)];
|
|
106
|
+
var close = parenthesized ? tokens[index + 3] : name;
|
|
107
|
+
if ((name == null ? void 0 : name.kind) !== "identifier" || name.text === "defined" || parenthesized && (close == null ? void 0 : close.text) !== ")") {
|
|
108
|
+
parts.push(token.text);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
var defined = isDefined(name.text);
|
|
112
|
+
if (defined === undefined) {
|
|
113
|
+
parts.push("defined");
|
|
114
|
+
if (parenthesized) parts.push("(");
|
|
115
|
+
parts.push(name.text);
|
|
116
|
+
if (parenthesized) parts.push(")");
|
|
117
|
+
} else {
|
|
118
|
+
parts.push(defined ? "1" : "0");
|
|
119
|
+
}
|
|
120
|
+
index += parenthesized ? 3 : 1;
|
|
121
|
+
}
|
|
122
|
+
return parts.join(" ");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Expands object-like and function-like macros with the expression parser's tokenization rules.
|
|
126
|
+
* @param expression - Expression after any caller-owned `defined` resolution.
|
|
127
|
+
* @param resolveMacro - Resolves source or runtime macro definitions by name.
|
|
128
|
+
* @returns Token-normalized expansion or a deterministic depth error.
|
|
129
|
+
*/ function expandPreprocessorExpressionMacros(expression, resolveMacro) {
|
|
130
|
+
var expanded = expandMacroTokens(tokenize(expression).slice(0, -1), resolveMacro, tokenize, true, 0, {
|
|
131
|
+
remaining: MAX_MACRO_EXPANSION_TOKENS
|
|
132
|
+
});
|
|
133
|
+
return typeof expanded === "string" ? {
|
|
134
|
+
expression: "",
|
|
135
|
+
error: expanded
|
|
136
|
+
} : {
|
|
137
|
+
expression: expanded.map(function(token) {
|
|
138
|
+
return token.text;
|
|
139
|
+
}).join(" ")
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Expands shader macros using the same argument prescan and rescan rules as conditional expressions.
|
|
144
|
+
* @param source - Shader text without macro definition or conditional directives.
|
|
145
|
+
* @param resolveMacro - Resolves the macro state active at this source location.
|
|
146
|
+
* @returns Expanded shader source, or a deterministic expansion-limit error.
|
|
147
|
+
*/ function expandShaderMacros(source, resolveMacro) {
|
|
148
|
+
var expanded = expandMacroTokens(tokenizeShader(source).slice(0, -1), resolveMacro, tokenizeShaderReplacement, false, 0, {
|
|
149
|
+
remaining: MAX_MACRO_EXPANSION_TOKENS
|
|
150
|
+
});
|
|
151
|
+
return typeof expanded === "string" ? {
|
|
152
|
+
source: "",
|
|
153
|
+
error: expanded
|
|
154
|
+
} : {
|
|
155
|
+
source: serializeShaderTokens(expanded)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function expandMacroTokens(input, resolveMacro, tokenizeReplacement, protectDefined, depth, budget) {
|
|
159
|
+
var tokens = input.slice();
|
|
160
|
+
var output = [];
|
|
161
|
+
var index = 0;
|
|
162
|
+
while(index < tokens.length){
|
|
163
|
+
var // Rescan in place so an object alias can form a call with the following original tokens
|
|
164
|
+
_tokens;
|
|
165
|
+
var _token_disabledMacros, _tokens_openParen;
|
|
166
|
+
var token = tokens[index];
|
|
167
|
+
if (protectDefined && token.text === "defined") {
|
|
168
|
+
var _tokens_index;
|
|
169
|
+
output.push(token);
|
|
170
|
+
index++;
|
|
171
|
+
var count = ((_tokens_index = tokens[index]) == null ? void 0 : _tokens_index.text) === "(" ? 3 : 1;
|
|
172
|
+
for(var i = 0; i < count && index < tokens.length; i++)output.push(tokens[index++]);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
var macro = token.kind === "identifier" && !((_token_disabledMacros = token.disabledMacros) == null ? void 0 : _token_disabledMacros.has(token.text)) ? resolveMacro(token.text) : undefined;
|
|
176
|
+
var openParen = index + 1;
|
|
177
|
+
if (macro == null ? void 0 : macro.parameters) {
|
|
178
|
+
var _tokens_openParen1;
|
|
179
|
+
while(((_tokens_openParen1 = tokens[openParen]) == null ? void 0 : _tokens_openParen1.kind) === "trivia")openParen++;
|
|
180
|
+
}
|
|
181
|
+
if (!macro || macro.parameters && ((_tokens_openParen = tokens[openParen]) == null ? void 0 : _tokens_openParen.text) !== "(") {
|
|
182
|
+
output.push(token);
|
|
183
|
+
index++;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
var _token_expansionDepth;
|
|
187
|
+
var expansionDepth = Math.max(depth, (_token_expansionDepth = token.expansionDepth) != null ? _token_expansionDepth : 0) + 1;
|
|
188
|
+
if (expansionDepth > MAX_MACRO_EXPANSION_DEPTH) {
|
|
189
|
+
return "Preprocessor macro expansion exceeds " + MAX_MACRO_EXPANSION_DEPTH + " nested replacements.";
|
|
190
|
+
}
|
|
191
|
+
var invocationEnd = index;
|
|
192
|
+
var args = [];
|
|
193
|
+
var disabledMacros = new Set(token.disabledMacros);
|
|
194
|
+
if (macro.parameters) {
|
|
195
|
+
var invocation = parseMacroInvocation(tokens, openParen);
|
|
196
|
+
if (!invocation) {
|
|
197
|
+
output.push(token);
|
|
198
|
+
index++;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
args = invocation.arguments;
|
|
202
|
+
if (macro.parameters.length === 0 && args.length === 1 && args[0].every(function(token) {
|
|
203
|
+
return token.kind === "trivia";
|
|
204
|
+
})) {
|
|
205
|
+
args = [];
|
|
206
|
+
}
|
|
207
|
+
if (args.length !== macro.parameters.length) {
|
|
208
|
+
output.push(token);
|
|
209
|
+
index++;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
invocationEnd = invocation.end;
|
|
213
|
+
// A function invocation inherits only exclusions present at both invocation boundaries
|
|
214
|
+
var closingExclusions = tokens[invocationEnd].disabledMacros;
|
|
215
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(disabledMacros), _step; !(_step = _iterator()).done;){
|
|
216
|
+
var name = _step.value;
|
|
217
|
+
if (!(closingExclusions == null ? void 0 : closingExclusions.has(name))) disabledMacros.delete(name);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
disabledMacros.add(token.text);
|
|
221
|
+
var replacement = [];
|
|
222
|
+
var expandedArguments = new Map();
|
|
223
|
+
for(var _iterator1 = _create_for_of_iterator_helper_loose(tokenizeReplacement(macro.body).slice(0, -1)), _step1; !(_step1 = _iterator1()).done;){
|
|
224
|
+
var _loop = function() {
|
|
225
|
+
var part = _step2.value;
|
|
226
|
+
var _part_disabledMacros;
|
|
227
|
+
if (--budget.remaining < 0) return {
|
|
228
|
+
v: "Preprocessor macro expansion exceeds " + MAX_MACRO_EXPANSION_TOKENS + " replacement tokens."
|
|
229
|
+
};
|
|
230
|
+
// Only macro names and invocation closing boundaries carry exclusions into later rescans.
|
|
231
|
+
if (part.kind !== "identifier" && part.text !== ")") {
|
|
232
|
+
replacement.push(part);
|
|
233
|
+
return "continue";
|
|
234
|
+
}
|
|
235
|
+
var exclusions = disabledMacros;
|
|
236
|
+
if ((_part_disabledMacros = part.disabledMacros) == null ? void 0 : _part_disabledMacros.size) {
|
|
237
|
+
exclusions = new Set(disabledMacros);
|
|
238
|
+
part.disabledMacros.forEach(function(name) {
|
|
239
|
+
return exclusions.add(name);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
var _part_expansionDepth;
|
|
243
|
+
replacement.push(_extends({}, part, {
|
|
244
|
+
disabledMacros: exclusions,
|
|
245
|
+
expansionDepth: Math.max(expansionDepth, (_part_expansionDepth = part.expansionDepth) != null ? _part_expansionDepth : 0)
|
|
246
|
+
}));
|
|
247
|
+
};
|
|
248
|
+
var bodyToken = _step1.value;
|
|
249
|
+
var _macro_parameters;
|
|
250
|
+
var _macro_parameters_indexOf;
|
|
251
|
+
var parameter = bodyToken.kind === "identifier" ? (_macro_parameters_indexOf = (_macro_parameters = macro.parameters) == null ? void 0 : _macro_parameters.indexOf(bodyToken.text)) != null ? _macro_parameters_indexOf : -1 : -1;
|
|
252
|
+
var substituted = [
|
|
253
|
+
bodyToken
|
|
254
|
+
];
|
|
255
|
+
if (parameter >= 0) {
|
|
256
|
+
var argument = expandedArguments.get(parameter);
|
|
257
|
+
if (!argument) {
|
|
258
|
+
// Arguments expand before this invocation disables its own name, including ID(ID(1))
|
|
259
|
+
var expanded = expandMacroTokens(args[parameter], resolveMacro, tokenizeReplacement, protectDefined, expansionDepth, budget);
|
|
260
|
+
if (typeof expanded === "string") return expanded;
|
|
261
|
+
expandedArguments.set(parameter, argument = expanded);
|
|
262
|
+
}
|
|
263
|
+
substituted = argument;
|
|
264
|
+
}
|
|
265
|
+
for(var _iterator2 = _create_for_of_iterator_helper_loose(substituted), _step2; !(_step2 = _iterator2()).done;){
|
|
266
|
+
var _ret = _loop();
|
|
267
|
+
if (_type_of(_ret) === "object") return _ret.v;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
(_tokens = tokens).splice.apply(_tokens, [].concat([
|
|
271
|
+
index,
|
|
272
|
+
invocationEnd - index + 1
|
|
273
|
+
], replacement));
|
|
274
|
+
}
|
|
275
|
+
return output;
|
|
276
|
+
}
|
|
277
|
+
var shaderMultiOperators = new Set([
|
|
278
|
+
"<<=",
|
|
279
|
+
">>=",
|
|
280
|
+
"++",
|
|
281
|
+
"--",
|
|
282
|
+
"<<",
|
|
283
|
+
">>",
|
|
284
|
+
"<=",
|
|
285
|
+
">=",
|
|
286
|
+
"==",
|
|
287
|
+
"!=",
|
|
288
|
+
"&&",
|
|
289
|
+
"||",
|
|
290
|
+
"^^",
|
|
291
|
+
"+=",
|
|
292
|
+
"-=",
|
|
293
|
+
"*=",
|
|
294
|
+
"/=",
|
|
295
|
+
"%=",
|
|
296
|
+
"&=",
|
|
297
|
+
"^=",
|
|
298
|
+
"|=",
|
|
299
|
+
"##"
|
|
300
|
+
]);
|
|
301
|
+
// Shader replacement lists use preprocessing numbers, not the integer-only #if grammar.
|
|
302
|
+
function tokenizeShader(source, removeComments) {
|
|
303
|
+
if (removeComments === void 0) removeComments = false;
|
|
304
|
+
var tokens = [];
|
|
305
|
+
var index = 0;
|
|
306
|
+
while(index < source.length){
|
|
307
|
+
var start = index;
|
|
308
|
+
var char = source.charCodeAt(index++);
|
|
309
|
+
var kind = void 0;
|
|
310
|
+
var comment = false;
|
|
311
|
+
var _source_index;
|
|
312
|
+
if (isWhitespace(char)) {
|
|
313
|
+
kind = "trivia";
|
|
314
|
+
while(isWhitespace(source.charCodeAt(index)))index++;
|
|
315
|
+
} else if (char === 47 && source[index] === "/") {
|
|
316
|
+
kind = "trivia";
|
|
317
|
+
comment = true;
|
|
318
|
+
while(index < source.length && source[index] !== "\n" && source[index] !== "\r")index++;
|
|
319
|
+
} else if (char === 47 && source[index] === "*") {
|
|
320
|
+
kind = "trivia";
|
|
321
|
+
comment = true;
|
|
322
|
+
var close = source.indexOf("*/", index + 1);
|
|
323
|
+
index = close < 0 ? source.length : close + 2;
|
|
324
|
+
} else if (char === 34 || char === 39) {
|
|
325
|
+
kind = "invalid";
|
|
326
|
+
while(index < source.length){
|
|
327
|
+
var next = source.charCodeAt(index++);
|
|
328
|
+
if (next === 92) index = Math.min(index + 1, source.length);
|
|
329
|
+
else if (next === char) break;
|
|
330
|
+
}
|
|
331
|
+
} else if (isIdentifierStart(char)) {
|
|
332
|
+
kind = "identifier";
|
|
333
|
+
while(isIdentifierPart(source.charCodeAt(index)))index++;
|
|
334
|
+
} else if (char >= 48 && char <= 57 || char === 46 && /[0-9]/.test((_source_index = source[index]) != null ? _source_index : "")) {
|
|
335
|
+
kind = "number";
|
|
336
|
+
while(index < source.length){
|
|
337
|
+
var next1 = source.charCodeAt(index);
|
|
338
|
+
if (isIdentifierPart(next1) || next1 === 46) index++;
|
|
339
|
+
else if ((next1 === 43 || next1 === 45) && /[eEpP]/.test(source[index - 1])) index++;
|
|
340
|
+
else break;
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
kind = "operator";
|
|
344
|
+
if (char === 60 || char === 62) {
|
|
345
|
+
if (shaderMultiOperators.has(source.slice(start, start + 3))) index = start + 3;
|
|
346
|
+
else if (shaderMultiOperators.has(source.slice(start, start + 2))) index = start + 2;
|
|
347
|
+
} else if ("+-*/%&|^!=#".includes(source[start]) && shaderMultiOperators.has(source.slice(start, start + 2))) {
|
|
348
|
+
index = start + 2;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
var text = source.slice(start, index);
|
|
352
|
+
tokens.push({
|
|
353
|
+
kind: kind,
|
|
354
|
+
text: removeComments && comment ? text.replace(/[^\r\n]/g, "") || " " : text,
|
|
355
|
+
start: start,
|
|
356
|
+
end: index
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
tokens.push({
|
|
360
|
+
kind: "end",
|
|
361
|
+
text: "",
|
|
362
|
+
start: index,
|
|
363
|
+
end: index
|
|
364
|
+
});
|
|
365
|
+
return tokens;
|
|
366
|
+
}
|
|
367
|
+
function tokenizeShaderReplacement(source) {
|
|
368
|
+
// A comment in a replacement list is whitespace; a trailing // must not swallow the caller's suffix.
|
|
369
|
+
return tokenizeShader(source, true);
|
|
370
|
+
}
|
|
371
|
+
function serializeShaderTokens(tokens) {
|
|
372
|
+
var parts = [];
|
|
373
|
+
var previous;
|
|
374
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(tokens), _step; !(_step = _iterator()).done;){
|
|
375
|
+
var token = _step.value;
|
|
376
|
+
if (previous && previous.kind !== "trivia" && token.kind !== "trivia") {
|
|
377
|
+
var word = previous.kind === "identifier" || previous.kind === "number";
|
|
378
|
+
var nextWord = token.kind === "identifier" || token.kind === "number";
|
|
379
|
+
var joined = previous.kind === "operator" && token.kind === "operator" ? previous.text + token.text : "";
|
|
380
|
+
// Replacement must not join two preprocessing tokens into a new number, operator or comment.
|
|
381
|
+
if (word && nextWord || previous.kind === "number" && (token.text === "." || /[eEpP]$/.test(previous.text) && /^[+-]/.test(token.text)) || previous.text === "." && token.kind === "number" || joined && previous.text.length < 2 && shaderMultiOperators.has(joined.slice(0, 2)) || joined && previous.text.length < 3 && shaderMultiOperators.has(joined.slice(0, 3)) || joined.startsWith("//") || joined.startsWith("/*")) parts.push(" ");
|
|
382
|
+
}
|
|
383
|
+
parts.push(token.text);
|
|
384
|
+
previous = token;
|
|
385
|
+
}
|
|
386
|
+
return parts.join("");
|
|
387
|
+
}
|
|
388
|
+
function parseMacroInvocation(tokens, openParen) {
|
|
389
|
+
var args = [
|
|
390
|
+
[]
|
|
391
|
+
];
|
|
392
|
+
var depth = 1;
|
|
393
|
+
for(var index = openParen + 1; index < tokens.length; index++){
|
|
394
|
+
var token = tokens[index];
|
|
395
|
+
if (token.text === "(") {
|
|
396
|
+
depth++;
|
|
397
|
+
args[args.length - 1].push(token);
|
|
398
|
+
} else if (token.text === ")") {
|
|
399
|
+
if (--depth === 0) {
|
|
400
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(args), _step; !(_step = _iterator()).done;){
|
|
401
|
+
var argument = _step.value;
|
|
402
|
+
trimMacroArgument(argument);
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
arguments: args,
|
|
406
|
+
end: index
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
args[args.length - 1].push(token);
|
|
410
|
+
} else if (token.text === "," && depth === 1) {
|
|
411
|
+
args.push([]);
|
|
412
|
+
} else {
|
|
413
|
+
args[args.length - 1].push(token);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function trimMacroArgument(tokens) {
|
|
418
|
+
// Call-site padding is not part of the replacement. Keep comments and line breaks intact.
|
|
419
|
+
for(var _i = 0, _iter = [
|
|
420
|
+
false,
|
|
421
|
+
true
|
|
422
|
+
]; _i < _iter.length; _i++){
|
|
423
|
+
var trailing = _iter[_i];
|
|
424
|
+
while(tokens.length){
|
|
425
|
+
var index = trailing ? tokens.length - 1 : 0;
|
|
426
|
+
var token = tokens[index];
|
|
427
|
+
if (token.kind !== "trivia") break;
|
|
428
|
+
var text = token.text.replace(trailing ? /[ \t\v\f]+$/ : /^[ \t\v\f]+/, "");
|
|
429
|
+
if (text === token.text) break;
|
|
430
|
+
if (text) {
|
|
431
|
+
tokens[index] = _extends({}, token, {
|
|
432
|
+
text: text
|
|
433
|
+
});
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
if (trailing) tokens.pop();
|
|
437
|
+
else tokens.shift();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Evaluates an expression whose result is independent of macro state.
|
|
443
|
+
* @param expression - Complete preprocessor expression text.
|
|
444
|
+
* @returns 32-bit result, or `undefined` when the expression is invalid, state-dependent, or unevaluable.
|
|
445
|
+
*/ function evaluateContextFreePreprocessorExpression(expression) {
|
|
446
|
+
var parsed = parsePreprocessorExpression(expression);
|
|
447
|
+
return parsed.ok ? evaluateContextFreePreprocessorCondition(parsed.condition) : undefined;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Evaluates a parsed condition whose result is independent of macro state.
|
|
451
|
+
* @param condition - Parsed preprocessor expression tree.
|
|
452
|
+
* @returns 32-bit result, or `undefined` when macro state or an invalid operation affects the result.
|
|
453
|
+
*/ function evaluateContextFreePreprocessorCondition(condition) {
|
|
454
|
+
var evaluated = evaluateStaticallyKnownPreprocessorCondition(condition);
|
|
455
|
+
return typeof evaluated === "number" ? evaluated : undefined;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Evaluates the part of a preprocessor expression determined by known source macro state.
|
|
459
|
+
* @param condition - Parsed preprocessor expression tree.
|
|
460
|
+
* @param context - Partially known macro values and definition states.
|
|
461
|
+
* @returns 32-bit result, or `undefined` when any reachable input remains unknown.
|
|
462
|
+
*/ function evaluatePartiallyKnownPreprocessorCondition(condition, context) {
|
|
463
|
+
return evaluatePartiallyKnownPreprocessorConditionResult(condition, context).value;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Evaluates the known portion of an expression while preserving definite evaluation failures.
|
|
467
|
+
* @param condition - Parsed preprocessor expression tree.
|
|
468
|
+
* @param context - Partially known macro values and definition states.
|
|
469
|
+
* @returns Known value, definite error, or an empty result when external state still matters.
|
|
470
|
+
*/ function evaluatePartiallyKnownPreprocessorConditionResult(condition, context) {
|
|
471
|
+
var evaluated = evaluateStaticallyKnownPreprocessorCondition(condition, context);
|
|
472
|
+
return typeof evaluated === "number" ? {
|
|
473
|
+
value: evaluated
|
|
474
|
+
} : typeof evaluated === "string" ? {
|
|
475
|
+
error: evaluated
|
|
476
|
+
} : {};
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Evaluates a parsed preprocessor expression with signed 32-bit arithmetic matching ANGLE's preprocessor.
|
|
480
|
+
* @param condition - Serializable expression tree.
|
|
481
|
+
* @param context - Active macro value and definition resolver.
|
|
482
|
+
* @returns Signed 32-bit result; nonzero values are true.
|
|
483
|
+
* @throws Error when an active expression divides by zero or contains a deferred node.
|
|
484
|
+
*/ function evaluatePreprocessorExpression(condition, context) {
|
|
485
|
+
var evaluated = evaluatePreprocessorExpressionInternal(condition, context);
|
|
486
|
+
if (typeof evaluated === "string") throw new Error(evaluated);
|
|
487
|
+
return evaluated;
|
|
488
|
+
}
|
|
489
|
+
var DIVISION_BY_ZERO_ERROR = "Division by zero in active preprocessor expression.";
|
|
490
|
+
var MODULO_BY_ZERO_ERROR = "Modulo by zero in active preprocessor expression.";
|
|
491
|
+
var INVALID_SHIFT_COUNT_ERROR = "Shift count must be between 0 and 31 in active preprocessor expression.";
|
|
492
|
+
function evaluatePreprocessorExpressionInternal(condition, context) {
|
|
493
|
+
switch(condition.t){
|
|
494
|
+
case "def":
|
|
495
|
+
return context.isDefined(condition.m) ? 1 : 0;
|
|
496
|
+
case "ndef":
|
|
497
|
+
return context.isDefined(condition.m) ? 0 : 1;
|
|
498
|
+
case "cmp":
|
|
499
|
+
return evaluateBinaryExpression(context.resolveIdentifier(condition.m), condition.op, condition.v);
|
|
500
|
+
case "and":
|
|
501
|
+
{
|
|
502
|
+
var left = evaluatePreprocessorExpressionInternal(condition.l, context);
|
|
503
|
+
if (typeof left === "string" || left === 0) return left;
|
|
504
|
+
var right = evaluatePreprocessorExpressionInternal(condition.r, context);
|
|
505
|
+
return typeof right === "string" ? right : right !== 0 ? 1 : 0;
|
|
506
|
+
}
|
|
507
|
+
case "or":
|
|
508
|
+
{
|
|
509
|
+
var left1 = evaluatePreprocessorExpressionInternal(condition.l, context);
|
|
510
|
+
if (typeof left1 === "string") return left1;
|
|
511
|
+
if (left1 !== 0) return 1;
|
|
512
|
+
var right1 = evaluatePreprocessorExpressionInternal(condition.r, context);
|
|
513
|
+
return typeof right1 === "string" ? right1 : right1 !== 0 ? 1 : 0;
|
|
514
|
+
}
|
|
515
|
+
case "not":
|
|
516
|
+
{
|
|
517
|
+
var value = evaluatePreprocessorExpressionInternal(condition.c, context);
|
|
518
|
+
return typeof value === "string" ? value : value === 0 ? 1 : 0;
|
|
519
|
+
}
|
|
520
|
+
case "bool":
|
|
521
|
+
return condition.v ? 1 : 0;
|
|
522
|
+
case "num":
|
|
523
|
+
return condition.v;
|
|
524
|
+
case "id":
|
|
525
|
+
return context.resolveIdentifier(condition.m);
|
|
526
|
+
case "unary":
|
|
527
|
+
{
|
|
528
|
+
var value1 = evaluatePreprocessorExpressionInternal(condition.c, context);
|
|
529
|
+
if (typeof value1 === "string") return value1;
|
|
530
|
+
return condition.op === "+" ? value1 | 0 : condition.op === "-" ? -value1 | 0 : ~value1;
|
|
531
|
+
}
|
|
532
|
+
case "binary":
|
|
533
|
+
{
|
|
534
|
+
var left2 = evaluatePreprocessorExpressionInternal(condition.l, context);
|
|
535
|
+
if (typeof left2 === "string") return left2;
|
|
536
|
+
var right2 = evaluatePreprocessorExpressionInternal(condition.r, context);
|
|
537
|
+
return typeof right2 === "string" ? right2 : evaluateBinaryExpression(left2, condition.op, right2);
|
|
538
|
+
}
|
|
539
|
+
case "deferred":
|
|
540
|
+
return "Deferred preprocessor expressions must be expanded before evaluation.";
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
var ExpressionParser = /*#__PURE__*/ function() {
|
|
544
|
+
function ExpressionParser(expression) {
|
|
545
|
+
this._index = 0;
|
|
546
|
+
this._sawExpandableIdentifier = false;
|
|
547
|
+
this._rightEdgeExpandable = false;
|
|
548
|
+
this._nestingDepth = 0;
|
|
549
|
+
this._tokens = tokenize(expression);
|
|
550
|
+
}
|
|
551
|
+
var _proto = ExpressionParser.prototype;
|
|
552
|
+
_proto.parse = function parse() {
|
|
553
|
+
var condition = this._parseRoot();
|
|
554
|
+
var invalid = this._invalidResult();
|
|
555
|
+
if (invalid) return invalid;
|
|
556
|
+
var evaluated = this._sawExpandableIdentifier ? undefined : evaluateStaticallyKnownPreprocessorCondition(condition);
|
|
557
|
+
return _extends({
|
|
558
|
+
ok: true,
|
|
559
|
+
condition: condition,
|
|
560
|
+
hasExpandableIdentifier: this._sawExpandableIdentifier
|
|
561
|
+
}, typeof evaluated === "string" ? {
|
|
562
|
+
evaluationError: evaluated
|
|
563
|
+
} : undefined);
|
|
564
|
+
};
|
|
565
|
+
_proto._parseRoot = function _parseRoot() {
|
|
566
|
+
var condition = this._parseBinary(1);
|
|
567
|
+
if (!this._failure) {
|
|
568
|
+
var token = this._current();
|
|
569
|
+
if (token.kind !== "end") {
|
|
570
|
+
var unexpectedExpandableIdentifier = token.kind === "identifier" && token.text !== "defined";
|
|
571
|
+
this._sawExpandableIdentifier || (this._sawExpandableIdentifier = unexpectedExpandableIdentifier);
|
|
572
|
+
var unsupportedConditionalOperator = token.text === "?" || token.text === ":";
|
|
573
|
+
var certain = unsupportedConditionalOperator || !this._rightEdgeExpandable && !unexpectedExpandableIdentifier && !(token.text === ")" && this._sawExpandableIdentifier);
|
|
574
|
+
this._fail("Unexpected token '" + token.text + "' in preprocessor expression.", token, certain);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return condition;
|
|
578
|
+
};
|
|
579
|
+
_proto._invalidResult = function _invalidResult() {
|
|
580
|
+
if (this._failure) {
|
|
581
|
+
// A macro supplying a closing delimiter may be the token where parsing stopped.
|
|
582
|
+
for(var i = this._index; i < this._tokens.length; i++){
|
|
583
|
+
var token = this._tokens[i];
|
|
584
|
+
if (token.kind === "identifier" && token.text !== "defined") {
|
|
585
|
+
this._sawExpandableIdentifier = true;
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return this._failure ? {
|
|
591
|
+
ok: false,
|
|
592
|
+
error: this._failure,
|
|
593
|
+
hasExpandableIdentifier: this._sawExpandableIdentifier
|
|
594
|
+
} : undefined;
|
|
595
|
+
};
|
|
596
|
+
_proto._parseBinary = function _parseBinary(minPrecedence) {
|
|
597
|
+
var left = this._parseUnary();
|
|
598
|
+
if (this._failure || !left) return undefined;
|
|
599
|
+
while(true){
|
|
600
|
+
var token = this._current();
|
|
601
|
+
var precedence = binaryPrecedence[token.text];
|
|
602
|
+
if (precedence === undefined || precedence < minPrecedence) return left;
|
|
603
|
+
this._index++;
|
|
604
|
+
var right = this._parseBinary(precedence + 1);
|
|
605
|
+
if (this._failure || !right) return undefined;
|
|
606
|
+
if (token.text === "&&") left = {
|
|
607
|
+
t: "and",
|
|
608
|
+
l: left,
|
|
609
|
+
r: right
|
|
610
|
+
};
|
|
611
|
+
else if (token.text === "||") left = {
|
|
612
|
+
t: "or",
|
|
613
|
+
l: left,
|
|
614
|
+
r: right
|
|
615
|
+
};
|
|
616
|
+
else left = {
|
|
617
|
+
t: "binary",
|
|
618
|
+
op: token.text,
|
|
619
|
+
l: left,
|
|
620
|
+
r: right
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
_proto._parseUnary = function _parseUnary() {
|
|
625
|
+
var token = this._current();
|
|
626
|
+
if (token.kind === "operator" && (token.text === "+" || token.text === "-" || token.text === "!" || token.text === "~")) {
|
|
627
|
+
if (!this._enterNesting(token)) return;
|
|
628
|
+
this._index++;
|
|
629
|
+
var condition = this._parseUnary();
|
|
630
|
+
this._nestingDepth--;
|
|
631
|
+
if (!condition) return undefined;
|
|
632
|
+
return token.text === "!" ? {
|
|
633
|
+
t: "not",
|
|
634
|
+
c: condition
|
|
635
|
+
} : {
|
|
636
|
+
t: "unary",
|
|
637
|
+
op: token.text,
|
|
638
|
+
c: condition
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
return this._parsePrimary();
|
|
642
|
+
};
|
|
643
|
+
_proto._parsePrimary = function _parsePrimary() {
|
|
644
|
+
var token = this._current();
|
|
645
|
+
if (token.kind === "number") {
|
|
646
|
+
this._index++;
|
|
647
|
+
this._rightEdgeExpandable = false;
|
|
648
|
+
var value = parseIntegerLiteral(token.text);
|
|
649
|
+
if (value === undefined) {
|
|
650
|
+
this._fail("Integer literal exceeds 32 bits in preprocessor expression.", token, true);
|
|
651
|
+
return undefined;
|
|
652
|
+
}
|
|
653
|
+
return {
|
|
654
|
+
t: "num",
|
|
655
|
+
v: value
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
if (token.kind === "identifier") {
|
|
659
|
+
if (token.text === "defined") return this._parseDefined();
|
|
660
|
+
this._sawExpandableIdentifier = true;
|
|
661
|
+
this._rightEdgeExpandable = true;
|
|
662
|
+
this._index++;
|
|
663
|
+
return {
|
|
664
|
+
t: "id",
|
|
665
|
+
m: token.text
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
if (this._consume("(")) {
|
|
669
|
+
if (!this._enterNesting(token)) return;
|
|
670
|
+
var condition = this._parseBinary(1);
|
|
671
|
+
if (!this._failure && !this._consume(")")) {
|
|
672
|
+
this._fail("Expected ')' in preprocessor expression.", this._current(), false);
|
|
673
|
+
}
|
|
674
|
+
if (!this._failure) this._rightEdgeExpandable = false;
|
|
675
|
+
this._nestingDepth--;
|
|
676
|
+
return condition;
|
|
677
|
+
}
|
|
678
|
+
if (token.kind === "end") {
|
|
679
|
+
this._fail("Expected an operand before the end of the preprocessor expression.", token, true);
|
|
680
|
+
} else {
|
|
681
|
+
this._fail("Expected an operand, found '" + token.text + "'.", token, true);
|
|
682
|
+
}
|
|
683
|
+
return undefined;
|
|
684
|
+
};
|
|
685
|
+
_proto._parseDefined = function _parseDefined() {
|
|
686
|
+
this._index++;
|
|
687
|
+
this._rightEdgeExpandable = false;
|
|
688
|
+
var parenthesized = this._consume("(");
|
|
689
|
+
var name = this._current();
|
|
690
|
+
if (name.kind !== "identifier" || name.text === "defined") {
|
|
691
|
+
this._fail("Expected a macro name after 'defined'.", name, true);
|
|
692
|
+
return undefined;
|
|
693
|
+
}
|
|
694
|
+
this._index++;
|
|
695
|
+
if (parenthesized && !this._consume(")")) {
|
|
696
|
+
this._fail("Expected ')' after the macro name in 'defined(...)'.", this._current(), true);
|
|
697
|
+
return undefined;
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
t: "def",
|
|
701
|
+
m: name.text
|
|
702
|
+
};
|
|
703
|
+
};
|
|
704
|
+
_proto._consume = function _consume(text) {
|
|
705
|
+
if (this._current().text !== text) return false;
|
|
706
|
+
this._index++;
|
|
707
|
+
return true;
|
|
708
|
+
};
|
|
709
|
+
_proto._enterNesting = function _enterNesting(token) {
|
|
710
|
+
if (this._nestingDepth >= MAX_EXPRESSION_NESTING) {
|
|
711
|
+
this._fail("Preprocessor expression nesting exceeds the supported depth of " + MAX_EXPRESSION_NESTING + ".", token, true);
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
this._nestingDepth++;
|
|
715
|
+
return true;
|
|
716
|
+
};
|
|
717
|
+
_proto._current = function _current() {
|
|
718
|
+
return this._tokens[this._index];
|
|
719
|
+
};
|
|
720
|
+
_proto._fail = function _fail(message, token, certain) {
|
|
721
|
+
var _this__failure;
|
|
722
|
+
(_this__failure = this._failure) != null ? _this__failure : this._failure = {
|
|
723
|
+
message: message,
|
|
724
|
+
start: token.start,
|
|
725
|
+
end: Math.max(token.end, token.start + 1),
|
|
726
|
+
certain: certain
|
|
727
|
+
};
|
|
728
|
+
};
|
|
729
|
+
return ExpressionParser;
|
|
730
|
+
}();
|
|
731
|
+
function tokenize(expression) {
|
|
732
|
+
var tokens = [];
|
|
733
|
+
var index = 0;
|
|
734
|
+
while(index < expression.length){
|
|
735
|
+
var charCode = expression.charCodeAt(index);
|
|
736
|
+
if (isWhitespace(charCode)) {
|
|
737
|
+
index++;
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
if (charCode === 47 && expression.charCodeAt(index + 1) === 47) break;
|
|
741
|
+
if (charCode === 47 && expression.charCodeAt(index + 1) === 42) {
|
|
742
|
+
var end = expression.indexOf("*/", index + 2);
|
|
743
|
+
if (end < 0) {
|
|
744
|
+
tokens.push({
|
|
745
|
+
kind: "invalid",
|
|
746
|
+
text: expression.slice(index),
|
|
747
|
+
start: index,
|
|
748
|
+
end: expression.length
|
|
749
|
+
});
|
|
750
|
+
index = expression.length;
|
|
751
|
+
} else {
|
|
752
|
+
index = end + 2;
|
|
753
|
+
}
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
if (isIdentifierStart(charCode)) {
|
|
757
|
+
var start = index++;
|
|
758
|
+
while(index < expression.length && isIdentifierPart(expression.charCodeAt(index)))index++;
|
|
759
|
+
tokens.push({
|
|
760
|
+
kind: "identifier",
|
|
761
|
+
text: expression.slice(start, index),
|
|
762
|
+
start: start,
|
|
763
|
+
end: index
|
|
764
|
+
});
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
768
|
+
var start1 = index;
|
|
769
|
+
if (charCode === 48 && (expression.charCodeAt(index + 1) === 88 || expression.charCodeAt(index + 1) === 120)) {
|
|
770
|
+
index += 2;
|
|
771
|
+
var digitStart = index;
|
|
772
|
+
while(index < expression.length && isHexDigit(expression.charCodeAt(index)))index++;
|
|
773
|
+
if (index === digitStart) {
|
|
774
|
+
tokens.push({
|
|
775
|
+
kind: "invalid",
|
|
776
|
+
text: expression.slice(start1, index),
|
|
777
|
+
start: start1,
|
|
778
|
+
end: index
|
|
779
|
+
});
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
} else if (charCode === 48) {
|
|
783
|
+
index++;
|
|
784
|
+
while(index < expression.length && expression.charCodeAt(index) >= 48 && expression.charCodeAt(index) <= 55)index++;
|
|
785
|
+
} else {
|
|
786
|
+
index++;
|
|
787
|
+
while(index < expression.length && expression.charCodeAt(index) >= 48 && expression.charCodeAt(index) <= 57)index++;
|
|
788
|
+
}
|
|
789
|
+
var suffixStart = index;
|
|
790
|
+
while(isIntegerSuffix(expression.charCodeAt(index)))index++;
|
|
791
|
+
var suffix = expression.slice(suffixStart, index);
|
|
792
|
+
if (!isValidIntegerSuffix(suffix) || isIdentifierStart(expression.charCodeAt(index))) {
|
|
793
|
+
while(isIdentifierPart(expression.charCodeAt(index)))index++;
|
|
794
|
+
tokens.push({
|
|
795
|
+
kind: "invalid",
|
|
796
|
+
text: expression.slice(start1, index),
|
|
797
|
+
start: start1,
|
|
798
|
+
end: index
|
|
799
|
+
});
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
tokens.push({
|
|
803
|
+
kind: "number",
|
|
804
|
+
text: expression.slice(start1, index),
|
|
805
|
+
start: start1,
|
|
806
|
+
end: index
|
|
807
|
+
});
|
|
808
|
+
continue;
|
|
809
|
+
}
|
|
810
|
+
var nextCharCode = expression.charCodeAt(index + 1);
|
|
811
|
+
if (isDoubleOperator(charCode, nextCharCode)) {
|
|
812
|
+
tokens.push({
|
|
813
|
+
kind: "operator",
|
|
814
|
+
text: expression.slice(index, index + 2),
|
|
815
|
+
start: index,
|
|
816
|
+
end: index + 2
|
|
817
|
+
});
|
|
818
|
+
index += 2;
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
if (isSingleOperator(charCode)) {
|
|
822
|
+
tokens.push({
|
|
823
|
+
kind: "operator",
|
|
824
|
+
text: expression[index],
|
|
825
|
+
start: index,
|
|
826
|
+
end: index + 1
|
|
827
|
+
});
|
|
828
|
+
index++;
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
tokens.push({
|
|
832
|
+
kind: "invalid",
|
|
833
|
+
text: expression[index],
|
|
834
|
+
start: index,
|
|
835
|
+
end: index + 1
|
|
836
|
+
});
|
|
837
|
+
index++;
|
|
838
|
+
}
|
|
839
|
+
tokens.push({
|
|
840
|
+
kind: "end",
|
|
841
|
+
text: "",
|
|
842
|
+
start: index,
|
|
843
|
+
end: index
|
|
844
|
+
});
|
|
845
|
+
return tokens;
|
|
846
|
+
}
|
|
847
|
+
function parseIntegerLiteral(literal) {
|
|
848
|
+
var end = literal.length;
|
|
849
|
+
while(end > 0 && isIntegerSuffix(literal.charCodeAt(end - 1)))end--;
|
|
850
|
+
var value;
|
|
851
|
+
if (literal.charCodeAt(0) === 48) {
|
|
852
|
+
var prefix = literal.charCodeAt(1);
|
|
853
|
+
if (prefix === 88 || prefix === 120) value = parseInt(literal.slice(2, end), 16);
|
|
854
|
+
else if (end > 1) value = parseInt(literal.slice(0, end), 8);
|
|
855
|
+
else value = 0;
|
|
856
|
+
} else {
|
|
857
|
+
value = Number(literal.slice(0, end));
|
|
858
|
+
}
|
|
859
|
+
return value <= 0xffffffff ? value | 0 : undefined;
|
|
860
|
+
}
|
|
861
|
+
function evaluateBinaryExpression(left, operator, right) {
|
|
862
|
+
switch(operator){
|
|
863
|
+
case "||":
|
|
864
|
+
return left !== 0 || right !== 0 ? 1 : 0;
|
|
865
|
+
case "&&":
|
|
866
|
+
return left !== 0 && right !== 0 ? 1 : 0;
|
|
867
|
+
case "|":
|
|
868
|
+
return left | right;
|
|
869
|
+
case "^":
|
|
870
|
+
return left ^ right;
|
|
871
|
+
case "&":
|
|
872
|
+
return left & right;
|
|
873
|
+
case "==":
|
|
874
|
+
return left === right ? 1 : 0;
|
|
875
|
+
case "!=":
|
|
876
|
+
return left !== right ? 1 : 0;
|
|
877
|
+
case "<":
|
|
878
|
+
return left < right ? 1 : 0;
|
|
879
|
+
case "<=":
|
|
880
|
+
return left <= right ? 1 : 0;
|
|
881
|
+
case ">":
|
|
882
|
+
return left > right ? 1 : 0;
|
|
883
|
+
case ">=":
|
|
884
|
+
return left >= right ? 1 : 0;
|
|
885
|
+
case "<<":
|
|
886
|
+
{
|
|
887
|
+
if (right < 0 || right > 31) return INVALID_SHIFT_COUNT_ERROR;
|
|
888
|
+
return left << right;
|
|
889
|
+
}
|
|
890
|
+
case ">>":
|
|
891
|
+
{
|
|
892
|
+
if (right < 0 || right > 31) return INVALID_SHIFT_COUNT_ERROR;
|
|
893
|
+
return left >>> right | 0;
|
|
894
|
+
}
|
|
895
|
+
case "+":
|
|
896
|
+
return left + right | 0;
|
|
897
|
+
case "-":
|
|
898
|
+
return left - right | 0;
|
|
899
|
+
case "*":
|
|
900
|
+
return Math.imul(left, right);
|
|
901
|
+
case "/":
|
|
902
|
+
if (right === 0) return DIVISION_BY_ZERO_ERROR;
|
|
903
|
+
if (left === -0x80000000 && right === -1) return 0x7fffffff;
|
|
904
|
+
return Math.trunc(left / right) | 0;
|
|
905
|
+
case "%":
|
|
906
|
+
if (right === 0) return MODULO_BY_ZERO_ERROR;
|
|
907
|
+
return left % right | 0;
|
|
908
|
+
default:
|
|
909
|
+
throw new Error("Unsupported preprocessor operator '" + operator + "'.");
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
function validateBinaryRightOperand(operator, right) {
|
|
913
|
+
if ((operator === "/" || operator === "%") && right === 0) {
|
|
914
|
+
return operator === "/" ? DIVISION_BY_ZERO_ERROR : MODULO_BY_ZERO_ERROR;
|
|
915
|
+
}
|
|
916
|
+
if ((operator === "<<" || operator === ">>") && right !== undefined && (right < 0 || right > 31)) {
|
|
917
|
+
return INVALID_SHIFT_COUNT_ERROR;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
function evaluateStaticallyKnownPreprocessorCondition(condition, context) {
|
|
921
|
+
switch(condition.t){
|
|
922
|
+
case "and":
|
|
923
|
+
{
|
|
924
|
+
var left = evaluateStaticallyKnownPreprocessorCondition(condition.l, context);
|
|
925
|
+
if (typeof left === "string") return left;
|
|
926
|
+
if (left === 0) return 0;
|
|
927
|
+
var right = evaluateStaticallyKnownPreprocessorCondition(condition.r, context);
|
|
928
|
+
if (typeof right === "string") return left === undefined ? undefined : right;
|
|
929
|
+
if (right === 0) return 0;
|
|
930
|
+
return left === undefined || right === undefined ? undefined : 1;
|
|
931
|
+
}
|
|
932
|
+
case "or":
|
|
933
|
+
{
|
|
934
|
+
var left1 = evaluateStaticallyKnownPreprocessorCondition(condition.l, context);
|
|
935
|
+
if (typeof left1 === "string") return left1;
|
|
936
|
+
if (left1 !== undefined && left1 !== 0) return 1;
|
|
937
|
+
var right1 = evaluateStaticallyKnownPreprocessorCondition(condition.r, context);
|
|
938
|
+
if (typeof right1 === "string") return left1 === undefined ? undefined : right1;
|
|
939
|
+
if (right1 !== undefined && right1 !== 0) return 1;
|
|
940
|
+
return left1 === undefined || right1 === undefined ? undefined : 0;
|
|
941
|
+
}
|
|
942
|
+
case "binary":
|
|
943
|
+
{
|
|
944
|
+
var left2 = evaluateStaticallyKnownPreprocessorCondition(condition.l, context);
|
|
945
|
+
var right2 = evaluateStaticallyKnownPreprocessorCondition(condition.r, context);
|
|
946
|
+
if (typeof left2 === "string") return left2;
|
|
947
|
+
if (typeof right2 === "string") return right2;
|
|
948
|
+
var rightOperandError = validateBinaryRightOperand(condition.op, right2);
|
|
949
|
+
if (rightOperandError) return rightOperandError;
|
|
950
|
+
if (left2 === undefined || right2 === undefined) {
|
|
951
|
+
return context ? evaluateBoundedIdentifierComparison(condition, left2, right2) : undefined;
|
|
952
|
+
}
|
|
953
|
+
var value = evaluateBinaryExpression(left2, condition.op, right2);
|
|
954
|
+
return value;
|
|
955
|
+
}
|
|
956
|
+
case "not":
|
|
957
|
+
{
|
|
958
|
+
var value1 = evaluateStaticallyKnownPreprocessorCondition(condition.c, context);
|
|
959
|
+
if (typeof value1 === "string") return value1;
|
|
960
|
+
return value1 === undefined ? undefined : value1 === 0 ? 1 : 0;
|
|
961
|
+
}
|
|
962
|
+
case "unary":
|
|
963
|
+
{
|
|
964
|
+
var value2 = evaluateStaticallyKnownPreprocessorCondition(condition.c, context);
|
|
965
|
+
if (typeof value2 === "string") return value2;
|
|
966
|
+
if (value2 === undefined) return undefined;
|
|
967
|
+
return condition.op === "+" ? value2 | 0 : condition.op === "-" ? -value2 | 0 : ~value2;
|
|
968
|
+
}
|
|
969
|
+
case "bool":
|
|
970
|
+
return condition.v ? 1 : 0;
|
|
971
|
+
case "num":
|
|
972
|
+
return condition.v;
|
|
973
|
+
case "def":
|
|
974
|
+
{
|
|
975
|
+
var defined = context == null ? void 0 : context.isDefined(condition.m);
|
|
976
|
+
return defined === undefined ? undefined : defined ? 1 : 0;
|
|
977
|
+
}
|
|
978
|
+
case "ndef":
|
|
979
|
+
{
|
|
980
|
+
var defined1 = context == null ? void 0 : context.isDefined(condition.m);
|
|
981
|
+
return defined1 === undefined ? undefined : defined1 ? 0 : 1;
|
|
982
|
+
}
|
|
983
|
+
case "cmp":
|
|
984
|
+
{
|
|
985
|
+
var resolved = context == null ? void 0 : context.resolveIdentifier(condition.m);
|
|
986
|
+
if (resolved == null ? void 0 : resolved.error) return resolved.error;
|
|
987
|
+
var value3 = resolved == null ? void 0 : resolved.value;
|
|
988
|
+
if (value3 === undefined) return context ? evaluateUnknownSignedComparison(condition.op, condition.v) : undefined;
|
|
989
|
+
var result = evaluateBinaryExpression(value3, condition.op, condition.v);
|
|
990
|
+
return typeof result === "string" ? undefined : result;
|
|
991
|
+
}
|
|
992
|
+
case "id":
|
|
993
|
+
{
|
|
994
|
+
var resolved1 = context == null ? void 0 : context.resolveIdentifier(condition.m);
|
|
995
|
+
return (resolved1 == null ? void 0 : resolved1.error) ? resolved1.error : resolved1 == null ? void 0 : resolved1.value;
|
|
996
|
+
}
|
|
997
|
+
case "deferred":
|
|
998
|
+
return undefined;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
function evaluateBoundedIdentifierComparison(condition, left, right) {
|
|
1002
|
+
if (!isComparisonOperator(condition.op)) return undefined;
|
|
1003
|
+
if (condition.l.t === "id" && left === undefined && right !== undefined) {
|
|
1004
|
+
return evaluateUnknownSignedComparison(condition.op, right);
|
|
1005
|
+
}
|
|
1006
|
+
if (condition.r.t === "id" && right === undefined && left !== undefined) {
|
|
1007
|
+
return evaluateUnknownSignedComparison(reverseComparison(condition.op), left);
|
|
1008
|
+
}
|
|
1009
|
+
return undefined;
|
|
1010
|
+
}
|
|
1011
|
+
function evaluateUnknownSignedComparison(operator, value) {
|
|
1012
|
+
if (!isComparisonOperator(operator) || operator === "==" || operator === "!=") return undefined;
|
|
1013
|
+
var atMinimum = evaluateBinaryExpression(-0x80000000, operator, value);
|
|
1014
|
+
var atMaximum = evaluateBinaryExpression(0x7fffffff, operator, value);
|
|
1015
|
+
return typeof atMinimum === "number" && atMinimum === atMaximum ? atMinimum : undefined;
|
|
1016
|
+
}
|
|
1017
|
+
function isComparisonOperator(operator) {
|
|
1018
|
+
return operator === "==" || operator === "!=" || operator === "<" || operator === "<=" || operator === ">" || operator === ">=";
|
|
1019
|
+
}
|
|
1020
|
+
function reverseComparison(operator) {
|
|
1021
|
+
switch(operator){
|
|
1022
|
+
case "<":
|
|
1023
|
+
return ">";
|
|
1024
|
+
case "<=":
|
|
1025
|
+
return ">=";
|
|
1026
|
+
case ">":
|
|
1027
|
+
return "<";
|
|
1028
|
+
case ">=":
|
|
1029
|
+
return "<=";
|
|
1030
|
+
default:
|
|
1031
|
+
return operator;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
function isWhitespace(charCode) {
|
|
1035
|
+
return charCode === 32 || charCode >= 9 && charCode <= 13;
|
|
1036
|
+
}
|
|
1037
|
+
function isIdentifierStart(charCode) {
|
|
1038
|
+
return charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122 || charCode === 95;
|
|
1039
|
+
}
|
|
1040
|
+
function isIdentifierPart(charCode) {
|
|
1041
|
+
return isIdentifierStart(charCode) || charCode >= 48 && charCode <= 57;
|
|
1042
|
+
}
|
|
1043
|
+
function isHexDigit(charCode) {
|
|
1044
|
+
return charCode >= 48 && charCode <= 57 || charCode >= 65 && charCode <= 70 || charCode >= 97 && charCode <= 102;
|
|
1045
|
+
}
|
|
1046
|
+
function isIntegerSuffix(charCode) {
|
|
1047
|
+
return charCode === 85 || charCode === 117;
|
|
1048
|
+
}
|
|
1049
|
+
function isValidIntegerSuffix(suffix) {
|
|
1050
|
+
return suffix === "" || suffix === "u" || suffix === "U";
|
|
1051
|
+
}
|
|
1052
|
+
function isDoubleOperator(charCode, nextCharCode) {
|
|
1053
|
+
return charCode === 124 && nextCharCode === 124 || charCode === 38 && nextCharCode === 38 || (charCode === 33 || charCode === 61) && nextCharCode === 61 || (charCode === 60 || charCode === 62) && (nextCharCode === 61 || nextCharCode === charCode);
|
|
1054
|
+
}
|
|
1055
|
+
function isSingleOperator(charCode) {
|
|
1056
|
+
return charCode === 33 || charCode === 37 || charCode === 38 || charCode === 40 || charCode === 41 || charCode === 42 || charCode === 43 || charCode === 45 || charCode === 47 || charCode === 58 || charCode === 60 || charCode === 62 || charCode === 63 || charCode === 94 || charCode === 124 || charCode === 126;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
var SHADER_ROOT_URL = "shaders://root/";
|
|
1060
|
+
var ABSOLUTE_URL_PATTERN = /^[A-Za-z][A-Za-z\d+.-]*:/;
|
|
1061
|
+
/**
|
|
1062
|
+
* Converts a registered shader-include key to its canonical lookup form.
|
|
1063
|
+
* @param includeKey - Logical project path, project-root path, or absolute URL.
|
|
1064
|
+
* @returns Canonical registry key without the virtual shader-root prefix.
|
|
1065
|
+
* @throws Error when the key is empty or an absolute URL is malformed.
|
|
1066
|
+
*/ function normalizeShaderIncludeKey(includeKey) {
|
|
1067
|
+
var normalized = includeKey.trim().replace(/\\/g, "/");
|
|
1068
|
+
if (!normalized) throw new Error("Shader include key cannot be empty.");
|
|
1069
|
+
if (normalized.startsWith(SHADER_ROOT_URL)) {
|
|
1070
|
+
var key = new URL(normalized).href.slice(SHADER_ROOT_URL.length);
|
|
1071
|
+
if (!key) throw new Error("Shader include key cannot be the virtual shader root.");
|
|
1072
|
+
return key;
|
|
1073
|
+
}
|
|
1074
|
+
if (ABSOLUTE_URL_PATTERN.test(normalized)) {
|
|
1075
|
+
return new URL(normalized).href;
|
|
1076
|
+
}
|
|
1077
|
+
return new URL(normalized.replace(/^\/+/, ""), SHADER_ROOT_URL).href.slice(SHADER_ROOT_URL.length);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
export { evaluateContextFreePreprocessorCondition, evaluateContextFreePreprocessorExpression, evaluatePartiallyKnownPreprocessorCondition, evaluatePartiallyKnownPreprocessorConditionResult, evaluatePreprocessorExpression, expandPreprocessorExpressionMacros, expandShaderMacros, normalizeShaderIncludeKey, parsePreprocessorExpression, resolvePreprocessorDefinedOperators };
|
|
1081
|
+
//# sourceMappingURL=module.js.map
|