Bug 1508063 - Part 2: Move auto-generated enum to BinASTEnum.h. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Thu, 29 Nov 2018 01:03:45 +0900
changeset 507728 391d7669e9b28c4475ead6f5f6771dfa1fd05deb
parent 507727 2abc868cd4169ab888b5a5e7d7ebd5687b06232d
child 507729 f96f280927ff0bc9340a7726d28851f884998126
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1508063
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1508063 - Part 2: Move auto-generated enum to BinASTEnum.h. r=Yoric
js/src/frontend/BinASTEnum.h
js/src/frontend/BinSource-auto.h
js/src/frontend/BinSource.h
js/src/frontend/BinSource.yaml
js/src/frontend/binsource/build.sh
js/src/frontend/binsource/src/main.rs
new file mode 100644
--- /dev/null
+++ b/js/src/frontend/BinASTEnum.h
@@ -0,0 +1,147 @@
+// 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: 4 -*-
+* vim: set ts=8 sts=4 et sw=4 tw=99:
+* 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/binsource/README.md.
+
+#ifndef frontend_BinASTEnum_h
+#define frontend_BinASTEnum_h
+
+namespace js {
+namespace frontend {
+namespace binast {
+
+// ----- Declaring string enums (by lexicographical order)
+
+enum class AssertedDeclaredKind {
+    // "var"
+    Var,
+    // "non-const lexical"
+    NonConstLexical,
+    // "const lexical"
+    ConstLexical,
+};
+
+enum class BinaryOperator {
+    // ","
+    Comma,
+    // "||"
+    LogicalOr,
+    // "&&"
+    LogicalAnd,
+    // "|"
+    BitOr,
+    // "^"
+    BitXor,
+    // "&"
+    BitAnd,
+    // "=="
+    Eq,
+    // "!="
+    Neq,
+    // "==="
+    StrictEq,
+    // "!=="
+    StrictNeq,
+    // "<"
+    LessThan,
+    // "<="
+    LeqThan,
+    // ">"
+    GreaterThan,
+    // ">="
+    GeqThan,
+    // "in"
+    In,
+    // "instanceof"
+    Instanceof,
+    // "<<"
+    Lsh,
+    // ">>"
+    Rsh,
+    // ">>>"
+    Ursh,
+    // "+"
+    Plus,
+    // "-"
+    Minus,
+    // "*"
+    Mul,
+    // "/"
+    Div,
+    // "%"
+    Mod,
+    // "**"
+    Pow,
+};
+
+enum class CompoundAssignmentOperator {
+    // "+="
+    PlusAssign,
+    // "-="
+    MinusAssign,
+    // "*="
+    MulAssign,
+    // "/="
+    DivAssign,
+    // "%="
+    ModAssign,
+    // "**="
+    PowAssign,
+    // "<<="
+    LshAssign,
+    // ">>="
+    RshAssign,
+    // ">>>="
+    UrshAssign,
+    // "|="
+    BitOrAssign,
+    // "^="
+    BitXorAssign,
+    // "&="
+    BitAndAssign,
+};
+
+enum class UnaryOperator {
+    // "+"
+    Plus,
+    // "-"
+    Minus,
+    // "!"
+    Not,
+    // "~"
+    BitNot,
+    // "typeof"
+    Typeof,
+    // "void"
+    Void,
+    // "delete"
+    Delete,
+};
+
+enum class UpdateOperator {
+    // "++"
+    Incr,
+    // "--"
+    Decr,
+};
+
+enum class VariableDeclarationKind {
+    // "var"
+    Var,
+    // "let"
+    Let,
+    // "const"
+    Const,
+};
+
+} // namespace binast
+} // namespace frontend
+} // namespace js
+
+#endif // frontend_BinASTEnum_h
--- a/js/src/frontend/BinSource-auto.h
+++ b/js/src/frontend/BinSource-auto.h
@@ -8,89 +8,16 @@
 
 // To generate this file, see the documentation in
 // js/src/frontend/binsource/README.md.
 
 // This file is meant to be included from the declaration
 // of class `BinASTParser`. The include may be public or private.
 
 
