| 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 455 } |
| 456 | 456 |
| 457 ZoneList<ExpressionT>* non_patterns_to_rewrite() { | 457 ZoneList<ExpressionT>* non_patterns_to_rewrite() { |
| 458 return &non_patterns_to_rewrite_; | 458 return &non_patterns_to_rewrite_; |
| 459 } | 459 } |
| 460 | 460 |
| 461 bool next_function_is_likely_called() const { | 461 bool next_function_is_likely_called() const { |
| 462 return next_function_is_likely_called_; | 462 return next_function_is_likely_called_; |
| 463 } | 463 } |
| 464 | 464 |
| 465 bool previous_function_was_likely_called() const { |
| 466 return previous_function_was_likely_called_; |
| 467 } |
| 468 |
| 465 void set_next_function_is_likely_called() { | 469 void set_next_function_is_likely_called() { |
| 466 next_function_is_likely_called_ = true; | 470 next_function_is_likely_called_ = true; |
| 467 } | 471 } |
| 468 | 472 |
| 469 private: | 473 private: |
| 470 void AddDestructuringAssignment(DestructuringAssignment pair) { | 474 void AddDestructuringAssignment(DestructuringAssignment pair) { |
| 471 destructuring_assignments_to_rewrite_.Add(pair, this->zone()); | 475 destructuring_assignments_to_rewrite_.Add(pair, this->zone()); |
| 472 } | 476 } |
| 473 | 477 |
| 474 void AddNonPatternForRewriting(ExpressionT expr, bool* ok) { | 478 void AddNonPatternForRewriting(ExpressionT expr, bool* ok) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 498 FunctionState* outer_function_state_; | 502 FunctionState* outer_function_state_; |
| 499 | 503 |
| 500 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; | 504 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; |
| 501 TailCallExpressionList tail_call_expressions_; | 505 TailCallExpressionList tail_call_expressions_; |
| 502 ReturnExprContext return_expr_context_; | 506 ReturnExprContext return_expr_context_; |
| 503 ZoneList<ExpressionT> non_patterns_to_rewrite_; | 507 ZoneList<ExpressionT> non_patterns_to_rewrite_; |
| 504 | 508 |
| 505 ZoneList<typename ExpressionClassifier::Error> reported_errors_; | 509 ZoneList<typename ExpressionClassifier::Error> reported_errors_; |
| 506 | 510 |
| 507 // Record whether the next (=== immediately following) function literal is | 511 // Record whether the next (=== immediately following) function literal is |
| 508 // preceded by a parenthesis / exclamation mark. | 512 // preceded by a parenthesis / exclamation mark. Also record the previous |
| 509 // The FunctionState constructor will reset a parents' | 513 // state. |
| 510 // next_function_is_likely_called_ to prevent it from being 'reused' in the | 514 // These are managed by the FunctionState constructor; the caller may only |
| 511 // next function literal. | 515 // call set_next_function_is_likely_called. |
| 512 bool next_function_is_likely_called_; | 516 bool next_function_is_likely_called_; |
| 517 bool previous_function_was_likely_called_; |
| 513 | 518 |
| 514 friend Impl; | 519 friend Impl; |
| 515 friend class Checkpoint; | 520 friend class Checkpoint; |
| 516 }; | 521 }; |
| 517 | 522 |
| 518 // This scope sets current ReturnExprContext to given value. | 523 // This scope sets current ReturnExprContext to given value. |
| 519 class ReturnExprScope { | 524 class ReturnExprScope { |
| 520 public: | 525 public: |
| 521 explicit ReturnExprScope(FunctionState* function_state, | 526 explicit ReturnExprScope(FunctionState* function_state, |
| 522 ReturnExprContext return_expr_context) | 527 ReturnExprContext return_expr_context) |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 expected_property_count_(0), | 1459 expected_property_count_(0), |
| 1455 generator_object_variable_(nullptr), | 1460 generator_object_variable_(nullptr), |
| 1456 promise_variable_(nullptr), | 1461 promise_variable_(nullptr), |
| 1457 function_state_stack_(function_state_stack), | 1462 function_state_stack_(function_state_stack), |
| 1458 outer_function_state_(*function_state_stack), | 1463 outer_function_state_(*function_state_stack), |
| 1459 destructuring_assignments_to_rewrite_(16, scope->zone()), | 1464 destructuring_assignments_to_rewrite_(16, scope->zone()), |
| 1460 tail_call_expressions_(scope->zone()), | 1465 tail_call_expressions_(scope->zone()), |
| 1461 return_expr_context_(ReturnExprContext::kInsideValidBlock), | 1466 return_expr_context_(ReturnExprContext::kInsideValidBlock), |
| 1462 non_patterns_to_rewrite_(0, scope->zone()), | 1467 non_patterns_to_rewrite_(0, scope->zone()), |
| 1463 reported_errors_(16, scope->zone()), | 1468 reported_errors_(16, scope->zone()), |
| 1464 next_function_is_likely_called_(false) { | 1469 next_function_is_likely_called_(false), |
| 1470 previous_function_was_likely_called_(false) { |
| 1465 *function_state_stack = this; | 1471 *function_state_stack = this; |
| 1466 if (outer_function_state_) { | 1472 if (outer_function_state_) { |
| 1473 outer_function_state_->previous_function_was_likely_called_ = |
| 1474 outer_function_state_->next_function_is_likely_called_; |
| 1467 outer_function_state_->next_function_is_likely_called_ = false; | 1475 outer_function_state_->next_function_is_likely_called_ = false; |
| 1468 } | 1476 } |
| 1469 } | 1477 } |
| 1470 | 1478 |
| 1471 template <typename Impl> | 1479 template <typename Impl> |
| 1472 ParserBase<Impl>::FunctionState::~FunctionState() { | 1480 ParserBase<Impl>::FunctionState::~FunctionState() { |
| 1473 *function_state_stack_ = outer_function_state_; | 1481 *function_state_stack_ = outer_function_state_; |
| 1474 } | 1482 } |
| 1475 | 1483 |
| 1476 template <typename Impl> | 1484 template <typename Impl> |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 if (right->IsSpread()) { | 1896 if (right->IsSpread()) { |
| 1889 classifier()->RecordArrowFormalParametersError( | 1897 classifier()->RecordArrowFormalParametersError( |
| 1890 scanner()->location(), MessageTemplate::kParamAfterRest); | 1898 scanner()->location(), MessageTemplate::kParamAfterRest); |
| 1891 } | 1899 } |
| 1892 | 1900 |
| 1893 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN && | 1901 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN && |
| 1894 PeekAhead() == Token::ARROW) { | 1902 PeekAhead() == Token::ARROW) { |
| 1895 // a trailing comma is allowed at the end of an arrow parameter list | 1903 // a trailing comma is allowed at the end of an arrow parameter list |
| 1896 break; | 1904 break; |
| 1897 } | 1905 } |
| 1906 |
| 1907 // Pass on the 'set_next_function_is_likely_called' flag if we have |
| 1908 // several function literals separated by comma. |
| 1909 if (peek() == Token::FUNCTION && |
| 1910 function_state_->previous_function_was_likely_called()) { |
| 1911 function_state_->set_next_function_is_likely_called(); |
| 1912 } |
| 1898 } | 1913 } |
| 1899 | 1914 |
| 1900 return result; | 1915 return result; |
| 1901 } | 1916 } |
| 1902 | 1917 |
| 1903 template <typename Impl> | 1918 template <typename Impl> |
| 1904 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral( | 1919 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral( |
| 1905 bool* ok) { | 1920 bool* ok) { |
| 1906 // ArrayLiteral :: | 1921 // ArrayLiteral :: |
| 1907 // '[' Expression? (',' Expression?)* ']' | 1922 // '[' Expression? (',' Expression?)* ']' |
| (...skipping 3549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5457 has_seen_constructor_ = true; | 5472 has_seen_constructor_ = true; |
| 5458 return; | 5473 return; |
| 5459 } | 5474 } |
| 5460 } | 5475 } |
| 5461 | 5476 |
| 5462 | 5477 |
| 5463 } // namespace internal | 5478 } // namespace internal |
| 5464 } // namespace v8 | 5479 } // namespace v8 |
| 5465 | 5480 |
| 5466 #endif // V8_PARSING_PARSER_BASE_H | 5481 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |