Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1662)

Unified Diff: src/parsing/parser.cc

Issue 2179423002: [parser] Refactor parser and preparser traits (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: More changes after reviewers' comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index f60c05896f02cfd6f7590727343765f6034c85e6..9a4cc7425a565b02f99de04c05c55700d8dc0ca3 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -389,12 +389,10 @@ bool ParserTraits::IsEval(const AstRawString* identifier) const {
return identifier == parser_->ast_value_factory()->eval_string();
}
-
bool ParserTraits::IsArguments(const AstRawString* identifier) const {
return identifier == parser_->ast_value_factory()->arguments_string();
}
-
bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
return IsEval(identifier) || IsArguments(identifier);
}
@@ -591,34 +589,32 @@ Expression* ParserTraits::BuildIteratorResult(Expression* value, bool done) {
Expression* ParserTraits::NewThrowReferenceError(
MessageTemplate::Template message, int pos) {
- return NewThrowError(Runtime::kNewReferenceError, message,
- parser_->ast_value_factory()->empty_string(), pos);
+ return parser_->NewThrowError(Runtime::kNewReferenceError, message,
+ parser_->ast_value_factory()->empty_string(),
+ pos);
}
Expression* ParserTraits::NewThrowSyntaxError(MessageTemplate::Template message,
const AstRawString* arg,
int pos) {
- return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
+ return parser_->NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
}
Expression* ParserTraits::NewThrowTypeError(MessageTemplate::Template message,
const AstRawString* arg, int pos) {
- return NewThrowError(Runtime::kNewTypeError, message, arg, pos);
+ return parser_->NewThrowError(Runtime::kNewTypeError, message, arg, pos);
}
-
-Expression* ParserTraits::NewThrowError(Runtime::FunctionId id,
- MessageTemplate::Template message,
- const AstRawString* arg, int pos) {
- Zone* zone = parser_->zone();
- ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone);
- args->Add(parser_->factory()->NewSmiLiteral(message, pos), zone);
- args->Add(parser_->factory()->NewStringLiteral(arg, pos), zone);
- CallRuntime* call_constructor =
- parser_->factory()->NewCallRuntime(id, args, pos);
- return parser_->factory()->NewThrow(call_constructor, pos);
+Expression* Parser::NewThrowError(Runtime::FunctionId id,
+ MessageTemplate::Template message,
+ const AstRawString* arg, int pos) {
+ ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone());
+ args->Add(factory()->NewSmiLiteral(message, pos), zone());
+ args->Add(factory()->NewStringLiteral(arg, pos), zone());
+ CallRuntime* call_constructor = factory()->NewCallRuntime(id, args, pos);
+ return factory()->NewThrow(call_constructor, pos);
}
@@ -637,21 +633,6 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location,
}
-void ParserTraits::ReportMessage(MessageTemplate::Template message,
- const char* arg, ParseErrorType error_type) {
- Scanner::Location source_location = parser_->scanner()->location();
- ReportMessageAt(source_location, message, arg, error_type);
-}
-
-
-void ParserTraits::ReportMessage(MessageTemplate::Template message,
- const AstRawString* arg,
- ParseErrorType error_type) {
- Scanner::Location source_location = parser_->scanner()->location();
- ReportMessageAt(source_location, message, arg, error_type);
-}
-
-
void ParserTraits::ReportMessageAt(Scanner::Location source_location,
MessageTemplate::Template message,
const AstRawString* arg,
@@ -1317,9 +1298,9 @@ void Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
// in the body of a function with non-simple parameter list, on
// 29/7/2015. https://goo.gl/ueA7Ln
const AstRawString* string = literal->raw_value()->AsString();
- ParserTraits::ReportMessageAt(
- token_loc, MessageTemplate::kIllegalLanguageModeDirective,
- string);
+ ReportMessageAt(token_loc,
+ MessageTemplate::kIllegalLanguageModeDirective,
+ string);
*ok = false;
return;
}
@@ -2069,9 +2050,9 @@ Variable* Parser::Declare(Declaration* declaration,
// In harmony we treat re-declarations as early errors. See
// ES5 16 for a definition of early errors.
if (declaration_kind == DeclarationDescriptor::NORMAL) {
- ParserTraits::ReportMessage(MessageTemplate::kVarRedeclaration, name);
+ ReportMessage(MessageTemplate::kVarRedeclaration, name);
} else {
- ParserTraits::ReportMessage(MessageTemplate::kParamDupe);
+ ReportMessage(MessageTemplate::kParamDupe);
}
*ok = false;
return nullptr;
@@ -2464,7 +2445,7 @@ Block* Parser::ParseVariableDeclarations(
// ES6 'const' and binding patterns require initializers.
if (parsing_result->descriptor.mode == CONST ||
!pattern->IsVariableProxy()) {
- ParserTraits::ReportMessageAt(
+ ReportMessageAt(
Scanner::Location(decl_pos, scanner()->location().end_pos),
MessageTemplate::kDeclarationMissingInitializer,
!pattern->IsVariableProxy() ? "destructuring" : "const");
@@ -2527,8 +2508,8 @@ Statement* Parser::ParseFunctionDeclaration(bool* ok) {
if (Check(Token::MUL)) {
flags |= ParseFunctionFlags::kIsGenerator;
if (allow_harmony_restrictive_declarations()) {
- ParserTraits::ReportMessageAt(scanner()->location(),
- MessageTemplate::kGeneratorInLegacyContext);
+ ReportMessageAt(scanner()->location(),
+ MessageTemplate::kGeneratorInLegacyContext);
*ok = false;
return nullptr;
}
@@ -2576,7 +2557,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
// structured. However, these are probably changes we want to
// make later anyway so we should go back and fix this then.
if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
- ParserTraits::ReportMessage(MessageTemplate::kLabelRedeclaration, label);
+ ReportMessage(MessageTemplate::kLabelRedeclaration, label);
*ok = false;
return NULL;
}
@@ -2661,7 +2642,7 @@ Statement* Parser::ParseContinueStatement(bool* ok) {
if (label != NULL) {
message = MessageTemplate::kUnknownLabel;
}
- ParserTraits::ReportMessage(message, label);
+ ReportMessage(message, label);
*ok = false;
return NULL;
}
@@ -2698,7 +2679,7 @@ Statement* Parser::ParseBreakStatement(ZoneList<const AstRawString*>* labels,
if (label != NULL) {
message = MessageTemplate::kUnknownLabel;
}
- ParserTraits::ReportMessage(message, label);
+ ReportMessage(message, label);
*ok = false;
return NULL;
}
@@ -3081,8 +3062,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
position == kNoSourcePosition
? Scanner::Location::invalid()
: Scanner::Location(position, position + 1);
- ParserTraits::ReportMessageAt(
- location, MessageTemplate::kVarRedeclaration, name);
+ ReportMessageAt(location, MessageTemplate::kVarRedeclaration, name);
*ok = false;
return nullptr;
}
@@ -3392,9 +3372,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
for_of->Initialize(body, iterator, assign_iterator, next_result, result_done,
assign_each);
- return finalize
- ? ParserTraits::FinalizeForOfStatement(for_of, completion, nopos)
- : for_of;
+ return finalize ? FinalizeForOfStatement(for_of, completion, nopos) : for_of;
}
Statement* Parser::DesugarLexicalBindingsInForStatement(
@@ -3686,10 +3664,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
if (CheckInOrOf(&mode, ok)) {
if (!*ok) return nullptr;
if (parsing_result.declarations.length() != 1) {
- ParserTraits::ReportMessageAt(
- parsing_result.bindings_loc,
- MessageTemplate::kForInOfLoopMultiBindings,
- ForEachStatement::VisitModeString(mode));
+ ReportMessageAt(parsing_result.bindings_loc,
+ MessageTemplate::kForInOfLoopMultiBindings,
+ ForEachStatement::VisitModeString(mode));
*ok = false;
return nullptr;
}
@@ -3704,10 +3681,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
if (allow_harmony_for_in()) {
++use_counts_[v8::Isolate::kForInInitializer];
}
- ParserTraits::ReportMessageAt(
- parsing_result.first_initializer_loc,
- MessageTemplate::kForInOfLoopInitializer,
- ForEachStatement::VisitModeString(mode));
+ ReportMessageAt(parsing_result.first_initializer_loc,
+ MessageTemplate::kForInOfLoopInitializer,
+ ForEachStatement::VisitModeString(mode));
*ok = false;
return nullptr;
}
@@ -3816,9 +3792,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
ast_value_factory()
->dot_catch_string()) { // i.e. is a simple binding
if (bound_names.Contains(name)) {
- ParserTraits::ReportMessageAt(
- parsing_result.bindings_loc,
- MessageTemplate::kVarRedeclaration, name);
+ ReportMessageAt(parsing_result.bindings_loc,
+ MessageTemplate::kVarRedeclaration, name);
*ok = false;
return nullptr;
}
@@ -4066,7 +4041,7 @@ Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
}
-void ParserTraits::ParseArrowFunctionFormalParameters(
+void Parser::ParseArrowFunctionFormalParameters(
ParserFormalParameters* parameters, Expression* expr, int end_pos,
bool* ok) {
// ArrowFunctionFormals ::
@@ -4198,8 +4173,8 @@ void ParserTraits::ParseArrowFunctionFormalParameterList(
const Scope::Snapshot& scope_snapshot, bool* ok) {
if (expr->IsEmptyParentheses()) return;
- ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos,
- CHECK_OK_VOID);
+ parser_->ParseArrowFunctionFormalParameters(
+ parameters, expr, params_loc.end_pos, CHECK_OK_VOID);
scope_snapshot.Reparent(parameters->scope);
@@ -4573,9 +4548,9 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
return;
}
if (logger.has_error()) {
- ParserTraits::ReportMessageAt(
- Scanner::Location(logger.start(), logger.end()), logger.message(),
- logger.argument_opt(), logger.error_type());
+ ReportMessageAt(Scanner::Location(logger.start(), logger.end()),
+ logger.message(), logger.argument_opt(),
+ logger.error_type());
*ok = false;
return;
}
@@ -5169,7 +5144,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
// Check that the function is defined.
if (context_index == Context::kNotFound) {
- ParserTraits::ReportMessage(MessageTemplate::kNotDefined, name);
+ ReportMessage(MessageTemplate::kNotDefined, name);
*ok = false;
return NULL;
}
@@ -5193,8 +5168,7 @@ void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
position == kNoSourcePosition
? Scanner::Location::invalid()
: Scanner::Location(position, position + 1);
- ParserTraits::ReportMessageAt(location, MessageTemplate::kVarRedeclaration,
- name);
+ ReportMessageAt(location, MessageTemplate::kVarRedeclaration, name);
*ok = false;
}
}
@@ -6093,19 +6067,17 @@ void ParserTraits::SetFunctionNameFromPropertyName(
DCHECK(!value->IsAnonymousFunctionDefinition() ||
property->kind() == ObjectLiteralProperty::COMPUTED);
- SetFunctionName(value, name);
+ parser_->SetFunctionName(value, name);
}
void ParserTraits::SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier) {
if (!identifier->IsVariableProxy()) return;
- SetFunctionName(value, identifier->AsVariableProxy()->raw_name());
+ parser_->SetFunctionName(value, identifier->AsVariableProxy()->raw_name());
}
-
-void ParserTraits::SetFunctionName(Expression* value,
- const AstRawString* name) {
+void Parser::SetFunctionName(Expression* value, const AstRawString* name) {
DCHECK_NOT_NULL(name);
if (!value->IsAnonymousFunctionDefinition()) return;
auto function = value->AsFunctionLiteral();
@@ -6198,457 +6170,431 @@ void ParserTraits::SetFunctionName(Expression* value,
// output = %_Call(iteratorReturn, iterator, input);
// if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
-Expression* ParserTraits::RewriteYieldStar(
- Expression* generator, Expression* iterable, int pos) {
+Expression* Parser::RewriteYieldStar(Expression* generator,
+ Expression* iterable, int pos) {
const int nopos = kNoSourcePosition;
- auto factory = parser_->factory();
- auto avfactory = parser_->ast_value_factory();
- auto zone = parser_->zone();
-
-
// Forward definition for break/continue statements.
- WhileStatement* loop = factory->NewWhileStatement(nullptr, nopos);
-
+ WhileStatement* loop = factory()->NewWhileStatement(nullptr, nopos);
// let input = undefined;
- Variable* var_input = parser_->NewTemporary(avfactory->empty_string());
+ Variable* var_input = NewTemporary(ast_value_factory()->empty_string());
Statement* initialize_input;
{
- Expression* input_proxy = factory->NewVariableProxy(var_input);
- Expression* assignment = factory->NewAssignment(
- Token::ASSIGN, input_proxy, factory->NewUndefinedLiteral(nopos), nopos);
- initialize_input = factory->NewExpressionStatement(assignment, nopos);
+ Expression* input_proxy = factory()->NewVariableProxy(var_input);
+ Expression* assignment =
+ factory()->NewAssignment(Token::ASSIGN, input_proxy,
+ factory()->NewUndefinedLiteral(nopos), nopos);
+ initialize_input = factory()->NewExpressionStatement(assignment, nopos);
}
-
// let mode = kNext;
- Variable* var_mode = parser_->NewTemporary(avfactory->empty_string());
+ Variable* var_mode = NewTemporary(ast_value_factory()->empty_string());
Statement* initialize_mode;
{
- Expression* mode_proxy = factory->NewVariableProxy(var_mode);
- Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
+ Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
+ Expression* knext =
+ factory()->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
Expression* assignment =
- factory->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos);
- initialize_mode = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos);
+ initialize_mode = factory()->NewExpressionStatement(assignment, nopos);
}
-
// let output = undefined;
- Variable* var_output = parser_->NewTemporary(avfactory->empty_string());
+ Variable* var_output = NewTemporary(ast_value_factory()->empty_string());
Statement* initialize_output;
{
- Expression* output_proxy = factory->NewVariableProxy(var_output);
- Expression* assignment = factory->NewAssignment(
- Token::ASSIGN, output_proxy, factory->NewUndefinedLiteral(nopos),
- nopos);
- initialize_output = factory->NewExpressionStatement(assignment, nopos);
+ Expression* output_proxy = factory()->NewVariableProxy(var_output);
+ Expression* assignment =
+ factory()->NewAssignment(Token::ASSIGN, output_proxy,
+ factory()->NewUndefinedLiteral(nopos), nopos);
+ initialize_output = factory()->NewExpressionStatement(assignment, nopos);
}
-
// let iterator = iterable[Symbol.iterator];
- Variable* var_iterator = parser_->NewTemporary(avfactory->empty_string());
+ Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string());
Statement* get_iterator;
{
- Expression* iterator = GetIterator(iterable, factory, nopos);
- Expression* iterator_proxy = factory->NewVariableProxy(var_iterator);
- Expression* assignment = factory->NewAssignment(
+ Expression* iterator = GetIterator(iterable, factory(), nopos);
+ Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator);
+ Expression* assignment = factory()->NewAssignment(
Token::ASSIGN, iterator_proxy, iterator, nopos);
- get_iterator = factory->NewExpressionStatement(assignment, nopos);
+ get_iterator = factory()->NewExpressionStatement(assignment, nopos);
}
-
// if (!IS_RECEIVER(iterator)) throw MakeTypeError(kSymbolIteratorInvalid);
Statement* validate_iterator;
{
Expression* is_receiver_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_iterator), zone);
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_iterator), zone());
is_receiver_call =
- factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
}
Statement* throw_call;
{
- Expression* call = NewThrowTypeError(
- MessageTemplate::kSymbolIteratorInvalid, avfactory->empty_string(),
- nopos);
- throw_call = factory->NewExpressionStatement(call, nopos);
+ Expression* call =
+ NewThrowTypeError(MessageTemplate::kSymbolIteratorInvalid,
+ ast_value_factory()->empty_string(), nopos);
+ throw_call = factory()->NewExpressionStatement(call, nopos);
}
- validate_iterator = factory->NewIfStatement(
- is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos);
+ validate_iterator = factory()->NewIfStatement(
+ is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
+ nopos);
}
-
// output = iterator.next(input);
Statement* call_next;
{
- Expression* iterator_proxy = factory->NewVariableProxy(var_iterator);
+ Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator);
Expression* literal =
- factory->NewStringLiteral(avfactory->next_string(), nopos);
+ factory()->NewStringLiteral(ast_value_factory()->next_string(), nopos);
Expression* next_property =
- factory->NewProperty(iterator_proxy, literal, nopos);
- Expression* input_proxy = factory->NewVariableProxy(var_input);
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(input_proxy, zone);
- Expression* call = factory->NewCall(next_property, args, nopos);
- Expression* output_proxy = factory->NewVariableProxy(var_output);
+ factory()->NewProperty(iterator_proxy, literal, nopos);
+ Expression* input_proxy = factory()->NewVariableProxy(var_input);
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(input_proxy, zone());
+ Expression* call = factory()->NewCall(next_property, args, nopos);
+ Expression* output_proxy = factory()->NewVariableProxy(var_output);
Expression* assignment =
- factory->NewAssignment(Token::ASSIGN, output_proxy, call, nopos);
- call_next = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewAssignment(Token::ASSIGN, output_proxy, call, nopos);
+ call_next = factory()->NewExpressionStatement(assignment, nopos);
}
-
// if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
Statement* validate_next_output;
{
Expression* is_receiver_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_output), zone);
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_output), zone());
is_receiver_call =
- factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
}
Statement* throw_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_output), zone);
- Expression* call = factory->NewCallRuntime(
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_output), zone());
+ Expression* call = factory()->NewCallRuntime(
Runtime::kThrowIteratorResultNotAnObject, args, nopos);
- throw_call = factory->NewExpressionStatement(call, nopos);
+ throw_call = factory()->NewExpressionStatement(call, nopos);
}
- validate_next_output = factory->NewIfStatement(
- is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos);
+ validate_next_output = factory()->NewIfStatement(
+ is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
+ nopos);
}
-
// let iteratorThrow = iterator.throw;
- Variable* var_throw = parser_->NewTemporary(avfactory->empty_string());
+ Variable* var_throw = NewTemporary(ast_value_factory()->empty_string());
Statement* get_throw;
{
- Expression* iterator_proxy = factory->NewVariableProxy(var_iterator);
+ Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator);
Expression* literal =
- factory->NewStringLiteral(avfactory->throw_string(), nopos);
+ factory()->NewStringLiteral(ast_value_factory()->throw_string(), nopos);
Expression* property =
- factory->NewProperty(iterator_proxy, literal, nopos);
- Expression* throw_proxy = factory->NewVariableProxy(var_throw);
- Expression* assignment = factory->NewAssignment(
- Token::ASSIGN, throw_proxy, property, nopos);
- get_throw = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewProperty(iterator_proxy, literal, nopos);
+ Expression* throw_proxy = factory()->NewVariableProxy(var_throw);
+ Expression* assignment =
+ factory()->NewAssignment(Token::ASSIGN, throw_proxy, property, nopos);
+ get_throw = factory()->NewExpressionStatement(assignment, nopos);
}
-
// if (IS_NULL_OR_UNDEFINED(iteratorThrow) {
// IteratorClose(iterator);
// throw MakeTypeError(kThrowMethodMissing);
// }
Statement* check_throw;
{
- Expression* condition = factory->NewCompareOperation(
- Token::EQ, factory->NewVariableProxy(var_throw),
- factory->NewNullLiteral(nopos), nopos);
-
- Expression* call = NewThrowTypeError(
- MessageTemplate::kThrowMethodMissing,
- avfactory->empty_string(), nopos);
- Statement* throw_call = factory->NewExpressionStatement(call, nopos);
+ Expression* condition = factory()->NewCompareOperation(
+ Token::EQ, factory()->NewVariableProxy(var_throw),
+ factory()->NewNullLiteral(nopos), nopos);
+ Expression* call =
+ NewThrowTypeError(MessageTemplate::kThrowMethodMissing,
+ ast_value_factory()->empty_string(), nopos);
+ Statement* throw_call = factory()->NewExpressionStatement(call, nopos);
- Block* then = factory->NewBlock(nullptr, 4+1, false, nopos);
- parser_->BuildIteratorCloseForCompletion(
+ Block* then = factory()->NewBlock(nullptr, 4 + 1, false, nopos);
+ BuildIteratorCloseForCompletion(
then->statements(), var_iterator,
- factory->NewSmiLiteral(Parser::kNormalCompletion, nopos));
- then->statements()->Add(throw_call, zone);
- check_throw = factory->NewIfStatement(
- condition, then, factory->NewEmptyStatement(nopos), nopos);
+ factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos));
+ then->statements()->Add(throw_call, zone());
+ check_throw = factory()->NewIfStatement(
+ condition, then, factory()->NewEmptyStatement(nopos), nopos);
}
-
// output = %_Call(iteratorThrow, iterator, input);
Statement* call_throw;
{
- auto args = new (zone) ZoneList<Expression*>(3, zone);
- args->Add(factory->NewVariableProxy(var_throw), zone);
- args->Add(factory->NewVariableProxy(var_iterator), zone);
- args->Add(factory->NewVariableProxy(var_input), zone);
+ auto args = new (zone()) ZoneList<Expression*>(3, zone());
+ args->Add(factory()->NewVariableProxy(var_throw), zone());
+ args->Add(factory()->NewVariableProxy(var_iterator), zone());
+ args->Add(factory()->NewVariableProxy(var_input), zone());
Expression* call =
- factory->NewCallRuntime(Runtime::kInlineCall, args, nopos);
- Expression* assignment = factory->NewAssignment(
- Token::ASSIGN, factory->NewVariableProxy(var_output), call, nopos);
- call_throw = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos);
+ Expression* assignment = factory()->NewAssignment(
+ Token::ASSIGN, factory()->NewVariableProxy(var_output), call, nopos);
+ call_throw = factory()->NewExpressionStatement(assignment, nopos);
}
-
// if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
Statement* validate_throw_output;
{
Expression* is_receiver_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_output), zone);
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_output), zone());
is_receiver_call =
- factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
}
Statement* throw_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_output), zone);
- Expression* call = factory->NewCallRuntime(
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_output), zone());
+ Expression* call = factory()->NewCallRuntime(
Runtime::kThrowIteratorResultNotAnObject, args, nopos);
- throw_call = factory->NewExpressionStatement(call, nopos);
+ throw_call = factory()->NewExpressionStatement(call, nopos);
}
- validate_throw_output = factory->NewIfStatement(
- is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos);
+ validate_throw_output = factory()->NewIfStatement(
+ is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
+ nopos);
}
-
// if (output.done) break;
Statement* if_done;
{
- Expression* output_proxy = factory->NewVariableProxy(var_output);
+ Expression* output_proxy = factory()->NewVariableProxy(var_output);
Expression* literal =
- factory->NewStringLiteral(avfactory->done_string(), nopos);
- Expression* property = factory->NewProperty(output_proxy, literal, nopos);
- BreakStatement* break_loop = factory->NewBreakStatement(loop, nopos);
- if_done = factory->NewIfStatement(
- property, break_loop, factory->NewEmptyStatement(nopos), nopos);
+ factory()->NewStringLiteral(ast_value_factory()->done_string(), nopos);
+ Expression* property = factory()->NewProperty(output_proxy, literal, nopos);
+ BreakStatement* break_loop = factory()->NewBreakStatement(loop, nopos);
+ if_done = factory()->NewIfStatement(
+ property, break_loop, factory()->NewEmptyStatement(nopos), nopos);
}
// mode = kReturn;
Statement* set_mode_return;
{
- Expression* mode_proxy = factory->NewVariableProxy(var_mode);
+ Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
Expression* kreturn =
- factory->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
+ factory()->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
Expression* assignment =
- factory->NewAssignment(Token::ASSIGN, mode_proxy, kreturn, nopos);
- set_mode_return = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewAssignment(Token::ASSIGN, mode_proxy, kreturn, nopos);
+ set_mode_return = factory()->NewExpressionStatement(assignment, nopos);
}
// Yield(output);
Statement* yield_output;
{
- Expression* output_proxy = factory->NewVariableProxy(var_output);
- Yield* yield = factory->NewYield(generator, output_proxy, nopos,
- Yield::kOnExceptionThrow);
- yield_output = factory->NewExpressionStatement(yield, nopos);
+ Expression* output_proxy = factory()->NewVariableProxy(var_output);
+ Yield* yield = factory()->NewYield(generator, output_proxy, nopos,
+ Yield::kOnExceptionThrow);
+ yield_output = factory()->NewExpressionStatement(yield, nopos);
}
-
// mode = kNext;
Statement* set_mode_next;
{
- Expression* mode_proxy = factory->NewVariableProxy(var_mode);
- Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
+ Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
+ Expression* knext =
+ factory()->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
Expression* assignment =
- factory->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos);
- set_mode_next = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewAssignment(Token::ASSIGN, mode_proxy, knext, nopos);
+ set_mode_next = factory()->NewExpressionStatement(assignment, nopos);
}
-
// mode = kThrow;
Statement* set_mode_throw;
{
- Expression* mode_proxy = factory->NewVariableProxy(var_mode);
+ Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
Expression* kthrow =
- factory->NewSmiLiteral(JSGeneratorObject::kThrow, nopos);
+ factory()->NewSmiLiteral(JSGeneratorObject::kThrow, nopos);
Expression* assignment =
- factory->NewAssignment(Token::ASSIGN, mode_proxy, kthrow, nopos);
- set_mode_throw = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewAssignment(Token::ASSIGN, mode_proxy, kthrow, nopos);
+ set_mode_throw = factory()->NewExpressionStatement(assignment, nopos);
}
-
// input = function.sent;
Statement* get_input;
{
- Expression* function_sent = FunctionSentExpression(factory, nopos);
- Expression* input_proxy = factory->NewVariableProxy(var_input);
- Expression* assignment = factory->NewAssignment(
+ Expression* function_sent = FunctionSentExpression(factory(), nopos);
+ Expression* input_proxy = factory()->NewVariableProxy(var_input);
+ Expression* assignment = factory()->NewAssignment(
Token::ASSIGN, input_proxy, function_sent, nopos);
- get_input = factory->NewExpressionStatement(assignment, nopos);
+ get_input = factory()->NewExpressionStatement(assignment, nopos);
}
-
// if (mode === kReturn) {
// return {value: output.value, done: true};
// }
Statement* maybe_return_value;
{
- Expression* mode_proxy = factory->NewVariableProxy(var_mode);
+ Expression* mode_proxy = factory()->NewVariableProxy(var_mode);
Expression* kreturn =
- factory->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
- Expression* condition = factory->NewCompareOperation(
+ factory()->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
+ Expression* condition = factory()->NewCompareOperation(
Token::EQ_STRICT, mode_proxy, kreturn, nopos);
- Expression* output_proxy = factory->NewVariableProxy(var_output);
+ Expression* output_proxy = factory()->NewVariableProxy(var_output);
Expression* literal =
- factory->NewStringLiteral(avfactory->value_string(), nopos);
- Expression* property = factory->NewProperty(output_proxy, literal, nopos);
- Statement* return_value =
- factory->NewReturnStatement(BuildIteratorResult(property, true), nopos);
+ factory()->NewStringLiteral(ast_value_factory()->value_string(), nopos);
+ Expression* property = factory()->NewProperty(output_proxy, literal, nopos);
+ Statement* return_value = factory()->NewReturnStatement(
+ BuildIteratorResult(property, true), nopos);
- maybe_return_value = factory->NewIfStatement(
- condition, return_value, factory->NewEmptyStatement(nopos), nopos);
+ maybe_return_value = factory()->NewIfStatement(
+ condition, return_value, factory()->NewEmptyStatement(nopos), nopos);
}
-
// output.value
Statement* get_value;
{
- Expression* output_proxy = factory->NewVariableProxy(var_output);
+ Expression* output_proxy = factory()->NewVariableProxy(var_output);
Expression* literal =
- factory->NewStringLiteral(avfactory->value_string(), nopos);
- Expression* property = factory->NewProperty(output_proxy, literal, nopos);
- get_value = factory->NewExpressionStatement(property, nopos);
+ factory()->NewStringLiteral(ast_value_factory()->value_string(), nopos);
+ Expression* property = factory()->NewProperty(output_proxy, literal, nopos);
+ get_value = factory()->NewExpressionStatement(property, nopos);
}
-
// Now put things together.
-
// try { ... } catch(e) { ... }
Statement* try_catch;
{
- Block* try_block = factory->NewBlock(nullptr, 2, false, nopos);
- try_block->statements()->Add(yield_output, zone);
- try_block->statements()->Add(set_mode_next, zone);
+ Block* try_block = factory()->NewBlock(nullptr, 2, false, nopos);
+ try_block->statements()->Add(yield_output, zone());
+ try_block->statements()->Add(set_mode_next, zone());
- Block* catch_block = factory->NewBlock(nullptr, 1, false, nopos);
- catch_block->statements()->Add(set_mode_throw, zone);
+ Block* catch_block = factory()->NewBlock(nullptr, 1, false, nopos);
+ catch_block->statements()->Add(set_mode_throw, zone());
Scope* catch_scope = NewScope(CATCH_SCOPE);
catch_scope->set_is_hidden();
- const AstRawString* name = avfactory->dot_catch_string();
+ const AstRawString* name = ast_value_factory()->dot_catch_string();
Variable* catch_variable =
catch_scope->DeclareLocal(name, VAR, kCreatedInitialized,
Variable::NORMAL);
- try_catch = factory->NewTryCatchStatementForDesugaring(
+ try_catch = factory()->NewTryCatchStatementForDesugaring(
try_block, catch_scope, catch_variable, catch_block, nopos);
}
-
// try { ... } finally { ... }
Statement* try_finally;
{
- Block* try_block = factory->NewBlock(nullptr, 1, false, nopos);
- try_block->statements()->Add(try_catch, zone);
+ Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
+ try_block->statements()->Add(try_catch, zone());
- Block* finally = factory->NewBlock(nullptr, 2, false, nopos);
- finally->statements()->Add(get_input, zone);
- finally->statements()->Add(
- factory->NewContinueStatement(loop, nopos), zone);
+ Block* finally = factory()->NewBlock(nullptr, 2, false, nopos);
+ finally->statements()->Add(get_input, zone());
+ finally->statements()->Add(factory()->NewContinueStatement(loop, nopos),
+ zone());
- try_finally = factory->NewTryFinallyStatement(try_block, finally, nopos);
+ try_finally = factory()->NewTryFinallyStatement(try_block, finally, nopos);
}
-
// switch (mode) { ... }
- SwitchStatement* switch_mode = factory->NewSwitchStatement(nullptr, nopos);
+ SwitchStatement* switch_mode = factory()->NewSwitchStatement(nullptr, nopos);
{
- auto case_next = new (zone) ZoneList<Statement*>(3, zone);
- case_next->Add(call_next, zone);
- case_next->Add(validate_next_output, zone);
- case_next->Add(factory->NewBreakStatement(switch_mode, nopos), zone);
+ auto case_next = new (zone()) ZoneList<Statement*>(3, zone());
+ case_next->Add(call_next, zone());
+ case_next->Add(validate_next_output, zone());
+ case_next->Add(factory()->NewBreakStatement(switch_mode, nopos), zone());
- auto case_return = new (zone) ZoneList<Statement*>(5, zone);
+ auto case_return = new (zone()) ZoneList<Statement*>(5, zone());
BuildIteratorClose(case_return, var_iterator, var_input, var_output);
- case_return->Add(factory->NewBreakStatement(switch_mode, nopos), zone);
-
- auto case_throw = new (zone) ZoneList<Statement*>(5, zone);
- case_throw->Add(get_throw, zone);
- case_throw->Add(check_throw, zone);
- case_throw->Add(call_throw, zone);
- case_throw->Add(validate_throw_output, zone);
- case_throw->Add(factory->NewBreakStatement(switch_mode, nopos), zone);
-
- auto cases = new (zone) ZoneList<CaseClause*>(3, zone);
- Expression* knext = factory->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
+ case_return->Add(factory()->NewBreakStatement(switch_mode, nopos), zone());
+
+ auto case_throw = new (zone()) ZoneList<Statement*>(5, zone());
+ case_throw->Add(get_throw, zone());
+ case_throw->Add(check_throw, zone());
+ case_throw->Add(call_throw, zone());
+ case_throw->Add(validate_throw_output, zone());
+ case_throw->Add(factory()->NewBreakStatement(switch_mode, nopos), zone());
+
+ auto cases = new (zone()) ZoneList<CaseClause*>(3, zone());
+ Expression* knext =
+ factory()->NewSmiLiteral(JSGeneratorObject::kNext, nopos);
Expression* kreturn =
- factory->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
+ factory()->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
Expression* kthrow =
- factory->NewSmiLiteral(JSGeneratorObject::kThrow, nopos);
- cases->Add(factory->NewCaseClause(knext, case_next, nopos), zone);
- cases->Add(factory->NewCaseClause(kreturn, case_return, nopos), zone);
- cases->Add(factory->NewCaseClause(kthrow, case_throw, nopos), zone);
+ factory()->NewSmiLiteral(JSGeneratorObject::kThrow, nopos);
+ cases->Add(factory()->NewCaseClause(knext, case_next, nopos), zone());
+ cases->Add(factory()->NewCaseClause(kreturn, case_return, nopos), zone());
+ cases->Add(factory()->NewCaseClause(kthrow, case_throw, nopos), zone());
- switch_mode->Initialize(factory->NewVariableProxy(var_mode), cases);
+ switch_mode->Initialize(factory()->NewVariableProxy(var_mode), cases);
}
-
// while (true) { ... }
// Already defined earlier: WhileStatement* loop = ...
{
- Block* loop_body = factory->NewBlock(nullptr, 4, false, nopos);
- loop_body->statements()->Add(switch_mode, zone);
- loop_body->statements()->Add(if_done, zone);
- loop_body->statements()->Add(set_mode_return, zone);
- loop_body->statements()->Add(try_finally, zone);
+ Block* loop_body = factory()->NewBlock(nullptr, 4, false, nopos);
+ loop_body->statements()->Add(switch_mode, zone());
+ loop_body->statements()->Add(if_done, zone());
+ loop_body->statements()->Add(set_mode_return, zone());
+ loop_body->statements()->Add(try_finally, zone());
- loop->Initialize(factory->NewBooleanLiteral(true, nopos), loop_body);
+ loop->Initialize(factory()->NewBooleanLiteral(true, nopos), loop_body);
}
-
// do { ... }
DoExpression* yield_star;
{
// The rewriter needs to process the get_value statement only, hence we
// put the preceding statements into an init block.
- Block* do_block_ = factory->NewBlock(nullptr, 7, true, nopos);
- do_block_->statements()->Add(initialize_input, zone);
- do_block_->statements()->Add(initialize_mode, zone);
- do_block_->statements()->Add(initialize_output, zone);
- do_block_->statements()->Add(get_iterator, zone);
- do_block_->statements()->Add(validate_iterator, zone);
- do_block_->statements()->Add(loop, zone);
- do_block_->statements()->Add(maybe_return_value, zone);
+ Block* do_block_ = factory()->NewBlock(nullptr, 7, true, nopos);
+ do_block_->statements()->Add(initialize_input, zone());
+ do_block_->statements()->Add(initialize_mode, zone());
+ do_block_->statements()->Add(initialize_output, zone());
+ do_block_->statements()->Add(get_iterator, zone());
+ do_block_->statements()->Add(validate_iterator, zone());
+ do_block_->statements()->Add(loop, zone());
+ do_block_->statements()->Add(maybe_return_value, zone());
- Block* do_block = factory->NewBlock(nullptr, 2, false, nopos);
- do_block->statements()->Add(do_block_, zone);
- do_block->statements()->Add(get_value, zone);
+ Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos);
+ do_block->statements()->Add(do_block_, zone());
+ do_block->statements()->Add(get_value, zone());
Variable* dot_result =
- parser_->NewTemporary(avfactory->dot_result_string());
- yield_star = factory->NewDoExpression(do_block, dot_result, nopos);
- Rewriter::Rewrite(parser_, parser_->GetClosureScope(), yield_star,
- avfactory);
+ NewTemporary(ast_value_factory()->dot_result_string());
+ yield_star = factory()->NewDoExpression(do_block, dot_result, nopos);
+ Rewriter::Rewrite(this, GetClosureScope(), yield_star, ast_value_factory());
}
return yield_star;
}
-Statement* ParserTraits::CheckCallable(Variable* var, Expression* error,
- int pos) {
- auto factory = parser_->factory();
- auto avfactory = parser_->ast_value_factory();
+Statement* Parser::CheckCallable(Variable* var, Expression* error, int pos) {
const int nopos = kNoSourcePosition;
Statement* validate_var;
{
- Expression* type_of = factory->NewUnaryOperation(
- Token::TYPEOF, factory->NewVariableProxy(var), nopos);
- Expression* function_literal =
- factory->NewStringLiteral(avfactory->function_string(), nopos);
- Expression* condition = factory->NewCompareOperation(
+ Expression* type_of = factory()->NewUnaryOperation(
+ Token::TYPEOF, factory()->NewVariableProxy(var), nopos);
+ Expression* function_literal = factory()->NewStringLiteral(
+ ast_value_factory()->function_string(), nopos);
+ Expression* condition = factory()->NewCompareOperation(
Token::EQ_STRICT, type_of, function_literal, nopos);
- Statement* throw_call = factory->NewExpressionStatement(error, pos);
+ Statement* throw_call = factory()->NewExpressionStatement(error, pos);
- validate_var = factory->NewIfStatement(
- condition, factory->NewEmptyStatement(nopos), throw_call, nopos);
+ validate_var = factory()->NewIfStatement(
+ condition, factory()->NewEmptyStatement(nopos), throw_call, nopos);
}
return validate_var;
}
-void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements,
- Variable* iterator, Variable* input,
- Variable* var_output) {
+void Parser::BuildIteratorClose(ZoneList<Statement*>* statements,
+ Variable* iterator, Variable* input,
+ Variable* var_output) {
//
// This function adds four statements to [statements], corresponding to the
// following code:
@@ -6662,23 +6608,20 @@ void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements,
//
const int nopos = kNoSourcePosition;
- auto factory = parser_->factory();
- auto avfactory = parser_->ast_value_factory();
- auto zone = parser_->zone();
// let iteratorReturn = iterator.return;
Variable* var_return = var_output; // Reusing the output variable.
Statement* get_return;
{
- Expression* iterator_proxy = factory->NewVariableProxy(iterator);
- Expression* literal =
- factory->NewStringLiteral(avfactory->return_string(), nopos);
+ Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
+ Expression* literal = factory()->NewStringLiteral(
+ ast_value_factory()->return_string(), nopos);
Expression* property =
- factory->NewProperty(iterator_proxy, literal, nopos);
- Expression* return_proxy = factory->NewVariableProxy(var_return);
- Expression* assignment = factory->NewAssignment(
- Token::ASSIGN, return_proxy, property, nopos);
- get_return = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewProperty(iterator_proxy, literal, nopos);
+ Expression* return_proxy = factory()->NewVariableProxy(var_return);
+ Expression* assignment =
+ factory()->NewAssignment(Token::ASSIGN, return_proxy, property, nopos);
+ get_return = factory()->NewExpressionStatement(assignment, nopos);
}
// if (IS_NULL_OR_UNDEFINED(iteratorReturn) {
@@ -6686,33 +6629,33 @@ void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements,
// }
Statement* check_return;
{
- Expression* condition = factory->NewCompareOperation(
- Token::EQ, factory->NewVariableProxy(var_return),
- factory->NewNullLiteral(nopos), nopos);
+ Expression* condition = factory()->NewCompareOperation(
+ Token::EQ, factory()->NewVariableProxy(var_return),
+ factory()->NewNullLiteral(nopos), nopos);
- Expression* value = factory->NewVariableProxy(input);
+ Expression* value = factory()->NewVariableProxy(input);
Statement* return_input =
- factory->NewReturnStatement(BuildIteratorResult(value, true), nopos);
+ factory()->NewReturnStatement(BuildIteratorResult(value, true), nopos);
- check_return = factory->NewIfStatement(
- condition, return_input, factory->NewEmptyStatement(nopos), nopos);
+ check_return = factory()->NewIfStatement(
+ condition, return_input, factory()->NewEmptyStatement(nopos), nopos);
}
// output = %_Call(iteratorReturn, iterator, input);
Statement* call_return;
{
- auto args = new (zone) ZoneList<Expression*>(3, zone);
- args->Add(factory->NewVariableProxy(var_return), zone);
- args->Add(factory->NewVariableProxy(iterator), zone);
- args->Add(factory->NewVariableProxy(input), zone);
+ auto args = new (zone()) ZoneList<Expression*>(3, zone());
+ args->Add(factory()->NewVariableProxy(var_return), zone());
+ args->Add(factory()->NewVariableProxy(iterator), zone());
+ args->Add(factory()->NewVariableProxy(input), zone());
Expression* call =
- factory->NewCallRuntime(Runtime::kInlineCall, args, nopos);
- Expression* output_proxy = factory->NewVariableProxy(var_output);
- Expression* assignment = factory->NewAssignment(
- Token::ASSIGN, output_proxy, call, nopos);
- call_return = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos);
+ Expression* output_proxy = factory()->NewVariableProxy(var_output);
+ Expression* assignment =
+ factory()->NewAssignment(Token::ASSIGN, output_proxy, call, nopos);
+ call_return = factory()->NewExpressionStatement(assignment, nopos);
}
// if (!IS_RECEIVER(output)) %ThrowIteratorResultNotAnObject(output);
@@ -6720,34 +6663,35 @@ void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements,
{
Expression* is_receiver_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_output), zone);
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_output), zone());
is_receiver_call =
- factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
}
Statement* throw_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_output), zone);
- Expression* call = factory->NewCallRuntime(
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_output), zone());
+ Expression* call = factory()->NewCallRuntime(
Runtime::kThrowIteratorResultNotAnObject, args, nopos);
- throw_call = factory->NewExpressionStatement(call, nopos);
+ throw_call = factory()->NewExpressionStatement(call, nopos);
}
- validate_output = factory->NewIfStatement(
- is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos);
+ validate_output = factory()->NewIfStatement(
+ is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
+ nopos);
}
- statements->Add(get_return, zone);
- statements->Add(check_return, zone);
- statements->Add(call_return, zone);
- statements->Add(validate_output, zone);
+ statements->Add(get_return, zone());
+ statements->Add(check_return, zone());
+ statements->Add(call_return, zone());
+ statements->Add(validate_output, zone());
}
-void ParserTraits::FinalizeIteratorUse(Variable* completion,
- Expression* condition, Variable* iter,
- Block* iterator_use, Block* target) {
+void Parser::FinalizeIteratorUse(Variable* completion, Expression* condition,
+ Variable* iter, Block* iterator_use,
+ Block* target) {
//
// This function adds two statements to [target], corresponding to the
// following code:
@@ -6768,35 +6712,32 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
//
const int nopos = kNoSourcePosition;
- auto factory = parser_->factory();
- auto avfactory = parser_->ast_value_factory();
- auto scope = parser_->scope();
- auto zone = parser_->zone();
// completion = kNormalCompletion;
Statement* initialize_completion;
{
- Expression* proxy = factory->NewVariableProxy(completion);
- Expression* assignment = factory->NewAssignment(
+ Expression* proxy = factory()->NewVariableProxy(completion);
+ Expression* assignment = factory()->NewAssignment(
Token::ASSIGN, proxy,
- factory->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
- initialize_completion = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
+ initialize_completion =
+ factory()->NewExpressionStatement(assignment, nopos);
}
// if (completion === kAbruptCompletion) completion = kThrowCompletion;
Statement* set_completion_throw;
{
- Expression* condition = factory->NewCompareOperation(
- Token::EQ_STRICT, factory->NewVariableProxy(completion),
- factory->NewSmiLiteral(Parser::kAbruptCompletion, nopos), nopos);
+ Expression* condition = factory()->NewCompareOperation(
+ Token::EQ_STRICT, factory()->NewVariableProxy(completion),
+ factory()->NewSmiLiteral(Parser::kAbruptCompletion, nopos), nopos);
- Expression* proxy = factory->NewVariableProxy(completion);
- Expression* assignment = factory->NewAssignment(
+ Expression* proxy = factory()->NewVariableProxy(completion);
+ Expression* assignment = factory()->NewAssignment(
Token::ASSIGN, proxy,
- factory->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos);
- Statement* statement = factory->NewExpressionStatement(assignment, nopos);
- set_completion_throw = factory->NewIfStatement(
- condition, statement, factory->NewEmptyStatement(nopos), nopos);
+ factory()->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos);
+ Statement* statement = factory()->NewExpressionStatement(assignment, nopos);
+ set_completion_throw = factory()->NewIfStatement(
+ condition, statement, factory()->NewEmptyStatement(nopos), nopos);
}
// if (condition) {
@@ -6804,16 +6745,16 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
// }
Block* maybe_close;
{
- Block* block = factory->NewBlock(nullptr, 2, true, nopos);
- Expression* proxy = factory->NewVariableProxy(completion);
- parser_->BuildIteratorCloseForCompletion(block->statements(), iter, proxy);
+ Block* block = factory()->NewBlock(nullptr, 2, true, nopos);
+ Expression* proxy = factory()->NewVariableProxy(completion);
+ BuildIteratorCloseForCompletion(block->statements(), iter, proxy);
DCHECK(block->statements()->length() == 2);
- maybe_close = factory->NewBlock(nullptr, 1, true, nopos);
+ maybe_close = factory()->NewBlock(nullptr, 1, true, nopos);
maybe_close->statements()->Add(
- factory->NewIfStatement(condition, block,
- factory->NewEmptyStatement(nopos), nopos),
- zone);
+ factory()->NewIfStatement(condition, block,
+ factory()->NewEmptyStatement(nopos), nopos),
+ zone());
}
// try { #try_block }
@@ -6823,9 +6764,9 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
// }
Statement* try_catch;
{
- Scope* catch_scope = parser_->NewScopeWithParent(scope, CATCH_SCOPE);
+ Scope* catch_scope = NewScopeWithParent(scope(), CATCH_SCOPE);
Variable* catch_variable =
- catch_scope->DeclareLocal(avfactory->dot_catch_string(), VAR,
+ catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR,
kCreatedInitialized, Variable::NORMAL);
catch_scope->set_is_hidden();
@@ -6835,37 +6776,37 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
// TryCatchStatementForReThrow below (which does not clear the pending
// message), rather than a TryCatchStatement.
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(catch_variable), zone);
- rethrow = factory->NewExpressionStatement(
- factory->NewCallRuntime(Runtime::kReThrow, args, nopos), nopos);
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(catch_variable), zone());
+ rethrow = factory()->NewExpressionStatement(
+ factory()->NewCallRuntime(Runtime::kReThrow, args, nopos), nopos);
}
- Block* catch_block = factory->NewBlock(nullptr, 2, false, nopos);
- catch_block->statements()->Add(set_completion_throw, zone);
- catch_block->statements()->Add(rethrow, zone);
+ Block* catch_block = factory()->NewBlock(nullptr, 2, false, nopos);
+ catch_block->statements()->Add(set_completion_throw, zone());
+ catch_block->statements()->Add(rethrow, zone());
- try_catch = factory->NewTryCatchStatementForReThrow(
+ try_catch = factory()->NewTryCatchStatementForReThrow(
iterator_use, catch_scope, catch_variable, catch_block, nopos);
}
// try { #try_catch } finally { #maybe_close }
Statement* try_finally;
{
- Block* try_block = factory->NewBlock(nullptr, 1, false, nopos);
- try_block->statements()->Add(try_catch, zone);
+ Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
+ try_block->statements()->Add(try_catch, zone());
try_finally =
- factory->NewTryFinallyStatement(try_block, maybe_close, nopos);
+ factory()->NewTryFinallyStatement(try_block, maybe_close, nopos);
}
- target->statements()->Add(initialize_completion, zone);
- target->statements()->Add(try_finally, zone);
+ target->statements()->Add(initialize_completion, zone());
+ target->statements()->Add(try_finally, zone());
}
-void ParserTraits::BuildIteratorCloseForCompletion(
- ZoneList<Statement*>* statements, Variable* iterator,
- Expression* completion) {
+void Parser::BuildIteratorCloseForCompletion(ZoneList<Statement*>* statements,
+ Variable* iterator,
+ Expression* completion) {
//
// This function adds two statements to [statements], corresponding to the
// following code:
@@ -6887,24 +6828,19 @@ void ParserTraits::BuildIteratorCloseForCompletion(
//
const int nopos = kNoSourcePosition;
- auto factory = parser_->factory();
- auto avfactory = parser_->ast_value_factory();
- auto zone = parser_->zone();
-
-
// let iteratorReturn = iterator.return;
- Variable* var_return = parser_->NewTemporary(avfactory->empty_string());
+ Variable* var_return = NewTemporary(ast_value_factory()->empty_string());
Statement* get_return;
{
- Expression* iterator_proxy = factory->NewVariableProxy(iterator);
- Expression* literal =
- factory->NewStringLiteral(avfactory->return_string(), nopos);
+ Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
+ Expression* literal = factory()->NewStringLiteral(
+ ast_value_factory()->return_string(), nopos);
Expression* property =
- factory->NewProperty(iterator_proxy, literal, nopos);
- Expression* return_proxy = factory->NewVariableProxy(var_return);
- Expression* assignment = factory->NewAssignment(
- Token::ASSIGN, return_proxy, property, nopos);
- get_return = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewProperty(iterator_proxy, literal, nopos);
+ Expression* return_proxy = factory()->NewVariableProxy(var_return);
+ Expression* assignment =
+ factory()->NewAssignment(Token::ASSIGN, return_proxy, property, nopos);
+ get_return = factory()->NewExpressionStatement(assignment, nopos);
}
// if (!IS_CALLABLE(iteratorReturn)) {
@@ -6912,35 +6848,35 @@ void ParserTraits::BuildIteratorCloseForCompletion(
// }
Statement* check_return_callable;
{
- Expression* throw_expr = NewThrowTypeError(
- MessageTemplate::kReturnMethodNotCallable,
- avfactory->empty_string(), nopos);
+ Expression* throw_expr =
+ NewThrowTypeError(MessageTemplate::kReturnMethodNotCallable,
+ ast_value_factory()->empty_string(), nopos);
check_return_callable = CheckCallable(var_return, throw_expr, nopos);
}
// try { %_Call(iteratorReturn, iterator) } catch (_) { }
Statement* try_call_return;
{
- auto args = new (zone) ZoneList<Expression*>(2, zone);
- args->Add(factory->NewVariableProxy(var_return), zone);
- args->Add(factory->NewVariableProxy(iterator), zone);
+ auto args = new (zone()) ZoneList<Expression*>(2, zone());
+ args->Add(factory()->NewVariableProxy(var_return), zone());
+ args->Add(factory()->NewVariableProxy(iterator), zone());
Expression* call =
- factory->NewCallRuntime(Runtime::kInlineCall, args, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos);
- Block* try_block = factory->NewBlock(nullptr, 1, false, nopos);
- try_block->statements()->Add(factory->NewExpressionStatement(call, nopos),
- zone);
+ Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
+ try_block->statements()->Add(factory()->NewExpressionStatement(call, nopos),
+ zone());
- Block* catch_block = factory->NewBlock(nullptr, 0, false, nopos);
+ Block* catch_block = factory()->NewBlock(nullptr, 0, false, nopos);
Scope* catch_scope = NewScope(CATCH_SCOPE);
- Variable* catch_variable = catch_scope->DeclareLocal(
- avfactory->dot_catch_string(), VAR, kCreatedInitialized,
- Variable::NORMAL);
+ Variable* catch_variable =
+ catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR,
+ kCreatedInitialized, Variable::NORMAL);
catch_scope->set_is_hidden();
- try_call_return = factory->NewTryCatchStatement(
+ try_call_return = factory()->NewTryCatchStatement(
try_block, catch_scope, catch_variable, catch_block, nopos);
}
@@ -6950,44 +6886,45 @@ void ParserTraits::BuildIteratorCloseForCompletion(
// }
Block* validate_return;
{
- Variable* var_output = parser_->NewTemporary(avfactory->empty_string());
+ Variable* var_output = NewTemporary(ast_value_factory()->empty_string());
Statement* call_return;
{
- auto args = new (zone) ZoneList<Expression*>(2, zone);
- args->Add(factory->NewVariableProxy(var_return), zone);
- args->Add(factory->NewVariableProxy(iterator), zone);
+ auto args = new (zone()) ZoneList<Expression*>(2, zone());
+ args->Add(factory()->NewVariableProxy(var_return), zone());
+ args->Add(factory()->NewVariableProxy(iterator), zone());
Expression* call =
- factory->NewCallRuntime(Runtime::kInlineCall, args, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos);
- Expression* output_proxy = factory->NewVariableProxy(var_output);
+ Expression* output_proxy = factory()->NewVariableProxy(var_output);
Expression* assignment =
- factory->NewAssignment(Token::ASSIGN, output_proxy, call, nopos);
- call_return = factory->NewExpressionStatement(assignment, nopos);
+ factory()->NewAssignment(Token::ASSIGN, output_proxy, call, nopos);
+ call_return = factory()->NewExpressionStatement(assignment, nopos);
}
Expression* is_receiver_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_output), zone);
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_output), zone());
is_receiver_call =
- factory->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
+ factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos);
}
Statement* throw_call;
{
- auto args = new (zone) ZoneList<Expression*>(1, zone);
- args->Add(factory->NewVariableProxy(var_output), zone);
- Expression* call = factory->NewCallRuntime(
+ auto args = new (zone()) ZoneList<Expression*>(1, zone());
+ args->Add(factory()->NewVariableProxy(var_output), zone());
+ Expression* call = factory()->NewCallRuntime(
Runtime::kThrowIteratorResultNotAnObject, args, nopos);
- throw_call = factory->NewExpressionStatement(call, nopos);
+ throw_call = factory()->NewExpressionStatement(call, nopos);
}
- Statement* check_return = factory->NewIfStatement(
- is_receiver_call, factory->NewEmptyStatement(nopos), throw_call, nopos);
+ Statement* check_return = factory()->NewIfStatement(
+ is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
+ nopos);
- validate_return = factory->NewBlock(nullptr, 2, false, nopos);
- validate_return->statements()->Add(call_return, zone);
- validate_return->statements()->Add(check_return, zone);
+ validate_return = factory()->NewBlock(nullptr, 2, false, nopos);
+ validate_return->statements()->Add(call_return, zone());
+ validate_return->statements()->Add(check_return, zone());
}
// if (completion === kThrowCompletion) {
@@ -6998,38 +6935,36 @@ void ParserTraits::BuildIteratorCloseForCompletion(
// }
Statement* call_return_carefully;
{
- Expression* condition = factory->NewCompareOperation(
+ Expression* condition = factory()->NewCompareOperation(
Token::EQ_STRICT, completion,
- factory->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos);
+ factory()->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos);
- Block* then_block = factory->NewBlock(nullptr, 2, false, nopos);
- then_block->statements()->Add(check_return_callable, zone);
- then_block->statements()->Add(try_call_return, zone);
+ Block* then_block = factory()->NewBlock(nullptr, 2, false, nopos);
+ then_block->statements()->Add(check_return_callable, zone());
+ then_block->statements()->Add(try_call_return, zone());
- call_return_carefully =
- factory->NewIfStatement(condition, then_block, validate_return, nopos);
+ call_return_carefully = factory()->NewIfStatement(condition, then_block,
+ validate_return, nopos);
}
// if (!IS_NULL_OR_UNDEFINED(iteratorReturn)) { ... }
Statement* maybe_call_return;
{
- Expression* condition = factory->NewCompareOperation(
- Token::EQ, factory->NewVariableProxy(var_return),
- factory->NewNullLiteral(nopos), nopos);
+ Expression* condition = factory()->NewCompareOperation(
+ Token::EQ, factory()->NewVariableProxy(var_return),
+ factory()->NewNullLiteral(nopos), nopos);
- maybe_call_return =
- factory->NewIfStatement(condition, factory->NewEmptyStatement(nopos),
- call_return_carefully, nopos);
+ maybe_call_return = factory()->NewIfStatement(
+ condition, factory()->NewEmptyStatement(nopos), call_return_carefully,
+ nopos);
}
-
- statements->Add(get_return, zone);
- statements->Add(maybe_call_return, zone);
+ statements->Add(get_return, zone());
+ statements->Add(maybe_call_return, zone());
}
-Statement* ParserTraits::FinalizeForOfStatement(ForOfStatement* loop,
- Variable* var_completion,
- int pos) {
+Statement* Parser::FinalizeForOfStatement(ForOfStatement* loop,
+ Variable* var_completion, int pos) {
//
// This function replaces the loop with the following wrapping:
//
@@ -7052,27 +6987,25 @@ Statement* ParserTraits::FinalizeForOfStatement(ForOfStatement* loop,
//
const int nopos = kNoSourcePosition;
- auto factory = parser_->factory();
- auto zone = parser_->zone();
// !(completion === kNormalCompletion || IS_UNDEFINED(#iterator))
Expression* closing_condition;
{
- Expression* lhs = factory->NewCompareOperation(
- Token::EQ_STRICT, factory->NewVariableProxy(var_completion),
- factory->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
- Expression* rhs = factory->NewCompareOperation(
- Token::EQ_STRICT, factory->NewVariableProxy(loop->iterator()),
- factory->NewUndefinedLiteral(nopos), nopos);
- closing_condition = factory->NewUnaryOperation(
- Token::NOT, factory->NewBinaryOperation(Token::OR, lhs, rhs, nopos),
+ Expression* lhs = factory()->NewCompareOperation(
+ Token::EQ_STRICT, factory()->NewVariableProxy(var_completion),
+ factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos);
+ Expression* rhs = factory()->NewCompareOperation(
+ Token::EQ_STRICT, factory()->NewVariableProxy(loop->iterator()),
+ factory()->NewUndefinedLiteral(nopos), nopos);
+ closing_condition = factory()->NewUnaryOperation(
+ Token::NOT, factory()->NewBinaryOperation(Token::OR, lhs, rhs, nopos),
nopos);
}
- Block* final_loop = factory->NewBlock(nullptr, 2, false, nopos);
+ Block* final_loop = factory()->NewBlock(nullptr, 2, false, nopos);
{
- Block* try_block = factory->NewBlock(nullptr, 1, false, nopos);
- try_block->statements()->Add(loop, zone);
+ Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
+ try_block->statements()->Add(loop, zone());
FinalizeIteratorUse(var_completion, closing_condition, loop->iterator(),
try_block, final_loop);
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698