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

Unified Diff: src/parsing/parser-base.h

Issue 2664083002: [ignition] desugar async functions/generators/modules in BytecodeGenerator
Patch Set: get rid of lambdas, for better or worse.. Created 3 years, 10 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
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 56b40abf987917ad7df9b94180daacba8597ad24..6af95e6672e5107a922b022a6473a7379444cde2 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -427,23 +427,12 @@ class ParserBase {
FunctionKind kind() const { return scope()->function_kind(); }
FunctionState* outer() const { return outer_function_state_; }
- void set_generator_object_variable(typename Types::Variable* variable) {
- DCHECK_NOT_NULL(variable);
- DCHECK(IsResumableFunction(kind()));
- DCHECK(scope()->has_forced_context_allocation());
- generator_object_variable_ = variable;
- }
typename Types::Variable* generator_object_variable() const {
- return generator_object_variable_;
+ return scope()->generator_object_var();
}
- void set_promise_variable(typename Types::Variable* variable) {
- DCHECK(variable != NULL);
- DCHECK(IsAsyncFunction(kind()));
- promise_variable_ = variable;
- }
typename Types::Variable* promise_variable() const {
- return promise_variable_;
+ return scope()->promise_var();
}
const ZoneList<DestructuringAssignment>&
@@ -1233,9 +1222,9 @@ class ParserBase {
StatementT ParseNativeDeclaration(bool* ok);
// Consumes the ending }.
- void ParseFunctionBody(StatementListT result, IdentifierT function_name,
- int pos, const FormalParametersT& parameters,
- FunctionKind kind,
+ void ParseFunctionBody(StatementListT result, BlockT* init_block,
+ IdentifierT function_name, int pos,
+ const FormalParametersT& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, bool* ok);
// Under some circumstances, we allow preparsing to abort if the preparsed
@@ -3972,21 +3961,10 @@ ParserBase<Impl>::ParseAsyncFunctionDeclaration(
template <typename Impl>
void ParserBase<Impl>::ParseFunctionBody(
- typename ParserBase<Impl>::StatementListT result, IdentifierT function_name,
+ typename ParserBase<Impl>::StatementListT result,
+ typename ParserBase<Impl>::BlockT* init_block, IdentifierT function_name,
int pos, const FormalParametersT& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, bool* ok) {
- static const int kFunctionNameAssignmentIndex = 0;
- if (function_type == FunctionLiteral::kNamedExpression) {
- DCHECK(!impl()->IsEmptyIdentifier(function_name));
- // If we have a named function expression, we add a local variable
- // declaration to the body of the function with the name of the
- // function and let it refer to the function itself (closure).
- // Not having parsed the function body, the language mode may still change,
- // so we reserve a spot and create the actual const assignment later.
- DCHECK_EQ(kFunctionNameAssignmentIndex, result->length());
- result->Add(impl()->NullStatement(), zone());
- }
-
DeclarationScope* function_scope = scope()->AsDeclarationScope();
DeclarationScope* inner_scope = function_scope;
BlockT inner_block = impl()->NullBlock();
@@ -4028,18 +4006,13 @@ void ParserBase<Impl>::ParseFunctionBody(
DCHECK_EQ(function_scope, scope());
DCHECK_EQ(function_scope, inner_scope->outer_scope());
impl()->SetLanguageMode(function_scope, inner_scope->language_mode());
- BlockT init_block =
+ *init_block =
impl()->BuildParameterInitializationBlock(parameters, CHECK_OK_VOID);
if (is_sloppy(inner_scope->language_mode())) {
impl()->InsertSloppyBlockFunctionVarBindings(inner_scope);
}
- // TODO(littledan): Merge the two rejection blocks into one
- if (IsAsyncFunction(kind)) {
- init_block = impl()->BuildRejectPromiseOnException(init_block);
- }
-
inner_scope->set_end_position(scanner()->location().end_pos);
if (inner_scope->FinalizeBlockScope() != nullptr) {
impl()->CheckConflictingVarDeclarations(inner_scope, CHECK_OK_VOID);
@@ -4047,7 +4020,6 @@ void ParserBase<Impl>::ParseFunctionBody(
}
inner_scope = nullptr;
- result->Add(init_block, zone());
result->Add(inner_block, zone());
} else {
DCHECK_EQ(inner_scope, function_scope);
@@ -4063,9 +4035,8 @@ void ParserBase<Impl>::ParseFunctionBody(
function_scope->DeclareArguments(ast_value_factory());
}
- impl()->CreateFunctionNameAssignment(function_name, pos, function_type,
- function_scope, result,
- kFunctionNameAssignmentIndex);
+ impl()->CreateFunctionNameVariable(function_name, function_type,
+ function_scope);
impl()->MarkCollectedTailCallExpressions();
}
@@ -4163,6 +4134,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
return impl()->EmptyExpression();
}
+ BlockT parameter_init_block = impl()->NullBlock();
StatementListT body = impl()->NullStatementList();
int materialized_literal_count = -1;
int expected_property_count = -1;
@@ -4231,10 +4203,10 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
if (!is_lazy_top_level_function) {
Consume(Token::LBRACE);
body = impl()->NewStatementList(8);
- impl()->ParseFunctionBody(body, impl()->EmptyIdentifier(),
- kNoSourcePosition, formal_parameters, kind,
- FunctionLiteral::kAnonymousExpression,
- CHECK_OK);
+ impl()->ParseFunctionBody(
+ body, &parameter_init_block, impl()->EmptyIdentifier(),
+ kNoSourcePosition, formal_parameters, kind,
+ FunctionLiteral::kAnonymousExpression, CHECK_OK);
materialized_literal_count =
function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count();
@@ -4248,8 +4220,10 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
ReturnExprScope allow_tail_calls(
function_state_, ReturnExprContext::kInsideValidReturnStatement);
body = impl()->NewStatementList(1);
- impl()->AddParameterInitializationBlock(
- formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK);
+ if (!formal_parameters.is_simple) {
+ parameter_init_block = impl()->BuildParameterInitializationBlock(
+ formal_parameters, CHECK_OK);
+ }
ExpressionClassifier classifier(this);
if (kind == kAsyncArrowFunction) {
ParseAsyncFunctionBody(scope(), body, kAsyncArrowFunction,
@@ -4306,6 +4280,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
FunctionLiteral::kAnonymousExpression, eager_compile_hint,
formal_parameters.scope->start_position(), has_braces,
function_literal_id);
+ function_literal->set_parameter_init_block(parameter_init_block);
function_literal->set_function_token_position(
formal_parameters.scope->start_position());
@@ -4398,20 +4373,16 @@ void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body,
bool* ok) {
impl()->PrepareAsyncFunctionBody(body, kind, pos);
- BlockT block = factory()->NewBlock(nullptr, 8, true, kNoSourcePosition);
-
ExpressionT return_value = impl()->EmptyExpression();
if (body_type == FunctionBodyType::kNormal) {
- ParseStatementList(block->statements(), Token::RBRACE,
- CHECK_OK_CUSTOM(Void));
+ ParseStatementList(body, Token::RBRACE, CHECK_OK_CUSTOM(Void));
return_value = factory()->NewUndefinedLiteral(kNoSourcePosition);
} else {
return_value = ParseAssignmentExpression(accept_IN, CHECK_OK_CUSTOM(Void));
impl()->RewriteNonPattern(CHECK_OK_CUSTOM(Void));
}
- impl()->RewriteAsyncFunctionBody(body, block, return_value,
- CHECK_OK_CUSTOM(Void));
+ impl()->RewriteAsyncFunctionBody(body, return_value, CHECK_OK_CUSTOM(Void));
scope->set_end_position(scanner()->location().end_pos);
}

Powered by Google App Engine
This is Rietveld 408576698