Bug 1553482 - Use BinASTInterfaceAndField in Context;r=arai

Depends on D32295

Differential Revision: https://phabricator.services.mozilla.com/D32395

--HG--
extra : moz-landing-system : lando
This commit is contained in:
David Teller 2019-05-24 12:11:02 +00:00
Родитель b39f990648
Коммит 4eddbb64f5
8 изменённых файлов: 623 добавлений и 320 удалений

1
Cargo.lock сгенерированный
Просмотреть файл

@ -229,6 +229,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "binast"
version = "0.1.1"
dependencies = [
"Inflector 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"binjs_meta 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",

Просмотреть файл

@ -91,6 +91,7 @@ hpp:
#define frontend_BinASTParser_h
#include "mozilla/Maybe.h"
#include "mozilla/Variant.h"
#include "frontend/BCEParserHandle.h"
#include "frontend/BinASTParserPerTokenizer.h"
@ -122,6 +123,9 @@ hpp:
using AutoTaggedTuple = typename Tokenizer::AutoTaggedTuple;
using Chars = typename Tokenizer::Chars;
using Context = typename BinASTTokenReaderBase::Context;
using ListContext = typename BinASTTokenReaderBase::ListContext;
using FieldContext = typename BinASTTokenReaderBase::FieldContext;
using RootContext = typename BinASTTokenReaderBase::RootContext;
public:
// Auto-generated types.
@ -637,7 +641,7 @@ BreakStatement:
block:
replace: |
RootedAtom label(cx_);
MOZ_TRY_VAR(label, tokenizer_->readMaybeAtom(fieldContext++));
MOZ_TRY_VAR(label, tokenizer_->readMaybeAtom(Context(FieldContext(BinASTInterfaceAndField::BreakStatement__Label))));
build: |
if (label) {
@ -781,7 +785,7 @@ ContinueStatement:
block:
replace: |
RootedAtom label(cx_);
MOZ_TRY_VAR(label, tokenizer_->readMaybeAtom(fieldContext++));
MOZ_TRY_VAR(label, tokenizer_->readMaybeAtom(Context(FieldContext(BinASTInterfaceAndField::ContinueStatement__Label))));
build: |
if (label) {
@ -1294,7 +1298,7 @@ LiteralRegExpExpression:
block:
replace: |
Chars flags(cx_);
MOZ_TRY(tokenizer_->readChars(flags, fieldContext++));
MOZ_TRY(tokenizer_->readChars(flags, Context(FieldContext(BinASTInterfaceAndField::BreakStatement__Label))));
build: |
RegExpFlags reflags = RegExpFlag::NoFlags;
for (auto c : flags) {

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -13,6 +13,7 @@
#define frontend_BinASTParser_h
#include "mozilla/Maybe.h"
#include "mozilla/Variant.h"
#include "frontend/BCEParserHandle.h"
#include "frontend/BinASTParserPerTokenizer.h"
@ -44,6 +45,9 @@ class BinASTParser : public BinASTParserPerTokenizer<Tok> {
using AutoTaggedTuple = typename Tokenizer::AutoTaggedTuple;
using Chars = typename Tokenizer::Chars;
using Context = typename BinASTTokenReaderBase::Context;
using ListContext = typename BinASTTokenReaderBase::ListContext;
using FieldContext = typename BinASTTokenReaderBase::FieldContext;
using RootContext = typename BinASTTokenReaderBase::RootContext;
public:
// Auto-generated types.

Просмотреть файл

@ -133,7 +133,7 @@ JS::Result<ParseNode*> BinASTParserPerTokenizer<Tok>::parseAux(
MOZ_TRY(tokenizer_->readHeader());
ParseNode* result(nullptr);
const Context topContext(Context::topLevel());
const Context topContext((RootContext()));
MOZ_TRY_VAR(result, asFinalParser()->parseProgram(topContext));
mozilla::Maybe<GlobalScope::Data*> bindings =
@ -196,7 +196,7 @@ JS::Result<FunctionNode*> BinASTParserPerTokenizer<Tok>::parseLazyFunction(
// Inject a toplevel context (i.e. no parent) to parse the lazy content.
// In the future, we may move this to a more specific context.
const Context context(Context::topLevel());
const Context context((RootContext()));
MOZ_TRY(
(asFinalParser()->*parseFunc)(func->nargs(), &params, &tmpBody, context));

Просмотреть файл

@ -57,6 +57,7 @@ class BinASTParserPerTokenizer : public BinASTParserBase,
using AutoTaggedTuple = typename Tokenizer::AutoTaggedTuple;
using BinASTFields = typename Tokenizer::BinASTFields;
using Chars = typename Tokenizer::Chars;
using RootContext = BinASTTokenReaderBase::RootContext;
using Context = BinASTTokenReaderBase::Context;
public:

Просмотреть файл

@ -7,6 +7,8 @@
#ifndef frontend_BinASTTokenReaderBase_h
#define frontend_BinASTTokenReaderBase_h
#include "mozilla/Variant.h"
#include <string.h>
#include "frontend/BinASTToken.h"
@ -27,54 +29,30 @@ class MOZ_STACK_CLASS BinASTTokenReaderBase {
template <typename T>
using ErrorResult = mozilla::GenericErrorResult<T>;
// The context in which we read a token.
struct Context {
// Construct a context for a root node.
constexpr static Context topLevel() {
return Context(BinASTKind::_Null, 0, ElementOf::TaggedTuple);
}
// Part of variant `Context`
// Reading the root of the tree, before we enter any tagged tuple.
struct RootContext {};
Context arrayElement() const {
return Context(kind, fieldIndex, ElementOf::Array);
}
// Construct a context for a field of a tagged tuple.
constexpr static Context firstField(BinASTKind kind) {
return Context(kind, 0, ElementOf::TaggedTuple);
}
const Context operator++(int) {
MOZ_ASSERT(elementOf == ElementOf::TaggedTuple);
Context result = *this;
fieldIndex++;
return result;
}
// The kind of the tagged tuple containing the token.
//
// If the parent is the root, use `BinASTKind::_Null`.
BinASTKind kind;
// The index of the token as a field of the parent.
uint8_t fieldIndex;
enum class ElementOf {
// This token is an element of an array.
Array,
// This token is a field of a tagged tuple.
TaggedTuple,
};
ElementOf elementOf;
Context() = delete;
private:
constexpr Context(BinASTKind kind_, uint8_t fieldIndex_,
ElementOf elementOf_)
: kind(kind_), fieldIndex(fieldIndex_), elementOf(elementOf_) {}
// Part of variant `Context`
// Reading an element from a list.
struct ListContext {
const BinASTInterfaceAndField position;
const BinASTList content;
ListContext(const BinASTInterfaceAndField position,
const BinASTList content)
: position(position), content(content) {}
};
// Part of variant `Context`
// Reading a field from an interface.
struct FieldContext {
const BinASTInterfaceAndField position;
FieldContext(const BinASTInterfaceAndField position) : position(position) {}
};
// The context in which we read a token.
typedef mozilla::Variant<RootContext, ListContext, FieldContext> Context;
// The information needed to skip a subtree.
class SkippableSubTree {
public:

Просмотреть файл

@ -1097,7 +1097,7 @@ enum class BinASTInterfaceAndField: uint16_t {
}
// Keep the simple name of sums and lists if there is one.
match *alias_type.spec() {
TypeSpec::TypeSum(ref contents ) => {
TypeSpec::TypeSum(_) => {
if optional {
Cow::from(format!("OPTIONAL_SUM({name})", name = name.to_cpp_enum_case()))
} else {
@ -1632,8 +1632,8 @@ impl CPPExporter {
MOZ_TRY(tokenizer_->enterList(length, context, guard));{empty_check}
{init}
const Context childContext(context.arrayElement());
for (uint32_t i = 0; i < length; ++i) {{
const Context childContext(Context(ListContext(context.as<FieldContext>().position, BinASTList::{content_kind})));
{call}
{append} }}
@ -1641,6 +1641,7 @@ impl CPPExporter {
return result;
}}\n",
first_line = first_line,
content_kind = parser.name.to_class_cases(),
empty_check =
if parser.supports_empty {
"".to_string()
@ -1963,7 +1964,9 @@ impl CPPExporter {
let mut fields_implem = String::new();
for field in interface.contents().fields() {
let context = "fieldContext++";
let context = format!("Context(FieldContext(BinASTInterfaceAndField::{kind}__{field}))",
kind = name.to_cpp_enum_case(),
field = field.name().to_cpp_enum_case());
let rules_for_this_field = rules_for_this_interface.by_field.get(field.name())
.cloned()
@ -2165,7 +2168,7 @@ impl CPPExporter {
{{
MOZ_ASSERT(kind == BinASTKind::{kind});
BINJS_TRY(CheckRecursionLimit(cx_));
{maybe_field_context}{check_fields}
{check_fields}
{pre}{fields_implem}
{post} return result;
}}
@ -2177,11 +2180,6 @@ impl CPPExporter {
post = build_result.newline_if_not_empty(),
kind = name.to_cpp_enum_case(),
first_line = first_line,
maybe_field_context = if interface.contents().fields().len() > 0 {
" Context fieldContext = Context::firstField(kind);\n"
} else {
""
},
));
}
}