[parser] Clean up (pre)parser traits, part 4
This patch moves the following methods from the traits objects to the (pre)parser implementation objects: - ExpressionFromIdentifier - ExpressionFromLiteral - ExpressionFromString - FunctionSentExpression - GetNextSymbol - GetNumberAsSymbol - GetSymbol - NewExpressionList - NewPropertyList - NewStatementList - NewSuperCallReference - NewSuperPropertyReference - NewTargetExpression - ThisExpression Also, the method GetIterator is specific only to the parser and is removed from the preparser's implementation. R=adamk@chromium.org, marja@chromium.org BUG= LOG=N Review-Url: https://codereview.chromium.org/2274113002 Cr-Commit-Position: refs/heads/master@{#38890}
This commit is contained in:
parent
6e67d04260
commit
3c1d076a85
@ -1424,7 +1424,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
|
||||
Token::Value next = Next();
|
||||
if (next == Token::IDENTIFIER || next == Token::ASYNC ||
|
||||
(next == Token::AWAIT && !parsing_module_ && !is_async_function())) {
|
||||
IdentifierT name = this->GetSymbol(scanner());
|
||||
IdentifierT name = impl()->GetSymbol();
|
||||
// When this function is used to read a formal parameter, we don't always
|
||||
// know whether the function is going to be strict or sloppy. Indeed for
|
||||
// arrow functions we don't always know that the identifier we are reading
|
||||
@ -1467,7 +1467,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
|
||||
classifier->RecordLetPatternError(scanner()->location(),
|
||||
MessageTemplate::kLetInLexicalBinding);
|
||||
}
|
||||
return this->GetSymbol(scanner());
|
||||
return impl()->GetSymbol();
|
||||
} else {
|
||||
this->ReportUnexpectedToken(next);
|
||||
*ok = false;
|
||||
@ -1494,7 +1494,7 @@ ParserBase<Impl>::ParseIdentifierOrStrictReservedWord(
|
||||
return impl()->EmptyIdentifier();
|
||||
}
|
||||
|
||||
return this->GetSymbol(scanner());
|
||||
return impl()->GetSymbol();
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
@ -1512,7 +1512,7 @@ typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName(
|
||||
return impl()->EmptyIdentifier();
|
||||
}
|
||||
|
||||
return this->GetSymbol(scanner());
|
||||
return impl()->GetSymbol();
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
@ -1528,7 +1528,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral(
|
||||
|
||||
int literal_index = function_state_->NextMaterializedLiteralIndex();
|
||||
|
||||
IdentifierT js_pattern = this->GetNextSymbol(scanner());
|
||||
IdentifierT js_pattern = impl()->GetNextSymbol();
|
||||
Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags();
|
||||
if (flags.IsNothing()) {
|
||||
Next();
|
||||
@ -1566,7 +1566,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
|
||||
case Token::THIS: {
|
||||
BindingPatternUnexpectedToken(classifier);
|
||||
Consume(Token::THIS);
|
||||
return this->ThisExpression(beg_pos);
|
||||
return impl()->ThisExpression(beg_pos);
|
||||
}
|
||||
|
||||
case Token::NULL_LITERAL:
|
||||
@ -1575,7 +1575,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
|
||||
case Token::SMI:
|
||||
case Token::NUMBER:
|
||||
BindingPatternUnexpectedToken(classifier);
|
||||
return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory());
|
||||
return impl()->ExpressionFromLiteral(Next(), beg_pos);
|
||||
|
||||
case Token::ASYNC:
|
||||
if (allow_harmony_async_await() &&
|
||||
@ -1596,14 +1596,14 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
|
||||
case Token::FUTURE_STRICT_RESERVED_WORD: {
|
||||
// Using eval or arguments in this context is OK even in strict mode.
|
||||
IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK);
|
||||
return this->ExpressionFromIdentifier(name, beg_pos,
|
||||
scanner()->location().end_pos);
|
||||
return impl()->ExpressionFromIdentifier(name, beg_pos,
|
||||
scanner()->location().end_pos);
|
||||
}
|
||||
|
||||
case Token::STRING: {
|
||||
BindingPatternUnexpectedToken(classifier);
|
||||
Consume(Token::STRING);
|
||||
return this->ExpressionFromString(beg_pos, scanner(), factory());
|
||||
return impl()->ExpressionFromString(beg_pos);
|
||||
}
|
||||
|
||||
case Token::ASSIGN_DIV:
|
||||
@ -1801,8 +1801,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral(
|
||||
// '[' Expression? (',' Expression?)* ']'
|
||||
|
||||
int pos = peek_position();
|
||||
typename Traits::Type::ExpressionList values =
|
||||
this->NewExpressionList(4, zone_);
|
||||
typename Traits::Type::ExpressionList values = impl()->NewExpressionList(4);
|
||||
int first_spread_index = -1;
|
||||
Expect(Token::LBRACK, CHECK_OK);
|
||||
while (peek() != Token::RBRACK) {
|
||||
@ -1889,17 +1888,17 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
|
||||
switch (token) {
|
||||
case Token::STRING:
|
||||
Consume(Token::STRING);
|
||||
*name = this->GetSymbol(scanner());
|
||||
*name = impl()->GetSymbol();
|
||||
break;
|
||||
|
||||
case Token::SMI:
|
||||
Consume(Token::SMI);
|
||||
*name = this->GetNumberAsSymbol(scanner());
|
||||
*name = impl()->GetNumberAsSymbol();
|
||||
break;
|
||||
|
||||
case Token::NUMBER:
|
||||
Consume(Token::NUMBER);
|
||||
*name = this->GetNumberAsSymbol(scanner());
|
||||
*name = impl()->GetNumberAsSymbol();
|
||||
break;
|
||||
|
||||
case Token::LBRACK: {
|
||||
@ -2013,7 +2012,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
|
||||
MessageTemplate::kAwaitBindingIdentifier);
|
||||
}
|
||||
ExpressionT lhs =
|
||||
this->ExpressionFromIdentifier(*name, next_beg_pos, next_end_pos);
|
||||
impl()->ExpressionFromIdentifier(*name, next_beg_pos, next_end_pos);
|
||||
CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
|
||||
|
||||
ExpressionT value;
|
||||
@ -2152,8 +2151,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
|
||||
// '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
|
||||
|
||||
int pos = peek_position();
|
||||
typename Traits::Type::PropertyList properties =
|
||||
this->NewPropertyList(4, zone_);
|
||||
typename Traits::Type::PropertyList properties = impl()->NewPropertyList(4);
|
||||
int number_of_boilerplate_properties = 0;
|
||||
bool has_computed_names = false;
|
||||
ObjectLiteralChecker checker(this);
|
||||
@ -2210,8 +2208,7 @@ ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc,
|
||||
// '(' (AssignmentExpression)*[','] ')'
|
||||
|
||||
Scanner::Location spread_arg = Scanner::Location::invalid();
|
||||
typename Traits::Type::ExpressionList result =
|
||||
this->NewExpressionList(4, zone_);
|
||||
typename Traits::Type::ExpressionList result = impl()->NewExpressionList(4);
|
||||
Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList));
|
||||
bool done = (peek() == Token::RPAREN);
|
||||
bool was_unspread = false;
|
||||
@ -2333,7 +2330,7 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN,
|
||||
// async Identifier => AsyncConciseBody
|
||||
IdentifierT name =
|
||||
ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
|
||||
expression = this->ExpressionFromIdentifier(
|
||||
expression = impl()->ExpressionFromIdentifier(
|
||||
name, position(), scanner()->location().end_pos, InferName::kNo);
|
||||
if (fni_) {
|
||||
// Remove `async` keyword from inferred name stack.
|
||||
@ -2928,7 +2925,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier,
|
||||
// Explicit calls to the super constructor using super() perform an
|
||||
// implicit binding assignment to the 'this' variable.
|
||||
if (is_super_call) {
|
||||
ExpressionT this_expr = this->ThisExpression(pos);
|
||||
ExpressionT this_expr = impl()->ThisExpression(pos);
|
||||
result =
|
||||
factory()->NewAssignment(Token::INIT, this_expr, result, pos);
|
||||
}
|
||||
@ -3025,8 +3022,7 @@ ParserBase<Impl>::ParseMemberWithNewPrefixesExpression(
|
||||
return result;
|
||||
}
|
||||
// NewExpression without arguments.
|
||||
return factory()->NewCallNew(result, this->NewExpressionList(0, zone_),
|
||||
new_pos);
|
||||
return factory()->NewCallNew(result, impl()->NewExpressionList(0), new_pos);
|
||||
}
|
||||
// No 'new' or 'super' keyword.
|
||||
return this->ParseMemberExpression(classifier, is_async, ok);
|
||||
@ -3065,7 +3061,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
|
||||
return impl()->EmptyExpression();
|
||||
}
|
||||
|
||||
return this->FunctionSentExpression(factory(), pos);
|
||||
return impl()->FunctionSentExpression(pos);
|
||||
}
|
||||
|
||||
FunctionKind function_kind = Check(Token::MUL)
|
||||
@ -3112,14 +3108,14 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression(
|
||||
IsClassConstructor(kind)) {
|
||||
if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
|
||||
scope->RecordSuperPropertyUsage();
|
||||
return this->NewSuperPropertyReference(factory(), pos);
|
||||
return impl()->NewSuperPropertyReference(pos);
|
||||
}
|
||||
// new super() is never allowed.
|
||||
// super() is only allowed in derived constructor
|
||||
if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
|
||||
// TODO(rossberg): This might not be the correct FunctionState for the
|
||||
// method here.
|
||||
return this->NewSuperCallReference(factory(), pos);
|
||||
return impl()->NewSuperCallReference(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3156,7 +3152,7 @@ ParserBase<Impl>::ParseNewTargetExpression(bool* ok) {
|
||||
return impl()->EmptyExpression();
|
||||
}
|
||||
|
||||
return this->NewTargetExpression(pos);
|
||||
return impl()->NewTargetExpression(pos);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
@ -3432,7 +3428,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
|
||||
bool is_lazily_parsed = (mode() == PARSE_LAZILY &&
|
||||
formal_parameters.scope->AllowsLazyParsing());
|
||||
if (is_lazily_parsed) {
|
||||
body = this->NewStatementList(0, zone());
|
||||
body = impl()->NewStatementList(0);
|
||||
impl()->SkipLazyFunctionBody(&materialized_literal_count,
|
||||
&expected_property_count, CHECK_OK);
|
||||
if (formal_parameters.materialized_literals_count > 0) {
|
||||
@ -3454,7 +3450,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
|
||||
function_state_->return_expr_context());
|
||||
ReturnExprScope allow_tail_calls(
|
||||
function_state_, ReturnExprContext::kInsideValidReturnStatement);
|
||||
body = this->NewStatementList(1, zone());
|
||||
body = impl()->NewStatementList(1);
|
||||
this->AddParameterInitializationBlock(formal_parameters, body, is_async,
|
||||
CHECK_OK);
|
||||
ExpressionClassifier classifier(this);
|
||||
|
@ -434,96 +434,62 @@ Expression* Parser::NewThrowError(Runtime::FunctionId id,
|
||||
return factory()->NewThrow(call_constructor, pos);
|
||||
}
|
||||
|
||||
const AstRawString* ParserBaseTraits<Parser>::GetSymbol(
|
||||
Scanner* scanner) const {
|
||||
const AstRawString* result =
|
||||
delegate()->scanner()->CurrentSymbol(delegate()->ast_value_factory());
|
||||
DCHECK(result != NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
const AstRawString* ParserBaseTraits<Parser>::GetNumberAsSymbol(
|
||||
Scanner* scanner) const {
|
||||
double double_value = delegate()->scanner()->DoubleValue();
|
||||
char array[100];
|
||||
const char* string = DoubleToCString(double_value, ArrayVector(array));
|
||||
return delegate()->ast_value_factory()->GetOneByteString(string);
|
||||
}
|
||||
|
||||
const AstRawString* ParserBaseTraits<Parser>::GetNextSymbol(
|
||||
Scanner* scanner) const {
|
||||
return delegate()->scanner()->NextSymbol(delegate()->ast_value_factory());
|
||||
}
|
||||
|
||||
Expression* ParserBaseTraits<Parser>::ThisExpression(int pos) {
|
||||
return delegate()->NewUnresolved(
|
||||
delegate()->ast_value_factory()->this_string(), pos, pos + 4,
|
||||
Variable::THIS);
|
||||
}
|
||||
|
||||
Expression* ParserBaseTraits<Parser>::NewSuperPropertyReference(
|
||||
AstNodeFactory* factory, int pos) {
|
||||
Expression* Parser::NewSuperPropertyReference(int pos) {
|
||||
// this_function[home_object_symbol]
|
||||
VariableProxy* this_function_proxy = delegate()->NewUnresolved(
|
||||
delegate()->ast_value_factory()->this_function_string(), pos);
|
||||
VariableProxy* this_function_proxy =
|
||||
NewUnresolved(ast_value_factory()->this_function_string(), pos);
|
||||
Expression* home_object_symbol_literal =
|
||||
factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition);
|
||||
Expression* home_object = factory->NewProperty(
|
||||
factory()->NewSymbolLiteral("home_object_symbol", kNoSourcePosition);
|
||||
Expression* home_object = factory()->NewProperty(
|
||||
this_function_proxy, home_object_symbol_literal, pos);
|
||||
return factory->NewSuperPropertyReference(
|
||||
return factory()->NewSuperPropertyReference(
|
||||
ThisExpression(pos)->AsVariableProxy(), home_object, pos);
|
||||
}
|
||||
|
||||
Expression* ParserBaseTraits<Parser>::NewSuperCallReference(
|
||||
AstNodeFactory* factory, int pos) {
|
||||
VariableProxy* new_target_proxy = delegate()->NewUnresolved(
|
||||
delegate()->ast_value_factory()->new_target_string(), pos);
|
||||
VariableProxy* this_function_proxy = delegate()->NewUnresolved(
|
||||
delegate()->ast_value_factory()->this_function_string(), pos);
|
||||
return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(),
|
||||
new_target_proxy, this_function_proxy,
|
||||
pos);
|
||||
Expression* Parser::NewSuperCallReference(int pos) {
|
||||
VariableProxy* new_target_proxy =
|
||||
NewUnresolved(ast_value_factory()->new_target_string(), pos);
|
||||
VariableProxy* this_function_proxy =
|
||||
NewUnresolved(ast_value_factory()->this_function_string(), pos);
|
||||
return factory()->NewSuperCallReference(
|
||||
ThisExpression(pos)->AsVariableProxy(), new_target_proxy,
|
||||
this_function_proxy, pos);
|
||||
}
|
||||
|
||||
Expression* ParserBaseTraits<Parser>::NewTargetExpression(int pos) {
|
||||
Expression* Parser::NewTargetExpression(int pos) {
|
||||
static const int kNewTargetStringLength = 10;
|
||||
auto proxy = delegate()->NewUnresolved(
|
||||
delegate()->ast_value_factory()->new_target_string(), pos,
|
||||
pos + kNewTargetStringLength);
|
||||
auto proxy = NewUnresolved(ast_value_factory()->new_target_string(), pos,
|
||||
pos + kNewTargetStringLength);
|
||||
proxy->set_is_new_target();
|
||||
return proxy;
|
||||
}
|
||||
|
||||
Expression* ParserBaseTraits<Parser>::FunctionSentExpression(
|
||||
AstNodeFactory* factory, int pos) const {
|
||||
Expression* Parser::FunctionSentExpression(int pos) {
|
||||
// We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator).
|
||||
Zone* zone = delegate()->zone();
|
||||
ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone);
|
||||
VariableProxy* generator = factory->NewVariableProxy(
|
||||
delegate()->function_state_->generator_object_variable());
|
||||
args->Add(generator, zone);
|
||||
return factory->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos,
|
||||
args, pos);
|
||||
ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone());
|
||||
VariableProxy* generator =
|
||||
factory()->NewVariableProxy(function_state_->generator_object_variable());
|
||||
args->Add(generator, zone());
|
||||
return factory()->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos,
|
||||
args, pos);
|
||||
}
|
||||
|
||||
Literal* ParserBaseTraits<Parser>::ExpressionFromLiteral(
|
||||
Token::Value token, int pos, Scanner* scanner,
|
||||
AstNodeFactory* factory) const {
|
||||
Literal* Parser::ExpressionFromLiteral(Token::Value token, int pos) {
|
||||
switch (token) {
|
||||
case Token::NULL_LITERAL:
|
||||
return factory->NewNullLiteral(pos);
|
||||
return factory()->NewNullLiteral(pos);
|
||||
case Token::TRUE_LITERAL:
|
||||
return factory->NewBooleanLiteral(true, pos);
|
||||
return factory()->NewBooleanLiteral(true, pos);
|
||||
case Token::FALSE_LITERAL:
|
||||
return factory->NewBooleanLiteral(false, pos);
|
||||
return factory()->NewBooleanLiteral(false, pos);
|
||||
case Token::SMI: {
|
||||
int value = scanner->smi_value();
|
||||
return factory->NewSmiLiteral(value, pos);
|
||||
int value = scanner()->smi_value();
|
||||
return factory()->NewSmiLiteral(value, pos);
|
||||
}
|
||||
case Token::NUMBER: {
|
||||
bool has_dot = scanner->ContainsDot();
|
||||
double value = scanner->DoubleValue();
|
||||
return factory->NewNumberLiteral(value, pos, has_dot);
|
||||
bool has_dot = scanner()->ContainsDot();
|
||||
double value = scanner()->DoubleValue();
|
||||
return factory()->NewNumberLiteral(value, pos, has_dot);
|
||||
}
|
||||
default:
|
||||
DCHECK(false);
|
||||
@ -531,32 +497,13 @@ Literal* ParserBaseTraits<Parser>::ExpressionFromLiteral(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Expression* ParserBaseTraits<Parser>::ExpressionFromIdentifier(
|
||||
const AstRawString* name, int start_position, int end_position,
|
||||
InferName infer) {
|
||||
if (infer == InferName::kYes && delegate()->fni_ != NULL) {
|
||||
delegate()->fni_->PushVariableName(name);
|
||||
}
|
||||
return delegate()->NewUnresolved(name, start_position, end_position);
|
||||
}
|
||||
|
||||
Expression* ParserBaseTraits<Parser>::ExpressionFromString(
|
||||
int pos, Scanner* scanner, AstNodeFactory* factory) const {
|
||||
const AstRawString* symbol = GetSymbol(scanner);
|
||||
if (delegate()->fni_ != NULL) delegate()->fni_->PushLiteralName(symbol);
|
||||
return factory->NewStringLiteral(symbol, pos);
|
||||
}
|
||||
|
||||
Expression* ParserBaseTraits<Parser>::GetIterator(Expression* iterable,
|
||||
AstNodeFactory* factory,
|
||||
int pos) {
|
||||
Expression* Parser::GetIterator(Expression* iterable, int pos) {
|
||||
Expression* iterator_symbol_literal =
|
||||
factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition);
|
||||
factory()->NewSymbolLiteral("iterator_symbol", kNoSourcePosition);
|
||||
Expression* prop =
|
||||
factory->NewProperty(iterable, iterator_symbol_literal, pos);
|
||||
Zone* zone = delegate()->zone();
|
||||
ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone);
|
||||
return factory->NewCall(prop, args, pos);
|
||||
factory()->NewProperty(iterable, iterator_symbol_literal, pos);
|
||||
ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(0, zone());
|
||||
return factory()->NewCall(prop, args, pos);
|
||||
}
|
||||
|
||||
void Parser::MarkTailPosition(Expression* expression) {
|
||||
@ -1166,7 +1113,7 @@ const AstRawString* Parser::ParseModuleSpecifier(bool* ok) {
|
||||
// StringLiteral
|
||||
|
||||
Expect(Token::STRING, CHECK_OK);
|
||||
return GetSymbol(scanner());
|
||||
return GetSymbol();
|
||||
}
|
||||
|
||||
|
||||
@ -3019,8 +2966,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
|
||||
{
|
||||
assign_iterator = factory()->NewAssignment(
|
||||
Token::ASSIGN, factory()->NewVariableProxy(iterator),
|
||||
GetIterator(iterable, factory(), iterable->position()),
|
||||
iterable->position());
|
||||
GetIterator(iterable, iterable->position()), iterable->position());
|
||||
}
|
||||
|
||||
// !%_IsJSReceiver(result = iterator.next()) &&
|
||||
@ -4743,7 +4689,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
|
||||
|
||||
|
||||
ClassLiteralChecker checker(this);
|
||||
ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone());
|
||||
ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4);
|
||||
FunctionLiteral* constructor = nullptr;
|
||||
bool has_seen_constructor = false;
|
||||
|
||||
@ -5689,7 +5635,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
|
||||
if (spread == nullptr) {
|
||||
// If the element is not a spread, we're adding a single:
|
||||
// %AppendElement($R, value)
|
||||
ZoneList<Expression*>* append_element_args = NewExpressionList(2, zone());
|
||||
ZoneList<Expression*>* append_element_args = NewExpressionList(2);
|
||||
append_element_args->Add(factory()->NewVariableProxy(result), zone());
|
||||
append_element_args->Add(value, zone());
|
||||
do_block->statements()->Add(
|
||||
@ -5705,8 +5651,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
|
||||
// %AppendElement($R, each)
|
||||
Statement* append_body;
|
||||
{
|
||||
ZoneList<Expression*>* append_element_args =
|
||||
NewExpressionList(2, zone());
|
||||
ZoneList<Expression*>* append_element_args = NewExpressionList(2);
|
||||
append_element_args->Add(factory()->NewVariableProxy(result), zone());
|
||||
append_element_args->Add(factory()->NewVariableProxy(each), zone());
|
||||
append_body = factory()->NewExpressionStatement(
|
||||
@ -5918,7 +5863,7 @@ Expression* Parser::RewriteYieldStar(Expression* generator,
|
||||
Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string());
|
||||
Statement* get_iterator;
|
||||
{
|
||||
Expression* iterator = GetIterator(iterable, factory(), nopos);
|
||||
Expression* iterator = GetIterator(iterable, nopos);
|
||||
Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator);
|
||||
Expression* assignment = factory()->NewAssignment(
|
||||
Token::ASSIGN, iterator_proxy, iterator, nopos);
|
||||
@ -6127,7 +6072,7 @@ Expression* Parser::RewriteYieldStar(Expression* generator,
|
||||
// input = function.sent;
|
||||
Statement* get_input;
|
||||
{
|
||||
Expression* function_sent = FunctionSentExpression(factory(), nopos);
|
||||
Expression* function_sent = FunctionSentExpression(nopos);
|
||||
Expression* input_proxy = factory()->NewVariableProxy(var_input);
|
||||
Expression* assignment = factory()->NewAssignment(
|
||||
Token::ASSIGN, input_proxy, function_sent, nopos);
|
||||
|
@ -175,38 +175,6 @@ class ParserBaseTraits<Parser> {
|
||||
return reinterpret_cast<const Parser*>(this);
|
||||
}
|
||||
|
||||
// Producing data during the recursive descent.
|
||||
const AstRawString* GetSymbol(Scanner* scanner) const;
|
||||
const AstRawString* GetNextSymbol(Scanner* scanner) const;
|
||||
const AstRawString* GetNumberAsSymbol(Scanner* scanner) const;
|
||||
|
||||
Expression* ThisExpression(int pos = kNoSourcePosition);
|
||||
Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos);
|
||||
Expression* NewSuperCallReference(AstNodeFactory* factory, int pos);
|
||||
Expression* NewTargetExpression(int pos);
|
||||
Expression* FunctionSentExpression(AstNodeFactory* factory, int pos) const;
|
||||
Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
|
||||
AstNodeFactory* factory) const;
|
||||
Expression* ExpressionFromIdentifier(const AstRawString* name,
|
||||
int start_position, int end_position,
|
||||
InferName = InferName::kYes);
|
||||
Expression* ExpressionFromString(int pos, Scanner* scanner,
|
||||
AstNodeFactory* factory) const;
|
||||
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory,
|
||||
int pos);
|
||||
ZoneList<v8::internal::Expression*>* NewExpressionList(int size,
|
||||
Zone* zone) const {
|
||||
return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
|
||||
}
|
||||
ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size,
|
||||
Zone* zone) const {
|
||||
return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
|
||||
}
|
||||
ZoneList<v8::internal::Statement*>* NewStatementList(int size,
|
||||
Zone* zone) const {
|
||||
return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
|
||||
}
|
||||
|
||||
V8_INLINE void AddParameterInitializationBlock(
|
||||
const ParserFormalParameters& parameters,
|
||||
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok);
|
||||
@ -543,6 +511,7 @@ class Parser : public ParserBase<Parser> {
|
||||
Expression* BuildIteratorNextResult(Expression* iterator, Variable* result,
|
||||
int pos);
|
||||
|
||||
Expression* GetIterator(Expression* iterable, int pos);
|
||||
|
||||
// Initialize the components of a for-in / for-of statement.
|
||||
Statement* InitializeForEachStatement(ForEachStatement* stmt,
|
||||
@ -977,6 +946,64 @@ class Parser : public ParserBase<Parser> {
|
||||
return factory()->NewTheHoleLiteral(kNoSourcePosition);
|
||||
}
|
||||
|
||||
// Producing data during the recursive descent.
|
||||
V8_INLINE const AstRawString* GetSymbol() const {
|
||||
const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory());
|
||||
DCHECK(result != NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
V8_INLINE const AstRawString* GetNextSymbol() const {
|
||||
return scanner()->NextSymbol(ast_value_factory());
|
||||
}
|
||||
|
||||
V8_INLINE const AstRawString* GetNumberAsSymbol() const {
|
||||
double double_value = scanner()->DoubleValue();
|
||||
char array[100];
|
||||
const char* string = DoubleToCString(double_value, ArrayVector(array));
|
||||
return ast_value_factory()->GetOneByteString(string);
|
||||
}
|
||||
|
||||
V8_INLINE Expression* ThisExpression(int pos = kNoSourcePosition) {
|
||||
return NewUnresolved(ast_value_factory()->this_string(), pos, pos + 4,
|
||||
Variable::THIS);
|
||||
}
|
||||
|
||||
Expression* NewSuperPropertyReference(int pos);
|
||||
Expression* NewSuperCallReference(int pos);
|
||||
Expression* NewTargetExpression(int pos);
|
||||
Expression* FunctionSentExpression(int pos);
|
||||
|
||||
Literal* ExpressionFromLiteral(Token::Value token, int pos);
|
||||
|
||||
V8_INLINE Expression* ExpressionFromIdentifier(
|
||||
const AstRawString* name, int start_position, int end_position,
|
||||
InferName infer = InferName::kYes) {
|
||||
if (infer == InferName::kYes && fni_ != NULL) {
|
||||
fni_->PushVariableName(name);
|
||||
}
|
||||
return NewUnresolved(name, start_position, end_position);
|
||||
}
|
||||
|
||||
V8_INLINE Expression* ExpressionFromString(int pos) {
|
||||
const AstRawString* symbol = GetSymbol();
|
||||
if (fni_ != NULL) fni_->PushLiteralName(symbol);
|
||||
return factory()->NewStringLiteral(symbol, pos);
|
||||
}
|
||||
|
||||
V8_INLINE ZoneList<v8::internal::Expression*>* NewExpressionList(
|
||||
int size) const {
|
||||
return new (zone()) ZoneList<v8::internal::Expression*>(size, zone());
|
||||
}
|
||||
V8_INLINE ZoneList<ObjectLiteral::Property*>* NewPropertyList(
|
||||
int size) const {
|
||||
return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone());
|
||||
}
|
||||
V8_INLINE ZoneList<v8::internal::Statement*>* NewStatementList(
|
||||
int size) const {
|
||||
return new (zone()) ZoneList<v8::internal::Statement*>(size, zone());
|
||||
}
|
||||
|
||||
// Parser's private field members.
|
||||
|
||||
Scanner scanner_;
|
||||
|
@ -374,7 +374,7 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
|
||||
|
||||
auto temp = *temp_var = CreateTempVar(current_value_);
|
||||
auto iterator = CreateTempVar(parser_->GetIterator(
|
||||
factory()->NewVariableProxy(temp), factory(), kNoSourcePosition));
|
||||
factory()->NewVariableProxy(temp), kNoSourcePosition));
|
||||
auto done =
|
||||
CreateTempVar(factory()->NewBooleanLiteral(false, kNoSourcePosition));
|
||||
auto result = CreateTempVar();
|
||||
|
@ -41,9 +41,8 @@ namespace internal {
|
||||
#define DUMMY ) // to make indentation work
|
||||
#undef DUMMY
|
||||
|
||||
PreParserIdentifier ParserBaseTraits<PreParser>::GetSymbol(
|
||||
Scanner* scanner) const {
|
||||
switch (scanner->current_token()) {
|
||||
PreParserIdentifier PreParser::GetSymbol() const {
|
||||
switch (scanner()->current_token()) {
|
||||
case Token::ENUM:
|
||||
return PreParserIdentifier::Enum();
|
||||
case Token::AWAIT:
|
||||
@ -59,28 +58,20 @@ PreParserIdentifier ParserBaseTraits<PreParser>::GetSymbol(
|
||||
case Token::ASYNC:
|
||||
return PreParserIdentifier::Async();
|
||||
default:
|
||||
if (scanner->UnescapedLiteralMatches("eval", 4))
|
||||
if (scanner()->UnescapedLiteralMatches("eval", 4))
|
||||
return PreParserIdentifier::Eval();
|
||||
if (scanner->UnescapedLiteralMatches("arguments", 9))
|
||||
if (scanner()->UnescapedLiteralMatches("arguments", 9))
|
||||
return PreParserIdentifier::Arguments();
|
||||
if (scanner->UnescapedLiteralMatches("undefined", 9))
|
||||
if (scanner()->UnescapedLiteralMatches("undefined", 9))
|
||||
return PreParserIdentifier::Undefined();
|
||||
if (scanner->LiteralMatches("prototype", 9))
|
||||
if (scanner()->LiteralMatches("prototype", 9))
|
||||
return PreParserIdentifier::Prototype();
|
||||
if (scanner->LiteralMatches("constructor", 11))
|
||||
if (scanner()->LiteralMatches("constructor", 11))
|
||||
return PreParserIdentifier::Constructor();
|
||||
return PreParserIdentifier::Default();
|
||||
}
|
||||
}
|
||||
|
||||
PreParserExpression ParserBaseTraits<PreParser>::ExpressionFromString(
|
||||
int pos, Scanner* scanner, PreParserFactory* factory) const {
|
||||
if (scanner->UnescapedLiteralMatches("use strict", 10)) {
|
||||
return PreParserExpression::UseStrictStringLiteral();
|
||||
}
|
||||
return PreParserExpression::StringLiteral();
|
||||
}
|
||||
|
||||
PreParser::PreParseResult PreParser::PreParseLazyFunction(
|
||||
LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
|
||||
bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark,
|
||||
|
@ -627,73 +627,6 @@ class ParserBaseTraits<PreParser> {
|
||||
// A dummy function, just useful as an argument to CHECK_OK_CUSTOM.
|
||||
static void Void() {}
|
||||
|
||||
// Producing data during the recursive descent.
|
||||
PreParserIdentifier GetSymbol(Scanner* scanner) const;
|
||||
|
||||
PreParserIdentifier GetNextSymbol(Scanner* scanner) const {
|
||||
return PreParserIdentifier::Default();
|
||||
}
|
||||
|
||||
PreParserIdentifier GetNumberAsSymbol(Scanner* scanner) const {
|
||||
return PreParserIdentifier::Default();
|
||||
}
|
||||
|
||||
PreParserExpression ThisExpression(int pos = kNoSourcePosition) {
|
||||
return PreParserExpression::This();
|
||||
}
|
||||
|
||||
PreParserExpression NewSuperPropertyReference(PreParserFactory* factory,
|
||||
int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
PreParserExpression NewSuperCallReference(PreParserFactory* factory,
|
||||
int pos) {
|
||||
return PreParserExpression::SuperCallReference();
|
||||
}
|
||||
|
||||
PreParserExpression NewTargetExpression(int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
PreParserExpression FunctionSentExpression(PreParserFactory* factory,
|
||||
int pos) const {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
PreParserExpression ExpressionFromLiteral(Token::Value token, int pos,
|
||||
Scanner* scanner,
|
||||
PreParserFactory* factory) const {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
PreParserExpression ExpressionFromIdentifier(PreParserIdentifier name,
|
||||
int start_position,
|
||||
int end_position,
|
||||
InferName = InferName::kYes) {
|
||||
return PreParserExpression::FromIdentifier(name);
|
||||
}
|
||||
|
||||
PreParserExpression ExpressionFromString(int pos, Scanner* scanner,
|
||||
PreParserFactory* factory) const;
|
||||
|
||||
PreParserExpression GetIterator(PreParserExpression iterable,
|
||||
PreParserFactory* factory, int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
PreParserExpressionList NewExpressionList(int size, Zone* zone) const {
|
||||
return PreParserExpressionList();
|
||||
}
|
||||
|
||||
PreParserExpressionList NewPropertyList(int size, Zone* zone) const {
|
||||
return PreParserExpressionList();
|
||||
}
|
||||
|
||||
PreParserStatementList NewStatementList(int size, Zone* zone) const {
|
||||
return PreParserStatementList();
|
||||
}
|
||||
|
||||
void AddParameterInitializationBlock(
|
||||
const PreParserFormalParameters& parameters, PreParserStatementList body,
|
||||
bool is_async, bool* ok) {}
|
||||
@ -1145,6 +1078,67 @@ class PreParser : public ParserBase<PreParser> {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
// Producing data during the recursive descent.
|
||||
PreParserIdentifier GetSymbol() const;
|
||||
|
||||
V8_INLINE PreParserIdentifier GetNextSymbol() const {
|
||||
return PreParserIdentifier::Default();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserIdentifier GetNumberAsSymbol() const {
|
||||
return PreParserIdentifier::Default();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpression ThisExpression(int pos = kNoSourcePosition) {
|
||||
return PreParserExpression::This();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpression NewSuperPropertyReference(int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpression NewSuperCallReference(int pos) {
|
||||
return PreParserExpression::SuperCallReference();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpression NewTargetExpression(int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpression FunctionSentExpression(int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpression ExpressionFromLiteral(Token::Value token,
|
||||
int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpression ExpressionFromIdentifier(
|
||||
PreParserIdentifier name, int start_position, int end_position,
|
||||
InferName infer = InferName::kYes) {
|
||||
return PreParserExpression::FromIdentifier(name);
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpression ExpressionFromString(int pos) {
|
||||
if (scanner()->UnescapedLiteralMatches("use strict", 10)) {
|
||||
return PreParserExpression::UseStrictStringLiteral();
|
||||
}
|
||||
return PreParserExpression::StringLiteral();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpressionList NewExpressionList(int size) const {
|
||||
return PreParserExpressionList();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserExpressionList NewPropertyList(int size) const {
|
||||
return PreParserExpressionList();
|
||||
}
|
||||
|
||||
V8_INLINE PreParserStatementList NewStatementList(int size) const {
|
||||
return PreParserStatementList();
|
||||
}
|
||||
|
||||
// Preparser's private field members.
|
||||
|
||||
int* use_counts_;
|
||||
|
Loading…
Reference in New Issue
Block a user