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_harmony_do_expressions_(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(harmony_do_expressions); |
139 #undef ALLOW_ACCESSORS | 142 #undef ALLOW_ACCESSORS |
140 | 143 |
| 144 uintptr_t stack_limit() const { return stack_limit_; } |
| 145 |
141 protected: | 146 protected: |
142 enum AllowRestrictedIdentifiers { | 147 enum AllowRestrictedIdentifiers { |
143 kAllowRestrictedIdentifiers, | 148 kAllowRestrictedIdentifiers, |
144 kDontAllowRestrictedIdentifiers | 149 kDontAllowRestrictedIdentifiers |
145 }; | 150 }; |
146 | 151 |
147 enum Mode { | 152 enum Mode { |
148 PARSE_LAZILY, | 153 PARSE_LAZILY, |
149 PARSE_EAGERLY | 154 PARSE_EAGERLY |
150 }; | 155 }; |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 bool allow_harmony_sloppy_function_; | 840 bool allow_harmony_sloppy_function_; |
836 bool allow_harmony_sloppy_let_; | 841 bool allow_harmony_sloppy_let_; |
837 bool allow_harmony_rest_parameters_; | 842 bool allow_harmony_rest_parameters_; |
838 bool allow_harmony_default_parameters_; | 843 bool allow_harmony_default_parameters_; |
839 bool allow_harmony_spread_calls_; | 844 bool allow_harmony_spread_calls_; |
840 bool allow_harmony_destructuring_; | 845 bool allow_harmony_destructuring_; |
841 bool allow_harmony_spread_arrays_; | 846 bool allow_harmony_spread_arrays_; |
842 bool allow_harmony_new_target_; | 847 bool allow_harmony_new_target_; |
843 bool allow_strong_mode_; | 848 bool allow_strong_mode_; |
844 bool allow_legacy_const_; | 849 bool allow_legacy_const_; |
| 850 bool allow_harmony_do_expressions_; |
845 }; | 851 }; |
846 | 852 |
847 | 853 |
848 class PreParserIdentifier { | 854 class PreParserIdentifier { |
849 public: | 855 public: |
850 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 856 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
851 static PreParserIdentifier Default() { | 857 static PreParserIdentifier Default() { |
852 return PreParserIdentifier(kUnknownIdentifier); | 858 return PreParserIdentifier(kUnknownIdentifier); |
853 } | 859 } |
854 static PreParserIdentifier Eval() { | 860 static PreParserIdentifier Eval() { |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 ExpressionClassifier* classifier) { | 1697 ExpressionClassifier* classifier) { |
1692 if (!classifier->is_simple_parameter_list()) { | 1698 if (!classifier->is_simple_parameter_list()) { |
1693 scope->SetHasNonSimpleParameters(); | 1699 scope->SetHasNonSimpleParameters(); |
1694 } | 1700 } |
1695 } | 1701 } |
1696 | 1702 |
1697 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 1703 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
1698 | 1704 |
1699 // Temporary glue; these functions will move to ParserBase. | 1705 // Temporary glue; these functions will move to ParserBase. |
1700 PreParserExpression ParseV8Intrinsic(bool* ok); | 1706 PreParserExpression ParseV8Intrinsic(bool* ok); |
| 1707 V8_INLINE PreParserExpression ParseDoExpression(bool* ok); |
1701 PreParserExpression ParseFunctionLiteral( | 1708 PreParserExpression ParseFunctionLiteral( |
1702 PreParserIdentifier name, Scanner::Location function_name_location, | 1709 PreParserIdentifier name, Scanner::Location function_name_location, |
1703 FunctionNameValidity function_name_validity, FunctionKind kind, | 1710 FunctionNameValidity function_name_validity, FunctionKind kind, |
1704 int function_token_position, FunctionLiteral::FunctionType type, | 1711 int function_token_position, FunctionLiteral::FunctionType type, |
1705 FunctionLiteral::ArityRestriction arity_restriction, | 1712 FunctionLiteral::ArityRestriction arity_restriction, |
1706 LanguageMode language_mode, bool* ok); | 1713 LanguageMode language_mode, bool* ok); |
1707 | 1714 |
1708 PreParserExpression ParseClassLiteral(PreParserIdentifier name, | 1715 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
1709 Scanner::Location class_name_location, | 1716 Scanner::Location class_name_location, |
1710 bool name_is_strict_reserved, int pos, | 1717 bool name_is_strict_reserved, int pos, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 Statement ParseSwitchStatement(bool* ok); | 1838 Statement ParseSwitchStatement(bool* ok); |
1832 Statement ParseDoWhileStatement(bool* ok); | 1839 Statement ParseDoWhileStatement(bool* ok); |
1833 Statement ParseWhileStatement(bool* ok); | 1840 Statement ParseWhileStatement(bool* ok); |
1834 Statement ParseForStatement(bool* ok); | 1841 Statement ParseForStatement(bool* ok); |
1835 Statement ParseThrowStatement(bool* ok); | 1842 Statement ParseThrowStatement(bool* ok); |
1836 Statement ParseTryStatement(bool* ok); | 1843 Statement ParseTryStatement(bool* ok); |
1837 Statement ParseDebuggerStatement(bool* ok); | 1844 Statement ParseDebuggerStatement(bool* ok); |
1838 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 1845 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
1839 Expression ParseObjectLiteral(bool* ok); | 1846 Expression ParseObjectLiteral(bool* ok); |
1840 Expression ParseV8Intrinsic(bool* ok); | 1847 Expression ParseV8Intrinsic(bool* ok); |
| 1848 Expression ParseDoExpression(bool* ok); |
1841 | 1849 |
1842 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, | 1850 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, |
1843 int* expected_property_count, bool* ok); | 1851 int* expected_property_count, bool* ok); |
1844 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 1852 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
1845 PreParserIdentifier function_name, int pos, | 1853 PreParserIdentifier function_name, int pos, |
1846 const PreParserFormalParameters& parameters, FunctionKind kind, | 1854 const PreParserFormalParameters& parameters, FunctionKind kind, |
1847 FunctionLiteral::FunctionType function_type, bool* ok); | 1855 FunctionLiteral::FunctionType function_type, bool* ok); |
1848 | 1856 |
1849 Expression ParseFunctionLiteral( | 1857 Expression ParseFunctionLiteral( |
1850 Identifier name, Scanner::Location function_name_location, | 1858 Identifier name, Scanner::Location function_name_location, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 // lists that are too long. | 1904 // lists that are too long. |
1897 | 1905 |
1898 // Accomodate array literal for rest parameter. | 1906 // Accomodate array literal for rest parameter. |
1899 if (params.IsArrowFunctionFormalParametersWithRestParameter()) { | 1907 if (params.IsArrowFunctionFormalParametersWithRestParameter()) { |
1900 ++parameters->materialized_literals_count; | 1908 ++parameters->materialized_literals_count; |
1901 pre_parser_->function_state_->NextMaterializedLiteralIndex(); | 1909 pre_parser_->function_state_->NextMaterializedLiteralIndex(); |
1902 } | 1910 } |
1903 } | 1911 } |
1904 | 1912 |
1905 | 1913 |
| 1914 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { |
| 1915 return pre_parser_->ParseDoExpression(ok); |
| 1916 } |
| 1917 |
| 1918 |
1906 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1919 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1907 PreParserIdentifier function_name, int pos, | 1920 PreParserIdentifier function_name, int pos, |
1908 const PreParserFormalParameters& parameters, FunctionKind kind, | 1921 const PreParserFormalParameters& parameters, FunctionKind kind, |
1909 FunctionLiteral::FunctionType function_type, bool* ok) { | 1922 FunctionLiteral::FunctionType function_type, bool* ok) { |
1910 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1923 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
1911 | 1924 |
1912 ParseStatementList(Token::RBRACE, ok); | 1925 ParseStatementList(Token::RBRACE, ok); |
1913 if (!*ok) return PreParserStatementList(); | 1926 if (!*ok) return PreParserStatementList(); |
1914 | 1927 |
1915 Expect(Token::RBRACE, ok); | 1928 Expect(Token::RBRACE, ok); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2216 // 'false' | 2229 // 'false' |
2217 // Identifier | 2230 // Identifier |
2218 // Number | 2231 // Number |
2219 // String | 2232 // String |
2220 // ArrayLiteral | 2233 // ArrayLiteral |
2221 // ObjectLiteral | 2234 // ObjectLiteral |
2222 // RegExpLiteral | 2235 // RegExpLiteral |
2223 // ClassLiteral | 2236 // ClassLiteral |
2224 // '(' Expression ')' | 2237 // '(' Expression ')' |
2225 // TemplateLiteral | 2238 // TemplateLiteral |
| 2239 // do Block |
2226 | 2240 |
2227 int beg_pos = scanner()->peek_location().beg_pos; | 2241 int beg_pos = scanner()->peek_location().beg_pos; |
2228 int end_pos = scanner()->peek_location().end_pos; | 2242 int end_pos = scanner()->peek_location().end_pos; |
2229 ExpressionT result = this->EmptyExpression(); | 2243 ExpressionT result = this->EmptyExpression(); |
2230 Token::Value token = peek(); | 2244 Token::Value token = peek(); |
2231 switch (token) { | 2245 switch (token) { |
2232 case Token::THIS: { | 2246 case Token::THIS: { |
2233 BindingPatternUnexpectedToken(classifier); | 2247 BindingPatternUnexpectedToken(classifier); |
2234 Consume(Token::THIS); | 2248 Consume(Token::THIS); |
2235 if (FLAG_strong_this && is_strong(language_mode())) { | 2249 if (FLAG_strong_this && is_strong(language_mode())) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2396 MessageTemplate::kUnexpectedTemplateString); | 2410 MessageTemplate::kUnexpectedTemplateString); |
2397 result = this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, | 2411 result = this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, |
2398 classifier, CHECK_OK); | 2412 classifier, CHECK_OK); |
2399 break; | 2413 break; |
2400 | 2414 |
2401 case Token::MOD: | 2415 case Token::MOD: |
2402 if (allow_natives() || extension_ != NULL) { | 2416 if (allow_natives() || extension_ != NULL) { |
2403 result = this->ParseV8Intrinsic(CHECK_OK); | 2417 result = this->ParseV8Intrinsic(CHECK_OK); |
2404 break; | 2418 break; |
2405 } | 2419 } |
| 2420 |
| 2421 case Token::DO: |
| 2422 // TODO(caitp): reorganize ParsePrimaryExpression() to not require this |
| 2423 // extra `token == Token::DO` test due to potential fall-through |
| 2424 if (token == Token::DO && allow_harmony_do_expressions()) { |
| 2425 BindingPatternUnexpectedToken(classifier); |
| 2426 result = Traits::ParseDoExpression(CHECK_OK); |
| 2427 break; |
| 2428 } |
2406 // If we're not allowing special syntax we fall-through to the | 2429 // If we're not allowing special syntax we fall-through to the |
2407 // default case. | 2430 // default case. |
2408 | 2431 |
2409 default: { | 2432 default: { |
2410 Next(); | 2433 Next(); |
2411 ReportUnexpectedToken(token); | 2434 ReportUnexpectedToken(token); |
2412 *ok = false; | 2435 *ok = false; |
2413 } | 2436 } |
2414 } | 2437 } |
2415 | 2438 |
(...skipping 1775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4191 return; | 4214 return; |
4192 } | 4215 } |
4193 has_seen_constructor_ = true; | 4216 has_seen_constructor_ = true; |
4194 return; | 4217 return; |
4195 } | 4218 } |
4196 } | 4219 } |
4197 } // namespace internal | 4220 } // namespace internal |
4198 } // namespace v8 | 4221 } // namespace v8 |
4199 | 4222 |
4200 #endif // V8_PREPARSER_H | 4223 #endif // V8_PREPARSER_H |
OLD | NEW |