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

Side by Side Diff: src/preparser.h

Issue 1170263002: Revert of [es6] Parsing of new.target (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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/parser.cc ('k') | src/preparser.cc » ('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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 scanner_(scanner), 90 scanner_(scanner),
91 stack_overflow_(false), 91 stack_overflow_(false),
92 allow_lazy_(false), 92 allow_lazy_(false),
93 allow_natives_(false), 93 allow_natives_(false),
94 allow_harmony_arrow_functions_(false), 94 allow_harmony_arrow_functions_(false),
95 allow_harmony_object_literals_(false), 95 allow_harmony_object_literals_(false),
96 allow_harmony_sloppy_(false), 96 allow_harmony_sloppy_(false),
97 allow_harmony_computed_property_names_(false), 97 allow_harmony_computed_property_names_(false),
98 allow_harmony_rest_params_(false), 98 allow_harmony_rest_params_(false),
99 allow_harmony_spreadcalls_(false), 99 allow_harmony_spreadcalls_(false),
100 allow_harmony_destructuring_(false),
101 allow_harmony_spread_arrays_(false),
102 allow_harmony_new_target_(false),
103 allow_strong_mode_(false) {} 100 allow_strong_mode_(false) {}
104 101
105 #define ALLOW_ACCESSORS(name) \ 102 // Getters that indicate whether certain syntactical constructs are
106 bool allow_##name() const { return allow_##name##_; } \ 103 // allowed to be parsed by this instance of the parser.
107 void set_allow_##name(bool allow) { allow_##name##_ = allow; } 104 bool allow_lazy() const { return allow_lazy_; }
108 105 bool allow_natives() const { return allow_natives_; }
109 ALLOW_ACCESSORS(lazy); 106 bool allow_harmony_arrow_functions() const {
110 ALLOW_ACCESSORS(natives); 107 return allow_harmony_arrow_functions_;
111 ALLOW_ACCESSORS(harmony_arrow_functions); 108 }
112 ALLOW_ACCESSORS(harmony_object_literals);
113 ALLOW_ACCESSORS(harmony_sloppy);
114 ALLOW_ACCESSORS(harmony_computed_property_names);
115 ALLOW_ACCESSORS(harmony_rest_params);
116 ALLOW_ACCESSORS(harmony_spreadcalls);
117 ALLOW_ACCESSORS(harmony_destructuring);
118 ALLOW_ACCESSORS(harmony_spread_arrays);
119 ALLOW_ACCESSORS(harmony_new_target);
120 ALLOW_ACCESSORS(strong_mode);
121 #undef ALLOW_ACCESSORS
122
123 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } 109 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); }
124 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } 110 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); }
111 bool allow_harmony_object_literals() const {
112 return allow_harmony_object_literals_;
113 }
114 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; }
125 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } 115 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); }
116 bool allow_harmony_computed_property_names() const {
117 return allow_harmony_computed_property_names_;
118 }
119 bool allow_harmony_rest_params() const {
120 return allow_harmony_rest_params_;
121 }
122 bool allow_harmony_spreadcalls() const { return allow_harmony_spreadcalls_; }
123 bool allow_harmony_destructuring() const {
124 return allow_harmony_destructuring_;
125 }
126 bool allow_harmony_spread_arrays() const {
127 return allow_harmony_spread_arrays_;
128 }
126 129
127 void set_allow_harmony_modules(bool a) { scanner()->SetHarmonyModules(a); } 130 bool allow_strong_mode() const { return allow_strong_mode_; }
128 void set_allow_harmony_classes(bool a) { scanner()->SetHarmonyClasses(a); } 131
129 void set_allow_harmony_unicode(bool a) { scanner()->SetHarmonyUnicode(a); } 132 // Setters that determine whether certain syntactical constructs are
133 // allowed to be parsed by this instance of the parser.
134 void set_allow_lazy(bool allow) { allow_lazy_ = allow; }
135 void set_allow_natives(bool allow) { allow_natives_ = allow; }
136 void set_allow_harmony_arrow_functions(bool allow) {
137 allow_harmony_arrow_functions_ = allow;
138 }
139 void set_allow_harmony_modules(bool allow) {
140 scanner()->SetHarmonyModules(allow);
141 }
142 void set_allow_harmony_classes(bool allow) {
143 scanner()->SetHarmonyClasses(allow);
144 }
145 void set_allow_harmony_object_literals(bool allow) {
146 allow_harmony_object_literals_ = allow;
147 }
148 void set_allow_harmony_sloppy(bool allow) {
149 allow_harmony_sloppy_ = allow;
150 }
151 void set_allow_harmony_unicode(bool allow) {
152 scanner()->SetHarmonyUnicode(allow);
153 }
154 void set_allow_harmony_computed_property_names(bool allow) {
155 allow_harmony_computed_property_names_ = allow;
156 }
157 void set_allow_harmony_rest_params(bool allow) {
158 allow_harmony_rest_params_ = allow;
159 }
160 void set_allow_harmony_spreadcalls(bool allow) {
161 allow_harmony_spreadcalls_ = allow;
162 }
163 void set_allow_strong_mode(bool allow) { allow_strong_mode_ = allow; }
164 void set_allow_harmony_destructuring(bool allow) {
165 allow_harmony_destructuring_ = allow;
166 }
167 void set_allow_harmony_spread_arrays(bool allow) {
168 allow_harmony_spread_arrays_ = allow;
169 }
130 170
131 protected: 171 protected:
132 enum AllowRestrictedIdentifiers { 172 enum AllowRestrictedIdentifiers {
133 kAllowRestrictedIdentifiers, 173 kAllowRestrictedIdentifiers,
134 kDontAllowRestrictedIdentifiers 174 kDontAllowRestrictedIdentifiers
135 }; 175 };
136 176
137 enum Mode { 177 enum Mode {
138 PARSE_LAZILY, 178 PARSE_LAZILY,
139 PARSE_EAGERLY 179 PARSE_EAGERLY
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 Scope* NewScope(Scope* parent, ScopeType scope_type) { 342 Scope* NewScope(Scope* parent, ScopeType scope_type) {
303 // Must always pass the function kind for FUNCTION_SCOPE and ARROW_SCOPE. 343 // Must always pass the function kind for FUNCTION_SCOPE and ARROW_SCOPE.
304 DCHECK(scope_type != FUNCTION_SCOPE); 344 DCHECK(scope_type != FUNCTION_SCOPE);
305 DCHECK(scope_type != ARROW_SCOPE); 345 DCHECK(scope_type != ARROW_SCOPE);
306 return NewScope(parent, scope_type, kNormalFunction); 346 return NewScope(parent, scope_type, kNormalFunction);
307 } 347 }
308 348
309 Scope* NewScope(Scope* parent, ScopeType scope_type, FunctionKind kind) { 349 Scope* NewScope(Scope* parent, ScopeType scope_type, FunctionKind kind) {
310 DCHECK(ast_value_factory()); 350 DCHECK(ast_value_factory());
311 DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules()); 351 DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules());
312 DCHECK(!IsArrowFunction(kind) || scope_type == ARROW_SCOPE); 352 DCHECK(scope_type != ARROW_SCOPE || IsArrowFunction(kind));
313 Scope* result = new (zone()) 353 Scope* result = new (zone())
314 Scope(zone(), parent, scope_type, ast_value_factory(), kind); 354 Scope(zone(), parent, scope_type, ast_value_factory(), kind);
315 result->Initialize(); 355 result->Initialize();
316 return result; 356 return result;
317 } 357 }
318 358
319 Scanner* scanner() const { return scanner_; } 359 Scanner* scanner() const { return scanner_; }
320 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } 360 AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
321 int position() { return scanner_->location().beg_pos; } 361 int position() { return scanner_->location().beg_pos; }
322 int peek_position() { return scanner_->peek_location().beg_pos; } 362 int peek_position() { return scanner_->peek_location().beg_pos; }
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 ExpressionT ParseMemberExpressionContinuation( 905 ExpressionT ParseMemberExpressionContinuation(
866 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); 906 ExpressionT expression, ExpressionClassifier* classifier, bool* ok);
867 ExpressionT ParseArrowFunctionLiteral(Scope* function_scope, bool has_rest, 907 ExpressionT ParseArrowFunctionLiteral(Scope* function_scope, bool has_rest,
868 const ExpressionClassifier& classifier, 908 const ExpressionClassifier& classifier,
869 bool* ok); 909 bool* ok);
870 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, 910 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start,
871 ExpressionClassifier* classifier, bool* ok); 911 ExpressionClassifier* classifier, bool* ok);
872 void AddTemplateExpression(ExpressionT); 912 void AddTemplateExpression(ExpressionT);
873 ExpressionT ParseSuperExpression(bool is_new, 913 ExpressionT ParseSuperExpression(bool is_new,
874 ExpressionClassifier* classifier, bool* ok); 914 ExpressionClassifier* classifier, bool* ok);
875 ExpressionT ParseNewTargetExpression(bool* ok);
876 ExpressionT ParseStrongInitializationExpression( 915 ExpressionT ParseStrongInitializationExpression(
877 ExpressionClassifier* classifier, bool* ok); 916 ExpressionClassifier* classifier, bool* ok);
878 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, 917 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier,
879 bool* ok); 918 bool* ok);
880 919
881 void ParseFormalParameter(FormalParameterScopeT* scope, bool is_rest, 920 void ParseFormalParameter(FormalParameterScopeT* scope, bool is_rest,
882 ExpressionClassifier* classifier, bool* ok); 921 ExpressionClassifier* classifier, bool* ok);
883 int ParseFormalParameterList(FormalParameterScopeT* scope, bool* has_rest, 922 int ParseFormalParameterList(FormalParameterScopeT* scope, bool* has_rest,
884 ExpressionClassifier* classifier, bool* ok); 923 ExpressionClassifier* classifier, bool* ok);
885 void CheckArityRestrictions( 924 void CheckArityRestrictions(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 bool allow_lazy_; 1015 bool allow_lazy_;
977 bool allow_natives_; 1016 bool allow_natives_;
978 bool allow_harmony_arrow_functions_; 1017 bool allow_harmony_arrow_functions_;
979 bool allow_harmony_object_literals_; 1018 bool allow_harmony_object_literals_;
980 bool allow_harmony_sloppy_; 1019 bool allow_harmony_sloppy_;
981 bool allow_harmony_computed_property_names_; 1020 bool allow_harmony_computed_property_names_;
982 bool allow_harmony_rest_params_; 1021 bool allow_harmony_rest_params_;
983 bool allow_harmony_spreadcalls_; 1022 bool allow_harmony_spreadcalls_;
984 bool allow_harmony_destructuring_; 1023 bool allow_harmony_destructuring_;
985 bool allow_harmony_spread_arrays_; 1024 bool allow_harmony_spread_arrays_;
986 bool allow_harmony_new_target_;
987 bool allow_strong_mode_; 1025 bool allow_strong_mode_;
988 }; 1026 };
989 1027
990 1028
991 class PreParserIdentifier { 1029 class PreParserIdentifier {
992 public: 1030 public:
993 PreParserIdentifier() : type_(kUnknownIdentifier) {} 1031 PreParserIdentifier() : type_(kUnknownIdentifier) {}
994 static PreParserIdentifier Default() { 1032 static PreParserIdentifier Default() {
995 return PreParserIdentifier(kUnknownIdentifier); 1033 return PreParserIdentifier(kUnknownIdentifier);
996 } 1034 }
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 int pos) { 1724 int pos) {
1687 return PreParserExpression::Default(); 1725 return PreParserExpression::Default();
1688 } 1726 }
1689 1727
1690 static PreParserExpression SuperCallReference(Scope* scope, 1728 static PreParserExpression SuperCallReference(Scope* scope,
1691 PreParserFactory* factory, 1729 PreParserFactory* factory,
1692 int pos) { 1730 int pos) {
1693 return PreParserExpression::Default(); 1731 return PreParserExpression::Default();
1694 } 1732 }
1695 1733
1696 static PreParserExpression NewTargetExpression(Scope* scope,
1697 PreParserFactory* factory,
1698 int pos) {
1699 return PreParserExpression::Default();
1700 }
1701
1702 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope, 1734 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope,
1703 int pos, int end_pos) { 1735 int pos, int end_pos) {
1704 return PreParserExpression::Default(); 1736 return PreParserExpression::Default();
1705 } 1737 }
1706 1738
1707 static PreParserExpression ExpressionFromLiteral( 1739 static PreParserExpression ExpressionFromLiteral(
1708 Token::Value token, int pos, Scanner* scanner, 1740 Token::Value token, int pos, Scanner* scanner,
1709 PreParserFactory* factory) { 1741 PreParserFactory* factory) {
1710 return PreParserExpression::Default(); 1742 return PreParserExpression::Default();
1711 } 1743 }
(...skipping 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after
3293 } 3325 }
3294 } 3326 }
3295 3327
3296 3328
3297 template <class Traits> 3329 template <class Traits>
3298 typename ParserBase<Traits>::ExpressionT 3330 typename ParserBase<Traits>::ExpressionT
3299 ParserBase<Traits>::ParseMemberWithNewPrefixesExpression( 3331 ParserBase<Traits>::ParseMemberWithNewPrefixesExpression(
3300 ExpressionClassifier* classifier, bool* ok) { 3332 ExpressionClassifier* classifier, bool* ok) {
3301 // NewExpression :: 3333 // NewExpression ::
3302 // ('new')+ MemberExpression 3334 // ('new')+ MemberExpression
3303 //
3304 // NewTarget ::
3305 // 'new' '.' 'target'
3306 3335
3307 // The grammar for new expressions is pretty warped. We can have several 'new' 3336 // The grammar for new expressions is pretty warped. We can have several 'new'
3308 // keywords following each other, and then a MemberExpression. When we see '(' 3337 // keywords following each other, and then a MemberExpression. When we see '('
3309 // after the MemberExpression, it's associated with the rightmost unassociated 3338 // after the MemberExpression, it's associated with the rightmost unassociated
3310 // 'new' to create a NewExpression with arguments. However, a NewExpression 3339 // 'new' to create a NewExpression with arguments. However, a NewExpression
3311 // can also occur without arguments. 3340 // can also occur without arguments.
3312 3341
3313 // Examples of new expression: 3342 // Examples of new expression:
3314 // new foo.bar().baz means (new (foo.bar)()).baz 3343 // new foo.bar().baz means (new (foo.bar)()).baz
3315 // new foo()() means (new foo())() 3344 // new foo()() means (new foo())()
3316 // new new foo()() means (new (new foo())()) 3345 // new new foo()() means (new (new foo())())
3317 // new new foo means new (new foo) 3346 // new new foo means new (new foo)
3318 // new new foo() means new (new foo()) 3347 // new new foo() means new (new foo())
3319 // new new foo().bar().baz means (new (new foo()).bar()).baz 3348 // new new foo().bar().baz means (new (new foo()).bar()).baz
3320 3349
3321 if (peek() == Token::NEW) { 3350 if (peek() == Token::NEW) {
3322 BindingPatternUnexpectedToken(classifier); 3351 BindingPatternUnexpectedToken(classifier);
3323 Consume(Token::NEW); 3352 Consume(Token::NEW);
3324 int new_pos = position(); 3353 int new_pos = position();
3325 ExpressionT result = this->EmptyExpression(); 3354 ExpressionT result = this->EmptyExpression();
3326 if (peek() == Token::SUPER) { 3355 if (peek() == Token::SUPER) {
3327 const bool is_new = true; 3356 const bool is_new = true;
3328 result = ParseSuperExpression(is_new, classifier, CHECK_OK); 3357 result = ParseSuperExpression(is_new, classifier, CHECK_OK);
3329 } else if (allow_harmony_new_target() && peek() == Token::PERIOD) {
3330 return ParseNewTargetExpression(CHECK_OK);
3331 } else { 3358 } else {
3332 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); 3359 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK);
3333 } 3360 }
3334 if (peek() == Token::LPAREN) { 3361 if (peek() == Token::LPAREN) {
3335 // NewExpression with arguments. 3362 // NewExpression with arguments.
3336 Scanner::Location spread_pos; 3363 Scanner::Location spread_pos;
3337 typename Traits::Type::ExpressionList args = 3364 typename Traits::Type::ExpressionList args =
3338 this->ParseArguments(&spread_pos, classifier, CHECK_OK); 3365 this->ParseArguments(&spread_pos, classifier, CHECK_OK);
3339 3366
3340 if (spread_pos.IsValid()) { 3367 if (spread_pos.IsValid()) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
3544 3571
3545 template <class Traits> 3572 template <class Traits>
3546 typename ParserBase<Traits>::ExpressionT 3573 typename ParserBase<Traits>::ExpressionT
3547 ParserBase<Traits>::ParseSuperExpression(bool is_new, 3574 ParserBase<Traits>::ParseSuperExpression(bool is_new,
3548 ExpressionClassifier* classifier, 3575 ExpressionClassifier* classifier,
3549 bool* ok) { 3576 bool* ok) {
3550 int pos = position(); 3577 int pos = position();
3551 Expect(Token::SUPER, CHECK_OK); 3578 Expect(Token::SUPER, CHECK_OK);
3552 3579
3553 Scope* scope = scope_->DeclarationScope(); 3580 Scope* scope = scope_->DeclarationScope();
3581
3554 while (scope->is_eval_scope() || scope->is_arrow_scope()) { 3582 while (scope->is_eval_scope() || scope->is_arrow_scope()) {
3555 scope = scope->outer_scope(); 3583 scope = scope->outer_scope();
3556 DCHECK_NOT_NULL(scope); 3584 DCHECK_NOT_NULL(scope);
3557 scope = scope->DeclarationScope(); 3585 scope = scope->DeclarationScope();
3558 } 3586 }
3559 3587
3560 FunctionKind kind = scope->function_kind(); 3588 FunctionKind kind = scope->function_kind();
3561 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || 3589 if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
3562 i::IsConstructor(kind)) { 3590 i::IsConstructor(kind)) {
3563 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { 3591 if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
(...skipping 16 matching lines...) Expand all
3580 return this->SuperCallReference(scope_, factory(), pos); 3608 return this->SuperCallReference(scope_, factory(), pos);
3581 } 3609 }
3582 } 3610 }
3583 3611
3584 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); 3612 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper);
3585 *ok = false; 3613 *ok = false;
3586 return this->EmptyExpression(); 3614 return this->EmptyExpression();
3587 } 3615 }
3588 3616
3589 3617
3590 template <class Traits>
3591 typename ParserBase<Traits>::ExpressionT
3592 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
3593 int pos = position();
3594 Consume(Token::PERIOD);
3595 ExpectContextualKeyword(CStrVector("target"), CHECK_OK);
3596
3597 Scope* scope = scope_->DeclarationScope();
3598 while (scope->is_eval_scope() || scope->is_arrow_scope()) {
3599 scope = scope->outer_scope();
3600 DCHECK_NOT_NULL(scope);
3601 scope = scope->DeclarationScope();
3602 }
3603
3604 if (!scope->is_function_scope()) {
3605 ReportMessageAt(scanner()->location(),
3606 MessageTemplate::kUnexpectedNewTarget);
3607 *ok = false;
3608 return this->EmptyExpression();
3609 }
3610
3611 return this->NewTargetExpression(scope_, factory(), pos);
3612 }
3613
3614
3615 template <class Traits> 3618 template <class Traits>
3616 typename ParserBase<Traits>::ExpressionT 3619 typename ParserBase<Traits>::ExpressionT
3617 ParserBase<Traits>::ParseMemberExpressionContinuation( 3620 ParserBase<Traits>::ParseMemberExpressionContinuation(
3618 ExpressionT expression, ExpressionClassifier* classifier, bool* ok) { 3621 ExpressionT expression, ExpressionClassifier* classifier, bool* ok) {
3619 // Parses this part of MemberExpression: 3622 // Parses this part of MemberExpression:
3620 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* 3623 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)*
3621 while (true) { 3624 while (true) {
3622 switch (peek()) { 3625 switch (peek()) {
3623 case Token::LBRACK: { 3626 case Token::LBRACK: {
3624 BindingPatternUnexpectedToken(classifier); 3627 BindingPatternUnexpectedToken(classifier);
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
4046 *ok = false; 4049 *ok = false;
4047 return; 4050 return;
4048 } 4051 }
4049 has_seen_constructor_ = true; 4052 has_seen_constructor_ = true;
4050 return; 4053 return;
4051 } 4054 }
4052 } 4055 }
4053 } } // v8::internal 4056 } } // v8::internal
4054 4057
4055 #endif // V8_PREPARSER_H 4058 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698