From 14632329ccc6c05dc5e01741f14e05216cf73ccf Mon Sep 17 00:00:00 2001 From: David Teller Date: Fri, 24 May 2019 09:08:54 +0000 Subject: [PATCH] Bug 1553482 - Generating BINAST_TOTAL_NUMBER_OF_FIELDS, BINAST_NUMBER_OF_LIST_TYPES;r=arai Differential Revision: https://phabricator.services.mozilla.com/D32289 --HG-- extra : moz-landing-system : lando --- js/src/frontend/BinASTToken.h | 8 ++++++++ js/src/frontend/binast/src/main.rs | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/js/src/frontend/BinASTToken.h b/js/src/frontend/BinASTToken.h index ad043cb40d88..cfeec35fe93a 100644 --- a/js/src/frontend/BinASTToken.h +++ b/js/src/frontend/BinASTToken.h @@ -289,6 +289,10 @@ enum class BinASTField : uint16_t { // The number of distinct values of BinASTField. const size_t BINASTFIELD_LIMIT = 69; +// The total number of fields across all interfaces. Used typically to maintain +// a probability table per field. +const size_t BINAST_TOTAL_NUMBER_OF_FIELDS = 275; + /** * The different variants of Binary AST string enums, as per * the specifications of Binary AST, as a single macro and @@ -365,6 +369,10 @@ enum class BinASTVariant : uint16_t { // The number of distinct values of BinASTVariant. const size_t BINASTVARIANT_LIMIT = 49; +// The total number of lists across all interfaces. Used typically to maintain a +// probability table per field. +const size_t BINAST_TOTAL_NUMBER_OF_LISTS = 22; + /** * Return a string describing a `BinASTKind`. */ diff --git a/js/src/frontend/binast/src/main.rs b/js/src/frontend/binast/src/main.rs index a95cb6e5d1ee..ca4f920d3b35 100644 --- a/js/src/frontend/binast/src/main.rs +++ b/js/src/frontend/binast/src/main.rs @@ -994,7 +994,13 @@ enum class BinASTField: uint16_t { #undef EMIT_ENUM }; "); - buffer.push_str(&format!("\n// The number of distinct values of BinASTField.\nconst size_t BINASTFIELD_LIMIT = {};\n\n\n", field_limit)); + buffer.push_str(&format!("\n// The number of distinct values of BinASTField.\nconst size_t BINASTFIELD_LIMIT = {};\n", field_limit)); + + let total_number_of_fields: usize = self.syntax.interfaces_by_name() + .values() + .map(|interface| interface.contents().fields().len()) + .sum(); + buffer.push_str(&format!("\n// The total number of fields across all interfaces. Used typically to maintain a probability table per field.\nconst size_t BINAST_TOTAL_NUMBER_OF_FIELDS = {};\n\n\n", total_number_of_fields)); if self.rules.hpp_tokens_variants_doc.is_some() { buffer.push_str(&self.rules.hpp_tokens_variants_doc.reindent("")); @@ -1024,6 +1030,8 @@ enum class BinASTVariant: uint16_t { buffer.push_str(&format!("\n// The number of distinct values of BinASTVariant.\nconst size_t BINASTVARIANT_LIMIT = {};\n\n\n", variants_limit)); + buffer.push_str(&format!("\n// The total number of lists across all interfaces. Used typically to maintain a probability table per field.\nconst size_t BINAST_TOTAL_NUMBER_OF_LISTS = {};\n\n\n", self.list_parsers_to_generate.len())); + buffer.push_str(&self.rules.hpp_tokens_footer.reindent("")); buffer.push_str("\n"); }