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

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

Issue 2368083002: [parser] Refactor of ParseClass* and ParseNativeDeclaration (Closed)
Patch Set: Rebase again 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 PropertyList; 136 // typedef ObjectPropertyList;
137 // typedef ClassPropertyList;
137 // typedef FormalParameters; 138 // typedef FormalParameters;
138 // typedef Statement; 139 // typedef Statement;
139 // typedef StatementList; 140 // typedef StatementList;
140 // typedef Block; 141 // typedef Block;
141 // typedef BreakableStatement; 142 // typedef BreakableStatement;
142 // typedef IterationStatement; 143 // typedef IterationStatement;
143 // // For constructing objects returned by the traversing functions. 144 // // For constructing objects returned by the traversing functions.
144 // typedef Factory; 145 // typedef Factory;
145 // // For other implementation-specific tasks. 146 // // For other implementation-specific tasks.
146 // typedef Target; 147 // typedef Target;
147 // typedef TargetScope; 148 // typedef TargetScope;
148 // }; 149 // };
149 150
150 template <typename Impl> 151 template <typename Impl>
151 struct ParserTypes; 152 struct ParserTypes;
152 153
153 template <typename Impl> 154 template <typename Impl>
154 class ParserBase { 155 class ParserBase {
155 public: 156 public:
156 // Shorten type names defined by ParserTypes<Impl>. 157 // Shorten type names defined by ParserTypes<Impl>.
157 typedef ParserTypes<Impl> Types; 158 typedef ParserTypes<Impl> Types;
158 typedef typename Types::Identifier IdentifierT; 159 typedef typename Types::Identifier IdentifierT;
159 typedef typename Types::Expression ExpressionT; 160 typedef typename Types::Expression ExpressionT;
160 typedef typename Types::FunctionLiteral FunctionLiteralT; 161 typedef typename Types::FunctionLiteral FunctionLiteralT;
161 typedef typename Types::ObjectLiteralProperty ObjectLiteralPropertyT; 162 typedef typename Types::ObjectLiteralProperty ObjectLiteralPropertyT;
162 typedef typename Types::ClassLiteralProperty ClassLiteralPropertyT; 163 typedef typename Types::ClassLiteralProperty ClassLiteralPropertyT;
163 typedef typename Types::ExpressionList ExpressionListT; 164 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
674 DeclarationScope* NewScriptScope() const { 693 DeclarationScope* NewScriptScope() const {
675 return new (zone()) DeclarationScope(zone(), ast_value_factory()); 694 return new (zone()) DeclarationScope(zone(), ast_value_factory());
676 } 695 }
677 696
678 DeclarationScope* NewVarblockScope() const { 697 DeclarationScope* NewVarblockScope() const {
679 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); 698 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
680 } 699 }
681 700
682 ModuleScope* NewModuleScope(DeclarationScope* parent) const { 701 ModuleScope* NewModuleScope(DeclarationScope* parent) const {
683 return new (zone()) ModuleScope(parent, ast_value_factory()); 702 return new (zone()) ModuleScope(parent, ast_value_factory());
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 ExpressionT ParseMemberExpression(bool* is_async, bool* ok); 1186 ExpressionT ParseMemberExpression(bool* is_async, bool* ok);
1168 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, 1187 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression,
1169 bool* is_async, bool* ok); 1188 bool* is_async, bool* ok);
1170 ExpressionT ParseArrowFunctionLiteral(bool accept_IN, 1189 ExpressionT ParseArrowFunctionLiteral(bool accept_IN,
1171 const FormalParametersT& parameters, 1190 const FormalParametersT& parameters,
1172 bool* ok); 1191 bool* ok);
1173 void ParseAsyncFunctionBody(Scope* scope, StatementListT body, 1192 void ParseAsyncFunctionBody(Scope* scope, StatementListT body,
1174 FunctionKind kind, FunctionBodyType type, 1193 FunctionKind kind, FunctionBodyType type,
1175 bool accept_IN, int pos, bool* ok); 1194 bool accept_IN, int pos, bool* ok);
1176 ExpressionT ParseAsyncFunctionLiteral(bool* ok); 1195 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);
1177 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); 1200 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok);
1178 ExpressionT ParseSuperExpression(bool is_new, bool* ok); 1201 ExpressionT ParseSuperExpression(bool is_new, bool* ok);
1179 ExpressionT ParseNewTargetExpression(bool* ok); 1202 ExpressionT ParseNewTargetExpression(bool* ok);
1180 1203
1181 void ParseFormalParameter(FormalParametersT* parameters, bool* ok); 1204 void ParseFormalParameter(FormalParametersT* parameters, bool* ok);
1182 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); 1205 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok);
1183 void CheckArityRestrictions(int param_count, FunctionKind function_type, 1206 void CheckArityRestrictions(int param_count, FunctionKind function_type,
1184 bool has_rest, int formals_start_pos, 1207 bool has_rest, int formals_start_pos,
1185 int formals_end_pos, bool* ok); 1208 int formals_end_pos, bool* ok);
1186 1209
1187 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context, 1210 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context,
1188 DeclarationParsingResult* parsing_result, 1211 DeclarationParsingResult* parsing_result,
1189 ZoneList<const AstRawString*>* names, 1212 ZoneList<const AstRawString*>* names,
1190 bool* ok); 1213 bool* ok);
1191 StatementT ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, 1214 StatementT ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names,
1192 bool default_export, bool* ok); 1215 bool default_export, bool* ok);
1193 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, 1216 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
1194 bool default_export, bool* ok); 1217 bool default_export, bool* ok);
1195 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, 1218 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
1196 ZoneList<const AstRawString*>* names, 1219 ZoneList<const AstRawString*>* names,
1197 bool default_export, bool* ok); 1220 bool default_export, bool* ok);
1221 StatementT ParseClassDeclaration(ZoneList<const AstRawString*>* names,
1222 bool default_export, bool* ok);
1223 StatementT ParseNativeDeclaration(bool* ok);
1198 1224
1199 // Under some circumstances, we allow preparsing to abort if the preparsed 1225 // Under some circumstances, we allow preparsing to abort if the preparsed
1200 // function is "long and trivial", and fully parse instead. Our current 1226 // function is "long and trivial", and fully parse instead. Our current
1201 // definition of "long and trivial" is: 1227 // definition of "long and trivial" is:
1202 // - over kLazyParseTrialLimit statements 1228 // - over kLazyParseTrialLimit statements
1203 // - all starting with an identifier (i.e., no if, for, while, etc.) 1229 // - all starting with an identifier (i.e., no if, for, while, etc.)
1204 static const int kLazyParseTrialLimit = 200; 1230 static const int kLazyParseTrialLimit = 200;
1205 1231
1206 // TODO(nikolaos, marja): The first argument should not really be passed 1232 // TODO(nikolaos, marja): The first argument should not really be passed
1207 // by value. The method is expected to add the parsed statements to the 1233 // 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
1776 function_state_->set_next_function_is_parenthesized(peek() == 1802 function_state_->set_next_function_is_parenthesized(peek() ==
1777 Token::FUNCTION); 1803 Token::FUNCTION);
1778 ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK); 1804 ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK);
1779 Expect(Token::RPAREN, CHECK_OK); 1805 Expect(Token::RPAREN, CHECK_OK);
1780 return expr; 1806 return expr;
1781 } 1807 }
1782 1808
1783 case Token::CLASS: { 1809 case Token::CLASS: {
1784 BindingPatternUnexpectedToken(); 1810 BindingPatternUnexpectedToken();
1785 Consume(Token::CLASS); 1811 Consume(Token::CLASS);
1786 int class_token_position = position(); 1812 int class_token_pos = position();
1787 IdentifierT name = impl()->EmptyIdentifier(); 1813 IdentifierT name = impl()->EmptyIdentifier();
1788 bool is_strict_reserved_name = false; 1814 bool is_strict_reserved_name = false;
1789 Scanner::Location class_name_location = Scanner::Location::invalid(); 1815 Scanner::Location class_name_location = Scanner::Location::invalid();
1790 if (peek_any_identifier()) { 1816 if (peek_any_identifier()) {
1791 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 1817 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
1792 CHECK_OK); 1818 CHECK_OK);
1793 class_name_location = scanner()->location(); 1819 class_name_location = scanner()->location();
1794 } 1820 }
1795 return impl()->ParseClassLiteral(name, class_name_location, 1821 return ParseClassLiteral(name, class_name_location,
1796 is_strict_reserved_name, 1822 is_strict_reserved_name, class_token_pos, ok);
1797 class_token_position, ok);
1798 } 1823 }
1799 1824
1800 case Token::TEMPLATE_SPAN: 1825 case Token::TEMPLATE_SPAN:
1801 case Token::TEMPLATE_TAIL: 1826 case Token::TEMPLATE_TAIL:
1802 BindingPatternUnexpectedToken(); 1827 BindingPatternUnexpectedToken();
1803 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok); 1828 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok);
1804 1829
1805 case Token::MOD: 1830 case Token::MOD:
1806 if (allow_natives() || extension_ != NULL) { 1831 if (allow_natives() || extension_ != NULL) {
1807 BindingPatternUnexpectedToken(); 1832 BindingPatternUnexpectedToken();
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 return impl()->EmptyObjectLiteralProperty(); 2474 return impl()->EmptyObjectLiteralProperty();
2450 } 2475 }
2451 2476
2452 template <typename Impl> 2477 template <typename Impl>
2453 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( 2478 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
2454 bool* ok) { 2479 bool* ok) {
2455 // ObjectLiteral :: 2480 // ObjectLiteral ::
2456 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 2481 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
2457 2482
2458 int pos = peek_position(); 2483 int pos = peek_position();
2459 PropertyListT properties = impl()->NewPropertyList(4); 2484 typename Types::ObjectPropertyList properties =
2485 impl()->NewObjectPropertyList(4);
2460 int number_of_boilerplate_properties = 0; 2486 int number_of_boilerplate_properties = 0;
2461 bool has_computed_names = false; 2487 bool has_computed_names = false;
2462 ObjectLiteralChecker checker(this); 2488 ObjectLiteralChecker checker(this);
2463 2489
2464 Expect(Token::LBRACE, CHECK_OK); 2490 Expect(Token::LBRACE, CHECK_OK);
2465 2491
2466 while (peek() != Token::RBRACE) { 2492 while (peek() != Token::RBRACE) {
2467 FuncNameInferrer::State fni_state(fni_); 2493 FuncNameInferrer::State fni_state(fni_);
2468 2494
2469 bool is_computed_name = false; 2495 bool is_computed_name = false;
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
3694 : is_async ? FunctionKind::kAsyncFunction 3720 : is_async ? FunctionKind::kAsyncFunction
3695 : FunctionKind::kNormalFunction, 3721 : FunctionKind::kNormalFunction,
3696 pos, FunctionLiteral::kDeclaration, language_mode(), 3722 pos, FunctionLiteral::kDeclaration, language_mode(),
3697 CHECK_OK_CUSTOM(NullStatement)); 3723 CHECK_OK_CUSTOM(NullStatement));
3698 3724
3699 return impl()->DeclareFunction(variable_name, function, pos, is_generator, 3725 return impl()->DeclareFunction(variable_name, function, pos, is_generator,
3700 is_async, names, ok); 3726 is_async, names, ok);
3701 } 3727 }
3702 3728
3703 template <typename Impl> 3729 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>
3704 typename ParserBase<Impl>::StatementT 3796 typename ParserBase<Impl>::StatementT
3705 ParserBase<Impl>::ParseAsyncFunctionDeclaration( 3797 ParserBase<Impl>::ParseAsyncFunctionDeclaration(
3706 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { 3798 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
3707 // AsyncFunctionDeclaration :: 3799 // AsyncFunctionDeclaration ::
3708 // async [no LineTerminator here] function BindingIdentifier[Await] 3800 // async [no LineTerminator here] function BindingIdentifier[Await]
3709 // ( FormalParameters[Await] ) { AsyncFunctionBody } 3801 // ( FormalParameters[Await] ) { AsyncFunctionBody }
3710 DCHECK_EQ(scanner()->current_token(), Token::ASYNC); 3802 DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
3711 int pos = position(); 3803 int pos = position();
3712 if (scanner()->HasAnyLineTerminatorBeforeNext()) { 3804 if (scanner()->HasAnyLineTerminatorBeforeNext()) {
3713 *ok = false; 3805 *ok = false;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 FunctionLiteral::kNoDuplicateParameters, 4016 FunctionLiteral::kNoDuplicateParameters,
3925 FunctionLiteral::kAnonymousExpression, eager_compile_hint, 4017 FunctionLiteral::kAnonymousExpression, eager_compile_hint,
3926 formal_parameters.scope->start_position()); 4018 formal_parameters.scope->start_position());
3927 4019
3928 function_literal->set_function_token_position( 4020 function_literal->set_function_token_position(
3929 formal_parameters.scope->start_position()); 4021 formal_parameters.scope->start_position());
3930 if (should_be_used_once_hint) { 4022 if (should_be_used_once_hint) {
3931 function_literal->set_should_be_used_once_hint(); 4023 function_literal->set_should_be_used_once_hint();
3932 } 4024 }
3933 4025
3934 impl()->InferFunctionName(function_literal); 4026 impl()->AddFunctionForNameInference(function_literal);
3935 4027
3936 return function_literal; 4028 return function_literal;
3937 } 4029 }
3938 4030
3939 template <typename Impl> 4031 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>
3940 void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body, 4092 void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body,
3941 FunctionKind kind, 4093 FunctionKind kind,
3942 FunctionBodyType body_type, 4094 FunctionBodyType body_type,
3943 bool accept_IN, int pos, 4095 bool accept_IN, int pos,
3944 bool* ok) { 4096 bool* ok) {
3945 scope->ForceContextAllocation(); 4097 scope->ForceContextAllocation();
3946 4098
3947 impl()->PrepareAsyncFunctionBody(body, kind, pos); 4099 impl()->PrepareAsyncFunctionBody(body, kind, pos);
3948 4100
3949 BlockT block = factory()->NewBlock(nullptr, 8, true, kNoSourcePosition); 4101 BlockT block = factory()->NewBlock(nullptr, 8, true, kNoSourcePosition);
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
4280 // GeneratorDeclaration[?Yield, ?Default] 4432 // GeneratorDeclaration[?Yield, ?Default]
4281 // 4433 //
4282 // LexicalDeclaration[In, Yield] : 4434 // LexicalDeclaration[In, Yield] :
4283 // LetOrConst BindingList[?In, ?Yield] ; 4435 // LetOrConst BindingList[?In, ?Yield] ;
4284 4436
4285 switch (peek()) { 4437 switch (peek()) {
4286 case Token::FUNCTION: 4438 case Token::FUNCTION:
4287 return ParseHoistableDeclaration(nullptr, false, ok); 4439 return ParseHoistableDeclaration(nullptr, false, ok);
4288 case Token::CLASS: 4440 case Token::CLASS:
4289 Consume(Token::CLASS); 4441 Consume(Token::CLASS);
4290 return impl()->ParseClassDeclaration(nullptr, false, ok); 4442 return ParseClassDeclaration(nullptr, false, ok);
4291 case Token::VAR: 4443 case Token::VAR:
4292 case Token::CONST: 4444 case Token::CONST:
4293 return ParseVariableStatement(kStatementListItem, nullptr, ok); 4445 return ParseVariableStatement(kStatementListItem, nullptr, ok);
4294 case Token::LET: 4446 case Token::LET:
4295 if (IsNextLetKeyword()) { 4447 if (IsNextLetKeyword()) {
4296 return ParseVariableStatement(kStatementListItem, nullptr, ok); 4448 return ParseVariableStatement(kStatementListItem, nullptr, ok);
4297 } 4449 }
4298 break; 4450 break;
4299 case Token::ASYNC: 4451 case Token::ASYNC:
4300 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && 4452 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION &&
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4558 } 4710 }
4559 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); 4711 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok);
4560 } 4712 }
4561 4713
4562 // If we have an extension, we allow a native function declaration. 4714 // If we have an extension, we allow a native function declaration.
4563 // A native function declaration starts with "native function" with 4715 // A native function declaration starts with "native function" with
4564 // no line-terminator between the two words. 4716 // no line-terminator between the two words.
4565 if (extension_ != nullptr && peek() == Token::FUNCTION && 4717 if (extension_ != nullptr && peek() == Token::FUNCTION &&
4566 !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) && 4718 !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) &&
4567 !scanner()->literal_contains_escapes()) { 4719 !scanner()->literal_contains_escapes()) {
4568 return impl()->ParseNativeDeclaration(ok); 4720 return ParseNativeDeclaration(ok);
4569 } 4721 }
4570 4722
4571 // Parsed expression statement, followed by semicolon. 4723 // Parsed expression statement, followed by semicolon.
4572 ExpectSemicolon(CHECK_OK); 4724 ExpectSemicolon(CHECK_OK);
4573 return factory()->NewExpressionStatement(expr, pos); 4725 return factory()->NewExpressionStatement(expr, pos);
4574 } 4726 }
4575 4727
4576 template <typename Impl> 4728 template <typename Impl>
4577 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement( 4729 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
4578 ZoneList<const AstRawString*>* labels, bool* ok) { 4730 ZoneList<const AstRawString*>* labels, bool* ok) {
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
5285 has_seen_constructor_ = true; 5437 has_seen_constructor_ = true;
5286 return; 5438 return;
5287 } 5439 }
5288 } 5440 }
5289 5441
5290 5442
5291 } // namespace internal 5443 } // namespace internal
5292 } // namespace v8 5444 } // namespace v8
5293 5445
5294 #endif // V8_PARSING_PARSER_BASE_H 5446 #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