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

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

Issue 2509143003: Treat a '!' preceding a function literal as eager-compile hint. (Closed)
Patch Set: Rename, and remove this_function_* variants. Created 4 years, 1 month 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
« no previous file with comments | « src/parsing/parser.cc ('k') | test/cctest/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 return return_expr_context_; 449 return return_expr_context_;
450 } 450 }
451 void set_return_expr_context(ReturnExprContext context) { 451 void set_return_expr_context(ReturnExprContext context) {
452 return_expr_context_ = context; 452 return_expr_context_ = context;
453 } 453 }
454 454
455 ZoneList<ExpressionT>* non_patterns_to_rewrite() { 455 ZoneList<ExpressionT>* non_patterns_to_rewrite() {
456 return &non_patterns_to_rewrite_; 456 return &non_patterns_to_rewrite_;
457 } 457 }
458 458
459 bool next_function_is_parenthesized() const { 459 bool next_function_is_likely_called() const {
460 return next_function_is_parenthesized_; 460 return next_function_is_likely_called_;
461 } 461 }
462 462
463 void set_next_function_is_parenthesized(bool parenthesized) { 463 void set_next_function_is_likely_called() {
464 next_function_is_parenthesized_ = parenthesized; 464 next_function_is_likely_called_ = true;
465 }
466
467 bool this_function_is_parenthesized() const {
468 return this_function_is_parenthesized_;
469 } 465 }
470 466
471 private: 467 private:
472 void AddDestructuringAssignment(DestructuringAssignment pair) { 468 void AddDestructuringAssignment(DestructuringAssignment pair) {
473 destructuring_assignments_to_rewrite_.Add(pair, this->zone()); 469 destructuring_assignments_to_rewrite_.Add(pair, this->zone());
474 } 470 }
475 471
476 void AddNonPatternForRewriting(ExpressionT expr, bool* ok) { 472 void AddNonPatternForRewriting(ExpressionT expr, bool* ok) {
477 non_patterns_to_rewrite_.Add(expr, this->zone()); 473 non_patterns_to_rewrite_.Add(expr, this->zone());
478 if (non_patterns_to_rewrite_.length() >= 474 if (non_patterns_to_rewrite_.length() >=
(...skipping 20 matching lines...) Expand all
499 FunctionState** function_state_stack_; 495 FunctionState** function_state_stack_;
500 FunctionState* outer_function_state_; 496 FunctionState* outer_function_state_;
501 497
502 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; 498 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_;
503 TailCallExpressionList tail_call_expressions_; 499 TailCallExpressionList tail_call_expressions_;
504 ReturnExprContext return_expr_context_; 500 ReturnExprContext return_expr_context_;
505 ZoneList<ExpressionT> non_patterns_to_rewrite_; 501 ZoneList<ExpressionT> non_patterns_to_rewrite_;
506 502
507 ZoneList<typename ExpressionClassifier::Error> reported_errors_; 503 ZoneList<typename ExpressionClassifier::Error> reported_errors_;
508 504
509 // If true, the next (and immediately following) function literal is 505 // Record whether the next (=== immediately following) function literal is
510 // preceded by a parenthesis. 506 // preceded by a parenthesis / exclamation mark.
511 bool next_function_is_parenthesized_; 507 // The FunctionState constructor will reset a parents'
512 508 // next_function_is_likely_called_ to prevent it from being 'reused' in the
513 // The value of the parents' next_function_is_parenthesized_, as it applies 509 // next function literal.
514 // to this function. Filled in by constructor. 510 bool next_function_is_likely_called_;
515 bool this_function_is_parenthesized_;
516 511
517 friend Impl; 512 friend Impl;
518 friend class Checkpoint; 513 friend class Checkpoint;
519 }; 514 };
520 515
521 // This scope sets current ReturnExprContext to given value. 516 // This scope sets current ReturnExprContext to given value.
522 class ReturnExprScope { 517 class ReturnExprScope {
523 public: 518 public:
524 explicit ReturnExprScope(FunctionState* function_state, 519 explicit ReturnExprScope(FunctionState* function_state,
525 ReturnExprContext return_expr_context) 520 ReturnExprContext return_expr_context)
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 expected_property_count_(0), 1451 expected_property_count_(0),
1457 generator_object_variable_(nullptr), 1452 generator_object_variable_(nullptr),
1458 promise_variable_(nullptr), 1453 promise_variable_(nullptr),
1459 function_state_stack_(function_state_stack), 1454 function_state_stack_(function_state_stack),
1460 outer_function_state_(*function_state_stack), 1455 outer_function_state_(*function_state_stack),
1461 destructuring_assignments_to_rewrite_(16, scope->zone()), 1456 destructuring_assignments_to_rewrite_(16, scope->zone()),
1462 tail_call_expressions_(scope->zone()), 1457 tail_call_expressions_(scope->zone()),
1463 return_expr_context_(ReturnExprContext::kInsideValidBlock), 1458 return_expr_context_(ReturnExprContext::kInsideValidBlock),
1464 non_patterns_to_rewrite_(0, scope->zone()), 1459 non_patterns_to_rewrite_(0, scope->zone()),
1465 reported_errors_(16, scope->zone()), 1460 reported_errors_(16, scope->zone()),
1466 next_function_is_parenthesized_(false), 1461 next_function_is_likely_called_(false) {
1467 this_function_is_parenthesized_(false) {
1468 *function_state_stack = this; 1462 *function_state_stack = this;
1469 if (outer_function_state_) { 1463 if (outer_function_state_) {
1470 this_function_is_parenthesized_ = 1464 outer_function_state_->next_function_is_likely_called_ = false;
1471 outer_function_state_->next_function_is_parenthesized_;
1472 outer_function_state_->next_function_is_parenthesized_ = false;
1473 } 1465 }
1474 } 1466 }
1475 1467
1476 template <typename Impl> 1468 template <typename Impl>
1477 ParserBase<Impl>::FunctionState::~FunctionState() { 1469 ParserBase<Impl>::FunctionState::~FunctionState() {
1478 *function_state_stack_ = outer_function_state_; 1470 *function_state_stack_ = outer_function_state_;
1479 } 1471 }
1480 1472
1481 template <typename Impl> 1473 template <typename Impl>
1482 void ParserBase<Impl>::GetUnexpectedTokenMessage( 1474 void ParserBase<Impl>::GetUnexpectedTokenMessage(
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 if (Check(Token::RPAREN)) { 1771 if (Check(Token::RPAREN)) {
1780 // ()=>x. The continuation that looks for the => is in 1772 // ()=>x. The continuation that looks for the => is in
1781 // ParseAssignmentExpression. 1773 // ParseAssignmentExpression.
1782 classifier()->RecordExpressionError(scanner()->location(), 1774 classifier()->RecordExpressionError(scanner()->location(),
1783 MessageTemplate::kUnexpectedToken, 1775 MessageTemplate::kUnexpectedToken,
1784 Token::String(Token::RPAREN)); 1776 Token::String(Token::RPAREN));
1785 return factory()->NewEmptyParentheses(beg_pos); 1777 return factory()->NewEmptyParentheses(beg_pos);
1786 } 1778 }
1787 // Heuristically try to detect immediately called functions before 1779 // Heuristically try to detect immediately called functions before
1788 // seeing the call parentheses. 1780 // seeing the call parentheses.
1789 function_state_->set_next_function_is_parenthesized(peek() == 1781 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.
1790 Token::FUNCTION); 1782 function_state_->set_next_function_is_likely_called();
1791 ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK); 1783 ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK);
1792 Expect(Token::RPAREN, CHECK_OK); 1784 Expect(Token::RPAREN, CHECK_OK);
1793 return expr; 1785 return expr;
1794 } 1786 }
1795 1787
1796 case Token::CLASS: { 1788 case Token::CLASS: {
1797 BindingPatternUnexpectedToken(); 1789 BindingPatternUnexpectedToken();
1798 Consume(Token::CLASS); 1790 Consume(Token::CLASS);
1799 int class_token_pos = position(); 1791 int class_token_pos = position();
1800 IdentifierT name = impl()->EmptyIdentifier(); 1792 IdentifierT name = impl()->EmptyIdentifier();
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 // '!' UnaryExpression 2926 // '!' UnaryExpression
2935 // [+Await] AwaitExpression[?Yield] 2927 // [+Await] AwaitExpression[?Yield]
2936 2928
2937 Token::Value op = peek(); 2929 Token::Value op = peek();
2938 if (Token::IsUnaryOp(op)) { 2930 if (Token::IsUnaryOp(op)) {
2939 BindingPatternUnexpectedToken(); 2931 BindingPatternUnexpectedToken();
2940 ArrowFormalParametersUnexpectedToken(); 2932 ArrowFormalParametersUnexpectedToken();
2941 2933
2942 op = Next(); 2934 op = Next();
2943 int pos = position(); 2935 int pos = position();
2936
2937 // Assume "! function ..." indicates the function is likely to be called.
2938 if (op == Token::NOT && peek() == Token::FUNCTION)
2939 function_state_->set_next_function_is_likely_called();
2940
2944 ExpressionT expression = ParseUnaryExpression(CHECK_OK); 2941 ExpressionT expression = ParseUnaryExpression(CHECK_OK);
2945 impl()->RewriteNonPattern(CHECK_OK); 2942 impl()->RewriteNonPattern(CHECK_OK);
2946 2943
2947 if (op == Token::DELETE && is_strict(language_mode())) { 2944 if (op == Token::DELETE && is_strict(language_mode())) {
2948 if (impl()->IsIdentifier(expression)) { 2945 if (impl()->IsIdentifier(expression)) {
2949 // "delete identifier" is a syntax error in strict mode. 2946 // "delete identifier" is a syntax error in strict mode.
2950 ReportMessage(MessageTemplate::kStrictDelete); 2947 ReportMessage(MessageTemplate::kStrictDelete);
2951 *ok = false; 2948 *ok = false;
2952 return impl()->EmptyExpression(); 2949 return impl()->EmptyExpression();
2953 } 2950 }
(...skipping 2497 matching lines...) Expand 10 before | Expand all | Expand 10 after
5451 has_seen_constructor_ = true; 5448 has_seen_constructor_ = true;
5452 return; 5449 return;
5453 } 5450 }
5454 } 5451 }
5455 5452
5456 5453
5457 } // namespace internal 5454 } // namespace internal
5458 } // namespace v8 5455 } // namespace v8
5459 5456
5460 #endif // V8_PARSING_PARSER_BASE_H 5457 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | test/cctest/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698