Bug 1499574 - Part 1: In FOR_EACH_PARSE_NODE_KIND, list the arity of each node kind. r=jwalden
authorJason Orendorff <jorendorff@mozilla.com>
Tue, 23 Oct 2018 20:31:42 +0000
changeset 490997 bc839874f8d76fdac6ebd4162c3d5f70316d85dc
parent 490996 6f7a06a01dcd28db094a4aebb753fb91427457f5
child 490998 9d7dcb18cd7296847201c8cf8fcfa2674ebe2450
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjwalden
bugs1499574
milestone65.0a1
Bug 1499574 - Part 1: In FOR_EACH_PARSE_NODE_KIND, list the arity of each node kind. r=jwalden Differential Revision: https://phabricator.services.mozilla.com/D8935
js/src/frontend/ParseNode.cpp
js/src/frontend/ParseNode.h
js/src/frontend/TokenKind.h
--- a/js/src/frontend/ParseNode.cpp
+++ b/js/src/frontend/ParseNode.cpp
@@ -100,17 +100,17 @@ ParseNode::appendOrCreateList(ParseNodeK
 
     list->append(right);
     return list;
 }
 
 #ifdef DEBUG
 
 static const char * const parseNodeNames[] = {
-#define STRINGIFY(name) #name,
+#define STRINGIFY(name, _arity) #name,
     FOR_EACH_PARSE_NODE_KIND(STRINGIFY)
 #undef STRINGIFY
 };
 
 void
 frontend::DumpParseTree(ParseNode* pn, GenericPrinter& out, int indent)
 {
     if (pn == nullptr) {
--- a/js/src/frontend/ParseNode.h
+++ b/js/src/frontend/ParseNode.h
@@ -39,177 +39,177 @@ namespace js {
 namespace frontend {
 
 class ParseContext;
 class FullParseHandler;
 class FunctionBox;
 class ObjectBox;
 
 #define FOR_EACH_PARSE_NODE_KIND(F) \
-    F(EmptyStatement) \
-    F(ExpressionStatement) \
-    F(Comma) \
-    F(Conditional) \
-    F(Colon) \
-    F(Shorthand) \
-    F(Pos) \
-    F(Neg) \
-    F(PreIncrement) \
-    F(PostIncrement) \
-    F(PreDecrement) \
-    F(PostDecrement) \
-    F(PropertyName) \
-    F(Dot) \
-    F(Elem) \
-    F(Array) \
-    F(Elision) \
-    F(StatementList) \
-    F(Label) \
-    F(Object) \
-    F(Call) \
-    F(Arguments) \
-    F(Name) \
-    F(ObjectPropertyName) \
-    F(ComputedName) \
-    F(Number) \
-    F(String) \
-    F(TemplateStringList) \
-    F(TemplateString) \
-    F(TaggedTemplate) \
-    F(CallSiteObj) \
-    F(RegExp) \
-    F(True) \
-    F(False) \
-    F(Null) \
-    F(RawUndefined) \
-    F(This) \
-    F(Function) \
-    F(Module) \
-    F(If) \
-    F(Switch) \
-    F(Case) \
-    F(While) \
-    F(DoWhile) \
-    F(For) \
-    F(Break) \
-    F(Continue) \
-    F(Var) \
-    F(Const) \
-    F(With) \
-    F(Return) \
-    F(New) \
+    F(EmptyStatement, PN_NULLARY) \
+    F(ExpressionStatement, PN_UNARY) \
+    F(Comma, PN_LIST) \
+    F(Conditional, PN_TERNARY) \
+    F(Colon, PN_BINARY) \
+    F(Shorthand, PN_BINARY) \
+    F(Pos, PN_UNARY) \
+    F(Neg, PN_UNARY) \
+    F(PreIncrement, PN_UNARY) \
+    F(PostIncrement, PN_UNARY) \
+    F(PreDecrement, PN_UNARY) \
+    F(PostDecrement, PN_UNARY) \
+    F(PropertyName, PN_NAME) \
+    F(Dot, PN_BINARY) \
+    F(Elem, PN_BINARY) \
+    F(Array, PN_LIST) \
+    F(Elision, PN_NULLARY) \
+    F(StatementList, PN_LIST) \
+    F(Label, PN_NAME) \
+    F(Object, PN_LIST) \
+    F(Call, PN_BINARY) \
+    F(Arguments, PN_LIST) \
+    F(Name, PN_NAME) \
+    F(ObjectPropertyName, PN_NAME) \
+    F(ComputedName, PN_UNARY) \
+    F(Number, PN_NUMBER) \
+    F(String, PN_NAME) \
+    F(TemplateStringList, PN_LIST) \
+    F(TemplateString, PN_NAME) \
+    F(TaggedTemplate, PN_BINARY) \
+    F(CallSiteObj, PN_LIST) \
+    F(RegExp, PN_REGEXP) \
+    F(True, PN_NULLARY) \
+    F(False, PN_NULLARY) \
+    F(Null, PN_NULLARY) \
+    F(RawUndefined, PN_NULLARY) \
+    F(This, PN_UNARY) \
+    F(Function, PN_CODE) \
+    F(Module, PN_CODE) \
+    F(If, PN_TERNARY) \
+    F(Switch, PN_BINARY) \
+    F(Case, PN_BINARY) \
+    F(While, PN_BINARY) \
+    F(DoWhile, PN_BINARY) \
+    F(For, PN_BINARY) \
+    F(Break, PN_LOOP) \
+    F(Continue, PN_LOOP) \
+    F(Var, PN_LIST) \
+    F(Const, PN_LIST) \
+    F(With, PN_BINARY) \
+    F(Return, PN_UNARY) \
+    F(New, PN_BINARY) \
     /* Delete operations.  These must be sequential. */ \
-    F(DeleteName) \
-    F(DeleteProp) \
-    F(DeleteElem) \
-    F(DeleteExpr) \
-    F(Try) \
-    F(Catch) \
-    F(Throw) \
-    F(Debugger) \
-    F(Generator) \
-    F(InitialYield) \
-    F(Yield) \
-    F(YieldStar) \
-    F(LexicalScope) \
-    F(Let) \
-    F(Import) \
-    F(ImportSpecList) \
-    F(ImportSpec) \
-    F(Export) \
-    F(ExportFrom) \
-    F(ExportDefault) \
-    F(ExportSpecList) \
-    F(ExportSpec) \
-    F(ExportBatchSpec) \
-    F(ForIn) \
-    F(ForOf) \
-    F(ForHead) \
-    F(ParamsBody) \
-    F(Spread) \
-    F(MutateProto) \
-    F(Class) \
-    F(ClassMethod) \
-    F(ClassMethodList) \
-    F(ClassNames) \
-    F(NewTarget) \
-    F(PosHolder) \
-    F(SuperBase) \
-    F(SuperCall) \
-    F(SetThis) \
-    F(ImportMeta) \
-    F(CallImport) \
+    F(DeleteName, PN_UNARY) \
+    F(DeleteProp, PN_UNARY) \
+    F(DeleteElem, PN_UNARY) \
+    F(DeleteExpr, PN_UNARY) \
+    F(Try, PN_TERNARY) \
+    F(Catch, PN_BINARY) \
+    F(Throw, PN_UNARY) \
+    F(Debugger, PN_NULLARY) \
+    F(Generator, PN_NULLARY) \
+    F(InitialYield, PN_UNARY) \
+    F(Yield, PN_UNARY) \
+    F(YieldStar, PN_UNARY) \
+    F(LexicalScope, PN_SCOPE) \
+    F(Let, PN_LIST) \
+    F(Import, PN_BINARY) \
+    F(ImportSpecList, PN_LIST) \
+    F(ImportSpec, PN_BINARY) \
+    F(Export, PN_UNARY) \
+    F(ExportFrom, PN_BINARY) \
+    F(ExportDefault, PN_BINARY) \
+    F(ExportSpecList, PN_LIST) \
+    F(ExportSpec, PN_BINARY) \
+    F(ExportBatchSpec, PN_NULLARY) \
+    F(ForIn, PN_TERNARY) \
+    F(ForOf, PN_TERNARY) \
+    F(ForHead, PN_TERNARY) \
+    F(ParamsBody, PN_LIST) \
+    F(Spread, PN_UNARY) \
+    F(MutateProto, PN_UNARY) \
+    F(Class, PN_TERNARY) \
+    F(ClassMethod, PN_BINARY) \
+    F(ClassMethodList, PN_LIST) \
+    F(ClassNames, PN_BINARY) \
+    F(NewTarget, PN_BINARY) \
+    F(PosHolder, PN_NULLARY) \
+    F(SuperBase, PN_UNARY) \
+    F(SuperCall, PN_BINARY) \
+    F(SetThis, PN_BINARY) \
+    F(ImportMeta, PN_BINARY) \
+    F(CallImport, PN_BINARY) \
     \
     /* Unary operators. */ \
-    F(TypeOfName) \
-    F(TypeOfExpr) \
-    F(Void) \
-    F(Not) \
-    F(BitNot) \
-    F(Await) \
+    F(TypeOfName, PN_UNARY) \
+    F(TypeOfExpr, PN_UNARY) \
+    F(Void, PN_UNARY) \
+    F(Not, PN_UNARY) \
+    F(BitNot, PN_UNARY) \
+    F(Await, PN_UNARY) \
     \
     /* \
      * Binary operators. \
      * These must be in the same order as TOK_OR and friends in TokenStream.h. \
      */ \
-    F(Pipeline) \
-    F(Or) \
-    F(And) \
-    F(BitOr) \
-    F(BitXor) \
-    F(BitAnd) \
-    F(StrictEq) \
-    F(Eq) \
-    F(StrictNe) \
-    F(Ne) \
-    F(Lt) \
-    F(Le) \
-    F(Gt) \
-    F(Ge) \
-    F(InstanceOf) \
-    F(In) \
-    F(Lsh) \
-    F(Rsh) \
-    F(Ursh) \
-    F(Add) \
-    F(Sub) \
-    F(Star) \
-    F(Div) \
-    F(Mod) \
-    F(Pow) \
+    F(Pipeline, PN_LIST) \
+    F(Or, PN_LIST) \
+    F(And, PN_LIST) \
+    F(BitOr, PN_LIST) \
+    F(BitXor, PN_LIST) \
+    F(BitAnd, PN_LIST) \
+    F(StrictEq, PN_LIST) \
+    F(Eq, PN_LIST) \
+    F(StrictNe, PN_LIST) \
+    F(Ne, PN_LIST) \
+    F(Lt, PN_LIST) \
+    F(Le, PN_LIST) \
+    F(Gt, PN_LIST) \
+    F(Ge, PN_LIST) \
+    F(InstanceOf, PN_LIST) \
+    F(In, PN_LIST) \
+    F(Lsh, PN_LIST) \
+    F(Rsh, PN_LIST) \
+    F(Ursh, PN_LIST) \
+    F(Add, PN_LIST) \
+    F(Sub, PN_LIST) \
+    F(Star, PN_LIST) \
+    F(Div, PN_LIST) \
+    F(Mod, PN_LIST) \
+    F(Pow, PN_LIST) \
     \
     /* Assignment operators (= += -= etc.). */ \
     /* ParseNode::isAssignment assumes all these are consecutive. */ \
-    F(Assign) \
-    F(AddAssign) \
-    F(SubAssign) \
-    F(BitOrAssign) \
-    F(BitXorAssign) \
-    F(BitAndAssign) \
-    F(LshAssign) \
-    F(RshAssign) \
-    F(UrshAssign) \
-    F(MulAssign) \
-    F(DivAssign) \
-    F(ModAssign) \
-    F(PowAssign)
+    F(Assign, PN_BINARY) \
+    F(AddAssign, PN_BINARY) \
+    F(SubAssign, PN_BINARY) \
+    F(BitOrAssign, PN_BINARY) \
+    F(BitXorAssign, PN_BINARY) \
+    F(BitAndAssign, PN_BINARY) \
+    F(LshAssign, PN_BINARY) \
+    F(RshAssign, PN_BINARY) \
+    F(UrshAssign, PN_BINARY) \
+    F(MulAssign, PN_BINARY) \
+    F(DivAssign, PN_BINARY) \
+    F(ModAssign, PN_BINARY) \
+    F(PowAssign, PN_BINARY)
 
 /*
  * Parsing builds a tree of nodes that directs code generation.  This tree is
  * not a concrete syntax tree in all respects (for example, || and && are left
  * associative, but (A && B && C) translates into the right-associated tree
  * <A && <B && C>> so that code generation can emit a left-associative branch
  * around <B && C> when A is false).  Nodes are labeled by kind, with a
  * secondary JSOp label when needed.
  *
  * The long comment after this enum block describes the kinds in detail.
  */
 enum class ParseNodeKind : uint16_t
 {
-#define EMIT_ENUM(name) name,
+#define EMIT_ENUM(name, _arity) name,
     FOR_EACH_PARSE_NODE_KIND(EMIT_ENUM)
 #undef EMIT_ENUM
     Limit, /* domain size */
     BinOpFirst = ParseNodeKind::Pipeline,
     BinOpLast = ParseNodeKind::Pow,
     AssignmentStart = ParseNodeKind::Assign,
     AssignmentLast = ParseNodeKind::PowAssign
 };
--- a/js/src/frontend/TokenKind.h
+++ b/js/src/frontend/TokenKind.h
@@ -151,17 +151,17 @@
     range(StrictReservedKeywordLast, Public) \
     \
     /* \
      * The following token types occupy contiguous ranges to enable easy \
      * range-testing. \
      */ \
     /* \
      * Binary operators tokens, Or thru Pow. These must be in the same \
-     * order as F(OR) and friends in FOR_EACH_PARSE_NODE_KIND in ParseNode.h. \
+     * order as F(Or) and friends in FOR_EACH_PARSE_NODE_KIND in ParseNode.h. \
      */ \
     macro(Pipeline,     "'|>'") \
     range(BinOpFirst,   Pipeline) \
     macro(Or,           "'||'")   /* logical or */ \
     macro(And,          "'&&'")   /* logical and */ \
     macro(BitOr,        "'|'")    /* bitwise-or */ \
     macro(BitXor,       "'^'")    /* bitwise-xor */ \
     macro(BitAnd,       "'&'")    /* bitwise-and */ \