Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 void SkipMaterializedLiterals(int count) { | 420 void SkipMaterializedLiterals(int count) { |
| 421 next_materialized_literal_index_ += count; | 421 next_materialized_literal_index_ += count; |
| 422 } | 422 } |
| 423 | 423 |
| 424 void AddProperty() { expected_property_count_++; } | 424 void AddProperty() { expected_property_count_++; } |
| 425 int expected_property_count() { return expected_property_count_; } | 425 int expected_property_count() { return expected_property_count_; } |
| 426 | 426 |
| 427 FunctionKind kind() const { return scope()->function_kind(); } | 427 FunctionKind kind() const { return scope()->function_kind(); } |
| 428 FunctionState* outer() const { return outer_function_state_; } | 428 FunctionState* outer() const { return outer_function_state_; } |
| 429 | 429 |
| 430 void set_generator_object_variable(typename Types::Variable* variable) { | |
| 431 DCHECK_NOT_NULL(variable); | |
| 432 DCHECK(IsResumableFunction(kind())); | |
| 433 DCHECK(scope()->has_forced_context_allocation()); | |
| 434 generator_object_variable_ = variable; | |
| 435 } | |
| 436 typename Types::Variable* generator_object_variable() const { | 430 typename Types::Variable* generator_object_variable() const { |
| 437 return generator_object_variable_; | 431 return scope()->generator_object_var(); |
| 438 } | 432 } |
| 439 | 433 |
| 440 void set_promise_variable(typename Types::Variable* variable) { | |
| 441 DCHECK(variable != NULL); | |
| 442 DCHECK(IsAsyncFunction(kind())); | |
| 443 promise_variable_ = variable; | |
| 444 } | |
| 445 typename Types::Variable* promise_variable() const { | 434 typename Types::Variable* promise_variable() const { |
| 446 return promise_variable_; | 435 return scope()->promise_var(); |
| 447 } | 436 } |
| 448 | 437 |
| 449 const ZoneList<DestructuringAssignment>& | 438 const ZoneList<DestructuringAssignment>& |
| 450 destructuring_assignments_to_rewrite() const { | 439 destructuring_assignments_to_rewrite() const { |
| 451 return destructuring_assignments_to_rewrite_; | 440 return destructuring_assignments_to_rewrite_; |
| 452 } | 441 } |
| 453 | 442 |
| 454 TailCallExpressionList& tail_call_expressions() { | 443 TailCallExpressionList& tail_call_expressions() { |
| 455 return tail_call_expressions_; | 444 return tail_call_expressions_; |
| 456 } | 445 } |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1376 if (is_sloppy(scope->language_mode())) { | 1365 if (is_sloppy(scope->language_mode())) { |
| 1377 // For sloppy scopes we also have to record the call at function level, | 1366 // For sloppy scopes we also have to record the call at function level, |
| 1378 // in case it includes declarations that will be hoisted. | 1367 // in case it includes declarations that will be hoisted. |
| 1379 scope->GetDeclarationScope()->RecordEvalCall(); | 1368 scope->GetDeclarationScope()->RecordEvalCall(); |
| 1380 } | 1369 } |
| 1381 return Call::IS_POSSIBLY_EVAL; | 1370 return Call::IS_POSSIBLY_EVAL; |
| 1382 } | 1371 } |
| 1383 return Call::NOT_EVAL; | 1372 return Call::NOT_EVAL; |
| 1384 } | 1373 } |
| 1385 | 1374 |
| 1375 inline StatementT NewReturnStatement(ExpressionT expr, int pos) { | |
| 1376 if (V8_UNLIKELY(is_async_function())) { | |
| 1377 return factory()->NewAsyncReturnStatement(expr, pos); | |
| 1378 } | |
| 1379 return factory()->NewReturnStatement(expr, pos); | |
| 1380 } | |
| 1381 | |
| 1386 // Validation per ES6 object literals. | 1382 // Validation per ES6 object literals. |
| 1387 class ObjectLiteralChecker { | 1383 class ObjectLiteralChecker { |
| 1388 public: | 1384 public: |
| 1389 explicit ObjectLiteralChecker(ParserBase* parser) | 1385 explicit ObjectLiteralChecker(ParserBase* parser) |
| 1390 : parser_(parser), has_seen_proto_(false) {} | 1386 : parser_(parser), has_seen_proto_(false) {} |
| 1391 | 1387 |
| 1392 void CheckDuplicateProto(Token::Value property); | 1388 void CheckDuplicateProto(Token::Value property); |
| 1393 | 1389 |
| 1394 private: | 1390 private: |
| 1395 bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); } | 1391 bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); } |
| (...skipping 2873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4269 formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK); | 4265 formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK); |
| 4270 ExpressionClassifier classifier(this); | 4266 ExpressionClassifier classifier(this); |
| 4271 if (kind == kAsyncArrowFunction) { | 4267 if (kind == kAsyncArrowFunction) { |
| 4272 ParseAsyncFunctionBody(scope(), body, kAsyncArrowFunction, | 4268 ParseAsyncFunctionBody(scope(), body, kAsyncArrowFunction, |
| 4273 FunctionBodyType::kSingleExpression, accept_IN, | 4269 FunctionBodyType::kSingleExpression, accept_IN, |
| 4274 pos, CHECK_OK); | 4270 pos, CHECK_OK); |
| 4275 impl()->RewriteNonPattern(CHECK_OK); | 4271 impl()->RewriteNonPattern(CHECK_OK); |
| 4276 } else { | 4272 } else { |
| 4277 ExpressionT expression = ParseAssignmentExpression(accept_IN, CHECK_OK); | 4273 ExpressionT expression = ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 4278 impl()->RewriteNonPattern(CHECK_OK); | 4274 impl()->RewriteNonPattern(CHECK_OK); |
| 4279 body->Add( | 4275 body->Add(NewReturnStatement(expression, expression->position()), |
| 4280 factory()->NewReturnStatement(expression, expression->position()), | 4276 zone()); |
|
Dan Ehrenberg
2017/02/10 07:51:31
Nit: Revert irrelevant formatting change
caitp
2017/02/10 08:05:07
This isn't a formatting change, but the formatting
| |
| 4281 zone()); | |
| 4282 if (allow_tailcalls() && !is_sloppy(language_mode())) { | 4277 if (allow_tailcalls() && !is_sloppy(language_mode())) { |
| 4283 // ES6 14.6.1 Static Semantics: IsInTailPosition | 4278 // ES6 14.6.1 Static Semantics: IsInTailPosition |
| 4284 impl()->MarkTailPosition(expression); | 4279 impl()->MarkTailPosition(expression); |
| 4285 } | 4280 } |
| 4286 } | 4281 } |
| 4287 materialized_literal_count = function_state.materialized_literal_count(); | 4282 materialized_literal_count = function_state.materialized_literal_count(); |
| 4288 expected_property_count = function_state.expected_property_count(); | 4283 expected_property_count = function_state.expected_property_count(); |
| 4289 impl()->MarkCollectedTailCallExpressions(); | 4284 impl()->MarkCollectedTailCallExpressions(); |
| 4290 } | 4285 } |
| 4291 | 4286 |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5176 return_value = ParseExpression(true, CHECK_OK); | 5171 return_value = ParseExpression(true, CHECK_OK); |
| 5177 | 5172 |
| 5178 if (allow_tailcalls() && !is_sloppy(language_mode()) && !is_resumable()) { | 5173 if (allow_tailcalls() && !is_sloppy(language_mode()) && !is_resumable()) { |
| 5179 // ES6 14.6.1 Static Semantics: IsInTailPosition | 5174 // ES6 14.6.1 Static Semantics: IsInTailPosition |
| 5180 function_state_->AddImplicitTailCallExpression(return_value); | 5175 function_state_->AddImplicitTailCallExpression(return_value); |
| 5181 } | 5176 } |
| 5182 } | 5177 } |
| 5183 } | 5178 } |
| 5184 ExpectSemicolon(CHECK_OK); | 5179 ExpectSemicolon(CHECK_OK); |
| 5185 return_value = impl()->RewriteReturn(return_value, loc.beg_pos); | 5180 return_value = impl()->RewriteReturn(return_value, loc.beg_pos); |
| 5186 return factory()->NewReturnStatement(return_value, loc.beg_pos); | 5181 return NewReturnStatement(return_value, loc.beg_pos); |
| 5187 } | 5182 } |
| 5188 | 5183 |
| 5189 template <typename Impl> | 5184 template <typename Impl> |
| 5190 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement( | 5185 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement( |
| 5191 ZoneList<const AstRawString*>* labels, bool* ok) { | 5186 ZoneList<const AstRawString*>* labels, bool* ok) { |
| 5192 // WithStatement :: | 5187 // WithStatement :: |
| 5193 // 'with' '(' Expression ')' Statement | 5188 // 'with' '(' Expression ')' Statement |
| 5194 | 5189 |
| 5195 Expect(Token::WITH, CHECK_OK); | 5190 Expect(Token::WITH, CHECK_OK); |
| 5196 int pos = position(); | 5191 int pos = position(); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5774 } | 5769 } |
| 5775 | 5770 |
| 5776 #undef CHECK_OK | 5771 #undef CHECK_OK |
| 5777 #undef CHECK_OK_CUSTOM | 5772 #undef CHECK_OK_CUSTOM |
| 5778 #undef CHECK_OK_VOID | 5773 #undef CHECK_OK_VOID |
| 5779 | 5774 |
| 5780 } // namespace internal | 5775 } // namespace internal |
| 5781 } // namespace v8 | 5776 } // namespace v8 |
| 5782 | 5777 |
| 5783 #endif // V8_PARSING_PARSER_BASE_H | 5778 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |