[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:
nikolaos 2016-08-25 01:44:59 -07:00 committed by Commit bot
parent 6e67d04260
commit 3c1d076a85
6 changed files with 199 additions and 246 deletions

View File

@ -1424,7 +1424,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
Token::Value next = Next(); Token::Value next = Next();
if (next == Token::IDENTIFIER || next == Token::ASYNC || if (next == Token::IDENTIFIER || next == Token::ASYNC ||
(next == Token::AWAIT && !parsing_module_ && !is_async_function())) { (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 // 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 // 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 // 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(), classifier->RecordLetPatternError(scanner()->location(),
MessageTemplate::kLetInLexicalBinding); MessageTemplate::kLetInLexicalBinding);
} }
return this->GetSymbol(scanner()); return impl()->GetSymbol();
} else { } else {
this->ReportUnexpectedToken(next); this->ReportUnexpectedToken(next);
*ok = false; *ok = false;
@ -1494,7 +1494,7 @@ ParserBase<Impl>::ParseIdentifierOrStrictReservedWord(
return impl()->EmptyIdentifier(); return impl()->EmptyIdentifier();
} }
return this->GetSymbol(scanner()); return impl()->GetSymbol();
} }
template <typename Impl> template <typename Impl>
@ -1512,7 +1512,7 @@ typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName(
return impl()->EmptyIdentifier(); return impl()->EmptyIdentifier();
} }
return this->GetSymbol(scanner()); return impl()->GetSymbol();
} }
template <typename Impl> template <typename Impl>
@ -1528,7 +1528,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral(
int literal_index = function_state_->NextMaterializedLiteralIndex(); int literal_index = function_state_->NextMaterializedLiteralIndex();
IdentifierT js_pattern = this->GetNextSymbol(scanner()); IdentifierT js_pattern = impl()->GetNextSymbol();
Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags(); Maybe<RegExp::Flags> flags = scanner()->ScanRegExpFlags();
if (flags.IsNothing()) { if (flags.IsNothing()) {
Next(); Next();
@ -1566,7 +1566,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
case Token::THIS: { case Token::THIS: {
BindingPatternUnexpectedToken(classifier); BindingPatternUnexpectedToken(classifier);
Consume(Token::THIS); Consume(Token::THIS);
return this->ThisExpression(beg_pos); return impl()->ThisExpression(beg_pos);
} }
case Token::NULL_LITERAL: case Token::NULL_LITERAL:
@ -1575,7 +1575,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
case Token::SMI: case Token::SMI:
case Token::NUMBER: case Token::NUMBER:
BindingPatternUnexpectedToken(classifier); BindingPatternUnexpectedToken(classifier);
return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); return impl()->ExpressionFromLiteral(Next(), beg_pos);
case Token::ASYNC: case Token::ASYNC:
if (allow_harmony_async_await() && if (allow_harmony_async_await() &&
@ -1596,14 +1596,14 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
case Token::FUTURE_STRICT_RESERVED_WORD: { case Token::FUTURE_STRICT_RESERVED_WORD: {
// Using eval or arguments in this context is OK even in strict mode. // Using eval or arguments in this context is OK even in strict mode.
IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK);
return this->ExpressionFromIdentifier(name, beg_pos, return impl()->ExpressionFromIdentifier(name, beg_pos,
scanner()->location().end_pos); scanner()->location().end_pos);
} }
case Token::STRING: { case Token::STRING: {
BindingPatternUnexpectedToken(classifier); BindingPatternUnexpectedToken(classifier);
Consume(Token::STRING); Consume(Token::STRING);
return this->ExpressionFromString(beg_pos, scanner(), factory()); return impl()->ExpressionFromString(beg_pos);
} }
case Token::ASSIGN_DIV: case Token::ASSIGN_DIV:
@ -1801,8 +1801,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral(
// '[' Expression? (',' Expression?)* ']' // '[' Expression? (',' Expression?)* ']'
int pos = peek_position(); int pos = peek_position();
typename Traits::Type::ExpressionList values = typename Traits::Type::ExpressionList values = impl()->NewExpressionList(4);
this->NewExpressionList(4, zone_);
int first_spread_index = -1; int first_spread_index = -1;
Expect(Token::LBRACK, CHECK_OK); Expect(Token::LBRACK, CHECK_OK);
while (peek() != Token::RBRACK) { while (peek() != Token::RBRACK) {
@ -1889,17 +1888,17 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
switch (token) { switch (token) {
case Token::STRING: case Token::STRING:
Consume(Token::STRING); Consume(Token::STRING);
*name = this->GetSymbol(scanner()); *name = impl()->GetSymbol();
break; break;
case Token::SMI: case Token::SMI:
Consume(Token::SMI); Consume(Token::SMI);
*name = this->GetNumberAsSymbol(scanner()); *name = impl()->GetNumberAsSymbol();
break; break;
case Token::NUMBER: case Token::NUMBER:
Consume(Token::NUMBER); Consume(Token::NUMBER);
*name = this->GetNumberAsSymbol(scanner()); *name = impl()->GetNumberAsSymbol();
break; break;
case Token::LBRACK: { case Token::LBRACK: {
@ -2013,7 +2012,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
MessageTemplate::kAwaitBindingIdentifier); MessageTemplate::kAwaitBindingIdentifier);
} }
ExpressionT lhs = 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); CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
ExpressionT value; ExpressionT value;
@ -2152,8 +2151,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
// '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
int pos = peek_position(); int pos = peek_position();
typename Traits::Type::PropertyList properties = typename Traits::Type::PropertyList properties = impl()->NewPropertyList(4);
this->NewPropertyList(4, zone_);
int number_of_boilerplate_properties = 0; int number_of_boilerplate_properties = 0;
bool has_computed_names = false; bool has_computed_names = false;
ObjectLiteralChecker checker(this); ObjectLiteralChecker checker(this);
@ -2210,8 +2208,7 @@ ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc,
// '(' (AssignmentExpression)*[','] ')' // '(' (AssignmentExpression)*[','] ')'
Scanner::Location spread_arg = Scanner::Location::invalid(); Scanner::Location spread_arg = Scanner::Location::invalid();
typename Traits::Type::ExpressionList result = typename Traits::Type::ExpressionList result = impl()->NewExpressionList(4);
this->NewExpressionList(4, zone_);
Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList));
bool done = (peek() == Token::RPAREN); bool done = (peek() == Token::RPAREN);
bool was_unspread = false; bool was_unspread = false;
@ -2333,7 +2330,7 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN,
// async Identifier => AsyncConciseBody // async Identifier => AsyncConciseBody
IdentifierT name = IdentifierT name =
ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
expression = this->ExpressionFromIdentifier( expression = impl()->ExpressionFromIdentifier(
name, position(), scanner()->location().end_pos, InferName::kNo); name, position(), scanner()->location().end_pos, InferName::kNo);
if (fni_) { if (fni_) {
// Remove `async` keyword from inferred name stack. // 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 // Explicit calls to the super constructor using super() perform an
// implicit binding assignment to the 'this' variable. // implicit binding assignment to the 'this' variable.
if (is_super_call) { if (is_super_call) {
ExpressionT this_expr = this->ThisExpression(pos); ExpressionT this_expr = impl()->ThisExpression(pos);
result = result =
factory()->NewAssignment(Token::INIT, this_expr, result, pos); factory()->NewAssignment(Token::INIT, this_expr, result, pos);
} }
@ -3025,8 +3022,7 @@ ParserBase<Impl>::ParseMemberWithNewPrefixesExpression(
return result; return result;
} }
// NewExpression without arguments. // NewExpression without arguments.
return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), return factory()->NewCallNew(result, impl()->NewExpressionList(0), new_pos);
new_pos);
} }
// No 'new' or 'super' keyword. // No 'new' or 'super' keyword.
return this->ParseMemberExpression(classifier, is_async, ok); return this->ParseMemberExpression(classifier, is_async, ok);
@ -3065,7 +3061,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
return impl()->EmptyExpression(); return impl()->EmptyExpression();
} }
return this->FunctionSentExpression(factory(), pos); return impl()->FunctionSentExpression(pos);
} }
FunctionKind function_kind = Check(Token::MUL) FunctionKind function_kind = Check(Token::MUL)
@ -3112,14 +3108,14 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression(
IsClassConstructor(kind)) { IsClassConstructor(kind)) {
if (peek() == Token::PERIOD || peek() == Token::LBRACK) { if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
scope->RecordSuperPropertyUsage(); scope->RecordSuperPropertyUsage();
return this->NewSuperPropertyReference(factory(), pos); return impl()->NewSuperPropertyReference(pos);
} }
// new super() is never allowed. // new super() is never allowed.
// super() is only allowed in derived constructor // super() is only allowed in derived constructor
if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
// TODO(rossberg): This might not be the correct FunctionState for the // TODO(rossberg): This might not be the correct FunctionState for the
// method here. // method here.
return this->NewSuperCallReference(factory(), pos); return impl()->NewSuperCallReference(pos);
} }
} }
@ -3156,7 +3152,7 @@ ParserBase<Impl>::ParseNewTargetExpression(bool* ok) {
return impl()->EmptyExpression(); return impl()->EmptyExpression();
} }
return this->NewTargetExpression(pos); return impl()->NewTargetExpression(pos);
} }
template <typename Impl> template <typename Impl>
@ -3432,7 +3428,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
bool is_lazily_parsed = (mode() == PARSE_LAZILY && bool is_lazily_parsed = (mode() == PARSE_LAZILY &&
formal_parameters.scope->AllowsLazyParsing()); formal_parameters.scope->AllowsLazyParsing());
if (is_lazily_parsed) { if (is_lazily_parsed) {
body = this->NewStatementList(0, zone()); body = impl()->NewStatementList(0);
impl()->SkipLazyFunctionBody(&materialized_literal_count, impl()->SkipLazyFunctionBody(&materialized_literal_count,
&expected_property_count, CHECK_OK); &expected_property_count, CHECK_OK);
if (formal_parameters.materialized_literals_count > 0) { if (formal_parameters.materialized_literals_count > 0) {
@ -3454,7 +3450,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
function_state_->return_expr_context()); function_state_->return_expr_context());
ReturnExprScope allow_tail_calls( ReturnExprScope allow_tail_calls(
function_state_, ReturnExprContext::kInsideValidReturnStatement); function_state_, ReturnExprContext::kInsideValidReturnStatement);
body = this->NewStatementList(1, zone()); body = impl()->NewStatementList(1);
this->AddParameterInitializationBlock(formal_parameters, body, is_async, this->AddParameterInitializationBlock(formal_parameters, body, is_async,
CHECK_OK); CHECK_OK);
ExpressionClassifier classifier(this); ExpressionClassifier classifier(this);

View File

@ -434,96 +434,62 @@ Expression* Parser::NewThrowError(Runtime::FunctionId id,
return factory()->NewThrow(call_constructor, pos); return factory()->NewThrow(call_constructor, pos);
} }
const AstRawString* ParserBaseTraits<Parser>::GetSymbol( Expression* Parser::NewSuperPropertyReference(int pos) {
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) {
// this_function[home_object_symbol] // this_function[home_object_symbol]
VariableProxy* this_function_proxy = delegate()->NewUnresolved( VariableProxy* this_function_proxy =
delegate()->ast_value_factory()->this_function_string(), pos); NewUnresolved(ast_value_factory()->this_function_string(), pos);
Expression* home_object_symbol_literal = Expression* home_object_symbol_literal =
factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); factory()->NewSymbolLiteral("home_object_symbol", kNoSourcePosition);
Expression* home_object = factory->NewProperty( Expression* home_object = factory()->NewProperty(
this_function_proxy, home_object_symbol_literal, pos); this_function_proxy, home_object_symbol_literal, pos);
return factory->NewSuperPropertyReference( return factory()->NewSuperPropertyReference(
ThisExpression(pos)->AsVariableProxy(), home_object, pos); ThisExpression(pos)->AsVariableProxy(), home_object, pos);
} }
Expression* ParserBaseTraits<Parser>::NewSuperCallReference( Expression* Parser::NewSuperCallReference(int pos) {
AstNodeFactory* factory, int pos) { VariableProxy* new_target_proxy =
VariableProxy* new_target_proxy = delegate()->NewUnresolved( NewUnresolved(ast_value_factory()->new_target_string(), pos);
delegate()->ast_value_factory()->new_target_string(), pos); VariableProxy* this_function_proxy =
VariableProxy* this_function_proxy = delegate()->NewUnresolved( NewUnresolved(ast_value_factory()->this_function_string(), pos);
delegate()->ast_value_factory()->this_function_string(), pos); return factory()->NewSuperCallReference(
return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(), ThisExpression(pos)->AsVariableProxy(), new_target_proxy,
new_target_proxy, this_function_proxy, this_function_proxy, pos);
pos);
} }
Expression* ParserBaseTraits<Parser>::NewTargetExpression(int pos) { Expression* Parser::NewTargetExpression(int pos) {
static const int kNewTargetStringLength = 10; static const int kNewTargetStringLength = 10;
auto proxy = delegate()->NewUnresolved( auto proxy = NewUnresolved(ast_value_factory()->new_target_string(), pos,
delegate()->ast_value_factory()->new_target_string(), pos, pos + kNewTargetStringLength);
pos + kNewTargetStringLength);
proxy->set_is_new_target(); proxy->set_is_new_target();
return proxy; return proxy;
} }
Expression* ParserBaseTraits<Parser>::FunctionSentExpression( Expression* Parser::FunctionSentExpression(int pos) {
AstNodeFactory* factory, int pos) const {
// We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator).
Zone* zone = delegate()->zone(); ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone());
ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); VariableProxy* generator =
VariableProxy* generator = factory->NewVariableProxy( factory()->NewVariableProxy(function_state_->generator_object_variable());
delegate()->function_state_->generator_object_variable()); args->Add(generator, zone());
args->Add(generator, zone); return factory()->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos,
return factory->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos, args, pos);
args, pos);
} }
Literal* ParserBaseTraits<Parser>::ExpressionFromLiteral( Literal* Parser::ExpressionFromLiteral(Token::Value token, int pos) {
Token::Value token, int pos, Scanner* scanner,
AstNodeFactory* factory) const {
switch (token) { switch (token) {
case Token::NULL_LITERAL: case Token::NULL_LITERAL:
return factory->NewNullLiteral(pos); return factory()->NewNullLiteral(pos);
case Token::TRUE_LITERAL: case Token::TRUE_LITERAL:
return factory->NewBooleanLiteral(true, pos); return factory()->NewBooleanLiteral(true, pos);
case Token::FALSE_LITERAL: case Token::FALSE_LITERAL:
return factory->NewBooleanLiteral(false, pos); return factory()->NewBooleanLiteral(false, pos);
case Token::SMI: { case Token::SMI: {
int value = scanner->smi_value(); int value = scanner()->smi_value();
return factory->NewSmiLiteral(value, pos); return factory()->NewSmiLiteral(value, pos);
} }
case Token::NUMBER: { case Token::NUMBER: {
bool has_dot = scanner->ContainsDot(); bool has_dot = scanner()->ContainsDot();
double value = scanner->DoubleValue(); double value = scanner()->DoubleValue();
return factory->NewNumberLiteral(value, pos, has_dot); return factory()->NewNumberLiteral(value, pos, has_dot);
} }
default: default:
DCHECK(false); DCHECK(false);
@ -531,32 +497,13 @@ Literal* ParserBaseTraits<Parser>::ExpressionFromLiteral(
return NULL; return NULL;
} }
Expression* ParserBaseTraits<Parser>::ExpressionFromIdentifier( Expression* Parser::GetIterator(Expression* iterable, int pos) {
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* iterator_symbol_literal = Expression* iterator_symbol_literal =
factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); factory()->NewSymbolLiteral("iterator_symbol", kNoSourcePosition);
Expression* prop = Expression* prop =
factory->NewProperty(iterable, iterator_symbol_literal, pos); factory()->NewProperty(iterable, iterator_symbol_literal, pos);
Zone* zone = delegate()->zone(); ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(0, zone());
ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); return factory()->NewCall(prop, args, pos);
return factory->NewCall(prop, args, pos);
} }
void Parser::MarkTailPosition(Expression* expression) { void Parser::MarkTailPosition(Expression* expression) {
@ -1166,7 +1113,7 @@ const AstRawString* Parser::ParseModuleSpecifier(bool* ok) {
// StringLiteral // StringLiteral
Expect(Token::STRING, CHECK_OK); Expect(Token::STRING, CHECK_OK);
return GetSymbol(scanner()); return GetSymbol();
} }
@ -3019,8 +2966,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
{ {
assign_iterator = factory()->NewAssignment( assign_iterator = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(iterator), Token::ASSIGN, factory()->NewVariableProxy(iterator),
GetIterator(iterable, factory(), iterable->position()), GetIterator(iterable, iterable->position()), iterable->position());
iterable->position());
} }
// !%_IsJSReceiver(result = iterator.next()) && // !%_IsJSReceiver(result = iterator.next()) &&
@ -4743,7 +4689,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
ClassLiteralChecker checker(this); ClassLiteralChecker checker(this);
ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4);
FunctionLiteral* constructor = nullptr; FunctionLiteral* constructor = nullptr;
bool has_seen_constructor = false; bool has_seen_constructor = false;
@ -5689,7 +5635,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
if (spread == nullptr) { if (spread == nullptr) {
// If the element is not a spread, we're adding a single: // If the element is not a spread, we're adding a single:
// %AppendElement($R, value) // %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(factory()->NewVariableProxy(result), zone());
append_element_args->Add(value, zone()); append_element_args->Add(value, zone());
do_block->statements()->Add( do_block->statements()->Add(
@ -5705,8 +5651,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
// %AppendElement($R, each) // %AppendElement($R, each)
Statement* append_body; Statement* append_body;
{ {
ZoneList<Expression*>* append_element_args = ZoneList<Expression*>* append_element_args = NewExpressionList(2);
NewExpressionList(2, zone());
append_element_args->Add(factory()->NewVariableProxy(result), zone()); append_element_args->Add(factory()->NewVariableProxy(result), zone());
append_element_args->Add(factory()->NewVariableProxy(each), zone()); append_element_args->Add(factory()->NewVariableProxy(each), zone());
append_body = factory()->NewExpressionStatement( append_body = factory()->NewExpressionStatement(
@ -5918,7 +5863,7 @@ Expression* Parser::RewriteYieldStar(Expression* generator,
Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string()); Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string());
Statement* get_iterator; Statement* get_iterator;
{ {
Expression* iterator = GetIterator(iterable, factory(), nopos); Expression* iterator = GetIterator(iterable, nopos);
Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator);
Expression* assignment = factory()->NewAssignment( Expression* assignment = factory()->NewAssignment(
Token::ASSIGN, iterator_proxy, iterator, nopos); Token::ASSIGN, iterator_proxy, iterator, nopos);
@ -6127,7 +6072,7 @@ Expression* Parser::RewriteYieldStar(Expression* generator,
// input = function.sent; // input = function.sent;
Statement* get_input; Statement* get_input;
{ {
Expression* function_sent = FunctionSentExpression(factory(), nopos); Expression* function_sent = FunctionSentExpression(nopos);
Expression* input_proxy = factory()->NewVariableProxy(var_input); Expression* input_proxy = factory()->NewVariableProxy(var_input);
Expression* assignment = factory()->NewAssignment( Expression* assignment = factory()->NewAssignment(
Token::ASSIGN, input_proxy, function_sent, nopos); Token::ASSIGN, input_proxy, function_sent, nopos);

View File

@ -175,38 +175,6 @@ class ParserBaseTraits<Parser> {
return reinterpret_cast<const Parser*>(this); 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( V8_INLINE void AddParameterInitializationBlock(
const ParserFormalParameters& parameters, const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); 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, Expression* BuildIteratorNextResult(Expression* iterator, Variable* result,
int pos); int pos);
Expression* GetIterator(Expression* iterable, int pos);
// Initialize the components of a for-in / for-of statement. // Initialize the components of a for-in / for-of statement.
Statement* InitializeForEachStatement(ForEachStatement* stmt, Statement* InitializeForEachStatement(ForEachStatement* stmt,
@ -977,6 +946,64 @@ class Parser : public ParserBase<Parser> {
return factory()->NewTheHoleLiteral(kNoSourcePosition); 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. // Parser's private field members.
Scanner scanner_; Scanner scanner_;

View File

@ -374,7 +374,7 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
auto temp = *temp_var = CreateTempVar(current_value_); auto temp = *temp_var = CreateTempVar(current_value_);
auto iterator = CreateTempVar(parser_->GetIterator( auto iterator = CreateTempVar(parser_->GetIterator(
factory()->NewVariableProxy(temp), factory(), kNoSourcePosition)); factory()->NewVariableProxy(temp), kNoSourcePosition));
auto done = auto done =
CreateTempVar(factory()->NewBooleanLiteral(false, kNoSourcePosition)); CreateTempVar(factory()->NewBooleanLiteral(false, kNoSourcePosition));
auto result = CreateTempVar(); auto result = CreateTempVar();

View File

@ -41,9 +41,8 @@ namespace internal {
#define DUMMY ) // to make indentation work #define DUMMY ) // to make indentation work
#undef DUMMY #undef DUMMY
PreParserIdentifier ParserBaseTraits<PreParser>::GetSymbol( PreParserIdentifier PreParser::GetSymbol() const {
Scanner* scanner) const { switch (scanner()->current_token()) {
switch (scanner->current_token()) {
case Token::ENUM: case Token::ENUM:
return PreParserIdentifier::Enum(); return PreParserIdentifier::Enum();
case Token::AWAIT: case Token::AWAIT:
@ -59,28 +58,20 @@ PreParserIdentifier ParserBaseTraits<PreParser>::GetSymbol(
case Token::ASYNC: case Token::ASYNC:
return PreParserIdentifier::Async(); return PreParserIdentifier::Async();
default: default:
if (scanner->UnescapedLiteralMatches("eval", 4)) if (scanner()->UnescapedLiteralMatches("eval", 4))
return PreParserIdentifier::Eval(); return PreParserIdentifier::Eval();
if (scanner->UnescapedLiteralMatches("arguments", 9)) if (scanner()->UnescapedLiteralMatches("arguments", 9))
return PreParserIdentifier::Arguments(); return PreParserIdentifier::Arguments();
if (scanner->UnescapedLiteralMatches("undefined", 9)) if (scanner()->UnescapedLiteralMatches("undefined", 9))
return PreParserIdentifier::Undefined(); return PreParserIdentifier::Undefined();
if (scanner->LiteralMatches("prototype", 9)) if (scanner()->LiteralMatches("prototype", 9))
return PreParserIdentifier::Prototype(); return PreParserIdentifier::Prototype();
if (scanner->LiteralMatches("constructor", 11)) if (scanner()->LiteralMatches("constructor", 11))
return PreParserIdentifier::Constructor(); return PreParserIdentifier::Constructor();
return PreParserIdentifier::Default(); 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( PreParser::PreParseResult PreParser::PreParseLazyFunction(
LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark, bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark,

View File

@ -627,73 +627,6 @@ class ParserBaseTraits<PreParser> {
// A dummy function, just useful as an argument to CHECK_OK_CUSTOM. // A dummy function, just useful as an argument to CHECK_OK_CUSTOM.
static void Void() {} 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( void AddParameterInitializationBlock(
const PreParserFormalParameters& parameters, PreParserStatementList body, const PreParserFormalParameters& parameters, PreParserStatementList body,
bool is_async, bool* ok) {} bool is_async, bool* ok) {}
@ -1145,6 +1078,67 @@ class PreParser : public ParserBase<PreParser> {
return PreParserExpression::Default(); 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. // Preparser's private field members.
int* use_counts_; int* use_counts_;