1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
// This file was autogenerated by binjs_generate_spidermonkey,
// please DO NOT EDIT BY HAND.
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// To generate this file, see the documentation in
// js/src/frontend/binast/README.md.
#ifndef frontend_BinASTToken_h
#define frontend_BinASTToken_h
#include <stddef.h>
/**
* Definition of Binary AST tokens.
*
* In the Binary AST world, an AST is composed of nodes, where a node is
* defined by:
* - a Kind (see `BinASTKind`);
* - a list of fields, where each field is:
* - a Name (see `BinASTField`);
* - a Value, which may be either a node or a primitive value.
*
* The mapping between Kind and list of fields is determined entirely by
* the grammar of Binary AST. The mapping between (Kind, Name) and the
* structure of Value is also determined entirely by the grammar of
* Binary AST.
*
* As per the specifications of Binary AST, kinds may be added as the
* language grows, but never removed. The mapping between Kind and list
* of fields may also change to add new fields or make some fields optional,
* but may never remove a field. Finally, the mapping between (Kind, Name)
* and the structure of Value may be modified to add new possible values,
* but never to remove a value.
*
* A Binary AST parser must be able to fail gracefully when confronted with
* unknown Kinds or Names.
*/
namespace js {
namespace frontend {
/**
* The different kinds of Binary AST nodes, as per the specifications of
* Binary AST.
*
* These kinds match roughly with the `ParseNodeKind` used internally.
*
* Usage:
*
* ```c++
* #define WITH_KIND(CPP_NAME, SPEC_NAME) ...
* FOR_EACH_BIN_KIND(WITH_KIND)
* ```
*
*
* (sorted by alphabetical order)
*/
#define FOR_EACH_BIN_KIND(F) \
F(_Null, "") \
F(ArrayAssignmentTarget, "ArrayAssignmentTarget") \
F(ArrayBinding, "ArrayBinding") \
F(ArrayExpression, "ArrayExpression") \
F(ArrowExpressionContentsWithExpression, \
"ArrowExpressionContentsWithExpression") \
F(ArrowExpressionContentsWithFunctionBody, \
"ArrowExpressionContentsWithFunctionBody") \
F(AssertedBlockScope, "AssertedBlockScope") \
F(AssertedBoundName, "AssertedBoundName") \
F(AssertedBoundNamesScope, "AssertedBoundNamesScope") \
F(AssertedDeclaredName, "AssertedDeclaredName") \
F(AssertedParameterName, "AssertedParameterName") \
F(AssertedParameterScope, "AssertedParameterScope") \
F(AssertedPositionalParameterName, "AssertedPositionalParameterName") \
F(AssertedRestParameterName, "AssertedRestParameterName") \
F(AssertedScriptGlobalScope, "AssertedScriptGlobalScope") \
F(AssertedVarScope, "AssertedVarScope") \
F(AssignmentExpression, "AssignmentExpression") \
F(AssignmentTargetIdentifier, "AssignmentTargetIdentifier") \
F(AssignmentTargetPropertyIdentifier, "AssignmentTargetPropertyIdentifier") \
F(AssignmentTargetPropertyProperty, "AssignmentTargetPropertyProperty") \
F(AssignmentTargetWithInitializer, "AssignmentTargetWithInitializer") \
F(AwaitExpression, "AwaitExpression") \
F(BinaryExpression, "BinaryExpression") \
F(BindingIdentifier, "BindingIdentifier") \
F(BindingPropertyIdentifier, "BindingPropertyIdentifier") \
F(BindingPropertyProperty, "BindingPropertyProperty") \
F(BindingWithInitializer, "BindingWithInitializer") \
F(Block, "Block") \
F(BreakStatement, "BreakStatement") \
F(CallExpression, "CallExpression") \
F(CatchClause, "CatchClause") \
F(ClassDeclaration, "ClassDeclaration") \
F(ClassElement, "ClassElement") \
F(ClassExpression, "ClassExpression") \
F(CompoundAssignmentExpression, "CompoundAssignmentExpression") \
F(ComputedMemberAssignmentTarget, "ComputedMemberAssignmentTarget") \
F(ComputedMemberExpression, "ComputedMemberExpression") \
F(ComputedPropertyName, "ComputedPropertyName") \
F(ConditionalExpression, "ConditionalExpression") \
F(ContinueStatement, "ContinueStatement") \
F(DataProperty, "DataProperty") \
F(DebuggerStatement, "DebuggerStatement") \
F(Directive, "Directive") \
F(DoWhileStatement, "DoWhileStatement") \
F(EagerArrowExpressionWithExpression, "EagerArrowExpressionWithExpression") \
F(EagerArrowExpressionWithFunctionBody, \
"EagerArrowExpressionWithFunctionBody") \
F(EagerFunctionDeclaration, "EagerFunctionDeclaration") \
F(EagerFunctionExpression, "EagerFunctionExpression") \
F(EagerGetter, "EagerGetter") \
F(EagerMethod, "EagerMethod") \
F(EagerSetter, "EagerSetter") \
F(EmptyStatement, "EmptyStatement") \
F(Export, "Export") \
F(ExportAllFrom, "ExportAllFrom") \
F(ExportDefault, "ExportDefault") \
F(ExportFrom, "ExportFrom") \
F(ExportFromSpecifier, "ExportFromSpecifier") \
F(ExportLocalSpecifier, "ExportLocalSpecifier") \
F(ExportLocals, "ExportLocals") \
F(ExpressionStatement, "ExpressionStatement") \
F(ForInOfBinding, "ForInOfBinding") \
F(ForInStatement, "ForInStatement") \
F(ForOfStatement, "ForOfStatement") \
F(ForStatement, "ForStatement") \
F(FormalParameters, "FormalParameters") \
F(FunctionExpressionContents, "FunctionExpressionContents") \
F(FunctionOrMethodContents, "FunctionOrMethodContents") \
F(GetterContents, "GetterContents") \
F(IdentifierExpression, "IdentifierExpression") \
F(IfStatement, "IfStatement") \
F(Import, "Import") \
F(ImportNamespace, "ImportNamespace") \
F(ImportSpecifier, "ImportSpecifier") \
F(LabelledStatement, "LabelledStatement") \
F(LazyArrowExpressionWithExpression, "LazyArrowExpressionWithExpression") \
F(LazyArrowExpressionWithFunctionBody, \
"LazyArrowExpressionWithFunctionBody") \
F(LazyFunctionDeclaration, "LazyFunctionDeclaration") \
F(LazyFunctionExpression, "LazyFunctionExpression") \
F(LazyGetter, "LazyGetter") \
F(LazyMethod, "LazyMethod") \
F(LazySetter, "LazySetter") \
F(LiteralBooleanExpression, "LiteralBooleanExpression") \
F(LiteralInfinityExpression, "LiteralInfinityExpression") \
F(LiteralNullExpression, "LiteralNullExpression") \
F(LiteralNumericExpression, "LiteralNumericExpression") \
F(LiteralPropertyName, "LiteralPropertyName") \
F(LiteralRegExpExpression, "LiteralRegExpExpression") \
F(LiteralStringExpression, "LiteralStringExpression") \
F(Module, "Module") \
F(NewExpression, "NewExpression") \
F(NewTargetExpression, "NewTargetExpression") \
F(ObjectAssignmentTarget, "ObjectAssignmentTarget") \
F(ObjectBinding, "ObjectBinding") \
F(ObjectExpression, "ObjectExpression") \
F(ReturnStatement, "ReturnStatement") \
F(Script, "Script") \
F(SetterContents, "SetterContents") \
F(ShorthandProperty, "ShorthandProperty") \
F(SpreadElement, "SpreadElement") \
F(StaticMemberAssignmentTarget, "StaticMemberAssignmentTarget") \
F(StaticMemberExpression, "StaticMemberExpression") \
F(Super, "Super") \
F(SwitchCase, "SwitchCase") \
F(SwitchDefault, "SwitchDefault") \
F(SwitchStatement, "SwitchStatement") \
F(SwitchStatementWithDefault, "SwitchStatementWithDefault") \
F(TemplateElement, "TemplateElement") \
F(TemplateExpression, "TemplateExpression") \
F(ThisExpression, "ThisExpression") \
F(ThrowStatement, "ThrowStatement") \
F(TryCatchStatement, "TryCatchStatement") \
F(TryFinallyStatement, "TryFinallyStatement") \
F(UnaryExpression, "UnaryExpression") \
F(UpdateExpression, "UpdateExpression") \
F(VariableDeclaration, "VariableDeclaration") \
F(VariableDeclarator, "VariableDeclarator") \
F(WhileStatement, "WhileStatement") \
F(WithStatement, "WithStatement") \
F(YieldExpression, "YieldExpression") \
F(YieldStarExpression, "YieldStarExpression")
enum class BinASTKind {
#define EMIT_ENUM(name, _) name,
FOR_EACH_BIN_KIND(EMIT_ENUM)
#undef EMIT_ENUM
};
// The number of distinct values of BinASTKind.
const size_t BINASTKIND_LIMIT = 120;
/**
* The different fields of Binary AST nodes, as per the specifications of
* Binary AST.
*
* Usage:
*
* ```c++
* #define WITH_FIELD(CPP_NAME, SPEC_NAME) ...
* FOR_EACH_BIN_FIELD(WITH_FIELD)
* ```
*
* (sorted by alphabetical order)
*/
#define FOR_EACH_BIN_FIELD(F) \
F(Alternate, "alternate") \
F(Arguments, "arguments") \
F(Binding, "binding") \
F(BindingScope, "bindingScope") \
F(Body, "body") \
F(BodyScope, "bodyScope") \
F(BoundNames, "boundNames") \
F(Callee, "callee") \
F(Cases, "cases") \
F(CatchClause, "catchClause") \
F(Consequent, "consequent") \
F(Contents, "contents") \
F(ContentsSkip, "contents_skip") \
F(Declaration, "declaration") \
F(Declarators, "declarators") \
F(DeclaredNames, "declaredNames") \
F(DefaultBinding, "defaultBinding") \
F(DefaultCase, "defaultCase") \
F(Directives, "directives") \
F(Discriminant, "discriminant") \
F(Elements, "elements") \
F(ExportedName, "exportedName") \
F(Expression, "expression") \
F(Finalizer, "finalizer") \
F(Flags, "flags") \
F(HasDirectEval, "hasDirectEval") \
F(Index, "index") \
F(Init, "init") \
F(IsAsync, "isAsync") \
F(IsCaptured, "isCaptured") \
F(IsFunctionNameCaptured, "isFunctionNameCaptured") \
F(IsGenerator, "isGenerator") \
F(IsPrefix, "isPrefix") \
F(IsSimpleParameterList, "isSimpleParameterList") \
F(IsStatic, "isStatic") \
F(IsThisCaptured, "isThisCaptured") \
F(Items, "items") \
F(Kind, "kind") \
F(Label, "label") \
F(Left, "left") \
F(Length, "length") \
F(Method, "method") \
F(ModuleSpecifier, "moduleSpecifier") \
F(Name, "name") \
F(NamedExports, "namedExports") \
F(NamedImports, "namedImports") \
F(NamespaceBinding, "namespaceBinding") \
F(Object, "object") \
F(Operand, "operand") \
F(Operator, "operator") \
F(Param, "param") \
F(ParamNames, "paramNames") \
F(ParameterScope, "parameterScope") \
F(Params, "params") \
F(Pattern, "pattern") \
F(PostDefaultCases, "postDefaultCases") \
F(PreDefaultCases, "preDefaultCases") \
F(Properties, "properties") \
F(Property, "property") \
F(RawValue, "rawValue") \
F(Rest, "rest") \
F(Right, "right") \
F(Scope, "scope") \
F(Statements, "statements") \
F(Super, "super") \
F(Tag, "tag") \
F(Test, "test") \
F(Update, "update") \
F(Value, "value")
enum class BinASTField {
#define EMIT_ENUM(name, _) name,
FOR_EACH_BIN_FIELD(EMIT_ENUM)
#undef EMIT_ENUM
};
// The number of distinct values of BinASTField.
const size_t BINASTFIELD_LIMIT = 69;
/**
* The different variants of Binary AST string enums, as per
* the specifications of Binary AST, as a single macro and
* `enum class`.
*
* Separate enum classes are also defined in BinASTParser.h.
*
* Usage:
*
* ```c++
* #define WITH_VARIANT(CPP_NAME, SPEC_NAME) ...
* FOR_EACH_BIN_VARIANT(WITH_VARIANT)
* ```
*
* (sorted by alphabetical order)
*/
#define FOR_EACH_BIN_VARIANT(F) \
F(AssertedDeclaredKindConstLexical, "const lexical") \
F(AssertedDeclaredKindNonConstLexical, "non-const lexical") \
F(AssertedDeclaredKindOrVariableDeclarationKindVar, "var") \
F(BinaryOperatorBitAnd, "&") \
F(BinaryOperatorBitOr, "|") \
F(BinaryOperatorBitXor, "^") \
F(BinaryOperatorComma, ",") \
F(BinaryOperatorDiv, "/") \
F(BinaryOperatorEq, "==") \
F(BinaryOperatorGeqThan, ">=") \
F(BinaryOperatorGreaterThan, ">") \
F(BinaryOperatorIn, "in") \
F(BinaryOperatorInstanceof, "instanceof") \
F(BinaryOperatorLeqThan, "<=") \
F(BinaryOperatorLessThan, "<") \
F(BinaryOperatorLogicalAnd, "&&") \
F(BinaryOperatorLogicalOr, "||") \
F(BinaryOperatorLsh, "<<") \
F(BinaryOperatorMod, "%") \
F(BinaryOperatorMul, "*") \
F(BinaryOperatorNeq, "!=") \
F(BinaryOperatorOrUnaryOperatorMinus, "-") \
F(BinaryOperatorOrUnaryOperatorPlus, "+") \
F(BinaryOperatorPow, "**") \
F(BinaryOperatorRsh, ">>") \
F(BinaryOperatorStrictEq, "===") \
F(BinaryOperatorStrictNeq, "!==") \
F(BinaryOperatorUrsh, ">>>") \
F(CompoundAssignmentOperatorBitAndAssign, "&=") \
F(CompoundAssignmentOperatorBitOrAssign, "|=") \
F(CompoundAssignmentOperatorBitXorAssign, "^=") \
F(CompoundAssignmentOperatorDivAssign, "/=") \
F(CompoundAssignmentOperatorLshAssign, "<<=") \
F(CompoundAssignmentOperatorMinusAssign, "-=") \
F(CompoundAssignmentOperatorModAssign, "%=") \
F(CompoundAssignmentOperatorMulAssign, "*=") \
F(CompoundAssignmentOperatorPlusAssign, "+=") \
F(CompoundAssignmentOperatorPowAssign, "**=") \
F(CompoundAssignmentOperatorRshAssign, ">>=") \
F(CompoundAssignmentOperatorUrshAssign, ">>>=") \
F(UnaryOperatorBitNot, "~") \
F(UnaryOperatorDelete, "delete") \
F(UnaryOperatorNot, "!") \
F(UnaryOperatorTypeof, "typeof") \
F(UnaryOperatorVoid, "void") \
F(UpdateOperatorDecr, "--") \
F(UpdateOperatorIncr, "++") \
F(VariableDeclarationKindConst, "const") \
F(VariableDeclarationKindLet, "let")
enum class BinASTVariant {
#define EMIT_ENUM(name, _) name,
FOR_EACH_BIN_VARIANT(EMIT_ENUM)
#undef EMIT_ENUM
};
// The number of distinct values of BinASTVariant.
const size_t BINASTVARIANT_LIMIT = 49;
/**
* Return a string describing a `BinASTKind`.
*/
const char* describeBinASTKind(const BinASTKind& kind);
/**
* Return a string describing a `BinASTField`.
*/
const char* describeBinASTField(const BinASTField& field);
/**
* Return a string describing a `BinASTVariant`.
*/
const char* describeBinASTVariant(const BinASTVariant& variant);
} // namespace frontend
} // namespace js
#endif // frontend_BinASTToken_h