-// ----- Declaring string enums (by lexicographical order)
-enum class AssertedDeclaredKind {
-    Var                       /* "var" */,
-    NonConstLexical           /* "non-const lexical" */,
-    ConstLexical              /* "const lexical" */
-};
-
-enum class BinaryOperator {
-    Comma                     /* "," */,
-    LogicalOr                 /* "||" */,
-    LogicalAnd                /* "&&" */,
-    BitOr                     /* "|" */,
-    BitXor                    /* "^" */,
-    BitAnd                    /* "&" */,
-    Eq                        /* "==" */,
-    Neq                       /* "!=" */,
-    StrictEq                  /* "===" */,
-    StrictNeq                 /* "!==" */,
-    LessThan                  /* "<" */,
-    LeqThan                   /* "<=" */,
-    GreaterThan               /* ">" */,
-    GeqThan                   /* ">=" */,
-    In                        /* "in" */,
-    Instanceof                /* "instanceof" */,
-    Lsh                       /* "<<" */,
-    Rsh                       /* ">>" */,
-    Ursh                      /* ">>>" */,
-    Plus                      /* "+" */,
-    Minus                     /* "-" */,
-    Mul                       /* "*" */,
-    Div                       /* "/" */,
-    Mod                       /* "%" */,
-    Pow                       /* "**" */
-};
-
-enum class CompoundAssignmentOperator {
-    PlusAssign                /* "+=" */,
-    MinusAssign               /* "-=" */,
-    MulAssign                 /* "*=" */,
-    DivAssign                 /* "/=" */,
-    ModAssign                 /* "%=" */,
-    PowAssign                 /* "**=" */,
-    LshAssign                 /* "<<=" */,
-    RshAssign                 /* ">>=" */,
-    UrshAssign                /* ">>>=" */,
-    BitOrAssign               /* "|=" */,
-    BitXorAssign              /* "^=" */,
-    BitAndAssign              /* "&=" */
-};
-
-enum class UnaryOperator {
-    Plus                      /* "+" */,
-    Minus                     /* "-" */,
-    Not                       /* "!" */,
-    BitNot                    /* "~" */,
-    Typeof                    /* "typeof" */,
-    Void                      /* "void" */,
-    Delete                    /* "delete" */
-};
-
-enum class UpdateOperator {
-    Incr                      /* "++" */,
-    Decr                      /* "--" */
-};
-
-enum class VariableDeclarationKind {
-    Var                       /* "var" */,
-    Let                       /* "let" */,
-    Const                     /* "const" */
-};
-
-
-
 // ----- Sums of interfaces (by lexicographical order)
 // Implementations are autogenerated
 // `ParseNode*` may never be nullptr
 JS::Result<Ok> parseAssertedMaybePositionalParameterName(
     AssertedScopeKind scopeKind,
     MutableHandle<GCVector<JSAtom*>> positionalParams);
 JS::Result<ParseNode*> parseAssignmentTarget();
 JS::Result<ParseNode*> parseBinding();
--- a/js/src/frontend/BinSource.h
+++ b/js/src/frontend/BinSource.h
@@ -12,16 +12,17 @@
  *
  * At the time of this writing, this parser implements the grammar of ES5
  * and trusts its input (in particular, variable declarations).
  */
 
 #include "mozilla/Maybe.h"
 
 #include "frontend/BCEParserHandle.h"
+#include "frontend/BinASTEnum.h"
 #include "frontend/BinASTParserBase.h"
 #include "frontend/BinToken.h"
 #include "frontend/BinTokenReaderMultipart.h"
 #include "frontend/BinTokenReaderTester.h"
 #include "frontend/FullParseHandler.h"
 #include "frontend/ParseContext.h"
 #include "frontend/ParseNode.h"
 #include "frontend/SharedContext.h"
@@ -48,16 +49,25 @@ class BinASTParser : public BinASTParser
 
     using AutoList = typename Tokenizer::AutoList;
     using AutoTaggedTuple = typename Tokenizer::AutoTaggedTuple;
     using AutoTuple = typename Tokenizer::AutoTuple;
     using BinFields = typename Tokenizer::BinFields;
     using Chars = typename Tokenizer::Chars;
 
   public:
