| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 template <typename Traits> | 61 template <typename Traits> |
| 62 class ParserBase : public Traits { | 62 class ParserBase : public Traits { |
| 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(Isolate* isolate, typename Traits::Type::Zone* zone, |
| 72 ParserRecorder* log, typename Traits::Type::Zone* zone, | 72 Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension, |
| 73 typename Traits::Type::Parser this_object) | 73 ParserRecorder* log, typename Traits::Type::Parser this_object) |
| 74 : Traits(this_object), | 74 : Traits(this_object), |
| 75 parenthesized_function_(false), | 75 parenthesized_function_(false), |
| 76 scope_(NULL), | 76 scope_(NULL), |
| 77 function_state_(NULL), | 77 function_state_(NULL), |
| 78 extension_(extension), | 78 extension_(extension), |
| 79 fni_(NULL), | 79 fni_(NULL), |
| 80 log_(log), | 80 log_(log), |
| 81 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 81 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
| 82 stack_limit_(stack_limit), | 82 stack_limit_(stack_limit), |
| 83 isolate_(isolate), |
| 84 zone_(zone), |
| 83 scanner_(scanner), | 85 scanner_(scanner), |
| 84 stack_overflow_(false), | 86 stack_overflow_(false), |
| 85 allow_lazy_(false), | 87 allow_lazy_(false), |
| 86 allow_natives_(false), | 88 allow_natives_(false), |
| 87 allow_harmony_arrow_functions_(false), | 89 allow_harmony_arrow_functions_(false), |
| 88 allow_harmony_object_literals_(false), | 90 allow_harmony_object_literals_(false), |
| 89 allow_harmony_sloppy_(false), | 91 allow_harmony_sloppy_(false), |
| 90 allow_harmony_computed_property_names_(false), | 92 allow_harmony_computed_property_names_(false) {} |
| 91 zone_(zone) {} | |
| 92 | 93 |
| 93 // Getters that indicate whether certain syntactical constructs are | 94 // Getters that indicate whether certain syntactical constructs are |
| 94 // allowed to be parsed by this instance of the parser. | 95 // allowed to be parsed by this instance of the parser. |
| 95 bool allow_lazy() const { return allow_lazy_; } | 96 bool allow_lazy() const { return allow_lazy_; } |
| 96 bool allow_natives() const { return allow_natives_; } | 97 bool allow_natives() const { return allow_natives_; } |
| 97 bool allow_harmony_arrow_functions() const { | 98 bool allow_harmony_arrow_functions() const { |
| 98 return allow_harmony_arrow_functions_; | 99 return allow_harmony_arrow_functions_; |
| 99 } | 100 } |
| 100 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } | 101 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } |
| 101 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } | 102 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 290 } |
| 290 ~ParsingModeScope() { | 291 ~ParsingModeScope() { |
| 291 parser_->mode_ = old_mode_; | 292 parser_->mode_ = old_mode_; |
| 292 } | 293 } |
| 293 | 294 |
| 294 private: | 295 private: |
| 295 ParserBase* parser_; | 296 ParserBase* parser_; |
| 296 Mode old_mode_; | 297 Mode old_mode_; |
| 297 }; | 298 }; |
| 298 | 299 |
| 300 Isolate* isolate() const { return isolate_; } |
| 299 Scanner* scanner() const { return scanner_; } | 301 Scanner* scanner() const { return scanner_; } |
| 300 int position() { return scanner_->location().beg_pos; } | 302 int position() { return scanner_->location().beg_pos; } |
| 301 int peek_position() { return scanner_->peek_location().beg_pos; } | 303 int peek_position() { return scanner_->peek_location().beg_pos; } |
| 302 bool stack_overflow() const { return stack_overflow_; } | 304 bool stack_overflow() const { return stack_overflow_; } |
| 303 void set_stack_overflow() { stack_overflow_ = true; } | 305 void set_stack_overflow() { stack_overflow_ = true; } |
| 304 Mode mode() const { return mode_; } | 306 Mode mode() const { return mode_; } |
| 305 typename Traits::Type::Zone* zone() const { return zone_; } | 307 typename Traits::Type::Zone* zone() const { return zone_; } |
| 306 | 308 |
| 307 INLINE(Token::Value peek()) { | 309 INLINE(Token::Value peek()) { |
| 308 if (stack_overflow_) return Token::ILLEGAL; | 310 if (stack_overflow_) return Token::ILLEGAL; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 | 603 |
| 602 typename Traits::Type::Scope* scope_; // Scope stack. | 604 typename Traits::Type::Scope* scope_; // Scope stack. |
| 603 FunctionState* function_state_; // Function state stack. | 605 FunctionState* function_state_; // Function state stack. |
| 604 v8::Extension* extension_; | 606 v8::Extension* extension_; |
| 605 FuncNameInferrer* fni_; | 607 FuncNameInferrer* fni_; |
| 606 ParserRecorder* log_; | 608 ParserRecorder* log_; |
| 607 Mode mode_; | 609 Mode mode_; |
| 608 uintptr_t stack_limit_; | 610 uintptr_t stack_limit_; |
| 609 | 611 |
| 610 private: | 612 private: |
| 613 Isolate* isolate_; |
| 614 typename Traits::Type::Zone* zone_; // Only used by Parser. |
| 615 |
| 611 Scanner* scanner_; | 616 Scanner* scanner_; |
| 612 bool stack_overflow_; | 617 bool stack_overflow_; |
| 613 | 618 |
| 614 bool allow_lazy_; | 619 bool allow_lazy_; |
| 615 bool allow_natives_; | 620 bool allow_natives_; |
| 616 bool allow_harmony_arrow_functions_; | 621 bool allow_harmony_arrow_functions_; |
| 617 bool allow_harmony_object_literals_; | 622 bool allow_harmony_object_literals_; |
| 618 bool allow_harmony_sloppy_; | 623 bool allow_harmony_sloppy_; |
| 619 bool allow_harmony_computed_property_names_; | 624 bool allow_harmony_computed_property_names_; |
| 620 | |
| 621 typename Traits::Type::Zone* zone_; // Only used by Parser. | |
| 622 }; | 625 }; |
| 623 | 626 |
| 624 | 627 |
| 625 class PreParserIdentifier { | 628 class PreParserIdentifier { |
| 626 public: | 629 public: |
| 627 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 630 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
| 628 static PreParserIdentifier Default() { | 631 static PreParserIdentifier Default() { |
| 629 return PreParserIdentifier(kUnknownIdentifier); | 632 return PreParserIdentifier(kUnknownIdentifier); |
| 630 } | 633 } |
| 631 static PreParserIdentifier Eval() { | 634 static PreParserIdentifier Eval() { |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1487 public: | 1490 public: |
| 1488 typedef PreParserIdentifier Identifier; | 1491 typedef PreParserIdentifier Identifier; |
| 1489 typedef PreParserExpression Expression; | 1492 typedef PreParserExpression Expression; |
| 1490 typedef PreParserStatement Statement; | 1493 typedef PreParserStatement Statement; |
| 1491 | 1494 |
| 1492 enum PreParseResult { | 1495 enum PreParseResult { |
| 1493 kPreParseStackOverflow, | 1496 kPreParseStackOverflow, |
| 1494 kPreParseSuccess | 1497 kPreParseSuccess |
| 1495 }; | 1498 }; |
| 1496 | 1499 |
| 1497 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) | 1500 PreParser(Isolate* isolate, Scanner* scanner, ParserRecorder* log, |
| 1498 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, | 1501 uintptr_t stack_limit) |
| 1499 this) {} | 1502 : ParserBase<PreParserTraits>(isolate, NULL, scanner, stack_limit, NULL, |
| 1503 log, this) {} |
| 1500 | 1504 |
| 1501 // Pre-parse the program from the character stream; returns true on | 1505 // Pre-parse the program from the character stream; returns true on |
| 1502 // success (even if parsing failed, the pre-parse data successfully | 1506 // success (even if parsing failed, the pre-parse data successfully |
| 1503 // captured the syntax error), and false if a stack-overflow happened | 1507 // captured the syntax error), and false if a stack-overflow happened |
| 1504 // during parsing. | 1508 // during parsing. |
| 1505 PreParseResult PreParseProgram(int* materialized_literals = 0) { | 1509 PreParseResult PreParseProgram(int* materialized_literals = 0) { |
| 1506 PreParserScope scope(scope_, SCRIPT_SCOPE); | 1510 PreParserScope scope(scope_, SCRIPT_SCOPE); |
| 1507 PreParserFactory factory(NULL); | 1511 PreParserFactory factory(NULL); |
| 1508 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); | 1512 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); |
| 1509 bool ok = true; | 1513 bool ok = true; |
| (...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2800 default: | 2804 default: |
| 2801 return expression; | 2805 return expression; |
| 2802 } | 2806 } |
| 2803 } | 2807 } |
| 2804 DCHECK(false); | 2808 DCHECK(false); |
| 2805 return this->EmptyExpression(); | 2809 return this->EmptyExpression(); |
| 2806 } | 2810 } |
| 2807 | 2811 |
| 2808 | 2812 |
| 2809 template <class Traits> | 2813 template <class Traits> |
| 2810 typename ParserBase<Traits>::ExpressionT ParserBase< | 2814 typename ParserBase<Traits>::ExpressionT |
| 2811 Traits>::ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, | 2815 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, |
| 2812 bool* ok) { | 2816 ExpressionT params_ast, |
| 2817 bool* ok) { |
| 2813 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); | 2818 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); |
| 2814 typename Traits::Type::StatementList body; | 2819 typename Traits::Type::StatementList body; |
| 2815 int num_parameters = -1; | 2820 int num_parameters = -1; |
| 2816 int materialized_literal_count = -1; | 2821 int materialized_literal_count = -1; |
| 2817 int expected_property_count = -1; | 2822 int expected_property_count = -1; |
| 2818 int handler_count = 0; | 2823 int handler_count = 0; |
| 2819 | 2824 |
| 2820 { | 2825 { |
| 2821 typename Traits::Type::Factory function_factory(this->ast_value_factory()); | 2826 typename Traits::Type::Factory function_factory(this->ast_value_factory()); |
| 2822 FunctionState function_state(&function_state_, &scope_, | 2827 FunctionState function_state(&function_state_, &scope_, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3056 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 3061 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
| 3057 // Both accessors of the same type. | 3062 // Both accessors of the same type. |
| 3058 parser()->ReportMessage("accessor_get_set"); | 3063 parser()->ReportMessage("accessor_get_set"); |
| 3059 } | 3064 } |
| 3060 *ok = false; | 3065 *ok = false; |
| 3061 } | 3066 } |
| 3062 } | 3067 } |
| 3063 } } // v8::internal | 3068 } } // v8::internal |
| 3064 | 3069 |
| 3065 #endif // V8_PREPARSER_H | 3070 #endif // V8_PREPARSER_H |
| OLD | NEW |