Chromium Code Reviews| Index: src/parsing/parser-base.h |
| diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h |
| index 4fe27e2e5a364a79c103051da3159938b991e21a..ba70d2a432b7c919d8b0dab30dd0717045206594 100644 |
| --- a/src/parsing/parser-base.h |
| +++ b/src/parsing/parser-base.h |
| @@ -456,16 +456,12 @@ class ParserBase { |
| return &non_patterns_to_rewrite_; |
| } |
| - bool next_function_is_parenthesized() const { |
| - return next_function_is_parenthesized_; |
| + bool next_function_is_likely_called() const { |
| + return next_function_is_likely_called_; |
| } |
| - void set_next_function_is_parenthesized(bool parenthesized) { |
| - next_function_is_parenthesized_ = parenthesized; |
| - } |
| - |
| - bool this_function_is_parenthesized() const { |
| - return this_function_is_parenthesized_; |
| + void set_next_function_is_likely_called() { |
| + next_function_is_likely_called_ = true; |
| } |
| private: |
| @@ -506,13 +502,12 @@ class ParserBase { |
| ZoneList<typename ExpressionClassifier::Error> reported_errors_; |
| - // If true, the next (and immediately following) function literal is |
| - // preceded by a parenthesis. |
| - bool next_function_is_parenthesized_; |
| - |
| - // The value of the parents' next_function_is_parenthesized_, as it applies |
| - // to this function. Filled in by constructor. |
| - bool this_function_is_parenthesized_; |
| + // Record whether the next (=== immediately following) function literal is |
| + // preceded by a parenthesis / exclamation mark. |
| + // The FunctionState constructor will reset a parents' |
| + // next_function_is_likely_called_ to prevent it from being 'reused' in the |
| + // next function literal. |
| + bool next_function_is_likely_called_; |
| friend Impl; |
| friend class Checkpoint; |
| @@ -1463,13 +1458,10 @@ ParserBase<Impl>::FunctionState::FunctionState( |
| return_expr_context_(ReturnExprContext::kInsideValidBlock), |
| non_patterns_to_rewrite_(0, scope->zone()), |
| reported_errors_(16, scope->zone()), |
| - next_function_is_parenthesized_(false), |
| - this_function_is_parenthesized_(false) { |
| + next_function_is_likely_called_(false) { |
| *function_state_stack = this; |
| if (outer_function_state_) { |
| - this_function_is_parenthesized_ = |
| - outer_function_state_->next_function_is_parenthesized_; |
| - outer_function_state_->next_function_is_parenthesized_ = false; |
| + outer_function_state_->next_function_is_likely_called_ = false; |
| } |
| } |
| @@ -1786,8 +1778,8 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression( |
| } |
| // Heuristically try to detect immediately called functions before |
| // seeing the call parentheses. |
| - function_state_->set_next_function_is_parenthesized(peek() == |
| - Token::FUNCTION); |
| + if (peek() == Token::FUNCTION) |
|
Toon Verwaest
2016/11/18 13:59:48
use {} after if for statements that don't fit on t
vogelheim
2016/11/18 14:10:30
Done.
|
| + function_state_->set_next_function_is_likely_called(); |
| ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK); |
| Expect(Token::RPAREN, CHECK_OK); |
| return expr; |
| @@ -2941,6 +2933,11 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression( |
| op = Next(); |
| int pos = position(); |
| + |
| + // Assume "! function ..." indicates the function is likely to be called. |
| + if (op == Token::NOT && peek() == Token::FUNCTION) |
| + function_state_->set_next_function_is_likely_called(); |
| + |
| ExpressionT expression = ParseUnaryExpression(CHECK_OK); |
| impl()->RewriteNonPattern(CHECK_OK); |