+    // Auto-generated types.
+    using AssertedDeclaredKind = binast::AssertedDeclaredKind;
+    using BinaryOperator = binast::BinaryOperator;
+    using CompoundAssignmentOperator = binast::CompoundAssignmentOperator;
+    using UnaryOperator = binast::UnaryOperator;
+    using UpdateOperator = binast::UpdateOperator;
+    using VariableDeclarationKind = binast::VariableDeclarationKind;
+
+  public:
     BinASTParser(JSContext* cx, LifoAlloc& alloc, UsedNameTracker& usedNames, const JS::ReadOnlyCompileOptions& options,
                  HandleScriptSourceObject sourceObject, Handle<LazyScript*> lazyScript = nullptr)
         : BinASTParserBase(cx, alloc, usedNames, sourceObject, lazyScript)
         , options_(options)
         , variableDeclarationKind_(VariableDeclarationKind::Var)
     {
     }
     ~BinASTParser()
--- a/js/src/frontend/BinSource.yaml
+++ b/js/src/frontend/BinSource.yaml
@@ -80,16 +80,40 @@ hpp:
             * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
             // To generate this file, see the documentation in
             // js/src/frontend/binsource/README.md.
 
             // This file is meant to be included from the declaration
             // of class `BinASTParser`. The include may be public or private.
 
+    enums:
+        header: |
+            /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+            * vim: set ts=8 sts=4 et sw=4 tw=99:
+            * 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/binsource/README.md.
+
+            #ifndef frontend_BinASTEnum_h
+            #define frontend_BinASTEnum_h
+
+            namespace js {
+            namespace frontend {
+            namespace binast {
+        footer: |
+            } // namespace binast
+            } // namespace frontend
+            } // namespace js
+
+            #endif // frontend_BinASTEnum_h
+
     # Rules for generating BinToken.h
     tokens:
         kind:
             doc: |
                 /**
                  * The different kinds of Binary AST nodes, as per the specifications of
                  * Binary AST.
                  *
--- a/js/src/frontend/binsource/build.sh
+++ b/js/src/frontend/binsource/build.sh
@@ -1,8 +1,9 @@
 #!/bin/sh
 
 cargo run -- \
       ../BinSource.webidl_ \
       ../BinSource.yaml \
       --out-class ../BinSource-auto.h    \
       --out-impl ../BinSource-auto.cpp   \
+      --out-enum ../BinASTEnum.h    \
       --out-token ../BinToken.h
--- a/js/src/frontend/binsource/src/main.rs
+++ b/js/src/frontend/binsource/src/main.rs
@@ -134,21 +134,29 @@ struct GlobalRules {
     parser_list_append: Option<Rc<String>>,
 
     /// Header to add at the start of the .cpp file.
     cpp_header: Option<String>,
 
     /// Header to add at the end of the .cpp file.
     cpp_footer: Option<String>,
 
-    /// Header to add at the start of the .hpp file
-    /// defining the class data/methods.
+    /// Header to add at the start of the .hpp file.
+    /// defining the class.
     hpp_class_header: Option<String>,
 
     /// Header to add at the start of the .hpp file.
+    /// defining the enums.
+    hpp_enums_header: Option<String>,
+
+    /// Footer to add at the end of the .hpp file
+    /// defining the enums.
+    hpp_enums_footer: Option<String>,
+
+    /// Header to add at the start of the .hpp file.
     /// defining the tokens.
     hpp_tokens_header: Option<String>,
 
     /// Footer to add at the start of the .hpp file.
     /// defining the tokens.
     hpp_tokens_footer: Option<String>,
 
     /// Documentation for the `BinKind` class enum.
@@ -171,16 +179,18 @@ impl GlobalRules {
         let mut parser_class_name = None;
         let mut parser_class_template = None;
         let mut parser_type_ok = None;
         let mut parser_default_value = None;
         let mut parser_list_append = None;
         let mut cpp_header = None;
         let mut cpp_footer = None;
         let mut hpp_class_header = None;
+        let mut hpp_enums_header = None;
+        let mut hpp_enums_footer = None;
         let mut hpp_tokens_header = None;
         let mut hpp_tokens_footer = None;
         let mut hpp_tokens_kind_doc = None;
         let mut hpp_tokens_field_doc = None;
         let mut hpp_tokens_variants_doc = None;
         let mut per_node = HashMap::new();
 
         for (node_key, node_entries) in rules.iter() {
@@ -206,16 +216,20 @@ impl GlobalRules {
                         .unwrap_or_else(|_| panic!("Rule cpp.header must be a string"));
                     update_rule(&mut cpp_footer, &node_entries["footer"])
                         .unwrap_or_else(|_| panic!("Rule cpp.footer must be a string"));
                     continue;
                 }
                 "hpp" => {
                     update_rule(&mut hpp_class_header, &node_entries["class"]["header"])
                         .unwrap_or_else(|_| panic!("Rule hpp.class.header must be a string"));
+                    update_rule(&mut hpp_enums_header, &node_entries["enums"]["header"])
+                        .unwrap_or_else(|_| panic!("Rule hpp.enum.header must be a string"));
+                    update_rule(&mut hpp_enums_footer, &node_entries["enums"]["footer"])
+                        .unwrap_or_else(|_| panic!("Rule hpp.enum.footer must be a string"));
                     update_rule(&mut hpp_tokens_header, &node_entries["tokens"]["header"])
                         .unwrap_or_else(|_| panic!("Rule hpp.tokens.header must be a string"));
                     update_rule(&mut hpp_tokens_footer, &node_entries["tokens"]["footer"])
                         .unwrap_or_else(|_| panic!("Rule hpp.tokens.footer must be a string"));
                     update_rule(&mut hpp_tokens_kind_doc, &node_entries["tokens"]["kind"]["doc"])
                         .unwrap_or_else(|_| panic!("Rule hpp.tokens.kind.doc must be a string"));
                     update_rule(&mut hpp_tokens_field_doc, &node_entries["tokens"]["field"]["doc"])
                         .unwrap_or_else(|_| panic!("Rule hpp.tokens.field.doc must be a string"));
@@ -393,16 +407,18 @@ impl GlobalRules {
             parser_type_ok: parser_type_ok
                 .expect("parser.type-ok should be specified"),
             parser_default_value: parser_default_value
                 .expect("parser.default-value should be specified"),
             parser_list_append,
             cpp_header,
             cpp_footer,
             hpp_class_header,
+            hpp_enums_header,
+            hpp_enums_footer,
             hpp_tokens_header,
             hpp_tokens_footer,
             hpp_tokens_kind_doc,
             hpp_tokens_field_doc,
             hpp_tokens_variants_doc,
             per_node,
         }
     }
@@ -977,29 +993,36 @@ enum class BinVariant {
         buffer.push_str(&format!("\n// The number of distinct values of BinVariant.\nconst size_t BINVARIANT_LIMIT = {};\n\n\n",
             self.variants_by_symbol.len()));
 
         buffer.push_str(&self.rules.hpp_tokens_footer.reindent(""));
         buffer.push_str("\n");
     }
 
     /// Declare string enums
-    fn export_declare_string_enums_classes(&self, buffer: &mut String) {
-        buffer.push_str("\n\n// ----- Declaring string enums (by lexicographical order)\n");
+    fn export_declare_string_enums(&self, buffer: &mut String) {
+        buffer.push_str("
+// ----- Declaring string enums (by lexicographical order)
+");
         let string_enums_by_name = self.syntax.string_enums_by_name()
             .iter()
             .sorted_by(|a, b| str::cmp(a.0.to_str(), b.0.to_str()));
         for (name, enum_) in string_enums_by_name {
             let rendered_cases = enum_.strings()
                 .iter()
-                .map(|str| format!("{case:<20}      /* \"{original}\" */",
+                .map(|str| format!("    // \"{original}\"
+    {case},",
                     case = str.to_cpp_enum_case(),
                     original = str))
-                .format(",\n    ");
-            let rendered = format!("enum class {name} {{\n    {cases}\n}};\n\n",
+                .format("\n");
+            let rendered = format!("
+enum class {name} {{
+{cases}
+}};
+",
                 cases = rendered_cases,
                 name = name.to_class_cases());
             buffer.push_str(&rendered);
         }
     }
 
     fn export_declare_sums_of_interface_methods(&self, buffer: &mut String) {
         let sums_of_interfaces = self.syntax.resolved_sums_of_interfaces_by_name()
@@ -1149,26 +1172,41 @@ enum class BinVariant {
     fn to_spidermonkey_class_hpp(&self) -> String {
         let mut buffer = String::new();
 
         buffer.push_str(&self.generate_autogenerated_warning());
 
         buffer.push_str(&self.rules.hpp_class_header.reindent(""));
         buffer.push_str("\n");
 
-        self.export_declare_string_enums_classes(&mut buffer);
         self.export_declare_sums_of_interface_methods(&mut buffer);
         self.export_declare_single_interface_methods(&mut buffer);
         self.export_declare_string_enums_methods(&mut buffer);
         self.export_declare_list_methods(&mut buffer);
         self.export_declare_option_methods(&mut buffer);
 
         buffer.push_str("\n");
         buffer
     }
+
+    fn to_spidermonkey_enum_hpp(&self) -> String {
+        let mut buffer = String::new();
+
+        buffer.push_str(&self.generate_autogenerated_warning());
+
+        buffer.push_str(&self.rules.hpp_enums_header.reindent(""));
+        buffer.push_str("\n");
+
+        self.export_declare_string_enums(&mut buffer);
+
+        buffer.push_str("\n");
+        buffer.push_str(&self.rules.hpp_enums_footer.reindent(""));
+        buffer.push_str("\n");
+        buffer
+    }
 }
 
 impl CPPExporter {
     /// Generate implementation of a single typesum.
     fn generate_implement_sum(&self, buffer: &mut String, name: &NodeName, nodes: &HashSet<NodeName>) {
         // Generate comments (FIXME: We should use the actual webidl, not the resolved sum)
         let rules_for_this_sum = self.rules.get(name);
         let extra_params = rules_for_this_sum.extra_params;
@@ -1989,17 +2027,22 @@ fn main() {
                 .help("Input webidl file to use. Must be a webidl source file."),
             Arg::with_name("INPUT.yaml")
                 .required(true)
                 .help("Input rules file to use. Must be a yaml source file."),
             Arg::with_name("OUT_HEADER_CLASS_FILE")
                 .long("out-class")
                 .required(true)
                 .takes_value(true)
-                .help("Output header file (.h, designed to be included from within the class file)"),
+                .help("Output header file for class (.h)"),
+            Arg::with_name("OUT_HEADER_ENUM_FILE")
+                .long("out-enum")
+                .required(true)
+                .takes_value(true)
+                .help("Output header file for enum (.h)"),
             Arg::with_name("OUT_TOKEN_FILE")
                 .long("out-token")
                 .required(true)
                 .takes_value(true)
                 .help("Output token file (.h)"),
             Arg::with_name("OUT_IMPL_FILE")
                 .long("out-impl")
                 .required(true)
@@ -2096,15 +2139,17 @@ fn main() {
                             path = dest_path,
                             error = e));
 
         println!("done");
     };
 
     write_to("C++ class header code", "OUT_HEADER_CLASS_FILE",
         &exporter.to_spidermonkey_class_hpp());
+    write_to("C++ enum header code", "OUT_HEADER_ENUM_FILE",
+        &exporter.to_spidermonkey_enum_hpp());
     write_to("C++ token header code", "OUT_TOKEN_FILE",
         &exporter.to_spidermonkey_token_hpp());
     write_to("C++ token implementation code", "OUT_IMPL_FILE",
         &exporter.to_spidermonkey_cpp());
 
     println!("...done");
 }