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

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

Issue 2368083002: [parser] Refactor of ParseClass* and ParseNativeDeclaration (Closed)
Patch Set: More changes to address reviewers' comments 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
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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 : bound_names(1, parser->zone()), 673 : bound_names(1, parser->zone()),
674 mode(ForEachStatement::ENUMERATE), 674 mode(ForEachStatement::ENUMERATE),
675 each_loc(), 675 each_loc(),
676 parsing_result() {} 676 parsing_result() {}
677 ZoneList<const AstRawString*> bound_names; 677 ZoneList<const AstRawString*> bound_names;
678 ForEachStatement::VisitMode mode; 678 ForEachStatement::VisitMode mode;
679 Scanner::Location each_loc; 679 Scanner::Location each_loc;
680 DeclarationParsingResult parsing_result; 680 DeclarationParsingResult parsing_result;
681 }; 681 };
682 682
683 struct ClassInfo {
684 public:
685 explicit ClassInfo(ParserBase* parser)
686 : proxy(nullptr),
687 extends(parser->impl()->EmptyExpression()),
688 properties(parser->impl()->NewClassPropertyList(4)),
689 instance_field_initializers(parser->impl()->NewExpressionList(0)),
690 constructor(parser->impl()->EmptyFunctionLiteral()),
691 has_seen_constructor(false),
692 static_initializer_var(nullptr) {}
693 VariableProxy* proxy;
694 ExpressionT extends;
695 typename Types::ClassPropertyList properties;
696 ExpressionListT instance_field_initializers;
697 FunctionLiteralT constructor;
698 bool has_seen_constructor;
699 Variable* static_initializer_var;
700 };
701
683 DeclarationScope* NewScriptScope() const { 702 DeclarationScope* NewScriptScope() const {
684 return new (zone()) DeclarationScope(zone(), ast_value_factory()); 703 return new (zone()) DeclarationScope(zone(), ast_value_factory());
685 } 704 }
686 705
687 DeclarationScope* NewVarblockScope() const { 706 DeclarationScope* NewVarblockScope() const {
688 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); 707 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE);
689 } 708 }
690 709
691 ModuleScope* NewModuleScope(DeclarationScope* parent) const { 710 ModuleScope* NewModuleScope(DeclarationScope* parent) const {
692 return new (zone()) ModuleScope(parent, ast_value_factory()); 711 return new (zone()) ModuleScope(parent, ast_value_factory());
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 ExpressionT ParsePostfixExpression(bool* ok); 1201 ExpressionT ParsePostfixExpression(bool* ok);
1183 ExpressionT ParseLeftHandSideExpression(bool* ok); 1202 ExpressionT ParseLeftHandSideExpression(bool* ok);
1184 ExpressionT ParseMemberWithNewPrefixesExpression(bool* is_async, bool* ok); 1203 ExpressionT ParseMemberWithNewPrefixesExpression(bool* is_async, bool* ok);
1185 ExpressionT ParseMemberExpression(bool* is_async, bool* ok); 1204 ExpressionT ParseMemberExpression(bool* is_async, bool* ok);
1186 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, 1205 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression,
1187 bool* is_async, bool* ok); 1206 bool* is_async, bool* ok);
1188 ExpressionT ParseArrowFunctionLiteral(bool accept_IN, 1207 ExpressionT ParseArrowFunctionLiteral(bool accept_IN,
1189 const FormalParametersT& parameters, 1208 const FormalParametersT& parameters,
1190 bool is_async, 1209 bool is_async,
1191 bool* ok); 1210 bool* ok);
1211 ExpressionT ParseClassLiteral(IdentifierT name,
1212 Scanner::Location class_name_location,
1213 bool name_is_strict_reserved,
1214 int class_token_pos, bool* ok);
1192 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); 1215 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok);
1193 ExpressionT ParseSuperExpression(bool is_new, bool* ok); 1216 ExpressionT ParseSuperExpression(bool is_new, bool* ok);
1194 ExpressionT ParseNewTargetExpression(bool* ok); 1217 ExpressionT ParseNewTargetExpression(bool* ok);
1195 1218
1196 void ParseFormalParameter(FormalParametersT* parameters, bool* ok); 1219 void ParseFormalParameter(FormalParametersT* parameters, bool* ok);
1197 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); 1220 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok);
1198 void CheckArityRestrictions(int param_count, FunctionKind function_type, 1221 void CheckArityRestrictions(int param_count, FunctionKind function_type,
1199 bool has_rest, int formals_start_pos, 1222 bool has_rest, int formals_start_pos,
1200 int formals_end_pos, bool* ok); 1223 int formals_end_pos, bool* ok);
1201 1224
1202 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context, 1225 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context,
1203 DeclarationParsingResult* parsing_result, 1226 DeclarationParsingResult* parsing_result,
1204 ZoneList<const AstRawString*>* names, 1227 ZoneList<const AstRawString*>* names,
1205 bool* ok); 1228 bool* ok);
1206 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, 1229 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
1207 bool default_export, bool* ok); 1230 bool default_export, bool* ok);
1208 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, 1231 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
1209 ZoneList<const AstRawString*>* names, 1232 ZoneList<const AstRawString*>* names,
1210 bool default_export, bool* ok); 1233 bool default_export, bool* ok);
1234 StatementT ParseClassDeclaration(ZoneList<const AstRawString*>* names,
1235 bool default_export, bool* ok);
1236 StatementT ParseNativeDeclaration(bool* ok);
1211 1237
1212 // Under some circumstances, we allow preparsing to abort if the preparsed 1238 // Under some circumstances, we allow preparsing to abort if the preparsed
1213 // function is "long and trivial", and fully parse instead. Our current 1239 // function is "long and trivial", and fully parse instead. Our current
1214 // definition of "long and trivial" is: 1240 // definition of "long and trivial" is:
1215 // - over kLazyParseTrialLimit statements 1241 // - over kLazyParseTrialLimit statements
1216 // - all starting with an identifier (i.e., no if, for, while, etc.) 1242 // - all starting with an identifier (i.e., no if, for, while, etc.)
1217 static const int kLazyParseTrialLimit = 200; 1243 static const int kLazyParseTrialLimit = 200;
1218 1244
1219 // TODO(nikolaos, marja): The first argument should not really be passed 1245 // TODO(nikolaos, marja): The first argument should not really be passed
1220 // by value. The method is expected to add the parsed statements to the 1246 // by value. The method is expected to add the parsed statements to the
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 function_state_->set_next_function_is_parenthesized(peek() == 1816 function_state_->set_next_function_is_parenthesized(peek() ==
1791 Token::FUNCTION); 1817 Token::FUNCTION);
1792 ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK); 1818 ExpressionT expr = ParseExpressionCoverGrammar(true, CHECK_OK);
1793 Expect(Token::RPAREN, CHECK_OK); 1819 Expect(Token::RPAREN, CHECK_OK);
1794 return expr; 1820 return expr;
1795 } 1821 }
1796 1822
1797 case Token::CLASS: { 1823 case Token::CLASS: {
1798 BindingPatternUnexpectedToken(); 1824 BindingPatternUnexpectedToken();
1799 Consume(Token::CLASS); 1825 Consume(Token::CLASS);
1800 int class_token_position = position(); 1826 int class_token_pos = position();
1801 IdentifierT name = impl()->EmptyIdentifier(); 1827 IdentifierT name = impl()->EmptyIdentifier();
1802 bool is_strict_reserved_name = false; 1828 bool is_strict_reserved_name = false;
1803 Scanner::Location class_name_location = Scanner::Location::invalid(); 1829 Scanner::Location class_name_location = Scanner::Location::invalid();
1804 if (peek_any_identifier()) { 1830 if (peek_any_identifier()) {
1805 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 1831 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
1806 CHECK_OK); 1832 CHECK_OK);
1807 class_name_location = scanner()->location(); 1833 class_name_location = scanner()->location();
1808 } 1834 }
1809 return impl()->ParseClassLiteral(name, class_name_location, 1835 return ParseClassLiteral(name, class_name_location,
1810 is_strict_reserved_name, 1836 is_strict_reserved_name, class_token_pos, ok);
1811 class_token_position, ok);
1812 } 1837 }
1813 1838
1814 case Token::TEMPLATE_SPAN: 1839 case Token::TEMPLATE_SPAN:
1815 case Token::TEMPLATE_TAIL: 1840 case Token::TEMPLATE_TAIL:
1816 BindingPatternUnexpectedToken(); 1841 BindingPatternUnexpectedToken();
1817 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok); 1842 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok);
1818 1843
1819 case Token::MOD: 1844 case Token::MOD:
1820 if (allow_natives() || extension_ != NULL) { 1845 if (allow_natives() || extension_ != NULL) {
1821 BindingPatternUnexpectedToken(); 1846 BindingPatternUnexpectedToken();
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 return impl()->EmptyObjectLiteralProperty(); 2492 return impl()->EmptyObjectLiteralProperty();
2468 } 2493 }
2469 2494
2470 template <typename Impl> 2495 template <typename Impl>
2471 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( 2496 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
2472 bool* ok) { 2497 bool* ok) {
2473 // ObjectLiteral :: 2498 // ObjectLiteral ::
2474 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 2499 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
2475 2500
2476 int pos = peek_position(); 2501 int pos = peek_position();
2477 PropertyListT properties = impl()->NewPropertyList(4); 2502 typename Types::ObjectPropertyList properties =
2503 impl()->NewObjectPropertyList(4);
2478 int number_of_boilerplate_properties = 0; 2504 int number_of_boilerplate_properties = 0;
2479 bool has_computed_names = false; 2505 bool has_computed_names = false;
2480 ObjectLiteralChecker checker(this); 2506 ObjectLiteralChecker checker(this);
2481 2507
2482 Expect(Token::LBRACE, CHECK_OK); 2508 Expect(Token::LBRACE, CHECK_OK);
2483 2509
2484 while (peek() != Token::RBRACE) { 2510 while (peek() != Token::RBRACE) {
2485 FuncNameInferrer::State fni_state(fni_); 2511 FuncNameInferrer::State fni_state(fni_);
2486 2512
2487 bool is_computed_name = false; 2513 bool is_computed_name = false;
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 : is_async ? FunctionKind::kAsyncFunction 3825 : is_async ? FunctionKind::kAsyncFunction
3800 : FunctionKind::kNormalFunction, 3826 : FunctionKind::kNormalFunction,
3801 pos, FunctionLiteral::kDeclaration, language_mode(), 3827 pos, FunctionLiteral::kDeclaration, language_mode(),
3802 CHECK_OK_CUSTOM(NullStatement)); 3828 CHECK_OK_CUSTOM(NullStatement));
3803 3829
3804 return impl()->DeclareFunction(variable_name, function, pos, is_generator, 3830 return impl()->DeclareFunction(variable_name, function, pos, is_generator,
3805 is_async, names, ok); 3831 is_async, names, ok);
3806 } 3832 }
3807 3833
3808 template <typename Impl> 3834 template <typename Impl>
3835 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseClassDeclaration(
3836 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
3837 // ClassDeclaration ::
3838 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
3839 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
3840 //
3841 // The anonymous form is allowed iff [default_export] is true.
3842 //
3843 // 'class' is expected to be consumed by the caller.
3844 //
3845 // A ClassDeclaration
3846 //
3847 // class C { ... }
3848 //
3849 // has the same semantics as:
3850 //
3851 // let C = class C { ... };
3852 //
3853 // so rewrite it as such.
3854
3855 int class_token_pos = position();
3856 IdentifierT name = impl()->EmptyIdentifier();
3857 bool is_strict_reserved = false;
3858 IdentifierT variable_name = impl()->EmptyIdentifier();
3859 if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) {
3860 impl()->GetDefaultStrings(&name, &variable_name);
3861 } else {
3862 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved,
3863 CHECK_OK_CUSTOM(NullStatement));
3864 variable_name = name;
3865 }
3866
3867 ExpressionClassifier no_classifier(this);
3868 ExpressionT value =
3869 ParseClassLiteral(name, scanner()->location(), is_strict_reserved,
3870 class_token_pos, CHECK_OK_CUSTOM(NullStatement));
3871 return impl()->DeclareClass(variable_name, value, names, class_token_pos, ok);
3872 }
3873
3874 // Language extension which is only enabled for source files loaded
3875 // through the API's extension mechanism. A native function
3876 // declaration is resolved by looking up the function through a
3877 // callback provided by the extension.
3878 template <typename Impl>
3879 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseNativeDeclaration(
3880 bool* ok) {
3881 int pos = peek_position();
3882 Expect(Token::FUNCTION, CHECK_OK_CUSTOM(NullStatement));
3883 // Allow "eval" or "arguments" for backward compatibility.
3884 IdentifierT name = ParseIdentifier(kAllowRestrictedIdentifiers,
3885 CHECK_OK_CUSTOM(NullStatement));
3886 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullStatement));
3887 if (peek() != Token::RPAREN) {
3888 do {
3889 ParseIdentifier(kAllowRestrictedIdentifiers,
3890 CHECK_OK_CUSTOM(NullStatement));
3891 } while (Check(Token::COMMA));
3892 }
3893 Expect(Token::RPAREN, CHECK_OK_CUSTOM(NullStatement));
3894 Expect(Token::SEMICOLON, CHECK_OK_CUSTOM(NullStatement));
3895 return impl()->DeclareNative(name, pos, ok);
3896 }
3897
3898 template <typename Impl>
3809 void ParserBase<Impl>::CheckArityRestrictions(int param_count, 3899 void ParserBase<Impl>::CheckArityRestrictions(int param_count,
3810 FunctionKind function_kind, 3900 FunctionKind function_kind,
3811 bool has_rest, 3901 bool has_rest,
3812 int formals_start_pos, 3902 int formals_start_pos,
3813 int formals_end_pos, bool* ok) { 3903 int formals_end_pos, bool* ok) {
3814 if (IsGetterFunction(function_kind)) { 3904 if (IsGetterFunction(function_kind)) {
3815 if (param_count != 0) { 3905 if (param_count != 0) {
3816 impl()->ReportMessageAt( 3906 impl()->ReportMessageAt(
3817 Scanner::Location(formals_start_pos, formals_end_pos), 3907 Scanner::Location(formals_start_pos, formals_end_pos),
3818 MessageTemplate::kBadGetterArity); 3908 MessageTemplate::kBadGetterArity);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
4010 if (should_be_used_once_hint) { 4100 if (should_be_used_once_hint) {
4011 function_literal->set_should_be_used_once_hint(); 4101 function_literal->set_should_be_used_once_hint();
4012 } 4102 }
4013 4103
4014 impl()->InferFunctionName(function_literal); 4104 impl()->InferFunctionName(function_literal);
4015 4105
4016 return function_literal; 4106 return function_literal;
4017 } 4107 }
4018 4108
4019 template <typename Impl> 4109 template <typename Impl>
4110 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral(
4111 IdentifierT name, Scanner::Location class_name_location,
4112 bool name_is_strict_reserved, int class_token_pos, bool* ok) {
4113 // All parts of a ClassDeclaration and ClassExpression are strict code.
4114 if (name_is_strict_reserved) {
4115 impl()->ReportMessageAt(class_name_location,
4116 MessageTemplate::kUnexpectedStrictReserved);
4117 *ok = false;
4118 return impl()->EmptyExpression();
4119 }
4120 if (impl()->IsEvalOrArguments(name)) {
4121 impl()->ReportMessageAt(class_name_location,
4122 MessageTemplate::kStrictEvalArguments);
4123 *ok = false;
4124 return impl()->EmptyExpression();
4125 }
4126
4127 BlockState block_state(&scope_state_);
4128 RaiseLanguageMode(STRICT);
4129
4130 ClassInfo class_info(this);
4131 impl()->DeclareClassVariable(name, block_state.scope(), &class_info,
4132 class_token_pos, CHECK_OK);
4133
4134 if (Check(Token::EXTENDS)) {
4135 block_state.set_start_position(scanner()->location().end_pos);
4136 ExpressionClassifier extends_classifier(this);
4137 class_info.extends = ParseLeftHandSideExpression(CHECK_OK);
4138 CheckNoTailCallExpressions(CHECK_OK);
4139 impl()->RewriteNonPattern(CHECK_OK);
4140 impl()->AccumulateFormalParameterContainmentErrors();
4141 } else {
4142 block_state.set_start_position(scanner()->location().end_pos);
4143 }
4144
4145 ClassLiteralChecker checker(this);
4146
4147 Expect(Token::LBRACE, CHECK_OK);
4148
4149 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends);
4150 while (peek() != Token::RBRACE) {
4151 if (Check(Token::SEMICOLON)) continue;
4152 FuncNameInferrer::State fni_state(fni_);
4153 bool is_computed_name = false; // Classes do not care about computed
4154 // property names here.
4155 ExpressionClassifier property_classifier(this);
4156 ClassLiteralPropertyT property = ParseClassPropertyDefinition(
4157 &checker, has_extends, &is_computed_name,
4158 &class_info.has_seen_constructor, CHECK_OK);
4159 impl()->RewriteNonPattern(CHECK_OK);
4160 impl()->AccumulateFormalParameterContainmentErrors();
4161
4162 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK);
4163 impl()->Infer();
adamk 2016/09/26 20:36:32 This name should be longer, "Infer" is far too sho
nickie 2016/09/27 08:52:17 Done.
4164 }
4165
4166 Expect(Token::RBRACE, CHECK_OK);
4167 return impl()->RewriteClassLiteral(name, &class_info, class_token_pos, ok);
4168 }
4169
4170 template <typename Impl>
4020 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( 4171 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
4021 ExpressionT tag, int start, bool* ok) { 4172 ExpressionT tag, int start, bool* ok) {
4022 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal 4173 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal
4023 // text followed by a substitution expression), finalized by a single 4174 // text followed by a substitution expression), finalized by a single
4024 // TEMPLATE_TAIL. 4175 // TEMPLATE_TAIL.
4025 // 4176 //
4026 // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or 4177 // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or
4027 // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or 4178 // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or
4028 // NoSubstitutionTemplate. 4179 // NoSubstitutionTemplate.
4029 // 4180 //
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
4306 // GeneratorDeclaration[?Yield, ?Default] 4457 // GeneratorDeclaration[?Yield, ?Default]
4307 // 4458 //
4308 // LexicalDeclaration[In, Yield] : 4459 // LexicalDeclaration[In, Yield] :
4309 // LetOrConst BindingList[?In, ?Yield] ; 4460 // LetOrConst BindingList[?In, ?Yield] ;
4310 4461
4311 switch (peek()) { 4462 switch (peek()) {
4312 case Token::FUNCTION: 4463 case Token::FUNCTION:
4313 return ParseHoistableDeclaration(nullptr, false, ok); 4464 return ParseHoistableDeclaration(nullptr, false, ok);
4314 case Token::CLASS: 4465 case Token::CLASS:
4315 Consume(Token::CLASS); 4466 Consume(Token::CLASS);
4316 return impl()->ParseClassDeclaration(nullptr, false, ok); 4467 return ParseClassDeclaration(nullptr, false, ok);
4317 case Token::VAR: 4468 case Token::VAR:
4318 case Token::CONST: 4469 case Token::CONST:
4319 return ParseVariableStatement(kStatementListItem, nullptr, ok); 4470 return ParseVariableStatement(kStatementListItem, nullptr, ok);
4320 case Token::LET: 4471 case Token::LET:
4321 if (IsNextLetKeyword()) { 4472 if (IsNextLetKeyword()) {
4322 return ParseVariableStatement(kStatementListItem, nullptr, ok); 4473 return ParseVariableStatement(kStatementListItem, nullptr, ok);
4323 } 4474 }
4324 break; 4475 break;
4325 case Token::ASYNC: 4476 case Token::ASYNC:
4326 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && 4477 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION &&
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4584 } 4735 }
4585 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); 4736 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok);
4586 } 4737 }
4587 4738
4588 // If we have an extension, we allow a native function declaration. 4739 // If we have an extension, we allow a native function declaration.
4589 // A native function declaration starts with "native function" with 4740 // A native function declaration starts with "native function" with
4590 // no line-terminator between the two words. 4741 // no line-terminator between the two words.
4591 if (extension_ != nullptr && peek() == Token::FUNCTION && 4742 if (extension_ != nullptr && peek() == Token::FUNCTION &&
4592 !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) && 4743 !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) &&
4593 !scanner()->literal_contains_escapes()) { 4744 !scanner()->literal_contains_escapes()) {
4594 return impl()->ParseNativeDeclaration(ok); 4745 return ParseNativeDeclaration(ok);
4595 } 4746 }
4596 4747
4597 // Parsed expression statement, followed by semicolon. 4748 // Parsed expression statement, followed by semicolon.
4598 ExpectSemicolon(CHECK_OK); 4749 ExpectSemicolon(CHECK_OK);
4599 return factory()->NewExpressionStatement(expr, pos); 4750 return factory()->NewExpressionStatement(expr, pos);
4600 } 4751 }
4601 4752
4602 template <typename Impl> 4753 template <typename Impl>
4603 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement( 4754 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
4604 ZoneList<const AstRawString*>* labels, bool* ok) { 4755 ZoneList<const AstRawString*>* labels, bool* ok) {
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
5317 has_seen_constructor_ = true; 5468 has_seen_constructor_ = true;
5318 return; 5469 return;
5319 } 5470 }
5320 } 5471 }
5321 5472
5322 5473
5323 } // namespace internal 5474 } // namespace internal
5324 } // namespace v8 5475 } // namespace v8
5325 5476
5326 #endif // V8_PARSING_PARSER_BASE_H 5477 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« src/parsing/parser.cc ('K') | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698