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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/bailout-reason.h" | 8 #include "src/bailout-reason.h" |
| 9 #include "src/expression-classifier.h" | 9 #include "src/expression-classifier.h" |
| 10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 class ParserBase : public Traits { | 81 class ParserBase : public Traits { |
| 82 public: | 82 public: |
| 83 // Shorten type names defined by Traits. | 83 // Shorten type names defined by Traits. |
| 84 typedef typename Traits::Type::Expression ExpressionT; | 84 typedef typename Traits::Type::Expression ExpressionT; |
| 85 typedef typename Traits::Type::Identifier IdentifierT; | 85 typedef typename Traits::Type::Identifier IdentifierT; |
| 86 typedef typename Traits::Type::FormalParameter FormalParameterT; | 86 typedef typename Traits::Type::FormalParameter FormalParameterT; |
| 87 typedef typename Traits::Type::FormalParameters FormalParametersT; | 87 typedef typename Traits::Type::FormalParameters FormalParametersT; |
| 88 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 88 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
| 89 typedef typename Traits::Type::Literal LiteralT; | 89 typedef typename Traits::Type::Literal LiteralT; |
| 90 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 90 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
| 91 typedef typename Traits::Type::StatementList StatementListT; | |
| 91 | 92 |
| 92 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 93 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
| 93 v8::Extension* extension, AstValueFactory* ast_value_factory, | 94 v8::Extension* extension, AstValueFactory* ast_value_factory, |
| 94 ParserRecorder* log, typename Traits::Type::Parser this_object) | 95 ParserRecorder* log, typename Traits::Type::Parser this_object) |
| 95 : Traits(this_object), | 96 : Traits(this_object), |
| 96 parenthesized_function_(false), | 97 parenthesized_function_(false), |
| 97 scope_(NULL), | 98 scope_(NULL), |
| 98 function_state_(NULL), | 99 function_state_(NULL), |
| 99 extension_(extension), | 100 extension_(extension), |
| 100 fni_(NULL), | 101 fni_(NULL), |
| 101 ast_value_factory_(ast_value_factory), | 102 ast_value_factory_(ast_value_factory), |
| 102 log_(log), | 103 log_(log), |
| 103 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 104 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
| 104 stack_limit_(stack_limit), | 105 stack_limit_(stack_limit), |
| 105 zone_(zone), | 106 zone_(zone), |
| 106 scanner_(scanner), | 107 scanner_(scanner), |
| 107 stack_overflow_(false), | 108 stack_overflow_(false), |
| 108 allow_lazy_(false), | 109 allow_lazy_(false), |
| 109 allow_natives_(false), | 110 allow_natives_(false), |
| 110 allow_harmony_sloppy_(false), | 111 allow_harmony_sloppy_(false), |
| 111 allow_harmony_sloppy_function_(false), | 112 allow_harmony_sloppy_function_(false), |
| 112 allow_harmony_sloppy_let_(false), | 113 allow_harmony_sloppy_let_(false), |
| 113 allow_harmony_rest_parameters_(false), | 114 allow_harmony_rest_parameters_(false), |
| 114 allow_harmony_default_parameters_(false), | 115 allow_harmony_default_parameters_(false), |
| 115 allow_harmony_spread_calls_(false), | 116 allow_harmony_spread_calls_(false), |
| 116 allow_harmony_destructuring_(false), | 117 allow_harmony_destructuring_(false), |
| 117 allow_harmony_spread_arrays_(false), | 118 allow_harmony_spread_arrays_(false), |
| 118 allow_harmony_new_target_(false), | 119 allow_harmony_new_target_(false), |
| 119 allow_strong_mode_(false), | 120 allow_strong_mode_(false), |
| 120 allow_legacy_const_(true) {} | 121 allow_legacy_const_(true), |
| 122 allow_do_expression_parsing_(false) {} | |
| 121 | 123 |
| 122 #define ALLOW_ACCESSORS(name) \ | 124 #define ALLOW_ACCESSORS(name) \ |
| 123 bool allow_##name() const { return allow_##name##_; } \ | 125 bool allow_##name() const { return allow_##name##_; } \ |
| 124 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 126 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
| 125 | 127 |
| 126 ALLOW_ACCESSORS(lazy); | 128 ALLOW_ACCESSORS(lazy); |
| 127 ALLOW_ACCESSORS(natives); | 129 ALLOW_ACCESSORS(natives); |
| 128 ALLOW_ACCESSORS(harmony_sloppy); | 130 ALLOW_ACCESSORS(harmony_sloppy); |
| 129 ALLOW_ACCESSORS(harmony_sloppy_function); | 131 ALLOW_ACCESSORS(harmony_sloppy_function); |
| 130 ALLOW_ACCESSORS(harmony_sloppy_let); | 132 ALLOW_ACCESSORS(harmony_sloppy_let); |
| 131 ALLOW_ACCESSORS(harmony_rest_parameters); | 133 ALLOW_ACCESSORS(harmony_rest_parameters); |
| 132 ALLOW_ACCESSORS(harmony_default_parameters); | 134 ALLOW_ACCESSORS(harmony_default_parameters); |
| 133 ALLOW_ACCESSORS(harmony_spread_calls); | 135 ALLOW_ACCESSORS(harmony_spread_calls); |
| 134 ALLOW_ACCESSORS(harmony_destructuring); | 136 ALLOW_ACCESSORS(harmony_destructuring); |
| 135 ALLOW_ACCESSORS(harmony_spread_arrays); | 137 ALLOW_ACCESSORS(harmony_spread_arrays); |
| 136 ALLOW_ACCESSORS(harmony_new_target); | 138 ALLOW_ACCESSORS(harmony_new_target); |
| 137 ALLOW_ACCESSORS(strong_mode); | 139 ALLOW_ACCESSORS(strong_mode); |
| 138 ALLOW_ACCESSORS(legacy_const); | 140 ALLOW_ACCESSORS(legacy_const); |
| 141 ALLOW_ACCESSORS(do_expression_parsing); | |
| 139 #undef ALLOW_ACCESSORS | 142 #undef ALLOW_ACCESSORS |
| 140 | 143 |
| 144 INLINE(bool CheckStackOverflow()) { | |
| 145 if (stack_overflow_) return true; | |
| 146 if (GetCurrentStackPosition() >= stack_limit_) return false; | |
| 147 stack_overflow_ = true; | |
| 148 return true; | |
| 149 } | |
| 150 | |
| 141 protected: | 151 protected: |
| 142 enum AllowRestrictedIdentifiers { | 152 enum AllowRestrictedIdentifiers { |
| 143 kAllowRestrictedIdentifiers, | 153 kAllowRestrictedIdentifiers, |
| 144 kDontAllowRestrictedIdentifiers | 154 kDontAllowRestrictedIdentifiers |
| 145 }; | 155 }; |
| 146 | 156 |
| 147 enum Mode { | 157 enum Mode { |
| 148 PARSE_LAZILY, | 158 PARSE_LAZILY, |
| 149 PARSE_EAGERLY | 159 PARSE_EAGERLY |
| 150 }; | 160 }; |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 bool allow_harmony_sloppy_function_; | 844 bool allow_harmony_sloppy_function_; |
| 835 bool allow_harmony_sloppy_let_; | 845 bool allow_harmony_sloppy_let_; |
| 836 bool allow_harmony_rest_parameters_; | 846 bool allow_harmony_rest_parameters_; |
| 837 bool allow_harmony_default_parameters_; | 847 bool allow_harmony_default_parameters_; |
| 838 bool allow_harmony_spread_calls_; | 848 bool allow_harmony_spread_calls_; |
| 839 bool allow_harmony_destructuring_; | 849 bool allow_harmony_destructuring_; |
| 840 bool allow_harmony_spread_arrays_; | 850 bool allow_harmony_spread_arrays_; |
| 841 bool allow_harmony_new_target_; | 851 bool allow_harmony_new_target_; |
| 842 bool allow_strong_mode_; | 852 bool allow_strong_mode_; |
| 843 bool allow_legacy_const_; | 853 bool allow_legacy_const_; |
| 854 bool allow_do_expression_parsing_; | |
| 844 }; | 855 }; |
| 845 | 856 |
| 846 | 857 |
| 847 class PreParserIdentifier { | 858 class PreParserIdentifier { |
| 848 public: | 859 public: |
| 849 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 860 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
| 850 static PreParserIdentifier Default() { | 861 static PreParserIdentifier Default() { |
| 851 return PreParserIdentifier(kUnknownIdentifier); | 862 return PreParserIdentifier(kUnknownIdentifier); |
| 852 } | 863 } |
| 853 static PreParserIdentifier Eval() { | 864 static PreParserIdentifier Eval() { |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 1659 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
| 1649 PreParserIdentifier function_name, int pos, | 1660 PreParserIdentifier function_name, int pos, |
| 1650 const PreParserFormalParameters& parameters, FunctionKind kind, | 1661 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1651 FunctionLiteral::FunctionType function_type, bool* ok); | 1662 FunctionLiteral::FunctionType function_type, bool* ok); |
| 1652 | 1663 |
| 1653 V8_INLINE void ParseArrowFunctionFormalParameterList( | 1664 V8_INLINE void ParseArrowFunctionFormalParameterList( |
| 1654 PreParserFormalParameters* parameters, | 1665 PreParserFormalParameters* parameters, |
| 1655 PreParserExpression expression, const Scanner::Location& params_loc, | 1666 PreParserExpression expression, const Scanner::Location& params_loc, |
| 1656 Scanner::Location* duplicate_loc, bool* ok); | 1667 Scanner::Location* duplicate_loc, bool* ok); |
| 1657 | 1668 |
| 1669 V8_INLINE PreParserExpression ParseDoExpression(bool* ok); | |
| 1670 | |
| 1658 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} | 1671 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} |
| 1659 | 1672 |
| 1660 struct TemplateLiteralState {}; | 1673 struct TemplateLiteralState {}; |
| 1661 | 1674 |
| 1662 TemplateLiteralState OpenTemplateLiteral(int pos) { | 1675 TemplateLiteralState OpenTemplateLiteral(int pos) { |
| 1663 return TemplateLiteralState(); | 1676 return TemplateLiteralState(); |
| 1664 } | 1677 } |
| 1665 void AddTemplateSpan(TemplateLiteralState*, bool) {} | 1678 void AddTemplateSpan(TemplateLiteralState*, bool) {} |
| 1666 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} | 1679 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} |
| 1667 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, | 1680 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1807 // By making the 'exception handling' explicit, we are forced to check | 1820 // By making the 'exception handling' explicit, we are forced to check |
| 1808 // for failure at the call sites. | 1821 // for failure at the call sites. |
| 1809 Statement ParseStatementListItem(bool* ok); | 1822 Statement ParseStatementListItem(bool* ok); |
| 1810 void ParseStatementList(int end_token, bool* ok, | 1823 void ParseStatementList(int end_token, bool* ok, |
| 1811 Scanner::BookmarkScope* bookmark = nullptr); | 1824 Scanner::BookmarkScope* bookmark = nullptr); |
| 1812 Statement ParseStatement(bool* ok); | 1825 Statement ParseStatement(bool* ok); |
| 1813 Statement ParseSubStatement(bool* ok); | 1826 Statement ParseSubStatement(bool* ok); |
| 1814 Statement ParseFunctionDeclaration(bool* ok); | 1827 Statement ParseFunctionDeclaration(bool* ok); |
| 1815 Statement ParseClassDeclaration(bool* ok); | 1828 Statement ParseClassDeclaration(bool* ok); |
| 1816 Statement ParseBlock(bool* ok); | 1829 Statement ParseBlock(bool* ok); |
| 1830 Expression ParseDoExpression(bool* ok); | |
|
rossberg
2015/10/13 10:44:32
Nit: group this with the Expression parsing functi
caitp (gmail)
2015/10/13 15:05:59
Done.
| |
| 1817 Statement ParseVariableStatement(VariableDeclarationContext var_context, | 1831 Statement ParseVariableStatement(VariableDeclarationContext var_context, |
| 1818 bool* ok); | 1832 bool* ok); |
| 1819 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, | 1833 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, |
| 1820 int* num_decl, | 1834 int* num_decl, |
| 1821 Scanner::Location* first_initializer_loc, | 1835 Scanner::Location* first_initializer_loc, |
| 1822 Scanner::Location* bindings_loc, | 1836 Scanner::Location* bindings_loc, |
| 1823 bool* ok); | 1837 bool* ok); |
| 1824 Statement ParseExpressionOrLabelledStatement(bool* ok); | 1838 Statement ParseExpressionOrLabelledStatement(bool* ok); |
| 1825 Statement ParseIfStatement(bool* ok); | 1839 Statement ParseIfStatement(bool* ok); |
| 1826 Statement ParseContinueStatement(bool* ok); | 1840 Statement ParseContinueStatement(bool* ok); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1895 // lists that are too long. | 1909 // lists that are too long. |
| 1896 | 1910 |
| 1897 // Accomodate array literal for rest parameter. | 1911 // Accomodate array literal for rest parameter. |
| 1898 if (params.IsArrowFunctionFormalParametersWithRestParameter()) { | 1912 if (params.IsArrowFunctionFormalParametersWithRestParameter()) { |
| 1899 ++parameters->materialized_literals_count; | 1913 ++parameters->materialized_literals_count; |
| 1900 pre_parser_->function_state_->NextMaterializedLiteralIndex(); | 1914 pre_parser_->function_state_->NextMaterializedLiteralIndex(); |
| 1901 } | 1915 } |
| 1902 } | 1916 } |
| 1903 | 1917 |
| 1904 | 1918 |
| 1919 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { | |
| 1920 return pre_parser_->ParseDoExpression(ok); | |
| 1921 } | |
| 1922 | |
| 1923 | |
| 1905 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1924 PreParserStatementList PreParser::ParseEagerFunctionBody( |
| 1906 PreParserIdentifier function_name, int pos, | 1925 PreParserIdentifier function_name, int pos, |
| 1907 const PreParserFormalParameters& parameters, FunctionKind kind, | 1926 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1908 FunctionLiteral::FunctionType function_type, bool* ok) { | 1927 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 1909 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1928 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| 1910 | 1929 |
| 1911 ParseStatementList(Token::RBRACE, ok); | 1930 ParseStatementList(Token::RBRACE, ok); |
| 1912 if (!*ok) return PreParserStatementList(); | 1931 if (!*ok) return PreParserStatementList(); |
| 1913 | 1932 |
| 1914 Expect(Token::RBRACE, ok); | 1933 Expect(Token::RBRACE, ok); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2215 // 'false' | 2234 // 'false' |
| 2216 // Identifier | 2235 // Identifier |
| 2217 // Number | 2236 // Number |
| 2218 // String | 2237 // String |
| 2219 // ArrayLiteral | 2238 // ArrayLiteral |
| 2220 // ObjectLiteral | 2239 // ObjectLiteral |
| 2221 // RegExpLiteral | 2240 // RegExpLiteral |
| 2222 // ClassLiteral | 2241 // ClassLiteral |
| 2223 // '(' Expression ')' | 2242 // '(' Expression ')' |
| 2224 // TemplateLiteral | 2243 // TemplateLiteral |
| 2244 // do Block | |
| 2225 | 2245 |
| 2226 int beg_pos = scanner()->peek_location().beg_pos; | 2246 int beg_pos = scanner()->peek_location().beg_pos; |
| 2227 int end_pos = scanner()->peek_location().end_pos; | 2247 int end_pos = scanner()->peek_location().end_pos; |
| 2228 ExpressionT result = this->EmptyExpression(); | 2248 ExpressionT result = this->EmptyExpression(); |
| 2229 Token::Value token = peek(); | 2249 Token::Value token = peek(); |
| 2230 switch (token) { | 2250 switch (token) { |
| 2231 case Token::THIS: { | 2251 case Token::THIS: { |
| 2232 BindingPatternUnexpectedToken(classifier); | 2252 BindingPatternUnexpectedToken(classifier); |
| 2233 Consume(Token::THIS); | 2253 Consume(Token::THIS); |
| 2234 if (FLAG_strong_this && is_strong(language_mode())) { | 2254 if (FLAG_strong_this && is_strong(language_mode())) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2395 MessageTemplate::kUnexpectedTemplateString); | 2415 MessageTemplate::kUnexpectedTemplateString); |
| 2396 result = this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, | 2416 result = this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, |
| 2397 classifier, CHECK_OK); | 2417 classifier, CHECK_OK); |
| 2398 break; | 2418 break; |
| 2399 | 2419 |
| 2400 case Token::MOD: | 2420 case Token::MOD: |
| 2401 if (allow_natives() || extension_ != NULL) { | 2421 if (allow_natives() || extension_ != NULL) { |
| 2402 result = this->ParseV8Intrinsic(CHECK_OK); | 2422 result = this->ParseV8Intrinsic(CHECK_OK); |
| 2403 break; | 2423 break; |
| 2404 } | 2424 } |
| 2425 | |
| 2426 case Token::DO: | |
| 2427 if (token == Token::DO && allow_do_expression_parsing()) { | |
| 2428 BindingPatternUnexpectedToken(classifier); | |
| 2429 result = Traits::ParseDoExpression(CHECK_OK); | |
| 2430 break; | |
| 2431 } | |
| 2405 // If we're not allowing special syntax we fall-through to the | 2432 // If we're not allowing special syntax we fall-through to the |
| 2406 // default case. | 2433 // default case. |
| 2407 | 2434 |
| 2408 default: { | 2435 default: { |
| 2409 Next(); | 2436 Next(); |
| 2410 ReportUnexpectedToken(token); | 2437 ReportUnexpectedToken(token); |
| 2411 *ok = false; | 2438 *ok = false; |
| 2412 } | 2439 } |
| 2413 } | 2440 } |
| 2414 | 2441 |
| (...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4186 return; | 4213 return; |
| 4187 } | 4214 } |
| 4188 has_seen_constructor_ = true; | 4215 has_seen_constructor_ = true; |
| 4189 return; | 4216 return; |
| 4190 } | 4217 } |
| 4191 } | 4218 } |
| 4192 } // namespace internal | 4219 } // namespace internal |
| 4193 } // namespace v8 | 4220 } // namespace v8 |
| 4194 | 4221 |
| 4195 #endif // V8_PREPARSER_H | 4222 #endif // V8_PREPARSER_H |
| OLD | NEW |