shaderkit 0.6.4 → 0.8.0
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 -21
- package/README.md +781 -781
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/package.json +46 -40
- package/src/ast.ts +425 -425
- package/src/constants.ts +1005 -1005
- package/src/generator.ts +128 -128
- package/src/hoister.ts +171 -0
- package/src/index.ts +7 -7
- package/src/minifier.ts +445 -159
- package/src/parser.ts +878 -802
- package/src/tokenizer.ts +105 -89
- package/src/visitor.ts +131 -131
package/src/ast.ts
CHANGED
|
@@ -1,425 +1,425 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A position in the source code.
|
|
3
|
-
*/
|
|
4
|
-
// export interface Position {
|
|
5
|
-
// line: number // >= 1
|
|
6
|
-
// column: number // >= 0
|
|
7
|
-
// }
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Represents the source location of a node.
|
|
11
|
-
*/
|
|
12
|
-
// export interface SourceLocation {
|
|
13
|
-
// source: string | null
|
|
14
|
-
// start: Position
|
|
15
|
-
// end: Position
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Base interface for all AST nodes.
|
|
20
|
-
*/
|
|
21
|
-
export interface Node {
|
|
22
|
-
type: string
|
|
23
|
-
// loc: SourceLocation | null
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Represents the root of an AST.
|
|
28
|
-
*/
|
|
29
|
-
export interface Program extends Node {
|
|
30
|
-
type: 'Program'
|
|
31
|
-
body: Statement[]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* A variable identifier.
|
|
36
|
-
*/
|
|
37
|
-
export interface Identifier extends Node {
|
|
38
|
-
type: 'Identifier'
|
|
39
|
-
name: string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* A shader literal representing a `bool`, `float`, `int`, or `uint` type.
|
|
44
|
-
*/
|
|
45
|
-
export interface Literal extends Node {
|
|
46
|
-
type: 'Literal'
|
|
47
|
-
value: string /*| number | boolean*/
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* An array and its dimensions.
|
|
52
|
-
*/
|
|
53
|
-
export interface ArraySpecifier extends Node {
|
|
54
|
-
type: 'ArraySpecifier'
|
|
55
|
-
typeSpecifier: Identifier
|
|
56
|
-
dimensions: (Literal | Identifier | null)[]
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* An array initialization expression.
|
|
61
|
-
*/
|
|
62
|
-
export interface ArrayExpression extends Node {
|
|
63
|
-
type: 'ArrayExpression'
|
|
64
|
-
typeSpecifier: ArraySpecifier
|
|
65
|
-
elements: Expression[]
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export type UnaryOperator = '-' | '+' | '!' | '~'
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* A unary expression with a left or right handed operator.
|
|
72
|
-
*/
|
|
73
|
-
export interface UnaryExpression extends Node {
|
|
74
|
-
type: 'UnaryExpression'
|
|
75
|
-
operator: UnaryOperator
|
|
76
|
-
prefix: boolean
|
|
77
|
-
argument: Expression
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* An update expression with an optionally prefixed operator.
|
|
82
|
-
*/
|
|
83
|
-
export interface UpdateExpression extends Node {
|
|
84
|
-
type: 'UpdateExpression'
|
|
85
|
-
operator: UpdateOperator
|
|
86
|
-
argument: Expression
|
|
87
|
-
prefix: boolean
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export type UpdateOperator = '++' | '--'
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* A binary expression with a left and right operand.
|
|
94
|
-
*/
|
|
95
|
-
export interface BinaryExpression extends Node {
|
|
96
|
-
type: 'BinaryExpression'
|
|
97
|
-
operator: BinaryOperator
|
|
98
|
-
left: Expression
|
|
99
|
-
right: Expression
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export type BinaryOperator =
|
|
103
|
-
| ','
|
|
104
|
-
| '=='
|
|
105
|
-
| '!='
|
|
106
|
-
| '<'
|
|
107
|
-
| '<='
|
|
108
|
-
| '>'
|
|
109
|
-
| '>='
|
|
110
|
-
| '<<'
|
|
111
|
-
| '>>'
|
|
112
|
-
| '+'
|
|
113
|
-
| '-'
|
|
114
|
-
| '*'
|
|
115
|
-
| '/'
|
|
116
|
-
| '%'
|
|
117
|
-
| '|'
|
|
118
|
-
| '^'
|
|
119
|
-
| '&'
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* An assignment expression.
|
|
123
|
-
*/
|
|
124
|
-
export interface AssignmentExpression extends Node {
|
|
125
|
-
type: 'AssignmentExpression'
|
|
126
|
-
operator: AssignmentOperator
|
|
127
|
-
left: Expression
|
|
128
|
-
right: Expression
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export type AssignmentOperator = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '<<=' | '>>=' | '>>>=' | '|=' | '^=' | '&='
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* A logical operation between two expressions.
|
|
135
|
-
*/
|
|
136
|
-
export interface LogicalExpression extends Node {
|
|
137
|
-
type: 'LogicalExpression'
|
|
138
|
-
operator: LogicalOperator
|
|
139
|
-
left: Expression
|
|
140
|
-
right: Expression
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export type LogicalOperator = '||' | '&&' | '^^'
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* A member expression.
|
|
147
|
-
*/
|
|
148
|
-
export interface MemberExpression extends Node {
|
|
149
|
-
type: 'MemberExpression'
|
|
150
|
-
object: Expression
|
|
151
|
-
property: Expression
|
|
152
|
-
computed: boolean
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* A conditional expression or ternary.
|
|
157
|
-
*/
|
|
158
|
-
export interface ConditionalExpression extends Node {
|
|
159
|
-
type: 'ConditionalExpression'
|
|
160
|
-
test: Expression
|
|
161
|
-
alternate: Expression
|
|
162
|
-
consequent: Expression
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* A function call expression or struct initialization.
|
|
167
|
-
*/
|
|
168
|
-
export interface CallExpression extends Node {
|
|
169
|
-
type: 'CallExpression'
|
|
170
|
-
callee: Expression
|
|
171
|
-
arguments: Expression[]
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* An expression as a standalone statement.
|
|
176
|
-
*/
|
|
177
|
-
export interface ExpressionStatement extends Node {
|
|
178
|
-
type: 'ExpressionStatement'
|
|
179
|
-
expression: Expression
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* A block statement.
|
|
184
|
-
*/
|
|
185
|
-
export interface BlockStatement extends Node {
|
|
186
|
-
type: 'BlockStatement'
|
|
187
|
-
body: Statement[]
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* A return statement with an optional argument.
|
|
192
|
-
*/
|
|
193
|
-
export interface ReturnStatement extends Node {
|
|
194
|
-
type: 'ReturnStatement'
|
|
195
|
-
argument: Expression | null
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* A break statement.
|
|
200
|
-
*/
|
|
201
|
-
export interface BreakStatement extends Node {
|
|
202
|
-
type: 'BreakStatement'
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* A continue statement.
|
|
207
|
-
*/
|
|
208
|
-
export interface ContinueStatement extends Node {
|
|
209
|
-
type: 'ContinueStatement'
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* A discard statement in fragment shaders.
|
|
214
|
-
*/
|
|
215
|
-
export interface DiscardStatement extends Node {
|
|
216
|
-
type: 'DiscardStatement'
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* An if-else statement.
|
|
221
|
-
*/
|
|
222
|
-
export interface IfStatement extends Node {
|
|
223
|
-
type: 'IfStatement'
|
|
224
|
-
test: Expression
|
|
225
|
-
consequent: Statement
|
|
226
|
-
alternate: Statement | null
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* A switch statement.
|
|
231
|
-
*/
|
|
232
|
-
export interface SwitchStatement extends Node {
|
|
233
|
-
type: 'SwitchStatement'
|
|
234
|
-
discriminant: Expression
|
|
235
|
-
cases: SwitchCase[]
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* A switch-case statement. `test` is null for a `default` case.
|
|
240
|
-
*/
|
|
241
|
-
export interface SwitchCase extends Node {
|
|
242
|
-
type: 'SwitchCase'
|
|
243
|
-
test: Expression | null
|
|
244
|
-
consequent: Statement[]
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* A while statement.
|
|
249
|
-
*/
|
|
250
|
-
export interface WhileStatement extends Node {
|
|
251
|
-
type: 'WhileStatement'
|
|
252
|
-
test: Expression
|
|
253
|
-
body: Statement
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* A do-while statement.
|
|
258
|
-
*/
|
|
259
|
-
export interface DoWhileStatement extends Node {
|
|
260
|
-
type: 'DoWhileStatement'
|
|
261
|
-
body: Statement
|
|
262
|
-
test: Expression
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* A for statement.
|
|
267
|
-
*/
|
|
268
|
-
export interface ForStatement extends Node {
|
|
269
|
-
type: 'ForStatement'
|
|
270
|
-
init: VariableDeclaration | Expression | null
|
|
271
|
-
test: Expression | null
|
|
272
|
-
update: Expression | null
|
|
273
|
-
body: Statement
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export type ConstantQualifier = 'const'
|
|
277
|
-
export type ParameterQualifier = 'in' | 'out' | 'inout'
|
|
278
|
-
export type StorageQualifier = 'uniform' | 'in' | 'out' | 'attribute' | 'varying'
|
|
279
|
-
export type InterfaceStorageQualifier = 'uniform' | 'buffer'
|
|
280
|
-
export type MemoryQualifier = 'coherent' | 'volatile' | 'restrict' | 'readonly' | 'writeonly'
|
|
281
|
-
|
|
282
|
-
export type InterpolationQualifier = 'centroid' | 'smooth' | 'flat' | 'invariant'
|
|
283
|
-
export type LayoutQualifier = 'location' | 'std140' | 'packed' | 'shared'
|
|
284
|
-
export type PrecisionQualifier = 'highp' | 'mediump' | 'lowp'
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* A function declaration. `body` is null for overloads.
|
|
288
|
-
*/
|
|
289
|
-
export interface FunctionDeclaration extends Node {
|
|
290
|
-
type: 'FunctionDeclaration'
|
|
291
|
-
id: Identifier
|
|
292
|
-
qualifiers: PrecisionQualifier[]
|
|
293
|
-
typeSpecifier: Identifier | ArraySpecifier
|
|
294
|
-
params: FunctionParameter[]
|
|
295
|
-
body: BlockStatement | null
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* A function parameter within a function declaration.
|
|
300
|
-
*/
|
|
301
|
-
export interface FunctionParameter extends Node {
|
|
302
|
-
type: 'FunctionParameter'
|
|
303
|
-
id: Identifier | null
|
|
304
|
-
qualifiers: (ConstantQualifier | ParameterQualifier | PrecisionQualifier)[]
|
|
305
|
-
typeSpecifier: Identifier | ArraySpecifier
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* A variable declaration.
|
|
310
|
-
*/
|
|
311
|
-
export interface VariableDeclaration extends Node {
|
|
312
|
-
type: 'VariableDeclaration'
|
|
313
|
-
declarations: VariableDeclarator[]
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* A variable declarator within a variable declaration.
|
|
318
|
-
*/
|
|
319
|
-
export interface VariableDeclarator extends Node {
|
|
320
|
-
type: 'VariableDeclarator'
|
|
321
|
-
id: Identifier
|
|
322
|
-
qualifiers: (ConstantQualifier | InterpolationQualifier | StorageQualifier | PrecisionQualifier)[]
|
|
323
|
-
typeSpecifier: Identifier | ArraySpecifier
|
|
324
|
-
layout: Record<string, string | boolean> | null
|
|
325
|
-
init: Expression | null
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* A uniform declaration block with optional layout and qualifiers.
|
|
330
|
-
*/
|
|
331
|
-
export interface StructuredBufferDeclaration extends Node {
|
|
332
|
-
type: 'StructuredBufferDeclaration'
|
|
333
|
-
id: Identifier | null
|
|
334
|
-
qualifiers: (InterfaceStorageQualifier | MemoryQualifier | LayoutQualifier)[]
|
|
335
|
-
typeSpecifier: Identifier | ArraySpecifier
|
|
336
|
-
layout: Record<string, string | boolean> | null
|
|
337
|
-
members: VariableDeclaration[]
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* A struct declaration. Can be used as a type or constructor.
|
|
342
|
-
*/
|
|
343
|
-
export interface StructDeclaration extends Node {
|
|
344
|
-
type: 'StructDeclaration'
|
|
345
|
-
id: Identifier
|
|
346
|
-
members: VariableDeclaration[]
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* A GLSL preprocessor statement with an optional value.
|
|
351
|
-
*/
|
|
352
|
-
export interface PreprocessorStatement extends Node {
|
|
353
|
-
type: 'PreprocessorStatement'
|
|
354
|
-
name: string
|
|
355
|
-
value: Expression[] | null
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* A GLSL precision qualifier statement.
|
|
360
|
-
*/
|
|
361
|
-
export interface PrecisionQualifierStatement extends Node {
|
|
362
|
-
type: 'PrecisionQualifierStatement'
|
|
363
|
-
precision: PrecisionQualifier
|
|
364
|
-
typeSpecifier: Identifier
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* A GLSL invariant qualifier statement.
|
|
369
|
-
*/
|
|
370
|
-
export interface InvariantQualifierStatement extends Node {
|
|
371
|
-
type: 'InvariantQualifierStatement'
|
|
372
|
-
typeSpecifier: Identifier
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* A layout qualifier statement.
|
|
377
|
-
*/
|
|
378
|
-
export interface LayoutQualifierStatement extends Node {
|
|
379
|
-
type: 'LayoutQualifierStatement'
|
|
380
|
-
layout: Record<string, string | boolean>
|
|
381
|
-
qualifier: StorageQualifier
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
export type Expression =
|
|
385
|
-
| Literal
|
|
386
|
-
| Identifier
|
|
387
|
-
| ArrayExpression
|
|
388
|
-
| UnaryExpression
|
|
389
|
-
| UpdateExpression
|
|
390
|
-
| BinaryExpression
|
|
391
|
-
| AssignmentExpression
|
|
392
|
-
| LogicalExpression
|
|
393
|
-
| MemberExpression
|
|
394
|
-
| ConditionalExpression
|
|
395
|
-
| CallExpression
|
|
396
|
-
|
|
397
|
-
export type Statement =
|
|
398
|
-
| ExpressionStatement
|
|
399
|
-
| BlockStatement
|
|
400
|
-
| ReturnStatement
|
|
401
|
-
| BreakStatement
|
|
402
|
-
| ContinueStatement
|
|
403
|
-
| DiscardStatement
|
|
404
|
-
| IfStatement
|
|
405
|
-
| SwitchStatement
|
|
406
|
-
| WhileStatement
|
|
407
|
-
| DoWhileStatement
|
|
408
|
-
| ForStatement
|
|
409
|
-
| FunctionDeclaration
|
|
410
|
-
| VariableDeclaration
|
|
411
|
-
| StructuredBufferDeclaration
|
|
412
|
-
| StructDeclaration
|
|
413
|
-
| PreprocessorStatement
|
|
414
|
-
| PrecisionQualifierStatement
|
|
415
|
-
| InvariantQualifierStatement
|
|
416
|
-
| LayoutQualifierStatement
|
|
417
|
-
|
|
418
|
-
export type AST =
|
|
419
|
-
| Program
|
|
420
|
-
| ArraySpecifier
|
|
421
|
-
| SwitchCase
|
|
422
|
-
| FunctionParameter
|
|
423
|
-
| VariableDeclarator
|
|
424
|
-
| Expression
|
|
425
|
-
| Statement
|
|
1
|
+
/**
|
|
2
|
+
* A position in the source code.
|
|
3
|
+
*/
|
|
4
|
+
// export interface Position {
|
|
5
|
+
// line: number // >= 1
|
|
6
|
+
// column: number // >= 0
|
|
7
|
+
// }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents the source location of a node.
|
|
11
|
+
*/
|
|
12
|
+
// export interface SourceLocation {
|
|
13
|
+
// source: string | null
|
|
14
|
+
// start: Position
|
|
15
|
+
// end: Position
|
|
16
|
+
// }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Base interface for all AST nodes.
|
|
20
|
+
*/
|
|
21
|
+
export interface Node {
|
|
22
|
+
type: string
|
|
23
|
+
// loc: SourceLocation | null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Represents the root of an AST.
|
|
28
|
+
*/
|
|
29
|
+
export interface Program extends Node {
|
|
30
|
+
type: 'Program'
|
|
31
|
+
body: Statement[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A variable identifier.
|
|
36
|
+
*/
|
|
37
|
+
export interface Identifier extends Node {
|
|
38
|
+
type: 'Identifier'
|
|
39
|
+
name: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A shader literal representing a `bool`, `float`, `int`, or `uint` type.
|
|
44
|
+
*/
|
|
45
|
+
export interface Literal extends Node {
|
|
46
|
+
type: 'Literal'
|
|
47
|
+
value: string /*| number | boolean*/
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* An array and its dimensions.
|
|
52
|
+
*/
|
|
53
|
+
export interface ArraySpecifier extends Node {
|
|
54
|
+
type: 'ArraySpecifier'
|
|
55
|
+
typeSpecifier: Identifier
|
|
56
|
+
dimensions: (Literal | Identifier | null)[]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* An array initialization expression.
|
|
61
|
+
*/
|
|
62
|
+
export interface ArrayExpression extends Node {
|
|
63
|
+
type: 'ArrayExpression'
|
|
64
|
+
typeSpecifier: ArraySpecifier
|
|
65
|
+
elements: Expression[]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type UnaryOperator = '-' | '+' | '!' | '~'
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A unary expression with a left or right handed operator.
|
|
72
|
+
*/
|
|
73
|
+
export interface UnaryExpression extends Node {
|
|
74
|
+
type: 'UnaryExpression'
|
|
75
|
+
operator: UnaryOperator
|
|
76
|
+
prefix: boolean
|
|
77
|
+
argument: Expression
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* An update expression with an optionally prefixed operator.
|
|
82
|
+
*/
|
|
83
|
+
export interface UpdateExpression extends Node {
|
|
84
|
+
type: 'UpdateExpression'
|
|
85
|
+
operator: UpdateOperator
|
|
86
|
+
argument: Expression
|
|
87
|
+
prefix: boolean
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type UpdateOperator = '++' | '--'
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A binary expression with a left and right operand.
|
|
94
|
+
*/
|
|
95
|
+
export interface BinaryExpression extends Node {
|
|
96
|
+
type: 'BinaryExpression'
|
|
97
|
+
operator: BinaryOperator
|
|
98
|
+
left: Expression
|
|
99
|
+
right: Expression
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type BinaryOperator =
|
|
103
|
+
| ','
|
|
104
|
+
| '=='
|
|
105
|
+
| '!='
|
|
106
|
+
| '<'
|
|
107
|
+
| '<='
|
|
108
|
+
| '>'
|
|
109
|
+
| '>='
|
|
110
|
+
| '<<'
|
|
111
|
+
| '>>'
|
|
112
|
+
| '+'
|
|
113
|
+
| '-'
|
|
114
|
+
| '*'
|
|
115
|
+
| '/'
|
|
116
|
+
| '%'
|
|
117
|
+
| '|'
|
|
118
|
+
| '^'
|
|
119
|
+
| '&'
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* An assignment expression.
|
|
123
|
+
*/
|
|
124
|
+
export interface AssignmentExpression extends Node {
|
|
125
|
+
type: 'AssignmentExpression'
|
|
126
|
+
operator: AssignmentOperator
|
|
127
|
+
left: Expression
|
|
128
|
+
right: Expression
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type AssignmentOperator = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '<<=' | '>>=' | '>>>=' | '|=' | '^=' | '&='
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A logical operation between two expressions.
|
|
135
|
+
*/
|
|
136
|
+
export interface LogicalExpression extends Node {
|
|
137
|
+
type: 'LogicalExpression'
|
|
138
|
+
operator: LogicalOperator
|
|
139
|
+
left: Expression
|
|
140
|
+
right: Expression
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type LogicalOperator = '||' | '&&' | '^^'
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A member expression.
|
|
147
|
+
*/
|
|
148
|
+
export interface MemberExpression extends Node {
|
|
149
|
+
type: 'MemberExpression'
|
|
150
|
+
object: Expression
|
|
151
|
+
property: Expression
|
|
152
|
+
computed: boolean
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A conditional expression or ternary.
|
|
157
|
+
*/
|
|
158
|
+
export interface ConditionalExpression extends Node {
|
|
159
|
+
type: 'ConditionalExpression'
|
|
160
|
+
test: Expression
|
|
161
|
+
alternate: Expression
|
|
162
|
+
consequent: Expression
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A function call expression or struct initialization.
|
|
167
|
+
*/
|
|
168
|
+
export interface CallExpression extends Node {
|
|
169
|
+
type: 'CallExpression'
|
|
170
|
+
callee: Expression
|
|
171
|
+
arguments: Expression[]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* An expression as a standalone statement.
|
|
176
|
+
*/
|
|
177
|
+
export interface ExpressionStatement extends Node {
|
|
178
|
+
type: 'ExpressionStatement'
|
|
179
|
+
expression: Expression
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A block statement.
|
|
184
|
+
*/
|
|
185
|
+
export interface BlockStatement extends Node {
|
|
186
|
+
type: 'BlockStatement'
|
|
187
|
+
body: Statement[]
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A return statement with an optional argument.
|
|
192
|
+
*/
|
|
193
|
+
export interface ReturnStatement extends Node {
|
|
194
|
+
type: 'ReturnStatement'
|
|
195
|
+
argument: Expression | null
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* A break statement.
|
|
200
|
+
*/
|
|
201
|
+
export interface BreakStatement extends Node {
|
|
202
|
+
type: 'BreakStatement'
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* A continue statement.
|
|
207
|
+
*/
|
|
208
|
+
export interface ContinueStatement extends Node {
|
|
209
|
+
type: 'ContinueStatement'
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* A discard statement in fragment shaders.
|
|
214
|
+
*/
|
|
215
|
+
export interface DiscardStatement extends Node {
|
|
216
|
+
type: 'DiscardStatement'
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* An if-else statement.
|
|
221
|
+
*/
|
|
222
|
+
export interface IfStatement extends Node {
|
|
223
|
+
type: 'IfStatement'
|
|
224
|
+
test: Expression
|
|
225
|
+
consequent: Statement
|
|
226
|
+
alternate: Statement | null
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* A switch statement.
|
|
231
|
+
*/
|
|
232
|
+
export interface SwitchStatement extends Node {
|
|
233
|
+
type: 'SwitchStatement'
|
|
234
|
+
discriminant: Expression
|
|
235
|
+
cases: SwitchCase[]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* A switch-case statement. `test` is null for a `default` case.
|
|
240
|
+
*/
|
|
241
|
+
export interface SwitchCase extends Node {
|
|
242
|
+
type: 'SwitchCase'
|
|
243
|
+
test: Expression | null
|
|
244
|
+
consequent: Statement[]
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A while statement.
|
|
249
|
+
*/
|
|
250
|
+
export interface WhileStatement extends Node {
|
|
251
|
+
type: 'WhileStatement'
|
|
252
|
+
test: Expression
|
|
253
|
+
body: Statement
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* A do-while statement.
|
|
258
|
+
*/
|
|
259
|
+
export interface DoWhileStatement extends Node {
|
|
260
|
+
type: 'DoWhileStatement'
|
|
261
|
+
body: Statement
|
|
262
|
+
test: Expression
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* A for statement.
|
|
267
|
+
*/
|
|
268
|
+
export interface ForStatement extends Node {
|
|
269
|
+
type: 'ForStatement'
|
|
270
|
+
init: VariableDeclaration | Expression | null
|
|
271
|
+
test: Expression | null
|
|
272
|
+
update: Expression | null
|
|
273
|
+
body: Statement
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export type ConstantQualifier = 'const'
|
|
277
|
+
export type ParameterQualifier = 'in' | 'out' | 'inout'
|
|
278
|
+
export type StorageQualifier = 'uniform' | 'in' | 'out' | 'attribute' | 'varying'
|
|
279
|
+
export type InterfaceStorageQualifier = 'uniform' | 'buffer'
|
|
280
|
+
export type MemoryQualifier = 'coherent' | 'volatile' | 'restrict' | 'readonly' | 'writeonly'
|
|
281
|
+
|
|
282
|
+
export type InterpolationQualifier = 'centroid' | 'smooth' | 'flat' | 'invariant'
|
|
283
|
+
export type LayoutQualifier = 'location' | 'std140' | 'packed' | 'shared'
|
|
284
|
+
export type PrecisionQualifier = 'highp' | 'mediump' | 'lowp'
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* A function declaration. `body` is null for overloads.
|
|
288
|
+
*/
|
|
289
|
+
export interface FunctionDeclaration extends Node {
|
|
290
|
+
type: 'FunctionDeclaration'
|
|
291
|
+
id: Identifier
|
|
292
|
+
qualifiers: PrecisionQualifier[]
|
|
293
|
+
typeSpecifier: Identifier | ArraySpecifier
|
|
294
|
+
params: FunctionParameter[]
|
|
295
|
+
body: BlockStatement | null
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* A function parameter within a function declaration.
|
|
300
|
+
*/
|
|
301
|
+
export interface FunctionParameter extends Node {
|
|
302
|
+
type: 'FunctionParameter'
|
|
303
|
+
id: Identifier | null
|
|
304
|
+
qualifiers: (ConstantQualifier | ParameterQualifier | PrecisionQualifier)[]
|
|
305
|
+
typeSpecifier: Identifier | ArraySpecifier
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* A variable declaration.
|
|
310
|
+
*/
|
|
311
|
+
export interface VariableDeclaration extends Node {
|
|
312
|
+
type: 'VariableDeclaration'
|
|
313
|
+
declarations: VariableDeclarator[]
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* A variable declarator within a variable declaration.
|
|
318
|
+
*/
|
|
319
|
+
export interface VariableDeclarator extends Node {
|
|
320
|
+
type: 'VariableDeclarator'
|
|
321
|
+
id: Identifier
|
|
322
|
+
qualifiers: (ConstantQualifier | InterpolationQualifier | StorageQualifier | PrecisionQualifier)[]
|
|
323
|
+
typeSpecifier: Identifier | ArraySpecifier
|
|
324
|
+
layout: Record<string, string | boolean> | null
|
|
325
|
+
init: Expression | null
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A uniform declaration block with optional layout and qualifiers.
|
|
330
|
+
*/
|
|
331
|
+
export interface StructuredBufferDeclaration extends Node {
|
|
332
|
+
type: 'StructuredBufferDeclaration'
|
|
333
|
+
id: Identifier | null
|
|
334
|
+
qualifiers: (InterfaceStorageQualifier | MemoryQualifier | LayoutQualifier)[]
|
|
335
|
+
typeSpecifier: Identifier | ArraySpecifier
|
|
336
|
+
layout: Record<string, string | boolean> | null
|
|
337
|
+
members: VariableDeclaration[]
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* A struct declaration. Can be used as a type or constructor.
|
|
342
|
+
*/
|
|
343
|
+
export interface StructDeclaration extends Node {
|
|
344
|
+
type: 'StructDeclaration'
|
|
345
|
+
id: Identifier
|
|
346
|
+
members: VariableDeclaration[]
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* A GLSL preprocessor statement with an optional value.
|
|
351
|
+
*/
|
|
352
|
+
export interface PreprocessorStatement extends Node {
|
|
353
|
+
type: 'PreprocessorStatement'
|
|
354
|
+
name: string
|
|
355
|
+
value: Expression[] | null
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* A GLSL precision qualifier statement.
|
|
360
|
+
*/
|
|
361
|
+
export interface PrecisionQualifierStatement extends Node {
|
|
362
|
+
type: 'PrecisionQualifierStatement'
|
|
363
|
+
precision: PrecisionQualifier
|
|
364
|
+
typeSpecifier: Identifier
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* A GLSL invariant qualifier statement.
|
|
369
|
+
*/
|
|
370
|
+
export interface InvariantQualifierStatement extends Node {
|
|
371
|
+
type: 'InvariantQualifierStatement'
|
|
372
|
+
typeSpecifier: Identifier
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* A layout qualifier statement.
|
|
377
|
+
*/
|
|
378
|
+
export interface LayoutQualifierStatement extends Node {
|
|
379
|
+
type: 'LayoutQualifierStatement'
|
|
380
|
+
layout: Record<string, string | boolean>
|
|
381
|
+
qualifier: StorageQualifier
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export type Expression =
|
|
385
|
+
| Literal
|
|
386
|
+
| Identifier
|
|
387
|
+
| ArrayExpression
|
|
388
|
+
| UnaryExpression
|
|
389
|
+
| UpdateExpression
|
|
390
|
+
| BinaryExpression
|
|
391
|
+
| AssignmentExpression
|
|
392
|
+
| LogicalExpression
|
|
393
|
+
| MemberExpression
|
|
394
|
+
| ConditionalExpression
|
|
395
|
+
| CallExpression
|
|
396
|
+
|
|
397
|
+
export type Statement =
|
|
398
|
+
| ExpressionStatement
|
|
399
|
+
| BlockStatement
|
|
400
|
+
| ReturnStatement
|
|
401
|
+
| BreakStatement
|
|
402
|
+
| ContinueStatement
|
|
403
|
+
| DiscardStatement
|
|
404
|
+
| IfStatement
|
|
405
|
+
| SwitchStatement
|
|
406
|
+
| WhileStatement
|
|
407
|
+
| DoWhileStatement
|
|
408
|
+
| ForStatement
|
|
409
|
+
| FunctionDeclaration
|
|
410
|
+
| VariableDeclaration
|
|
411
|
+
| StructuredBufferDeclaration
|
|
412
|
+
| StructDeclaration
|
|
413
|
+
| PreprocessorStatement
|
|
414
|
+
| PrecisionQualifierStatement
|
|
415
|
+
| InvariantQualifierStatement
|
|
416
|
+
| LayoutQualifierStatement
|
|
417
|
+
|
|
418
|
+
export type AST =
|
|
419
|
+
| Program
|
|
420
|
+
| ArraySpecifier
|
|
421
|
+
| SwitchCase
|
|
422
|
+
| FunctionParameter
|
|
423
|
+
| VariableDeclarator
|
|
424
|
+
| Expression
|
|
425
|
+
| Statement
|