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

Side by Side Diff: src/parsing/parser-base.h

Issue 1895603002: [esnext] prototype runtime implementation for async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@AsyncFunction
Patch Set: properly rebase Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 18 matching lines...) Expand all
29 kDisallowLabelledFunctionStatement, 29 kDisallowLabelledFunctionStatement,
30 }; 30 };
31 31
32 enum class ParseFunctionFlags { 32 enum class ParseFunctionFlags {
33 kIsNormal = 0, 33 kIsNormal = 0,
34 kIsGenerator = 1, 34 kIsGenerator = 1,
35 kIsAsync = 2, 35 kIsAsync = 2,
36 kIsDefault = 4 36 kIsDefault = 4
37 }; 37 };
38 38
39 enum class FunctionBody {
40 Normal,
41 ArrowBlock = Normal,
42 ArrowConcise,
43 };
44
39 static inline ParseFunctionFlags operator|(ParseFunctionFlags lhs, 45 static inline ParseFunctionFlags operator|(ParseFunctionFlags lhs,
40 ParseFunctionFlags rhs) { 46 ParseFunctionFlags rhs) {
41 typedef unsigned char T; 47 typedef unsigned char T;
42 return static_cast<ParseFunctionFlags>(static_cast<T>(lhs) | 48 return static_cast<ParseFunctionFlags>(static_cast<T>(lhs) |
43 static_cast<T>(rhs)); 49 static_cast<T>(rhs));
44 } 50 }
45 51
46 static inline ParseFunctionFlags& operator|=(ParseFunctionFlags& lhs, 52 static inline ParseFunctionFlags& operator|=(ParseFunctionFlags& lhs,
47 const ParseFunctionFlags& rhs) { 53 const ParseFunctionFlags& rhs) {
48 lhs = lhs | rhs; 54 lhs = lhs | rhs;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 307
302 bool is_generator() const { return IsGeneratorFunction(kind_); } 308 bool is_generator() const { return IsGeneratorFunction(kind_); }
303 bool is_async_function() const { return IsAsyncFunction(kind_); } 309 bool is_async_function() const { return IsAsyncFunction(kind_); }
304 310
305 FunctionKind kind() const { return kind_; } 311 FunctionKind kind() const { return kind_; }
306 FunctionState* outer() const { return outer_function_state_; } 312 FunctionState* outer() const { return outer_function_state_; }
307 313
308 void set_generator_object_variable( 314 void set_generator_object_variable(
309 typename Traits::Type::GeneratorVariable* variable) { 315 typename Traits::Type::GeneratorVariable* variable) {
310 DCHECK(variable != NULL); 316 DCHECK(variable != NULL);
311 DCHECK(is_generator()); 317 DCHECK(is_generator() || is_async_function());
312 generator_object_variable_ = variable; 318 generator_object_variable_ = variable;
313 } 319 }
314 typename Traits::Type::GeneratorVariable* generator_object_variable() 320 typename Traits::Type::GeneratorVariable* generator_object_variable()
315 const { 321 const {
316 return generator_object_variable_; 322 return generator_object_variable_;
317 } 323 }
318 324
319 typename Traits::Type::Factory* factory() { return factory_; } 325 typename Traits::Type::Factory* factory() { return factory_; }
320 326
321 const List<DestructuringAssignment>& destructuring_assignments_to_rewrite() 327 const List<DestructuringAssignment>& destructuring_assignments_to_rewrite()
(...skipping 1820 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 parenthesized_formals, is_async, CHECK_OK); 2148 parenthesized_formals, is_async, CHECK_OK);
2143 // This reads strangely, but is correct: it checks whether any 2149 // This reads strangely, but is correct: it checks whether any
2144 // sub-expression of the parameter list failed to be a valid formal 2150 // sub-expression of the parameter list failed to be a valid formal
2145 // parameter initializer. Since YieldExpressions are banned anywhere 2151 // parameter initializer. Since YieldExpressions are banned anywhere
2146 // in an arrow parameter list, this is correct. 2152 // in an arrow parameter list, this is correct.
2147 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to 2153 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to
2148 // "YieldExpression", which is its only use. 2154 // "YieldExpression", which is its only use.
2149 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); 2155 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
2150 2156
2151 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); 2157 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
2152 Scope* scope = 2158 Scope* scope = this->NewScope(scope_, FUNCTION_SCOPE,
2153 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); 2159 is_async ? FunctionKind::kAsyncArrowFunction
2160 : FunctionKind::kArrowFunction);
2154 // Because the arrow's parameters were parsed in the outer scope, any 2161 // Because the arrow's parameters were parsed in the outer scope, any
2155 // usage flags that might have been triggered there need to be copied 2162 // usage flags that might have been triggered there need to be copied
2156 // to the arrow scope. 2163 // to the arrow scope.
2157 scope_->PropagateUsageFlagsToScope(scope); 2164 scope_->PropagateUsageFlagsToScope(scope);
2158 FormalParametersT parameters(scope); 2165 FormalParametersT parameters(scope);
2159 if (!arrow_formals_classifier.is_simple_parameter_list()) { 2166 if (!arrow_formals_classifier.is_simple_parameter_list()) {
2160 scope->SetHasNonSimpleParameters(); 2167 scope->SetHasNonSimpleParameters();
2161 parameters.is_simple = false; 2168 parameters.is_simple = false;
2162 } 2169 }
2163 2170
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 *ok = false; 3148 *ok = false;
3142 return this->EmptyExpression(); 3149 return this->EmptyExpression();
3143 } 3150 }
3144 3151
3145 typename Traits::Type::StatementList body; 3152 typename Traits::Type::StatementList body;
3146 int num_parameters = formal_parameters.scope->num_parameters(); 3153 int num_parameters = formal_parameters.scope->num_parameters();
3147 int materialized_literal_count = -1; 3154 int materialized_literal_count = -1;
3148 int expected_property_count = -1; 3155 int expected_property_count = -1;
3149 Scanner::Location super_loc; 3156 Scanner::Location super_loc;
3150 3157
3158 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
3151 { 3159 {
3152 typename Traits::Type::Factory function_factory(ast_value_factory()); 3160 typename Traits::Type::Factory function_factory(ast_value_factory());
3153 FunctionState function_state( 3161 FunctionState function_state(&function_state_, &scope_,
3154 &function_state_, &scope_, formal_parameters.scope, 3162 formal_parameters.scope, arrow_kind,
3155 is_async ? kAsyncArrowFunction : kArrowFunction, &function_factory); 3163 &function_factory);
3156 3164
3157 function_state.SkipMaterializedLiterals( 3165 function_state.SkipMaterializedLiterals(
3158 formal_parameters.materialized_literals_count); 3166 formal_parameters.materialized_literals_count);
3159 3167
3160 this->ReindexLiterals(formal_parameters); 3168 this->ReindexLiterals(formal_parameters);
3161 3169
3162 Expect(Token::ARROW, CHECK_OK); 3170 Expect(Token::ARROW, CHECK_OK);
3163 3171
3164 if (peek() == Token::LBRACE) { 3172 if (peek() == Token::LBRACE) {
3165 // Multiple statement body 3173 // Multiple statement body
3166 Consume(Token::LBRACE); 3174 Consume(Token::LBRACE);
3167 bool is_lazily_parsed = 3175 bool is_lazily_parsed =
3168 (mode() == PARSE_LAZILY && scope_->AllowsLazyParsing()); 3176 (mode() == PARSE_LAZILY && scope_->AllowsLazyParsing());
3169 if (is_lazily_parsed) { 3177 if (is_lazily_parsed) {
3170 body = this->NewStatementList(0, zone()); 3178 body = this->NewStatementList(0, zone());
3171 this->SkipLazyFunctionBody(&materialized_literal_count, 3179 this->SkipLazyFunctionBody(&materialized_literal_count,
3172 &expected_property_count, CHECK_OK); 3180 &expected_property_count, CHECK_OK);
3173 if (formal_parameters.materialized_literals_count > 0) { 3181 if (formal_parameters.materialized_literals_count > 0) {
3174 materialized_literal_count += 3182 materialized_literal_count +=
3175 formal_parameters.materialized_literals_count; 3183 formal_parameters.materialized_literals_count;
3176 } 3184 }
3177 } else { 3185 } else {
3178 body = this->ParseEagerFunctionBody( 3186 body = this->ParseEagerFunctionBody(
3179 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, 3187 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters,
3180 kArrowFunction, FunctionLiteral::kAnonymousExpression, CHECK_OK); 3188 arrow_kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
3181 materialized_literal_count = 3189 materialized_literal_count =
3182 function_state.materialized_literal_count(); 3190 function_state.materialized_literal_count();
3183 expected_property_count = function_state.expected_property_count(); 3191 expected_property_count = function_state.expected_property_count();
3184 } 3192 }
3185 } else { 3193 } else {
3186 // Single-expression body 3194 // Single-expression body
3187 int pos = position(); 3195 int pos = position();
3188 ExpressionClassifier classifier(this); 3196 ExpressionClassifier classifier(this);
3189 DCHECK(ReturnExprContext::kInsideValidBlock == 3197 DCHECK(ReturnExprContext::kInsideValidBlock ==
3190 function_state_->return_expr_context()); 3198 function_state_->return_expr_context());
3191 ReturnExprScope allow_tail_calls( 3199 ReturnExprScope allow_tail_calls(
3192 function_state_, ReturnExprContext::kInsideValidReturnStatement); 3200 function_state_, ReturnExprContext::kInsideValidReturnStatement);
3193 ExpressionT expression = 3201 ExpressionT expression =
3194 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); 3202 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
3195 Traits::RewriteNonPattern(&classifier, CHECK_OK); 3203 Traits::RewriteNonPattern(&classifier, CHECK_OK);
3196 body = this->NewStatementList(1, zone()); 3204 body = this->NewStatementList(1, zone());
3197 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); 3205 this->AddParameterInitializationBlock(formal_parameters, body, is_async,
3198 body->Add(factory()->NewReturnStatement(expression, pos), zone()); 3206 CHECK_OK);
3207 if (is_async) {
3208 this->ParseAsyncArrowSingleExpressionBody(body, accept_IN, &classifier,
3209 pos, CHECK_OK);
3210 } else {
3211 ExpressionT expression =
3212 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
3213 Traits::RewriteNonPattern(&classifier, CHECK_OK);
3214 body->Add(factory()->NewReturnStatement(expression, pos), zone());
3215 }
3199 materialized_literal_count = function_state.materialized_literal_count(); 3216 materialized_literal_count = function_state.materialized_literal_count();
3200 expected_property_count = function_state.expected_property_count(); 3217 expected_property_count = function_state.expected_property_count();
3201 if (allow_tailcalls() && !is_sloppy(language_mode())) { 3218 if (allow_tailcalls() && !is_sloppy(language_mode())) {
3202 // ES6 14.6.1 Static Semantics: IsInTailPosition 3219 // ES6 14.6.1 Static Semantics: IsInTailPosition
3203 this->MarkTailPosition(expression); 3220 this->MarkTailPosition(expression);
3204 } 3221 }
3205 this->MarkCollectedTailCallExpressions(); 3222 this->MarkCollectedTailCallExpressions();
3206 } 3223 }
3207 super_loc = function_state.super_location(); 3224 super_loc = function_state.super_location();
3208 3225
(...skipping 15 matching lines...) Expand all
3224 this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK); 3241 this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK);
3225 3242
3226 Traits::RewriteDestructuringAssignments(); 3243 Traits::RewriteDestructuringAssignments();
3227 } 3244 }
3228 3245
3229 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 3246 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
3230 this->EmptyIdentifierString(), formal_parameters.scope, body, 3247 this->EmptyIdentifierString(), formal_parameters.scope, body,
3231 materialized_literal_count, expected_property_count, num_parameters, 3248 materialized_literal_count, expected_property_count, num_parameters,
3232 FunctionLiteral::kNoDuplicateParameters, 3249 FunctionLiteral::kNoDuplicateParameters,
3233 FunctionLiteral::kAnonymousExpression, 3250 FunctionLiteral::kAnonymousExpression,
3234 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, 3251 FunctionLiteral::kShouldLazyCompile, arrow_kind,
3235 formal_parameters.scope->start_position()); 3252 formal_parameters.scope->start_position());
3236 3253
3237 function_literal->set_function_token_position( 3254 function_literal->set_function_token_position(
3238 formal_parameters.scope->start_position()); 3255 formal_parameters.scope->start_position());
3239 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); 3256 if (super_loc.IsValid()) function_state_->set_super_location(super_loc);
3240 3257
3241 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); 3258 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal);
3242 3259
3243 return function_literal; 3260 return function_literal;
3244 } 3261 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
3453 has_seen_constructor_ = true; 3470 has_seen_constructor_ = true;
3454 return; 3471 return;
3455 } 3472 }
3456 } 3473 }
3457 3474
3458 3475
3459 } // namespace internal 3476 } // namespace internal
3460 } // namespace v8 3477 } // namespace v8
3461 3478
3462 #endif // V8_PARSING_PARSER_BASE_H 3479 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698