Commit 748517f7 authored by verwaest's avatar verwaest Committed by Commit bot

Redirect most NewUnresolved calls over Parser

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2233473002
Cr-Commit-Position: refs/heads/master@{#38575}
parent 76b53534
......@@ -160,9 +160,9 @@ class Scope: public ZoneObject {
// Create a new unresolved variable.
VariableProxy* NewUnresolved(AstNodeFactory* factory,
const AstRawString* name,
Variable::Kind kind = Variable::NORMAL,
int start_position = kNoSourcePosition,
int end_position = kNoSourcePosition) {
int end_position = kNoSourcePosition,
Variable::Kind kind = Variable::NORMAL) {
// Note that we must not share the unresolved variables with
// the same name because they may be removed selectively via
// RemoveUnresolved().
......
......@@ -1550,7 +1550,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
case Token::THIS: {
BindingPatternUnexpectedToken(classifier);
Consume(Token::THIS);
return this->ThisExpression(factory(), beg_pos);
return this->ThisExpression(beg_pos);
}
case Token::NULL_LITERAL:
......@@ -1582,8 +1582,8 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
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, factory());
return this->ExpressionFromIdentifier(name, beg_pos,
scanner()->location().end_pos);
}
case Token::STRING: {
......@@ -2007,8 +2007,8 @@ ParserBase<Traits>::ParsePropertyDefinition(
MessageTemplate::kAwaitBindingIdentifier);
}
}
ExpressionT lhs = this->ExpressionFromIdentifier(*name, next_beg_pos,
next_end_pos, factory());
ExpressionT lhs =
this->ExpressionFromIdentifier(*name, next_beg_pos, next_end_pos);
CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
ExpressionT value;
......@@ -2317,8 +2317,8 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
// async Identifier => AsyncConciseBody
IdentifierT name =
ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
expression = this->ExpressionFromIdentifier(
name, position(), scanner()->location().end_pos, factory());
expression = this->ExpressionFromIdentifier(name, position(),
scanner()->location().end_pos);
}
if (peek() == Token::ARROW) {
......@@ -2762,8 +2762,8 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
Scanner::Location(beg_pos, scanner()->location().end_pos),
MessageTemplate::kAwaitBindingIdentifier);
return this->ExpressionFromIdentifier(
name, beg_pos, scanner()->location().end_pos, factory());
return this->ExpressionFromIdentifier(name, beg_pos,
scanner()->location().end_pos);
}
default:
break;
......@@ -2921,7 +2921,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
// 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(factory(), pos);
ExpressionT this_expr = this->ThisExpression(pos);
result =
factory()->NewAssignment(Token::INIT, this_expr, result, pos);
}
......@@ -3148,7 +3148,7 @@ ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
return this->EmptyExpression();
}
return this->NewTargetExpression(factory(), pos);
return this->NewTargetExpression(pos);
}
template <class Traits>
......
......@@ -275,9 +275,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
ZoneList<Expression*>* args =
new (zone()) ZoneList<Expression*>(2, zone());
VariableProxy* this_function_proxy = this->scope()->NewUnresolved(
factory(), ast_value_factory()->this_function_string(),
Variable::NORMAL, pos);
VariableProxy* this_function_proxy =
NewUnresolved(ast_value_factory()->this_function_string(), pos);
ZoneList<Expression*>* tmp =
new (zone()) ZoneList<Expression*>(1, zone());
tmp->Add(this_function_proxy, zone());
......@@ -290,9 +289,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
new (zone()) ZoneList<Expression*>(1, zone());
spread_args_expr->Add(spread_args, zone());
args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone());
VariableProxy* new_target_proxy = this->scope()->NewUnresolved(
factory(), ast_value_factory()->new_target_string(), Variable::NORMAL,
pos);
VariableProxy* new_target_proxy =
NewUnresolved(ast_value_factory()->new_target_string(), pos);
args->Add(new_target_proxy, zone());
CallRuntime* call = factory()->NewCallRuntime(
Context::REFLECT_CONSTRUCT_INDEX, args, pos);
......@@ -690,45 +688,40 @@ const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
}
Expression* ParserTraits::ThisExpression(AstNodeFactory* factory, int pos) {
return parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->this_string(), Variable::THIS, pos,
pos + 4);
Expression* ParserTraits::ThisExpression(int pos) {
return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(),
pos, pos + 4, Variable::THIS);
}
Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
int pos) {
// this_function[home_object_symbol]
VariableProxy* this_function_proxy = parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->this_function_string(),
Variable::NORMAL, pos);
VariableProxy* this_function_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->this_function_string(), pos);
Expression* home_object_symbol_literal =
factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition);
Expression* home_object = factory->NewProperty(
this_function_proxy, home_object_symbol_literal, pos);
return factory->NewSuperPropertyReference(
ThisExpression(factory, pos)->AsVariableProxy(), home_object, pos);
ThisExpression(pos)->AsVariableProxy(), home_object, pos);
}
Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
int pos) {
VariableProxy* new_target_proxy = parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->new_target_string(),
Variable::NORMAL, pos);
VariableProxy* this_function_proxy = parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->this_function_string(),
Variable::NORMAL, pos);
return factory->NewSuperCallReference(
ThisExpression(factory, pos)->AsVariableProxy(), new_target_proxy,
this_function_proxy, pos);
}
Expression* ParserTraits::NewTargetExpression(AstNodeFactory* factory,
int pos) {
VariableProxy* new_target_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->new_target_string(), pos);
VariableProxy* this_function_proxy = parser_->NewUnresolved(
parser_->ast_value_factory()->this_function_string(), pos);
return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(),
new_target_proxy, this_function_proxy,
pos);
}
Expression* ParserTraits::NewTargetExpression(int pos) {
static const int kNewTargetStringLength = 10;
auto proxy = parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->new_target_string(),
Variable::NORMAL, pos, pos + kNewTargetStringLength);
auto proxy =
parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(),
pos, pos + kNewTargetStringLength);
proxy->set_is_new_target();
return proxy;
}
......@@ -771,14 +764,11 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
return NULL;
}
Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
int start_position,
int end_position,
AstNodeFactory* factory) {
int end_position) {
if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name);
return parser_->scope()->NewUnresolved(factory, name, Variable::NORMAL,
start_position, end_position);
return parser_->NewUnresolved(name, start_position, end_position);
}
......@@ -1949,17 +1939,13 @@ Statement* Parser::ParseStatementAsUnlabelled(
}
}
VariableProxy* Parser::NewUnresolved(const AstRawString* name, int begin_pos,
int end_pos, Variable::Kind kind) {
return scope()->NewUnresolved(factory(), name, begin_pos, end_pos, kind);
}
VariableProxy* Parser::NewUnresolved(const AstRawString* name,
VariableMode mode) {
// If we are inside a function, a declaration of a 'var' variable is a
// truly local variable, and the scope of the variable is always the function
// scope.
// Let/const variables are always added to the immediately enclosing scope.
Scope* scope =
IsLexicalVariableMode(mode) ? this->scope() : GetDeclarationScope();
return scope->NewUnresolved(factory(), name, Variable::NORMAL,
scanner()->location().beg_pos,
VariableProxy* Parser::NewUnresolved(const AstRawString* name) {
return scope()->NewUnresolved(factory(), name, scanner()->location().beg_pos,
scanner()->location().end_pos);
}
......@@ -1977,9 +1963,13 @@ Declaration* Parser::DeclareVariable(const AstRawString* name,
VariableMode mode, InitializationFlag init,
int pos, bool* ok) {
DCHECK_NOT_NULL(name);
VariableProxy* proxy = NewUnresolved(name, mode);
Scope* scope =
IsLexicalVariableMode(mode) ? this->scope() : GetDeclarationScope();
VariableProxy* proxy =
scope->NewUnresolved(factory(), name, scanner()->location().beg_pos,
scanner()->location().end_pos);
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, scope(), pos);
factory()->NewVariableDeclaration(proxy, this->scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK);
return declaration;
}
......@@ -2212,7 +2202,7 @@ Statement* Parser::ParseHoistableDeclaration(
VariableMode mode =
(!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
: VAR;
VariableProxy* proxy = NewUnresolved(variable_name, mode);
VariableProxy* proxy = NewUnresolved(variable_name);
Declaration* declaration =
factory()->NewFunctionDeclaration(proxy, fun, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, mode, kCreatedInitialized,
......@@ -2720,7 +2710,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
tok == Token::RBRACE ||
tok == Token::EOS) {
if (IsSubclassConstructor(function_state_->kind())) {
return_value = ThisExpression(factory(), loc.beg_pos);
return_value = ThisExpression(loc.beg_pos);
} else {
return_value = GetLiteralUndefined(position());
}
......@@ -2767,9 +2757,8 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
factory()->NewUndefinedLiteral(kNoSourcePosition), pos);
// is_undefined ? this : is_object_conditional
return_value = factory()->NewConditional(is_undefined,
ThisExpression(factory(), pos),
is_object_conditional, pos);
return_value = factory()->NewConditional(
is_undefined, ThisExpression(pos), is_object_conditional, pos);
} else {
ReturnExprScope maybe_allow_tail_calls(
function_state_, ReturnExprContext::kInsideValidReturnStatement);
......@@ -3448,7 +3437,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
// For each lexical variable x:
// make statement: temp_x = x.
for (int i = 0; i < names->length(); i++) {
VariableProxy* proxy = NewUnresolved(names->at(i), LET);
VariableProxy* proxy = NewUnresolved(names->at(i));
Variable* temp = NewTemporary(temp_name);
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy,
......@@ -3719,7 +3708,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
++use_counts_[v8::Isolate::kForInInitializer];
const AstRawString* name =
decl.pattern->AsVariableProxy()->raw_name();
VariableProxy* single_var = NewUnresolved(name, VAR);
VariableProxy* single_var = NewUnresolved(name);
init_block = factory()->NewBlock(
nullptr, 2, true, parsing_result.descriptor.declaration_pos);
init_block->statements()->Add(
......@@ -4762,9 +4751,8 @@ Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) {
DCHECK_NOT_NULL(function_state_->generator_object_variable());
ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone());
args->Add(factory()->NewThisFunction(pos), zone());
args->Add(IsArrowFunction(kind)
? GetLiteralUndefined(pos)
: ThisExpression(factory(), kNoSourcePosition),
args->Add(IsArrowFunction(kind) ? GetLiteralUndefined(pos)
: ThisExpression(kNoSourcePosition),
zone());
return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args,
pos);
......@@ -4885,8 +4873,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
if (IsSubclassConstructor(kind)) {
body->Add(factory()->NewReturnStatement(
this->ThisExpression(factory(), kNoSourcePosition),
kNoSourcePosition),
this->ThisExpression(kNoSourcePosition), kNoSourcePosition),
zone());
}
}
......@@ -5009,7 +4996,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
VariableProxy* proxy = nullptr;
if (name != nullptr) {
proxy = NewUnresolved(name, CONST);
proxy = NewUnresolved(name);
// TODO(verwaest): declare via block_state.
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, block_state.scope(), pos);
......@@ -5213,7 +5200,7 @@ void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) {
const AstRawString* name = decl->proxy()->raw_name();
Variable* parameter = function_scope->LookupLocal(name);
if (parameter == nullptr) continue;
VariableProxy* to = NewUnresolved(name, VAR);
VariableProxy* to = NewUnresolved(name);
VariableProxy* from = factory()->NewVariableProxy(parameter);
Expression* assignment =
factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition);
......@@ -5694,7 +5681,7 @@ Expression* Parser::SpreadCall(Expression* function,
if (function->IsProperty()) {
// Method calls
if (function->AsProperty()->IsSuperAccess()) {
Expression* home = ThisExpression(factory(), kNoSourcePosition);
Expression* home = ThisExpression(kNoSourcePosition);
args->InsertAt(0, function, zone());
args->InsertAt(1, home, zone());
} else {
......@@ -5935,7 +5922,7 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left,
Expression* result;
DCHECK_NOT_NULL(lhs->raw_name());
result = this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(),
lhs->end_position(), factory());
lhs->end_position());
args->Add(left, zone());
args->Add(right, zone());
Expression* call =
......
......@@ -549,17 +549,15 @@ class ParserTraits {
const AstRawString* GetNextSymbol(Scanner* scanner);
const AstRawString* GetNumberAsSymbol(Scanner* scanner);
Expression* ThisExpression(AstNodeFactory* factory,
int pos = kNoSourcePosition);
Expression* ThisExpression(int pos);
Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos);
Expression* NewSuperCallReference(AstNodeFactory* factory, int pos);
Expression* NewTargetExpression(AstNodeFactory* factory, int pos);
Expression* NewTargetExpression(int pos);
Expression* FunctionSentExpression(AstNodeFactory* factory, int pos);
Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
AstNodeFactory* factory);
Expression* ExpressionFromIdentifier(const AstRawString* name,
int start_position, int end_position,
AstNodeFactory* factory);
int start_position, int end_position);
Expression* ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory);
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory,
......@@ -1086,7 +1084,10 @@ class Parser : public ParserBase<ParserTraits> {
bool* ok);
static InitializationFlag DefaultInitializationFlag(VariableMode mode);
VariableProxy* NewUnresolved(const AstRawString* name, VariableMode mode);
VariableProxy* NewUnresolved(const AstRawString* name, int begin_pos,
int end_pos = kNoSourcePosition,
Variable::Kind kind = Variable::NORMAL);
VariableProxy* NewUnresolved(const AstRawString* name);
Variable* Declare(Declaration* declaration,
DeclarationDescriptor::Kind declaration_kind,
VariableMode mode, InitializationFlag init, bool* ok,
......
......@@ -147,7 +147,9 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
// pre-resolve the proxy because it resides in the same scope as the
// declaration.
const AstRawString* name = pattern->raw_name();
VariableProxy* proxy = parser_->NewUnresolved(name, descriptor_->mode);
VariableProxy* proxy = descriptor_->scope->NewUnresolved(
factory(), name, parser_->scanner()->location().beg_pos,
parser_->scanner()->location().end_pos);
Declaration* declaration = factory()->NewVariableDeclaration(
proxy, descriptor_->scope, descriptor_->declaration_pos);
Variable* var = parser_->Declare(declaration, descriptor_->declaration_kind,
......
......@@ -801,8 +801,7 @@ class PreParserTraits {
return PreParserIdentifier::Default();
}
static PreParserExpression ThisExpression(PreParserFactory* factory,
int pos) {
static PreParserExpression ThisExpression(int pos) {
return PreParserExpression::This();
}
......@@ -816,8 +815,7 @@ class PreParserTraits {
return PreParserExpression::SuperCallReference();
}
static PreParserExpression NewTargetExpression(PreParserFactory* factory,
int pos) {
static PreParserExpression NewTargetExpression(int pos) {
return PreParserExpression::Default();
}
......@@ -832,9 +830,9 @@ class PreParserTraits {
return PreParserExpression::Default();
}
static PreParserExpression ExpressionFromIdentifier(
PreParserIdentifier name, int start_position, int end_position,
PreParserFactory* factory) {
static PreParserExpression ExpressionFromIdentifier(PreParserIdentifier name,
int start_position,
int end_position) {
return PreParserExpression::FromIdentifier(name);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment