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

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

Issue 2224843003: Reduce number of scope() accesses (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Undo unrelated change Created 4 years, 4 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
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('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/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 // '(' Expression ')' 1540 // '(' Expression ')'
1541 // TemplateLiteral 1541 // TemplateLiteral
1542 // do Block 1542 // do Block
1543 // AsyncFunctionExpression 1543 // AsyncFunctionExpression
1544 1544
1545 int beg_pos = peek_position(); 1545 int beg_pos = peek_position();
1546 switch (peek()) { 1546 switch (peek()) {
1547 case Token::THIS: { 1547 case Token::THIS: {
1548 BindingPatternUnexpectedToken(classifier); 1548 BindingPatternUnexpectedToken(classifier);
1549 Consume(Token::THIS); 1549 Consume(Token::THIS);
1550 return this->ThisExpression(scope(), factory(), beg_pos); 1550 return this->ThisExpression(factory(), beg_pos);
1551 } 1551 }
1552 1552
1553 case Token::NULL_LITERAL: 1553 case Token::NULL_LITERAL:
1554 case Token::TRUE_LITERAL: 1554 case Token::TRUE_LITERAL:
1555 case Token::FALSE_LITERAL: 1555 case Token::FALSE_LITERAL:
1556 BindingPatternUnexpectedToken(classifier); 1556 BindingPatternUnexpectedToken(classifier);
1557 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); 1557 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory());
1558 case Token::SMI: 1558 case Token::SMI:
1559 case Token::NUMBER: 1559 case Token::NUMBER:
1560 BindingPatternUnexpectedToken(classifier); 1560 BindingPatternUnexpectedToken(classifier);
(...skipping 12 matching lines...) Expand all
1573 case Token::IDENTIFIER: 1573 case Token::IDENTIFIER:
1574 case Token::LET: 1574 case Token::LET:
1575 case Token::STATIC: 1575 case Token::STATIC:
1576 case Token::YIELD: 1576 case Token::YIELD:
1577 case Token::AWAIT: 1577 case Token::AWAIT:
1578 case Token::ESCAPED_STRICT_RESERVED_WORD: 1578 case Token::ESCAPED_STRICT_RESERVED_WORD:
1579 case Token::FUTURE_STRICT_RESERVED_WORD: { 1579 case Token::FUTURE_STRICT_RESERVED_WORD: {
1580 // Using eval or arguments in this context is OK even in strict mode. 1580 // Using eval or arguments in this context is OK even in strict mode.
1581 IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); 1581 IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK);
1582 return this->ExpressionFromIdentifier( 1582 return this->ExpressionFromIdentifier(
1583 name, beg_pos, scanner()->location().end_pos, scope(), factory()); 1583 name, beg_pos, scanner()->location().end_pos, factory());
1584 } 1584 }
1585 1585
1586 case Token::STRING: { 1586 case Token::STRING: {
1587 BindingPatternUnexpectedToken(classifier); 1587 BindingPatternUnexpectedToken(classifier);
1588 Consume(Token::STRING); 1588 Consume(Token::STRING);
1589 return this->ExpressionFromString(beg_pos, scanner(), factory()); 1589 return this->ExpressionFromString(beg_pos, scanner(), factory());
1590 } 1590 }
1591 1591
1592 case Token::ASSIGN_DIV: 1592 case Token::ASSIGN_DIV:
1593 classifier->RecordBindingPatternError( 1593 classifier->RecordBindingPatternError(
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 if (is_async_function()) { 1997 if (is_async_function()) {
1998 classifier->RecordPatternError( 1998 classifier->RecordPatternError(
1999 Scanner::Location(next_beg_pos, next_end_pos), 1999 Scanner::Location(next_beg_pos, next_end_pos),
2000 MessageTemplate::kAwaitBindingIdentifier); 2000 MessageTemplate::kAwaitBindingIdentifier);
2001 } else { 2001 } else {
2002 classifier->RecordAsyncArrowFormalParametersError( 2002 classifier->RecordAsyncArrowFormalParametersError(
2003 Scanner::Location(next_beg_pos, next_end_pos), 2003 Scanner::Location(next_beg_pos, next_end_pos),
2004 MessageTemplate::kAwaitBindingIdentifier); 2004 MessageTemplate::kAwaitBindingIdentifier);
2005 } 2005 }
2006 } 2006 }
2007 ExpressionT lhs = this->ExpressionFromIdentifier( 2007 ExpressionT lhs = this->ExpressionFromIdentifier(*name, next_beg_pos,
2008 *name, next_beg_pos, next_end_pos, scope(), factory()); 2008 next_end_pos, factory());
2009 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); 2009 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
2010 2010
2011 ExpressionT value; 2011 ExpressionT value;
2012 if (peek() == Token::ASSIGN) { 2012 if (peek() == Token::ASSIGN) {
2013 Consume(Token::ASSIGN); 2013 Consume(Token::ASSIGN);
2014 ExpressionClassifier rhs_classifier(this); 2014 ExpressionClassifier rhs_classifier(this);
2015 ExpressionT rhs = this->ParseAssignmentExpression( 2015 ExpressionT rhs = this->ParseAssignmentExpression(
2016 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2016 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2017 Traits::RewriteNonPattern(&rhs_classifier, 2017 Traits::RewriteNonPattern(&rhs_classifier,
2018 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2018 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); 2308 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier);
2309 } 2309 }
2310 ExpressionT expression = this->ParseConditionalExpression( 2310 ExpressionT expression = this->ParseConditionalExpression(
2311 accept_IN, &arrow_formals_classifier, CHECK_OK); 2311 accept_IN, &arrow_formals_classifier, CHECK_OK);
2312 2312
2313 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) { 2313 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) {
2314 // async Identifier => AsyncConciseBody 2314 // async Identifier => AsyncConciseBody
2315 IdentifierT name = 2315 IdentifierT name =
2316 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); 2316 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
2317 expression = this->ExpressionFromIdentifier( 2317 expression = this->ExpressionFromIdentifier(
2318 name, position(), scanner()->location().end_pos, scope(), factory()); 2318 name, position(), scanner()->location().end_pos, factory());
2319 } 2319 }
2320 2320
2321 if (peek() == Token::ARROW) { 2321 if (peek() == Token::ARROW) {
2322 Scanner::Location arrow_loc = scanner()->peek_location(); 2322 Scanner::Location arrow_loc = scanner()->peek_location();
2323 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, 2323 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
2324 parenthesized_formals, is_async, CHECK_OK); 2324 parenthesized_formals, is_async, CHECK_OK);
2325 // This reads strangely, but is correct: it checks whether any 2325 // This reads strangely, but is correct: it checks whether any
2326 // sub-expression of the parameter list failed to be a valid formal 2326 // sub-expression of the parameter list failed to be a valid formal
2327 // parameter initializer. Since YieldExpressions are banned anywhere 2327 // parameter initializer. Since YieldExpressions are banned anywhere
2328 // in an arrow parameter list, this is correct. 2328 // in an arrow parameter list, this is correct.
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 // Possibly async arrow formals --- record ExpressionError just in case. 2753 // Possibly async arrow formals --- record ExpressionError just in case.
2754 ExpressionUnexpectedToken(classifier); 2754 ExpressionUnexpectedToken(classifier);
2755 classifier->RecordAsyncBindingPatternError( 2755 classifier->RecordAsyncBindingPatternError(
2756 Scanner::Location(beg_pos, scanner()->location().end_pos), 2756 Scanner::Location(beg_pos, scanner()->location().end_pos),
2757 MessageTemplate::kAwaitBindingIdentifier); 2757 MessageTemplate::kAwaitBindingIdentifier);
2758 classifier->RecordAsyncArrowFormalParametersError( 2758 classifier->RecordAsyncArrowFormalParametersError(
2759 Scanner::Location(beg_pos, scanner()->location().end_pos), 2759 Scanner::Location(beg_pos, scanner()->location().end_pos),
2760 MessageTemplate::kAwaitBindingIdentifier); 2760 MessageTemplate::kAwaitBindingIdentifier);
2761 2761
2762 return this->ExpressionFromIdentifier( 2762 return this->ExpressionFromIdentifier(
2763 name, beg_pos, scanner()->location().end_pos, scope(), factory()); 2763 name, beg_pos, scanner()->location().end_pos, factory());
2764 } 2764 }
2765 default: 2765 default:
2766 break; 2766 break;
2767 } 2767 }
2768 2768
2769 int await_pos = peek_position(); 2769 int await_pos = peek_position();
2770 Consume(Token::AWAIT); 2770 Consume(Token::AWAIT);
2771 2771
2772 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); 2772 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK);
2773 2773
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2911 if (spread_pos.IsValid()) { 2911 if (spread_pos.IsValid()) {
2912 args = Traits::PrepareSpreadArguments(args); 2912 args = Traits::PrepareSpreadArguments(args);
2913 result = Traits::SpreadCall(result, args, pos); 2913 result = Traits::SpreadCall(result, args, pos);
2914 } else { 2914 } else {
2915 result = factory()->NewCall(result, args, pos); 2915 result = factory()->NewCall(result, args, pos);
2916 } 2916 }
2917 2917
2918 // Explicit calls to the super constructor using super() perform an 2918 // Explicit calls to the super constructor using super() perform an
2919 // implicit binding assignment to the 'this' variable. 2919 // implicit binding assignment to the 'this' variable.
2920 if (is_super_call) { 2920 if (is_super_call) {
2921 ExpressionT this_expr = this->ThisExpression(scope(), factory(), pos); 2921 ExpressionT this_expr = this->ThisExpression(factory(), pos);
2922 result = 2922 result =
2923 factory()->NewAssignment(Token::INIT, this_expr, result, pos); 2923 factory()->NewAssignment(Token::INIT, this_expr, result, pos);
2924 } 2924 }
2925 2925
2926 if (fni_ != NULL) fni_->RemoveLastFunction(); 2926 if (fni_ != NULL) fni_->RemoveLastFunction();
2927 break; 2927 break;
2928 } 2928 }
2929 2929
2930 case Token::PERIOD: { 2930 case Token::PERIOD: {
2931 CheckNoTailCallExpressions(classifier, CHECK_OK); 2931 CheckNoTailCallExpressions(classifier, CHECK_OK);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
3049 ExpectMetaProperty(CStrVector("sent"), "function.sent", pos, CHECK_OK); 3049 ExpectMetaProperty(CStrVector("sent"), "function.sent", pos, CHECK_OK);
3050 3050
3051 if (!is_generator()) { 3051 if (!is_generator()) {
3052 // TODO(neis): allow escaping into closures? 3052 // TODO(neis): allow escaping into closures?
3053 ReportMessageAt(scanner()->location(), 3053 ReportMessageAt(scanner()->location(),
3054 MessageTemplate::kUnexpectedFunctionSent); 3054 MessageTemplate::kUnexpectedFunctionSent);
3055 *ok = false; 3055 *ok = false;
3056 return this->EmptyExpression(); 3056 return this->EmptyExpression();
3057 } 3057 }
3058 3058
3059 return this->FunctionSentExpression(scope(), factory(), pos); 3059 return this->FunctionSentExpression(factory(), pos);
3060 } 3060 }
3061 3061
3062 bool is_generator = Check(Token::MUL); 3062 bool is_generator = Check(Token::MUL);
3063 IdentifierT name = this->EmptyIdentifier(); 3063 IdentifierT name = this->EmptyIdentifier();
3064 bool is_strict_reserved_name = false; 3064 bool is_strict_reserved_name = false;
3065 Scanner::Location function_name_location = Scanner::Location::invalid(); 3065 Scanner::Location function_name_location = Scanner::Location::invalid();
3066 FunctionLiteral::FunctionType function_type = 3066 FunctionLiteral::FunctionType function_type =
3067 FunctionLiteral::kAnonymousExpression; 3067 FunctionLiteral::kAnonymousExpression;
3068 if (peek_any_identifier()) { 3068 if (peek_any_identifier()) {
3069 name = ParseIdentifierOrStrictReservedWord( 3069 name = ParseIdentifierOrStrictReservedWord(
(...skipping 25 matching lines...) Expand all
3095 ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) { 3095 ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) {
3096 Expect(Token::SUPER, CHECK_OK); 3096 Expect(Token::SUPER, CHECK_OK);
3097 int pos = position(); 3097 int pos = position();
3098 3098
3099 DeclarationScope* scope = this->scope()->GetReceiverScope(); 3099 DeclarationScope* scope = this->scope()->GetReceiverScope();
3100 FunctionKind kind = scope->function_kind(); 3100 FunctionKind kind = scope->function_kind();
3101 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || 3101 if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
3102 IsClassConstructor(kind)) { 3102 IsClassConstructor(kind)) {
3103 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { 3103 if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
3104 scope->RecordSuperPropertyUsage(); 3104 scope->RecordSuperPropertyUsage();
3105 return this->NewSuperPropertyReference(this->scope(), factory(), pos); 3105 return this->NewSuperPropertyReference(factory(), pos);
3106 } 3106 }
3107 // new super() is never allowed. 3107 // new super() is never allowed.
3108 // super() is only allowed in derived constructor 3108 // super() is only allowed in derived constructor
3109 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { 3109 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
3110 // TODO(rossberg): This might not be the correct FunctionState for the 3110 // TODO(rossberg): This might not be the correct FunctionState for the
3111 // method here. 3111 // method here.
3112 return this->NewSuperCallReference(this->scope(), factory(), pos); 3112 return this->NewSuperCallReference(factory(), pos);
3113 } 3113 }
3114 } 3114 }
3115 3115
3116 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); 3116 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper);
3117 *ok = false; 3117 *ok = false;
3118 return this->EmptyExpression(); 3118 return this->EmptyExpression();
3119 } 3119 }
3120 3120
3121 template <class Traits> 3121 template <class Traits>
3122 void ParserBase<Traits>::ExpectMetaProperty(Vector<const char> property_name, 3122 void ParserBase<Traits>::ExpectMetaProperty(Vector<const char> property_name,
(...skipping 15 matching lines...) Expand all
3138 int pos = position(); 3138 int pos = position();
3139 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); 3139 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK);
3140 3140
3141 if (!scope()->GetReceiverScope()->is_function_scope()) { 3141 if (!scope()->GetReceiverScope()->is_function_scope()) {
3142 ReportMessageAt(scanner()->location(), 3142 ReportMessageAt(scanner()->location(),
3143 MessageTemplate::kUnexpectedNewTarget); 3143 MessageTemplate::kUnexpectedNewTarget);
3144 *ok = false; 3144 *ok = false;
3145 return this->EmptyExpression(); 3145 return this->EmptyExpression();
3146 } 3146 }
3147 3147
3148 return this->NewTargetExpression(scope(), factory(), pos); 3148 return this->NewTargetExpression(factory(), pos);
3149 } 3149 }
3150 3150
3151 template <class Traits> 3151 template <class Traits>
3152 typename ParserBase<Traits>::ExpressionT 3152 typename ParserBase<Traits>::ExpressionT
3153 ParserBase<Traits>::ParseMemberExpressionContinuation( 3153 ParserBase<Traits>::ParseMemberExpressionContinuation(
3154 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, 3154 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier,
3155 bool* ok) { 3155 bool* ok) {
3156 // Parses this part of MemberExpression: 3156 // Parses this part of MemberExpression:
3157 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* 3157 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)*
3158 while (true) { 3158 while (true) {
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
3693 has_seen_constructor_ = true; 3693 has_seen_constructor_ = true;
3694 return; 3694 return;
3695 } 3695 }
3696 } 3696 }
3697 3697
3698 3698
3699 } // namespace internal 3699 } // namespace internal
3700 } // namespace v8 3700 } // namespace v8
3701 3701
3702 #endif // V8_PARSING_PARSER_BASE_H 3702 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698