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/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 public: | 63 public: |
64 // Shorten type names defined by Traits. | 64 // Shorten type names defined by Traits. |
65 typedef typename Traits::Type::Expression ExpressionT; | 65 typedef typename Traits::Type::Expression ExpressionT; |
66 typedef typename Traits::Type::Identifier IdentifierT; | 66 typedef typename Traits::Type::Identifier IdentifierT; |
67 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 67 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
68 typedef typename Traits::Type::Literal LiteralT; | 68 typedef typename Traits::Type::Literal LiteralT; |
69 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 69 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
70 | 70 |
71 ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension, | 71 ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension, |
72 ParserRecorder* log, typename Traits::Type::Zone* zone, | 72 ParserRecorder* log, typename Traits::Type::Zone* zone, |
| 73 AstNode::IdGen* ast_node_id_gen, |
73 typename Traits::Type::Parser this_object) | 74 typename Traits::Type::Parser this_object) |
74 : Traits(this_object), | 75 : Traits(this_object), |
75 parenthesized_function_(false), | 76 parenthesized_function_(false), |
76 scope_(NULL), | 77 scope_(NULL), |
77 function_state_(NULL), | 78 function_state_(NULL), |
78 extension_(extension), | 79 extension_(extension), |
79 fni_(NULL), | 80 fni_(NULL), |
80 log_(log), | 81 log_(log), |
81 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 82 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
82 stack_limit_(stack_limit), | 83 stack_limit_(stack_limit), |
83 scanner_(scanner), | 84 scanner_(scanner), |
84 stack_overflow_(false), | 85 stack_overflow_(false), |
85 allow_lazy_(false), | 86 allow_lazy_(false), |
86 allow_natives_syntax_(false), | 87 allow_natives_syntax_(false), |
87 allow_arrow_functions_(false), | 88 allow_arrow_functions_(false), |
88 allow_harmony_object_literals_(false), | 89 allow_harmony_object_literals_(false), |
89 zone_(zone) {} | 90 zone_(zone), |
| 91 ast_node_id_gen_(ast_node_id_gen) {} |
90 | 92 |
91 // Getters that indicate whether certain syntactical constructs are | 93 // Getters that indicate whether certain syntactical constructs are |
92 // allowed to be parsed by this instance of the parser. | 94 // allowed to be parsed by this instance of the parser. |
93 bool allow_lazy() const { return allow_lazy_; } | 95 bool allow_lazy() const { return allow_lazy_; } |
94 bool allow_natives_syntax() const { return allow_natives_syntax_; } | 96 bool allow_natives_syntax() const { return allow_natives_syntax_; } |
95 bool allow_arrow_functions() const { return allow_arrow_functions_; } | 97 bool allow_arrow_functions() const { return allow_arrow_functions_; } |
96 bool allow_modules() const { return scanner()->HarmonyModules(); } | 98 bool allow_modules() const { return scanner()->HarmonyModules(); } |
97 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } | 99 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } |
98 bool allow_harmony_numeric_literals() const { | 100 bool allow_harmony_numeric_literals() const { |
99 return scanner()->HarmonyNumericLiterals(); | 101 return scanner()->HarmonyNumericLiterals(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 Mode old_mode_; | 270 Mode old_mode_; |
269 }; | 271 }; |
270 | 272 |
271 Scanner* scanner() const { return scanner_; } | 273 Scanner* scanner() const { return scanner_; } |
272 int position() { return scanner_->location().beg_pos; } | 274 int position() { return scanner_->location().beg_pos; } |
273 int peek_position() { return scanner_->peek_location().beg_pos; } | 275 int peek_position() { return scanner_->peek_location().beg_pos; } |
274 bool stack_overflow() const { return stack_overflow_; } | 276 bool stack_overflow() const { return stack_overflow_; } |
275 void set_stack_overflow() { stack_overflow_ = true; } | 277 void set_stack_overflow() { stack_overflow_ = true; } |
276 Mode mode() const { return mode_; } | 278 Mode mode() const { return mode_; } |
277 typename Traits::Type::Zone* zone() const { return zone_; } | 279 typename Traits::Type::Zone* zone() const { return zone_; } |
| 280 AstNode::IdGen* ast_node_id_gen() const { return ast_node_id_gen_; } |
278 | 281 |
279 INLINE(Token::Value peek()) { | 282 INLINE(Token::Value peek()) { |
280 if (stack_overflow_) return Token::ILLEGAL; | 283 if (stack_overflow_) return Token::ILLEGAL; |
281 return scanner()->peek(); | 284 return scanner()->peek(); |
282 } | 285 } |
283 | 286 |
284 INLINE(Token::Value Next()) { | 287 INLINE(Token::Value Next()) { |
285 if (stack_overflow_) return Token::ILLEGAL; | 288 if (stack_overflow_) return Token::ILLEGAL; |
286 { | 289 { |
287 if (GetCurrentStackPosition() < stack_limit_) { | 290 if (GetCurrentStackPosition() < stack_limit_) { |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 private: | 573 private: |
571 Scanner* scanner_; | 574 Scanner* scanner_; |
572 bool stack_overflow_; | 575 bool stack_overflow_; |
573 | 576 |
574 bool allow_lazy_; | 577 bool allow_lazy_; |
575 bool allow_natives_syntax_; | 578 bool allow_natives_syntax_; |
576 bool allow_arrow_functions_; | 579 bool allow_arrow_functions_; |
577 bool allow_harmony_object_literals_; | 580 bool allow_harmony_object_literals_; |
578 | 581 |
579 typename Traits::Type::Zone* zone_; // Only used by Parser. | 582 typename Traits::Type::Zone* zone_; // Only used by Parser. |
| 583 AstNode::IdGen* ast_node_id_gen_; |
580 }; | 584 }; |
581 | 585 |
582 | 586 |
583 class PreParserIdentifier { | 587 class PreParserIdentifier { |
584 public: | 588 public: |
585 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 589 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
586 static PreParserIdentifier Default() { | 590 static PreParserIdentifier Default() { |
587 return PreParserIdentifier(kUnknownIdentifier); | 591 return PreParserIdentifier(kUnknownIdentifier); |
588 } | 592 } |
589 static PreParserIdentifier Eval() { | 593 static PreParserIdentifier Eval() { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 PreParserScope* operator->() { return this; } | 965 PreParserScope* operator->() { return this; } |
962 | 966 |
963 private: | 967 private: |
964 ScopeType scope_type_; | 968 ScopeType scope_type_; |
965 StrictMode strict_mode_; | 969 StrictMode strict_mode_; |
966 }; | 970 }; |
967 | 971 |
968 | 972 |
969 class PreParserFactory { | 973 class PreParserFactory { |
970 public: | 974 public: |
971 explicit PreParserFactory(void* unused_value_factory) {} | 975 PreParserFactory(void*, void*, void*) {} |
972 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 976 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
973 int pos) { | 977 int pos) { |
974 return PreParserExpression::Default(); | 978 return PreParserExpression::Default(); |
975 } | 979 } |
976 PreParserExpression NewNumberLiteral(double number, | 980 PreParserExpression NewNumberLiteral(double number, |
977 int pos) { | 981 int pos) { |
978 return PreParserExpression::Default(); | 982 return PreParserExpression::Default(); |
979 } | 983 } |
980 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 984 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
981 PreParserIdentifier js_flags, | 985 PreParserIdentifier js_flags, |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 typedef PreParserIdentifier Identifier; | 1410 typedef PreParserIdentifier Identifier; |
1407 typedef PreParserExpression Expression; | 1411 typedef PreParserExpression Expression; |
1408 typedef PreParserStatement Statement; | 1412 typedef PreParserStatement Statement; |
1409 | 1413 |
1410 enum PreParseResult { | 1414 enum PreParseResult { |
1411 kPreParseStackOverflow, | 1415 kPreParseStackOverflow, |
1412 kPreParseSuccess | 1416 kPreParseSuccess |
1413 }; | 1417 }; |
1414 | 1418 |
1415 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) | 1419 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) |
1416 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, | 1420 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, NULL, |
1417 this) {} | 1421 this) {} |
1418 | 1422 |
1419 // Pre-parse the program from the character stream; returns true on | 1423 // Pre-parse the program from the character stream; returns true on |
1420 // success (even if parsing failed, the pre-parse data successfully | 1424 // success (even if parsing failed, the pre-parse data successfully |
1421 // captured the syntax error), and false if a stack-overflow happened | 1425 // captured the syntax error), and false if a stack-overflow happened |
1422 // during parsing. | 1426 // during parsing. |
1423 PreParseResult PreParseProgram() { | 1427 PreParseResult PreParseProgram() { |
1424 PreParserScope scope(scope_, GLOBAL_SCOPE); | 1428 PreParserScope scope(scope_, GLOBAL_SCOPE); |
1425 PreParserFactory factory(NULL); | 1429 PreParserFactory factory(NULL, NULL, NULL); |
1426 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); | 1430 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); |
1427 bool ok = true; | 1431 bool ok = true; |
1428 int start_position = scanner()->peek_location().beg_pos; | 1432 int start_position = scanner()->peek_location().beg_pos; |
1429 ParseSourceElements(Token::EOS, &ok); | 1433 ParseSourceElements(Token::EOS, &ok); |
1430 if (stack_overflow()) return kPreParseStackOverflow; | 1434 if (stack_overflow()) return kPreParseStackOverflow; |
1431 if (!ok) { | 1435 if (!ok) { |
1432 ReportUnexpectedToken(scanner()->current_token()); | 1436 ReportUnexpectedToken(scanner()->current_token()); |
1433 } else if (scope_->strict_mode() == STRICT) { | 1437 } else if (scope_->strict_mode() == STRICT) { |
1434 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); | 1438 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); |
1435 } | 1439 } |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2605 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); | 2609 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); |
2606 typename Traits::Type::StatementList body; | 2610 typename Traits::Type::StatementList body; |
2607 typename Traits::Type::AstProperties ast_properties; | 2611 typename Traits::Type::AstProperties ast_properties; |
2608 BailoutReason dont_optimize_reason = kNoReason; | 2612 BailoutReason dont_optimize_reason = kNoReason; |
2609 int num_parameters = -1; | 2613 int num_parameters = -1; |
2610 int materialized_literal_count = -1; | 2614 int materialized_literal_count = -1; |
2611 int expected_property_count = -1; | 2615 int expected_property_count = -1; |
2612 int handler_count = 0; | 2616 int handler_count = 0; |
2613 | 2617 |
2614 { | 2618 { |
2615 typename Traits::Type::Factory function_factory(this->ast_value_factory()); | 2619 typename Traits::Type::Factory function_factory( |
| 2620 zone(), this->ast_value_factory(), ast_node_id_gen_); |
2616 FunctionState function_state(&function_state_, &scope_, | 2621 FunctionState function_state(&function_state_, &scope_, |
2617 Traits::Type::ptr_to_scope(scope), | 2622 Traits::Type::ptr_to_scope(scope), |
2618 &function_factory); | 2623 &function_factory); |
2619 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 2624 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
2620 num_parameters = Traits::DeclareArrowParametersFromExpression( | 2625 num_parameters = Traits::DeclareArrowParametersFromExpression( |
2621 params_ast, scope_, &dupe_error_loc, ok); | 2626 params_ast, scope_, &dupe_error_loc, ok); |
2622 if (!*ok) { | 2627 if (!*ok) { |
2623 ReportMessageAt( | 2628 ReportMessageAt( |
2624 Scanner::Location(start_pos, scanner()->location().beg_pos), | 2629 Scanner::Location(start_pos, scanner()->location().beg_pos), |
2625 "malformed_arrow_function_parameter_list"); | 2630 "malformed_arrow_function_parameter_list"); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2827 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2832 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
2828 // Both accessors of the same type. | 2833 // Both accessors of the same type. |
2829 parser()->ReportMessage("accessor_get_set"); | 2834 parser()->ReportMessage("accessor_get_set"); |
2830 } | 2835 } |
2831 *ok = false; | 2836 *ok = false; |
2832 } | 2837 } |
2833 } | 2838 } |
2834 } } // v8::internal | 2839 } } // v8::internal |
2835 | 2840 |
2836 #endif // V8_PREPARSER_H | 2841 #endif // V8_PREPARSER_H |
OLD | NEW |