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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 allow_lazy_(false), | 193 allow_lazy_(false), |
194 allow_natives_(false), | 194 allow_natives_(false), |
195 allow_tailcalls_(false), | 195 allow_tailcalls_(false), |
196 allow_harmony_restrictive_declarations_(false), | 196 allow_harmony_restrictive_declarations_(false), |
197 allow_harmony_do_expressions_(false), | 197 allow_harmony_do_expressions_(false), |
198 allow_harmony_for_in_(false), | 198 allow_harmony_for_in_(false), |
199 allow_harmony_function_sent_(false), | 199 allow_harmony_function_sent_(false), |
200 allow_harmony_async_await_(false), | 200 allow_harmony_async_await_(false), |
201 allow_harmony_restrictive_generators_(false), | 201 allow_harmony_restrictive_generators_(false), |
202 allow_harmony_trailing_commas_(false), | 202 allow_harmony_trailing_commas_(false), |
203 allow_harmony_class_fields_(false) {} | 203 allow_harmony_class_fields_(false), |
204 will_serialize_(false), | |
205 serializer_enabled_(false), | |
206 is_debug_(false) {} | |
204 | 207 |
205 #define ALLOW_ACCESSORS(name) \ | 208 #define ALLOW_ACCESSORS(name) \ |
206 bool allow_##name() const { return allow_##name##_; } \ | 209 bool allow_##name() const { return allow_##name##_; } \ |
207 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 210 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
208 | 211 |
209 ALLOW_ACCESSORS(lazy); | 212 ALLOW_ACCESSORS(lazy); |
210 ALLOW_ACCESSORS(natives); | 213 ALLOW_ACCESSORS(natives); |
211 ALLOW_ACCESSORS(tailcalls); | 214 ALLOW_ACCESSORS(tailcalls); |
212 ALLOW_ACCESSORS(harmony_restrictive_declarations); | 215 ALLOW_ACCESSORS(harmony_restrictive_declarations); |
213 ALLOW_ACCESSORS(harmony_do_expressions); | 216 ALLOW_ACCESSORS(harmony_do_expressions); |
214 ALLOW_ACCESSORS(harmony_for_in); | 217 ALLOW_ACCESSORS(harmony_for_in); |
215 ALLOW_ACCESSORS(harmony_function_sent); | 218 ALLOW_ACCESSORS(harmony_function_sent); |
216 ALLOW_ACCESSORS(harmony_async_await); | 219 ALLOW_ACCESSORS(harmony_async_await); |
217 ALLOW_ACCESSORS(harmony_restrictive_generators); | 220 ALLOW_ACCESSORS(harmony_restrictive_generators); |
218 ALLOW_ACCESSORS(harmony_trailing_commas); | 221 ALLOW_ACCESSORS(harmony_trailing_commas); |
219 ALLOW_ACCESSORS(harmony_class_fields); | 222 ALLOW_ACCESSORS(harmony_class_fields); |
220 | 223 |
221 #undef ALLOW_ACCESSORS | 224 #undef ALLOW_ACCESSORS |
222 | 225 |
223 uintptr_t stack_limit() const { return stack_limit_; } | 226 uintptr_t stack_limit() const { return stack_limit_; } |
224 | 227 |
225 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 228 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
226 | 229 |
230 bool will_serialize() const { return will_serialize_; } | |
231 void set_will_serialize(bool will_serialize) { | |
232 will_serialize_ = will_serialize; | |
233 } | |
234 bool serializer_enabled() const { return serializer_enabled_; } | |
235 void set_serializer_enabled(bool serializer_enabled) { | |
236 serializer_enabled_ = serializer_enabled; | |
237 } | |
238 bool is_debug() const { return is_debug_; } | |
239 void set_is_debug(bool is_debug) { is_debug_ = is_debug; } | |
240 | |
227 Zone* zone() const { return zone_; } | 241 Zone* zone() const { return zone_; } |
228 | 242 |
229 protected: | 243 protected: |
230 friend class v8::internal::ExpressionClassifier<ParserTypes<Impl>>; | 244 friend class v8::internal::ExpressionClassifier<ParserTypes<Impl>>; |
231 | 245 |
232 // clang-format off | |
jochen (gone - plz use gerrit)
2016/10/06 11:30:15
we shouldn't randomly disable clang-format, but st
| |
233 enum AllowRestrictedIdentifiers { | 246 enum AllowRestrictedIdentifiers { |
234 kAllowRestrictedIdentifiers, | 247 kAllowRestrictedIdentifiers, |
235 kDontAllowRestrictedIdentifiers | 248 kDontAllowRestrictedIdentifiers |
236 }; | 249 }; |
237 | 250 |
238 enum Mode { | 251 enum Mode { PARSE_LAZILY, PARSE_EAGERLY }; |
239 PARSE_LAZILY, | |
240 PARSE_EAGERLY | |
241 }; | |
242 | 252 |
243 enum LazyParsingResult { | 253 enum LazyParsingResult { kLazyParsingComplete, kLazyParsingAborted }; |
244 kLazyParsingComplete, | |
245 kLazyParsingAborted | |
246 }; | |
247 | 254 |
248 enum VariableDeclarationContext { | 255 enum VariableDeclarationContext { |
249 kStatementListItem, | 256 kStatementListItem, |
250 kStatement, | 257 kStatement, |
251 kForStatement | 258 kForStatement |
252 }; | 259 }; |
253 | 260 |
254 enum class FunctionBodyType { | 261 enum class FunctionBodyType { kNormal, kSingleExpression }; |
255 kNormal, | |
256 kSingleExpression | |
257 }; | |
258 // clang-format on | |
259 | 262 |
260 class Checkpoint; | 263 class Checkpoint; |
261 class ClassLiteralChecker; | 264 class ClassLiteralChecker; |
262 class ObjectLiteralChecker; | 265 class ObjectLiteralChecker; |
263 | 266 |
264 // --------------------------------------------------------------------------- | 267 // --------------------------------------------------------------------------- |
265 // ScopeState and its subclasses implement the parser's scope stack. | 268 // ScopeState and its subclasses implement the parser's scope stack. |
266 // ScopeState keeps track of the current scope, and the outer ScopeState. The | 269 // ScopeState keeps track of the current scope, and the outer ScopeState. The |
267 // parser's scope_state_ points to the top ScopeState. ScopeState's | 270 // parser's scope_state_ points to the top ScopeState. ScopeState's |
268 // constructor push on the scope stack and the destructors pop. BlockState and | 271 // constructor push on the scope stack and the destructors pop. BlockState and |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1449 bool allow_tailcalls_; | 1452 bool allow_tailcalls_; |
1450 bool allow_harmony_restrictive_declarations_; | 1453 bool allow_harmony_restrictive_declarations_; |
1451 bool allow_harmony_do_expressions_; | 1454 bool allow_harmony_do_expressions_; |
1452 bool allow_harmony_for_in_; | 1455 bool allow_harmony_for_in_; |
1453 bool allow_harmony_function_sent_; | 1456 bool allow_harmony_function_sent_; |
1454 bool allow_harmony_async_await_; | 1457 bool allow_harmony_async_await_; |
1455 bool allow_harmony_restrictive_generators_; | 1458 bool allow_harmony_restrictive_generators_; |
1456 bool allow_harmony_trailing_commas_; | 1459 bool allow_harmony_trailing_commas_; |
1457 bool allow_harmony_class_fields_; | 1460 bool allow_harmony_class_fields_; |
1458 | 1461 |
1462 bool will_serialize_; | |
1463 bool serializer_enabled_; | |
marja
2016/10/06 11:53:06
Seems unnecessary to need these bools in ParserBas
jochen (gone - plz use gerrit)
2016/10/06 15:05:04
allow_lazy is for native scripts for example - we
| |
1464 bool is_debug_; | |
1465 | |
1459 friend class DiscardableZoneScope; | 1466 friend class DiscardableZoneScope; |
1460 }; | 1467 }; |
1461 | 1468 |
1462 template <typename Impl> | 1469 template <typename Impl> |
1463 ParserBase<Impl>::FunctionState::FunctionState( | 1470 ParserBase<Impl>::FunctionState::FunctionState( |
1464 FunctionState** function_state_stack, ScopeState** scope_stack, | 1471 FunctionState** function_state_stack, ScopeState** scope_stack, |
1465 DeclarationScope* scope) | 1472 DeclarationScope* scope) |
1466 : ScopeState(scope_stack, scope), | 1473 : ScopeState(scope_stack, scope), |
1467 next_materialized_literal_index_(0), | 1474 next_materialized_literal_index_(0), |
1468 expected_property_count_(0), | 1475 expected_property_count_(0), |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2284 typename Types::StatementList body = impl()->NewStatementList(1); | 2291 typename Types::StatementList body = impl()->NewStatementList(1); |
2285 body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone()); | 2292 body->Add(factory()->NewReturnStatement(value, kNoSourcePosition), zone()); |
2286 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 2293 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
2287 impl()->EmptyIdentifierString(), initializer_scope, body, | 2294 impl()->EmptyIdentifierString(), initializer_scope, body, |
2288 initializer_state.materialized_literal_count(), | 2295 initializer_state.materialized_literal_count(), |
2289 initializer_state.expected_property_count(), 0, | 2296 initializer_state.expected_property_count(), 0, |
2290 FunctionLiteral::kNoDuplicateParameters, | 2297 FunctionLiteral::kNoDuplicateParameters, |
2291 FunctionLiteral::kAnonymousExpression, | 2298 FunctionLiteral::kAnonymousExpression, |
2292 FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position()); | 2299 FunctionLiteral::kShouldLazyCompile, initializer_scope->start_position()); |
2293 function_literal->set_is_class_field_initializer(true); | 2300 function_literal->set_is_class_field_initializer(true); |
2301 if (impl()->ShouldCompileLazily(function_literal)) { | |
2302 initializer_scope->SetShouldCompileLazily(true); | |
2303 } | |
2294 return function_literal; | 2304 return function_literal; |
2295 } | 2305 } |
2296 | 2306 |
2297 template <typename Impl> | 2307 template <typename Impl> |
2298 typename ParserBase<Impl>::ObjectLiteralPropertyT | 2308 typename ParserBase<Impl>::ObjectLiteralPropertyT |
2299 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, | 2309 ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, |
2300 bool* is_computed_name, | 2310 bool* is_computed_name, |
2301 bool* ok) { | 2311 bool* ok) { |
2302 bool is_get = false; | 2312 bool is_get = false; |
2303 bool is_set = false; | 2313 bool is_set = false; |
(...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4036 formal_parameters.scope->start_position()); | 4046 formal_parameters.scope->start_position()); |
4037 | 4047 |
4038 function_literal->set_function_token_position( | 4048 function_literal->set_function_token_position( |
4039 formal_parameters.scope->start_position()); | 4049 formal_parameters.scope->start_position()); |
4040 if (should_be_used_once_hint) { | 4050 if (should_be_used_once_hint) { |
4041 function_literal->set_should_be_used_once_hint(); | 4051 function_literal->set_should_be_used_once_hint(); |
4042 } | 4052 } |
4043 | 4053 |
4044 impl()->AddFunctionForNameInference(function_literal); | 4054 impl()->AddFunctionForNameInference(function_literal); |
4045 | 4055 |
4056 if (impl()->ShouldCompileLazily(function_literal)) { | |
4057 formal_parameters.scope->SetShouldCompileLazily(true); | |
4058 } | |
4059 | |
4046 return function_literal; | 4060 return function_literal; |
4047 } | 4061 } |
4048 | 4062 |
4049 template <typename Impl> | 4063 template <typename Impl> |
4050 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral( | 4064 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral( |
4051 IdentifierT name, Scanner::Location class_name_location, | 4065 IdentifierT name, Scanner::Location class_name_location, |
4052 bool name_is_strict_reserved, int class_token_pos, bool* ok) { | 4066 bool name_is_strict_reserved, int class_token_pos, bool* ok) { |
4053 // All parts of a ClassDeclaration and ClassExpression are strict code. | 4067 // All parts of a ClassDeclaration and ClassExpression are strict code. |
4054 if (name_is_strict_reserved) { | 4068 if (name_is_strict_reserved) { |
4055 impl()->ReportMessageAt(class_name_location, | 4069 impl()->ReportMessageAt(class_name_location, |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4686 template <typename Impl> | 4700 template <typename Impl> |
4687 typename ParserBase<Impl>::StatementT | 4701 typename ParserBase<Impl>::StatementT |
4688 ParserBase<Impl>::ParseExpressionOrLabelledStatement( | 4702 ParserBase<Impl>::ParseExpressionOrLabelledStatement( |
4689 ZoneList<const AstRawString*>* labels, | 4703 ZoneList<const AstRawString*>* labels, |
4690 AllowLabelledFunctionStatement allow_function, bool* ok) { | 4704 AllowLabelledFunctionStatement allow_function, bool* ok) { |
4691 // ExpressionStatement | LabelledStatement :: | 4705 // ExpressionStatement | LabelledStatement :: |
4692 // Expression ';' | 4706 // Expression ';' |
4693 // Identifier ':' Statement | 4707 // Identifier ':' Statement |
4694 // | 4708 // |
4695 // ExpressionStatement[Yield] : | 4709 // ExpressionStatement[Yield] : |
4696 // [lookahead ∉ {{, function, class, let [}] Expression[In, ?Yield] ; | 4710 // [lookahead notin {{, function, class, let [}] Expression[In, ?Yield] ; |
jochen (gone - plz use gerrit)
2016/10/06 11:30:14
clang-format.py can't deal with this character..
| |
4697 | 4711 |
4698 int pos = peek_position(); | 4712 int pos = peek_position(); |
4699 | 4713 |
4700 switch (peek()) { | 4714 switch (peek()) { |
4701 case Token::FUNCTION: | 4715 case Token::FUNCTION: |
4702 case Token::LBRACE: | 4716 case Token::LBRACE: |
4703 UNREACHABLE(); // Always handled by the callers. | 4717 UNREACHABLE(); // Always handled by the callers. |
4704 case Token::CLASS: | 4718 case Token::CLASS: |
4705 ReportUnexpectedToken(Next()); | 4719 ReportUnexpectedToken(Next()); |
4706 *ok = false; | 4720 *ok = false; |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5455 has_seen_constructor_ = true; | 5469 has_seen_constructor_ = true; |
5456 return; | 5470 return; |
5457 } | 5471 } |
5458 } | 5472 } |
5459 | 5473 |
5460 | 5474 |
5461 } // namespace internal | 5475 } // namespace internal |
5462 } // namespace v8 | 5476 } // namespace v8 |
5463 | 5477 |
5464 #endif // V8_PARSING_PARSER_BASE_H | 5478 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |