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

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

Issue 2380663002: Revert of [parser] Refactor of ParseClass* and ParseNativeDeclaration (Closed)
Patch Set: Created 4 years, 2 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/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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // // TODO(nikolaos): this one will probably go away, as it is 126 // // TODO(nikolaos): this one will probably go away, as it is
127 // // not related to pure parsing. 127 // // not related to pure parsing.
128 // typedef Variable; 128 // typedef Variable;
129 // // Return types for traversing functions. 129 // // Return types for traversing functions.
130 // typedef Identifier; 130 // typedef Identifier;
131 // typedef Expression; 131 // typedef Expression;
132 // typedef FunctionLiteral; 132 // typedef FunctionLiteral;
133 // typedef ObjectLiteralProperty; 133 // typedef ObjectLiteralProperty;
134 // typedef ClassLiteralProperty; 134 // typedef ClassLiteralProperty;
135 // typedef ExpressionList; 135 // typedef ExpressionList;
136 // typedef ObjectPropertyList; 136 // typedef PropertyList;
137 // typedef ClassPropertyList;
138 // typedef FormalParameters; 137 // typedef FormalParameters;
139 // typedef Statement; 138 // typedef Statement;
140 // typedef StatementList; 139 // typedef StatementList;
141 // typedef Block; 140 // typedef Block;
142 // typedef BreakableStatement; 141 // typedef BreakableStatement;
143 // typedef IterationStatement; 142 // typedef IterationStatement;
144 // // For constructing objects returned by the traversing functions. 143 // // For constructing objects returned by the traversing functions.
145 // typedef Factory; 144 // typedef Factory;
146 // // For other implementation-specific tasks. 145 // // For other implementation-specific tasks.
147 // typedef Target; 146 // typedef Target;
148 // typedef TargetScope; 147 // typedef TargetScope;
149 // }; 148 // };
150 149
151 template <typename Impl> 150 template <typename Impl>
152 struct ParserTypes; 151 struct ParserTypes;
153 152
154 template <typename Impl> 153 template <typename Impl>
155 class ParserBase { 154 class ParserBase {
156 public: 155 public:
157 // Shorten type names defined by ParserTypes<Impl>. 156 // Shorten type names defined by ParserTypes<Impl>.
158 typedef ParserTypes<Impl> Types; 157 typedef ParserTypes<Impl> Types;
159 typedef typename Types::Identifier IdentifierT; 158 typedef typename Types::Identifier IdentifierT;
160 typedef typename Types::Expression ExpressionT; 159 typedef typename Types::Expression ExpressionT;
161 typedef typename Types::FunctionLiteral FunctionLiteralT; 160 typedef typename Types::FunctionLiteral FunctionLiteralT;
162 typedef typename Types::ObjectLiteralProperty ObjectLiteralPropertyT; 161 typedef typename Types::ObjectLiteralProperty ObjectLiteralPropertyT;
163 typedef typename Types::ClassLiteralProperty ClassLiteralPropertyT; 162 typedef typename Types::ClassLiteralProperty ClassLiteralPropertyT;
164 typedef typename Types::ExpressionList ExpressionListT; 163 typedef typename Types::ExpressionList ExpressionListT;
164 typedef typename Types::PropertyList PropertyListT;
165 typedef typename Types::FormalParameters FormalParametersT; 165 typedef typename Types::FormalParameters FormalParametersT;
166 typedef typename Types::Statement StatementT; 166 typedef typename Types::Statement StatementT;
167 typedef typename Types::StatementList StatementListT; 167 typedef typename Types::StatementList StatementListT;
168 typedef typename Types::Block BlockT; 168 typedef typename Types::Block BlockT;
169 typedef typename v8::internal::ExpressionClassifier<Types> 169 typedef typename v8::internal::ExpressionClassifier<Types>
170 ExpressionClassifier; 170 ExpressionClassifier;
171 171
172 // All implementation-specific methods must be called through this. 172 // All implementation-specific methods must be called through this.
173 Impl* impl() { return static_cast<Impl*>(this); } 173 Impl* impl() { return static_cast<Impl*>(this); }
174 const Impl* impl() const { return static_cast<const Impl*>(this); } 174 const Impl* impl() const { return static_cast<const Impl*>(this); }
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 : bound_names(1, parser->zone()), 664 : bound_names(1, parser->zone()),
665 mode(ForEachStatement::ENUMERATE), 665 mode(ForEachStatement::ENUMERATE),
666 each_loc(), 666 each_loc(),
667 parsing_result() {} 667 parsing_result() {}
668 ZoneList<const AstRawString*> bound_names; 668 ZoneList<const AstRawString*> bound_names;
669 ForEachStatement::VisitMode mode; 669 ForEachStatement::VisitMode mode;
670 Scanner::Location each_loc; 670 Scanner::Location each_loc;
671 DeclarationParsingResult parsing_result; 671 DeclarationParsingResult parsing_result;
672 }; 672 };
673 673
674 struct ClassInfo {
675 public:
676 explicit ClassInfo(ParserBase* parser)
677 : proxy(nullptr),
678 extends(parser->impl()->EmptyExpression()),
679 properties(parser->impl()->NewClassPropertyList(4)),
680 instance_field_initializers(parser->impl()->NewExpressionList(0)),
681 constructor(parser->impl()->EmptyFunctionLiteral()),
682 has_seen_constructor(false),
683 static_initializer_var(nullptr) {}
684 VariableProxy* proxy;
685 ExpressionT extends;
686 typename Types::ClassPropertyList properties;
687 ExpressionListT instance_field_initializers;
688 FunctionLiteralT constructor;
689 bool has_seen_constructor;
690 Variable* static_initializer_var;
691 };
692
693 DeclarationScope* NewScriptScope() const { 674 DeclarationScope* NewScriptScope() const {
694 return new (zone()) DeclarationScope(zone(), ast_value_factory()); 675 return new (zone()) DeclarationScope(zone(), ast_value_factory());
695 } 676 }
696 677
697 DeclarationScope* NewVarblockScope() const { 678 DeclarationScope* NewVarblockScope() const {
698 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); 679 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
699 } 680 }
700 681
701 ModuleScope* NewModuleScope(DeclarationScope* parent) const { 682 ModuleScope* NewModuleScope(DeclarationScope* parent) const {
702 return new (zone()) ModuleScope(parent, ast_value_factory()); 683 return new (zone()) ModuleScope(parent, ast_value_factory());
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 ExpressionT ParseMemberExpression(bool* is_async, bool* ok); 1167 ExpressionT ParseMemberExpression(bool* is_async, bool* ok);
1187 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, 1168 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression,
1188 bool* is_async, bool* ok); 1169 bool* is_async, bool* ok);
1189 ExpressionT ParseArrowFunctionLiteral(bool accept_IN, 1170 ExpressionT ParseArrowFunctionLiteral(bool accept_IN,
1190 const FormalParametersT& parameters, 1171 const FormalParametersT& parameters,
1191 bool* ok); 1172 bool* ok);
1192 void ParseAsyncFunctionBody(Scope* scope, StatementListT body, 1173 void ParseAsyncFunctionBody(Scope* scope, StatementListT body,
1193 FunctionKind kind, FunctionBodyType type, 1174 FunctionKind kind, FunctionBodyType type,
1194 bool accept_IN, int pos, bool* ok); 1175 bool accept_IN, int pos, bool* ok);
1195 ExpressionT ParseAsyncFunctionLiteral(bool* ok); 1176 ExpressionT ParseAsyncFunctionLiteral(bool* ok);
1196 ExpressionT ParseClassLiteral(IdentifierT name,
1197 Scanner::Location class_name_location,
1198 bool name_is_strict_reserved,
1199 int class_token_pos, bool* ok);
1200 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); 1177 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok);
1201 ExpressionT ParseSuperExpression(bool is_new, bool* ok); 1178 ExpressionT ParseSuperExpression(bool is_new, bool* ok);
1202 ExpressionT ParseNewTargetExpression(bool* ok); 1179 ExpressionT ParseNewTargetExpression(bool* ok);
1203 1180
1204 void ParseFormalParameter(FormalParametersT* parameters, bool* ok); 1181 void ParseFormalParameter(FormalParametersT* parameters, bool* ok);
1205 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); 1182 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok);
1206 void CheckArityRestrictions(int param_count, FunctionKind function_type, 1183 void CheckArityRestrictions(int param_count, FunctionKind function_type,
1207 bool has_rest, int formals_start_pos, 1184 bool has_rest, int formals_start_pos,
1208 int formals_end_pos, bool* ok); 1185 int formals_end_pos, bool* ok);
1209 1186
1210 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context, 1187 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context,
1211 DeclarationParsingResult* parsing_result, 1188 DeclarationParsingResult* parsing_result,
1212 ZoneList<const AstRawString*>* names, 1189 ZoneList<const AstRawString*>* names,
1213 bool* ok); 1190 bool* ok);
1214 StatementT ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, 1191 StatementT ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names,
1215 bool default_export, bool* ok); 1192 bool default_export, bool* ok);
1216 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, 1193 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
1217 bool default_export, bool* ok); 1194 bool default_export, bool* ok);
1218 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, 1195 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
1219 ZoneList<const AstRawString*>* names, 1196 ZoneList<const AstRawString*>* names,
1220 bool default_export, bool* ok); 1197 bool default_export, bool* ok);
1221 StatementT ParseClassDeclaration(ZoneList<const AstRawString*>* names,
1222 bool default_export, bool* ok);
1223 StatementT ParseNativeDeclaration(bool* ok);
1224 1198
1225 // Under some circumstances, we allow preparsing to abort if the preparsed 1199 // Under some circumstances, we allow preparsing to abort if the preparsed
1226 // function is "long and trivial", and fully parse instead. Our current 1200 // function is "long and trivial", and fully parse instead. Our current
1227 // definition of "long and trivial" is: 1201 // definition of "long and trivial" is:
1228 // - over kLazyParseTrialLimit statements 1202 // - over kLazyParseTrialLimit statements
1229 // - all starting with an identifier (i.e., no if, for, while, etc.) 1203 // - all starting with an identifier (i.e., no if, for, while, etc.)
1230 static const int kLazyParseTrialLimit = 200; 1204 static const int kLazyParseTrialLimit = 200;
1231 1205
1232 // TODO(nikolaos, marja): The first argument should not really be passed 1206 // TODO(nikolaos, marja): The first argument should not really be passed
1233 // by value. The method is expected to add the parsed statements to the 1207 // by value. The method is expected to add the parsed statements to the
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 function_state_->set_next_function_is_parenthesized(peek() == 1776 function_state_->set_next_function_is_parenthesized(peek() ==
1803 Token::FUNCTION); 1777 Token::FUNCTION);
1804 ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK); 1778 ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK);
1805 Expect(Token::RPAREN, CHECK_OK); 1779 Expect(Token::RPAREN, CHECK_OK);
1806 return expr; 1780 return expr;
1807 } 1781 }
1808 1782
1809 case Token::CLASS: { 1783 case Token::CLASS: {
1810 BindingPatternUnexpectedToken(); 1784 BindingPatternUnexpectedToken();
1811 Consume(Token::CLASS); 1785 Consume(Token::CLASS);
1812 int class_token_pos = position(); 1786 int class_token_position = position();
1813 IdentifierT name = impl()->EmptyIdentifier(); 1787 IdentifierT name = impl()->EmptyIdentifier();
1814 bool is_strict_reserved_name = false; 1788 bool is_strict_reserved_name = false;
1815 Scanner::Location class_name_location = Scanner::Location::invalid(); 1789 Scanner::Location class_name_location = Scanner::Location::invalid();
1816 if (peek_any_identifier()) { 1790 if (peek_any_identifier()) {
1817 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 1791 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
1818 CHECK_OK); 1792 CHECK_OK);
1819 class_name_location = scanner()->location(); 1793 class_name_location = scanner()->location();
1820 } 1794 }
1821 return ParseClassLiteral(name, class_name_location, 1795 return impl()->ParseClassLiteral(name, class_name_location,
1822 is_strict_reserved_name, class_token_pos, ok); 1796 is_strict_reserved_name,
1797 class_token_position, ok);
1823 } 1798 }
1824 1799
1825 case Token::TEMPLATE_SPAN: 1800 case Token::TEMPLATE_SPAN:
1826 case Token::TEMPLATE_TAIL: 1801 case Token::TEMPLATE_TAIL:
1827 BindingPatternUnexpectedToken(); 1802 BindingPatternUnexpectedToken();
1828 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok); 1803 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok);
1829 1804
1830 case Token::MOD: 1805 case Token::MOD:
1831 if (allow_natives() || extension_ != NULL) { 1806 if (allow_natives() || extension_ != NULL) {
1832 BindingPatternUnexpectedToken(); 1807 BindingPatternUnexpectedToken();
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 return impl()->EmptyObjectLiteralProperty(); 2449 return impl()->EmptyObjectLiteralProperty();
2475 } 2450 }
2476 2451
2477 template <typename Impl> 2452 template <typename Impl>
2478 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( 2453 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
2479 bool* ok) { 2454 bool* ok) {
2480 // ObjectLiteral :: 2455 // ObjectLiteral ::
2481 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 2456 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
2482 2457
2483 int pos = peek_position(); 2458 int pos = peek_position();
2484 typename Types::ObjectPropertyList properties = 2459 PropertyListT properties = impl()->NewPropertyList(4);
2485 impl()->NewObjectPropertyList(4);
2486 int number_of_boilerplate_properties = 0; 2460 int number_of_boilerplate_properties = 0;
2487 bool has_computed_names = false; 2461 bool has_computed_names = false;
2488 ObjectLiteralChecker checker(this); 2462 ObjectLiteralChecker checker(this);
2489 2463
2490 Expect(Token::LBRACE, CHECK_OK); 2464 Expect(Token::LBRACE, CHECK_OK);
2491 2465
2492 while (peek() != Token::RBRACE) { 2466 while (peek() != Token::RBRACE) {
2493 FuncNameInferrer::State fni_state(fni_); 2467 FuncNameInferrer::State fni_state(fni_);
2494 2468
2495 bool is_computed_name = false; 2469 bool is_computed_name = false;
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
3720 : is_async ? FunctionKind::kAsyncFunction 3694 : is_async ? FunctionKind::kAsyncFunction
3721 : FunctionKind::kNormalFunction, 3695 : FunctionKind::kNormalFunction,
3722 pos, FunctionLiteral::kDeclaration, language_mode(), 3696 pos, FunctionLiteral::kDeclaration, language_mode(),
3723 CHECK_OK_CUSTOM(NullStatement)); 3697 CHECK_OK_CUSTOM(NullStatement));
3724 3698
3725 return impl()->DeclareFunction(variable_name, function, pos, is_generator, 3699 return impl()->DeclareFunction(variable_name, function, pos, is_generator,
3726 is_async, names, ok); 3700 is_async, names, ok);
3727 } 3701 }
3728 3702
3729 template <typename Impl> 3703 template <typename Impl>
3730 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseClassDeclaration(
3731 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
3732 // ClassDeclaration ::
3733 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
3734 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
3735 //
3736 // The anonymous form is allowed iff [default_export] is true.
3737 //
3738 // 'class' is expected to be consumed by the caller.
3739 //
3740 // A ClassDeclaration
3741 //
3742 // class C { ... }
3743 //
3744 // has the same semantics as:
3745 //
3746 // let C = class C { ... };
3747 //
3748 // so rewrite it as such.
3749
3750 int class_token_pos = position();
3751 IdentifierT name = impl()->EmptyIdentifier();
3752 bool is_strict_reserved = false;
3753 IdentifierT variable_name = impl()->EmptyIdentifier();
3754 if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) {
3755 impl()->GetDefaultStrings(&name, &variable_name);
3756 } else {
3757 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved,
3758 CHECK_OK_CUSTOM(NullStatement));
3759 variable_name = name;
3760 }
3761
3762 ExpressionClassifier no_classifier(this);
3763 ExpressionT value =
3764 ParseClassLiteral(name, scanner()->location(), is_strict_reserved,
3765 class_token_pos, CHECK_OK_CUSTOM(NullStatement));
3766 int end_pos = position();
3767 return impl()->DeclareClass(variable_name, value, names, class_token_pos,
3768 end_pos, ok);
3769 }
3770
3771 // Language extension which is only enabled for source files loaded
3772 // through the API's extension mechanism. A native function
3773 // declaration is resolved by looking up the function through a
3774 // callback provided by the extension.
3775 template <typename Impl>
3776 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseNativeDeclaration(
3777 bool* ok) {
3778 int pos = peek_position();
3779 Expect(Token::FUNCTION, CHECK_OK_CUSTOM(NullStatement));
3780 // Allow "eval" or "arguments" for backward compatibility.
3781 IdentifierT name = ParseIdentifier(kAllowRestrictedIdentifiers,
3782 CHECK_OK_CUSTOM(NullStatement));
3783 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullStatement));
3784 if (peek() != Token::RPAREN) {
3785 do {
3786 ParseIdentifier(kAllowRestrictedIdentifiers,
3787 CHECK_OK_CUSTOM(NullStatement));
3788 } while (Check(Token::COMMA));
3789 }
3790 Expect(Token::RPAREN, CHECK_OK_CUSTOM(NullStatement));
3791 Expect(Token::SEMICOLON, CHECK_OK_CUSTOM(NullStatement));
3792 return impl()->DeclareNative(name, pos, ok);
3793 }
3794
3795 template <typename Impl>
3796 typename ParserBase<Impl>::StatementT 3704 typename ParserBase<Impl>::StatementT
3797 ParserBase<Impl>::ParseAsyncFunctionDeclaration( 3705 ParserBase<Impl>::ParseAsyncFunctionDeclaration(
3798 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { 3706 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
3799 // AsyncFunctionDeclaration :: 3707 // AsyncFunctionDeclaration ::
3800 // async [no LineTerminator here] function BindingIdentifier[Await] 3708 // async [no LineTerminator here] function BindingIdentifier[Await]
3801 // ( FormalParameters[Await] ) { AsyncFunctionBody } 3709 // ( FormalParameters[Await] ) { AsyncFunctionBody }
3802 DCHECK_EQ(scanner()->current_token(), Token::ASYNC); 3710 DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
3803 int pos = position(); 3711 int pos = position();
3804 if (scanner()->HasAnyLineTerminatorBeforeNext()) { 3712 if (scanner()->HasAnyLineTerminatorBeforeNext()) {
3805 *ok = false; 3713 *ok = false;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
4016 FunctionLiteral::kNoDuplicateParameters, 3924 FunctionLiteral::kNoDuplicateParameters,
4017 FunctionLiteral::kAnonymousExpression, eager_compile_hint, 3925 FunctionLiteral::kAnonymousExpression, eager_compile_hint,
4018 formal_parameters.scope->start_position()); 3926 formal_parameters.scope->start_position());
4019 3927
4020 function_literal->set_function_token_position( 3928 function_literal->set_function_token_position(
4021 formal_parameters.scope->start_position()); 3929 formal_parameters.scope->start_position());
4022 if (should_be_used_once_hint) { 3930 if (should_be_used_once_hint) {
4023 function_literal->set_should_be_used_once_hint(); 3931 function_literal->set_should_be_used_once_hint();
4024 } 3932 }
4025 3933
4026 impl()->AddFunctionForNameInference(function_literal); 3934 impl()->InferFunctionName(function_literal);
4027 3935
4028 return function_literal; 3936 return function_literal;
4029 } 3937 }
4030 3938
4031 template <typename Impl> 3939 template <typename Impl>
4032 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral(
4033 IdentifierT name, Scanner::Location class_name_location,
4034 bool name_is_strict_reserved, int class_token_pos, bool* ok) {
4035 // All parts of a ClassDeclaration and ClassExpression are strict code.
4036 if (name_is_strict_reserved) {
4037 impl()->ReportMessageAt(class_name_location,
4038 MessageTemplate::kUnexpectedStrictReserved);
4039 *ok = false;
4040 return impl()->EmptyExpression();
4041 }
4042 if (impl()->IsEvalOrArguments(name)) {
4043 impl()->ReportMessageAt(class_name_location,
4044 MessageTemplate::kStrictEvalArguments);
4045 *ok = false;
4046 return impl()->EmptyExpression();
4047 }
4048
4049 BlockState block_state(zone(), &scope_state_);
4050 RaiseLanguageMode(STRICT);
4051
4052 ClassInfo class_info(this);
4053 impl()->DeclareClassVariable(name, block_state.scope(), &class_info,
4054 class_token_pos, CHECK_OK);
4055
4056 if (Check(Token::EXTENDS)) {
4057 block_state.set_start_position(scanner()->location().end_pos);
4058 ExpressionClassifier extends_classifier(this);
4059 class_info.extends = ParseLeftHandSideExpression(CHECK_OK);
4060 impl()->RewriteNonPattern(CHECK_OK);
4061 impl()->AccumulateFormalParameterContainmentErrors();
4062 } else {
4063 block_state.set_start_position(scanner()->location().end_pos);
4064 }
4065
4066 ClassLiteralChecker checker(this);
4067
4068 Expect(Token::LBRACE, CHECK_OK);
4069
4070 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends);
4071 while (peek() != Token::RBRACE) {
4072 if (Check(Token::SEMICOLON)) continue;
4073 FuncNameInferrer::State fni_state(fni_);
4074 bool is_computed_name = false; // Classes do not care about computed
4075 // property names here.
4076 ExpressionClassifier property_classifier(this);
4077 ClassLiteralPropertyT property = ParseClassPropertyDefinition(
4078 &checker, has_extends, &is_computed_name,
4079 &class_info.has_seen_constructor, CHECK_OK);
4080 impl()->RewriteNonPattern(CHECK_OK);
4081 impl()->AccumulateFormalParameterContainmentErrors();
4082
4083 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK);
4084 impl()->InferFunctionName();
4085 }
4086
4087 Expect(Token::RBRACE, CHECK_OK);
4088 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok);
4089 }
4090
4091 template <typename Impl>
4092 void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body, 3940 void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body,
4093 FunctionKind kind, 3941 FunctionKind kind,
4094 FunctionBodyType body_type, 3942 FunctionBodyType body_type,
4095 bool accept_IN, int pos, 3943 bool accept_IN, int pos,
4096 bool* ok) { 3944 bool* ok) {
4097 scope->ForceContextAllocation(); 3945 scope->ForceContextAllocation();
4098 3946
4099 impl()->PrepareAsyncFunctionBody(body, kind, pos); 3947 impl()->PrepareAsyncFunctionBody(body, kind, pos);
4100 3948
4101 BlockT block = factory()->NewBlock(nullptr, 8, true, kNoSourcePosition); 3949 BlockT block = factory()->NewBlock(nullptr, 8, true, kNoSourcePosition);
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
4432 // GeneratorDeclaration[?Yield, ?Default] 4280 // GeneratorDeclaration[?Yield, ?Default]
4433 // 4281 //
4434 // LexicalDeclaration[In, Yield] : 4282 // LexicalDeclaration[In, Yield] :
4435 // LetOrConst BindingList[?In, ?Yield] ; 4283 // LetOrConst BindingList[?In, ?Yield] ;
4436 4284
4437 switch (peek()) { 4285 switch (peek()) {
4438 case Token::FUNCTION: 4286 case Token::FUNCTION:
4439 return ParseHoistableDeclaration(nullptr, false, ok); 4287 return ParseHoistableDeclaration(nullptr, false, ok);
4440 case Token::CLASS: 4288 case Token::CLASS:
4441 Consume(Token::CLASS); 4289 Consume(Token::CLASS);
4442 return ParseClassDeclaration(nullptr, false, ok); 4290 return impl()->ParseClassDeclaration(nullptr, false, ok);
4443 case Token::VAR: 4291 case Token::VAR:
4444 case Token::CONST: 4292 case Token::CONST:
4445 return ParseVariableStatement(kStatementListItem, nullptr, ok); 4293 return ParseVariableStatement(kStatementListItem, nullptr, ok);
4446 case Token::LET: 4294 case Token::LET:
4447 if (IsNextLetKeyword()) { 4295 if (IsNextLetKeyword()) {
4448 return ParseVariableStatement(kStatementListItem, nullptr, ok); 4296 return ParseVariableStatement(kStatementListItem, nullptr, ok);
4449 } 4297 }
4450 break; 4298 break;
4451 case Token::ASYNC: 4299 case Token::ASYNC:
4452 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && 4300 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION &&
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4710 } 4558 }
4711 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); 4559 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok);
4712 } 4560 }
4713 4561
4714 // If we have an extension, we allow a native function declaration. 4562 // If we have an extension, we allow a native function declaration.
4715 // A native function declaration starts with "native function" with 4563 // A native function declaration starts with "native function" with
4716 // no line-terminator between the two words. 4564 // no line-terminator between the two words.
4717 if (extension_ != nullptr && peek() == Token::FUNCTION && 4565 if (extension_ != nullptr && peek() == Token::FUNCTION &&
4718 !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) && 4566 !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) &&
4719 !scanner()->literal_contains_escapes()) { 4567 !scanner()->literal_contains_escapes()) {
4720 return ParseNativeDeclaration(ok); 4568 return impl()->ParseNativeDeclaration(ok);
4721 } 4569 }
4722 4570
4723 // Parsed expression statement, followed by semicolon. 4571 // Parsed expression statement, followed by semicolon.
4724 ExpectSemicolon(CHECK_OK); 4572 ExpectSemicolon(CHECK_OK);
4725 return factory()->NewExpressionStatement(expr, pos); 4573 return factory()->NewExpressionStatement(expr, pos);
4726 } 4574 }
4727 4575
4728 template <typename Impl> 4576 template <typename Impl>
4729 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement( 4577 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
4730 ZoneList<const AstRawString*>* labels, bool* ok) { 4578 ZoneList<const AstRawString*>* labels, bool* ok) {
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
5437 has_seen_constructor_ = true; 5285 has_seen_constructor_ = true;
5438 return; 5286 return;
5439 } 5287 }
5440 } 5288 }
5441 5289
5442 5290
5443 } // namespace internal 5291 } // namespace internal
5444 } // namespace v8 5292 } // namespace v8
5445 5293
5446 #endif // V8_PARSING_PARSER_BASE_H 5294 #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