Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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), | |
|
marja
2016/09/26 09:35:26
The creation & modification (set_end_pos) & usage
nickie
2016/09/26 17:28:12
I'm afraid not much can be done about 'proxy' here
| |
| 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 Loading... | |
| 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, int pos, | |
| 1214 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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1799 Consume(Token::CLASS); | 1825 Consume(Token::CLASS); |
| 1800 int class_token_position = position(); | 1826 int class_token_position = 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_position, |
| 1811 class_token_position, ok); | 1837 ok); |
| 1812 } | 1838 } |
| 1813 | 1839 |
| 1814 case Token::TEMPLATE_SPAN: | 1840 case Token::TEMPLATE_SPAN: |
| 1815 case Token::TEMPLATE_TAIL: | 1841 case Token::TEMPLATE_TAIL: |
| 1816 BindingPatternUnexpectedToken(); | 1842 BindingPatternUnexpectedToken(); |
| 1817 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok); | 1843 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, ok); |
| 1818 | 1844 |
| 1819 case Token::MOD: | 1845 case Token::MOD: |
| 1820 if (allow_natives() || extension_ != NULL) { | 1846 if (allow_natives() || extension_ != NULL) { |
| 1821 BindingPatternUnexpectedToken(); | 1847 BindingPatternUnexpectedToken(); |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2467 return impl()->EmptyObjectLiteralProperty(); | 2493 return impl()->EmptyObjectLiteralProperty(); |
| 2468 } | 2494 } |
| 2469 | 2495 |
| 2470 template <typename Impl> | 2496 template <typename Impl> |
| 2471 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( | 2497 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( |
| 2472 bool* ok) { | 2498 bool* ok) { |
| 2473 // ObjectLiteral :: | 2499 // ObjectLiteral :: |
| 2474 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' | 2500 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' |
| 2475 | 2501 |
| 2476 int pos = peek_position(); | 2502 int pos = peek_position(); |
| 2477 PropertyListT properties = impl()->NewPropertyList(4); | 2503 typename Types::ObjectPropertyList properties = |
| 2504 impl()->NewObjectPropertyList(4); | |
| 2478 int number_of_boilerplate_properties = 0; | 2505 int number_of_boilerplate_properties = 0; |
| 2479 bool has_computed_names = false; | 2506 bool has_computed_names = false; |
| 2480 ObjectLiteralChecker checker(this); | 2507 ObjectLiteralChecker checker(this); |
| 2481 | 2508 |
| 2482 Expect(Token::LBRACE, CHECK_OK); | 2509 Expect(Token::LBRACE, CHECK_OK); |
| 2483 | 2510 |
| 2484 while (peek() != Token::RBRACE) { | 2511 while (peek() != Token::RBRACE) { |
| 2485 FuncNameInferrer::State fni_state(fni_); | 2512 FuncNameInferrer::State fni_state(fni_); |
| 2486 | 2513 |
| 2487 bool is_computed_name = false; | 2514 bool is_computed_name = false; |
| (...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3799 : is_async ? FunctionKind::kAsyncFunction | 3826 : is_async ? FunctionKind::kAsyncFunction |
| 3800 : FunctionKind::kNormalFunction, | 3827 : FunctionKind::kNormalFunction, |
| 3801 pos, FunctionLiteral::kDeclaration, language_mode(), | 3828 pos, FunctionLiteral::kDeclaration, language_mode(), |
| 3802 CHECK_OK_CUSTOM(NullStatement)); | 3829 CHECK_OK_CUSTOM(NullStatement)); |
| 3803 | 3830 |
| 3804 return impl()->DeclareFunction(variable_name, function, pos, is_generator, | 3831 return impl()->DeclareFunction(variable_name, function, pos, is_generator, |
| 3805 is_async, names, ok); | 3832 is_async, names, ok); |
| 3806 } | 3833 } |
| 3807 | 3834 |
| 3808 template <typename Impl> | 3835 template <typename Impl> |
| 3836 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseClassDeclaration( | |
| 3837 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { | |
| 3838 // ClassDeclaration :: | |
| 3839 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' | |
| 3840 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}' | |
| 3841 // | |
| 3842 // The anonymous form is allowed iff [default_export] is true. | |
| 3843 // | |
| 3844 // 'class' is expected to be consumed by the caller. | |
| 3845 // | |
| 3846 // A ClassDeclaration | |
| 3847 // | |
| 3848 // class C { ... } | |
| 3849 // | |
| 3850 // has the same semantics as: | |
| 3851 // | |
| 3852 // let C = class C { ... }; | |
| 3853 // | |
| 3854 // so rewrite it as such. | |
| 3855 | |
| 3856 int pos = position(); | |
| 3857 IdentifierT name = impl()->EmptyIdentifier(); | |
| 3858 bool is_strict_reserved = false; | |
| 3859 IdentifierT variable_name = impl()->EmptyIdentifier(); | |
| 3860 if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) { | |
| 3861 impl()->GetDefaultStrings(&name, &variable_name); | |
| 3862 } else { | |
| 3863 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, | |
| 3864 CHECK_OK_CUSTOM(NullStatement)); | |
| 3865 variable_name = name; | |
| 3866 } | |
| 3867 | |
| 3868 ExpressionClassifier no_classifier(this); | |
| 3869 ExpressionT value = | |
| 3870 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, | |
| 3871 CHECK_OK_CUSTOM(NullStatement)); | |
| 3872 return impl()->DeclareClass(variable_name, value, names, pos, ok); | |
| 3873 } | |
| 3874 | |
| 3875 // Language extension which is only enabled for source files loaded | |
| 3876 // through the API's extension mechanism. A native function | |
| 3877 // declaration is resolved by looking up the function through a | |
| 3878 // callback provided by the extension. | |
| 3879 template <typename Impl> | |
| 3880 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseNativeDeclaration( | |
| 3881 bool* ok) { | |
| 3882 int pos = peek_position(); | |
| 3883 Expect(Token::FUNCTION, CHECK_OK_CUSTOM(NullStatement)); | |
| 3884 // Allow "eval" or "arguments" for backward compatibility. | |
| 3885 IdentifierT name = ParseIdentifier(kAllowRestrictedIdentifiers, | |
| 3886 CHECK_OK_CUSTOM(NullStatement)); | |
| 3887 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullStatement)); | |
| 3888 if (peek() != Token::RPAREN) { | |
| 3889 do { | |
| 3890 ParseIdentifier(kAllowRestrictedIdentifiers, | |
| 3891 CHECK_OK_CUSTOM(NullStatement)); | |
| 3892 } while (Check(Token::COMMA)); | |
| 3893 } | |
| 3894 Expect(Token::RPAREN, CHECK_OK_CUSTOM(NullStatement)); | |
| 3895 Expect(Token::SEMICOLON, CHECK_OK_CUSTOM(NullStatement)); | |
| 3896 return impl()->DeclareNative(name, pos, ok); | |
| 3897 } | |
| 3898 | |
| 3899 template <typename Impl> | |
| 3809 void ParserBase<Impl>::CheckArityRestrictions(int param_count, | 3900 void ParserBase<Impl>::CheckArityRestrictions(int param_count, |
| 3810 FunctionKind function_kind, | 3901 FunctionKind function_kind, |
| 3811 bool has_rest, | 3902 bool has_rest, |
| 3812 int formals_start_pos, | 3903 int formals_start_pos, |
| 3813 int formals_end_pos, bool* ok) { | 3904 int formals_end_pos, bool* ok) { |
| 3814 if (IsGetterFunction(function_kind)) { | 3905 if (IsGetterFunction(function_kind)) { |
| 3815 if (param_count != 0) { | 3906 if (param_count != 0) { |
| 3816 impl()->ReportMessageAt( | 3907 impl()->ReportMessageAt( |
| 3817 Scanner::Location(formals_start_pos, formals_end_pos), | 3908 Scanner::Location(formals_start_pos, formals_end_pos), |
| 3818 MessageTemplate::kBadGetterArity); | 3909 MessageTemplate::kBadGetterArity); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4010 if (should_be_used_once_hint) { | 4101 if (should_be_used_once_hint) { |
| 4011 function_literal->set_should_be_used_once_hint(); | 4102 function_literal->set_should_be_used_once_hint(); |
| 4012 } | 4103 } |
| 4013 | 4104 |
| 4014 impl()->InferFunctionName(function_literal); | 4105 impl()->InferFunctionName(function_literal); |
| 4015 | 4106 |
| 4016 return function_literal; | 4107 return function_literal; |
| 4017 } | 4108 } |
| 4018 | 4109 |
| 4019 template <typename Impl> | 4110 template <typename Impl> |
| 4111 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral( | |
| 4112 IdentifierT name, Scanner::Location class_name_location, | |
| 4113 bool name_is_strict_reserved, int pos, bool* ok) { | |
|
marja
2016/09/26 09:35:26
Can you rename pos into something more illustrativ
nickie
2016/09/26 12:19:59
The 'pos' is the position of the class token, not
| |
| 4114 // All parts of a ClassDeclaration and ClassExpression are strict code. | |
| 4115 if (name_is_strict_reserved) { | |
| 4116 impl()->ReportMessageAt(class_name_location, | |
| 4117 MessageTemplate::kUnexpectedStrictReserved); | |
| 4118 *ok = false; | |
| 4119 return impl()->EmptyExpression(); | |
| 4120 } | |
| 4121 if (impl()->IsEvalOrArguments(name)) { | |
| 4122 impl()->ReportMessageAt(class_name_location, | |
| 4123 MessageTemplate::kStrictEvalArguments); | |
| 4124 *ok = false; | |
| 4125 return impl()->EmptyExpression(); | |
| 4126 } | |
| 4127 | |
| 4128 BlockState block_state(&scope_state_); | |
| 4129 RaiseLanguageMode(STRICT); | |
| 4130 | |
| 4131 ClassInfo class_info(this); | |
| 4132 impl()->DeclareClassVariable(name, block_state.scope(), &class_info, pos, | |
| 4133 CHECK_OK); | |
| 4134 | |
| 4135 if (Check(Token::EXTENDS)) { | |
| 4136 block_state.set_start_position(scanner()->location().end_pos); | |
| 4137 ExpressionClassifier extends_classifier(this); | |
| 4138 class_info.extends = ParseLeftHandSideExpression(CHECK_OK); | |
| 4139 CheckNoTailCallExpressions(CHECK_OK); | |
| 4140 impl()->RewriteNonPattern(CHECK_OK); | |
| 4141 impl()->AccumulateFormalParameterContainmentErrors(); | |
| 4142 } else { | |
| 4143 block_state.set_start_position(scanner()->location().end_pos); | |
| 4144 } | |
| 4145 | |
| 4146 ClassLiteralChecker checker(this); | |
| 4147 | |
| 4148 Expect(Token::LBRACE, CHECK_OK); | |
| 4149 | |
| 4150 const bool has_extends = !impl()->IsEmptyExpression(class_info.extends); | |
| 4151 while (peek() != Token::RBRACE) { | |
| 4152 if (Check(Token::SEMICOLON)) continue; | |
| 4153 FuncNameInferrer::State fni_state(fni_); | |
| 4154 bool is_computed_name = false; // Classes do not care about computed | |
| 4155 // property names here. | |
| 4156 ExpressionClassifier property_classifier(this); | |
| 4157 ClassLiteralPropertyT property = ParseClassPropertyDefinition( | |
| 4158 &checker, has_extends, &is_computed_name, | |
| 4159 &class_info.has_seen_constructor, CHECK_OK); | |
| 4160 impl()->RewriteNonPattern(CHECK_OK); | |
| 4161 impl()->AccumulateFormalParameterContainmentErrors(); | |
| 4162 | |
| 4163 impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK); | |
| 4164 impl()->Infer(); | |
| 4165 } | |
| 4166 | |
| 4167 Expect(Token::RBRACE, CHECK_OK); | |
| 4168 return impl()->RewriteClassLiteral(name, &class_info, pos, ok); | |
| 4169 } | |
| 4170 | |
| 4171 template <typename Impl> | |
| 4020 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( | 4172 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( |
| 4021 ExpressionT tag, int start, bool* ok) { | 4173 ExpressionT tag, int start, bool* ok) { |
| 4022 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal | 4174 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal |
| 4023 // text followed by a substitution expression), finalized by a single | 4175 // text followed by a substitution expression), finalized by a single |
| 4024 // TEMPLATE_TAIL. | 4176 // TEMPLATE_TAIL. |
| 4025 // | 4177 // |
| 4026 // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or | 4178 // In terms of draft language, TEMPLATE_SPAN may be either the TemplateHead or |
| 4027 // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or | 4179 // TemplateMiddle productions, while TEMPLATE_TAIL is either TemplateTail, or |
| 4028 // NoSubstitutionTemplate. | 4180 // NoSubstitutionTemplate. |
| 4029 // | 4181 // |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4306 // GeneratorDeclaration[?Yield, ?Default] | 4458 // GeneratorDeclaration[?Yield, ?Default] |
| 4307 // | 4459 // |
| 4308 // LexicalDeclaration[In, Yield] : | 4460 // LexicalDeclaration[In, Yield] : |
| 4309 // LetOrConst BindingList[?In, ?Yield] ; | 4461 // LetOrConst BindingList[?In, ?Yield] ; |
| 4310 | 4462 |
| 4311 switch (peek()) { | 4463 switch (peek()) { |
| 4312 case Token::FUNCTION: | 4464 case Token::FUNCTION: |
| 4313 return ParseHoistableDeclaration(nullptr, false, ok); | 4465 return ParseHoistableDeclaration(nullptr, false, ok); |
| 4314 case Token::CLASS: | 4466 case Token::CLASS: |
| 4315 Consume(Token::CLASS); | 4467 Consume(Token::CLASS); |
| 4316 return impl()->ParseClassDeclaration(nullptr, false, ok); | 4468 return ParseClassDeclaration(nullptr, false, ok); |
| 4317 case Token::VAR: | 4469 case Token::VAR: |
| 4318 case Token::CONST: | 4470 case Token::CONST: |
| 4319 return ParseVariableStatement(kStatementListItem, nullptr, ok); | 4471 return ParseVariableStatement(kStatementListItem, nullptr, ok); |
| 4320 case Token::LET: | 4472 case Token::LET: |
| 4321 if (IsNextLetKeyword()) { | 4473 if (IsNextLetKeyword()) { |
| 4322 return ParseVariableStatement(kStatementListItem, nullptr, ok); | 4474 return ParseVariableStatement(kStatementListItem, nullptr, ok); |
| 4323 } | 4475 } |
| 4324 break; | 4476 break; |
| 4325 case Token::ASYNC: | 4477 case Token::ASYNC: |
| 4326 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && | 4478 if (allow_harmony_async_await() && PeekAhead() == Token::FUNCTION && |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4584 } | 4736 } |
| 4585 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); | 4737 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); |
| 4586 } | 4738 } |
| 4587 | 4739 |
| 4588 // If we have an extension, we allow a native function declaration. | 4740 // If we have an extension, we allow a native function declaration. |
| 4589 // A native function declaration starts with "native function" with | 4741 // A native function declaration starts with "native function" with |
| 4590 // no line-terminator between the two words. | 4742 // no line-terminator between the two words. |
| 4591 if (extension_ != nullptr && peek() == Token::FUNCTION && | 4743 if (extension_ != nullptr && peek() == Token::FUNCTION && |
| 4592 !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) && | 4744 !scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) && |
| 4593 !scanner()->literal_contains_escapes()) { | 4745 !scanner()->literal_contains_escapes()) { |
| 4594 return impl()->ParseNativeDeclaration(ok); | 4746 return ParseNativeDeclaration(ok); |
| 4595 } | 4747 } |
| 4596 | 4748 |
| 4597 // Parsed expression statement, followed by semicolon. | 4749 // Parsed expression statement, followed by semicolon. |
| 4598 ExpectSemicolon(CHECK_OK); | 4750 ExpectSemicolon(CHECK_OK); |
| 4599 return factory()->NewExpressionStatement(expr, pos); | 4751 return factory()->NewExpressionStatement(expr, pos); |
| 4600 } | 4752 } |
| 4601 | 4753 |
| 4602 template <typename Impl> | 4754 template <typename Impl> |
| 4603 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement( | 4755 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement( |
| 4604 ZoneList<const AstRawString*>* labels, bool* ok) { | 4756 ZoneList<const AstRawString*>* labels, bool* ok) { |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5317 has_seen_constructor_ = true; | 5469 has_seen_constructor_ = true; |
| 5318 return; | 5470 return; |
| 5319 } | 5471 } |
| 5320 } | 5472 } |
| 5321 | 5473 |
| 5322 | 5474 |
| 5323 } // namespace internal | 5475 } // namespace internal |
| 5324 } // namespace v8 | 5476 } // namespace v8 |
| 5325 | 5477 |
| 5326 #endif // V8_PARSING_PARSER_BASE_H | 5478 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |