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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 } | 587 } |
587 bool IsAccessorAccessorConflict(PropertyKind type1, PropertyKind type2) { | 588 bool IsAccessorAccessorConflict(PropertyKind type1, PropertyKind type2) { |
588 return ((type1 | type2) & kValueFlag) == 0; | 589 return ((type1 | type2) & kValueFlag) == 0; |
589 } | 590 } |
590 | 591 |
591 ParserBase* parser_; | 592 ParserBase* parser_; |
592 DuplicateFinder finder_; | 593 DuplicateFinder finder_; |
593 StrictMode strict_mode_; | 594 StrictMode strict_mode_; |
594 }; | 595 }; |
595 | 596 |
597 Isolate* isolate() const { return isolate_; } | |
Michael Starzinger
2015/01/23 14:21:11
nit: Could we move this up to around line 300 near
danno
2015/01/23 14:45:20
Done.
| |
598 | |
596 // If true, the next (and immediately following) function literal is | 599 // If true, the next (and immediately following) function literal is |
597 // preceded by a parenthesis. | 600 // preceded by a parenthesis. |
598 // Heuristically that means that the function will be called immediately, | 601 // Heuristically that means that the function will be called immediately, |
599 // so never lazily compile it. | 602 // so never lazily compile it. |
600 bool parenthesized_function_; | 603 bool parenthesized_function_; |
601 | 604 |
602 typename Traits::Type::Scope* scope_; // Scope stack. | 605 typename Traits::Type::Scope* scope_; // Scope stack. |
603 FunctionState* function_state_; // Function state stack. | 606 FunctionState* function_state_; // Function state stack. |
604 v8::Extension* extension_; | 607 v8::Extension* extension_; |
605 FuncNameInferrer* fni_; | 608 FuncNameInferrer* fni_; |
606 ParserRecorder* log_; | 609 ParserRecorder* log_; |
607 Mode mode_; | 610 Mode mode_; |
608 uintptr_t stack_limit_; | 611 uintptr_t stack_limit_; |
609 | 612 |
610 private: | 613 private: |
614 Isolate* isolate_; | |
615 typename Traits::Type::Zone* zone_; // Only used by Parser. | |
616 | |
611 Scanner* scanner_; | 617 Scanner* scanner_; |
612 bool stack_overflow_; | 618 bool stack_overflow_; |
613 | 619 |
614 bool allow_lazy_; | 620 bool allow_lazy_; |
615 bool allow_natives_; | 621 bool allow_natives_; |
616 bool allow_harmony_arrow_functions_; | 622 bool allow_harmony_arrow_functions_; |
617 bool allow_harmony_object_literals_; | 623 bool allow_harmony_object_literals_; |
618 bool allow_harmony_sloppy_; | 624 bool allow_harmony_sloppy_; |
619 bool allow_harmony_computed_property_names_; | 625 bool allow_harmony_computed_property_names_; |
620 | |
621 typename Traits::Type::Zone* zone_; // Only used by Parser. | |
622 }; | 626 }; |
623 | 627 |
624 | 628 |
625 class PreParserIdentifier { | 629 class PreParserIdentifier { |
626 public: | 630 public: |
627 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 631 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
628 static PreParserIdentifier Default() { | 632 static PreParserIdentifier Default() { |
629 return PreParserIdentifier(kUnknownIdentifier); | 633 return PreParserIdentifier(kUnknownIdentifier); |
630 } | 634 } |
631 static PreParserIdentifier Eval() { | 635 static PreParserIdentifier Eval() { |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1022 PreParserScope* operator->() { return this; } | 1026 PreParserScope* operator->() { return this; } |
1023 | 1027 |
1024 private: | 1028 private: |
1025 ScopeType scope_type_; | 1029 ScopeType scope_type_; |
1026 StrictMode strict_mode_; | 1030 StrictMode strict_mode_; |
1027 }; | 1031 }; |
1028 | 1032 |
1029 | 1033 |
1030 class PreParserFactory { | 1034 class PreParserFactory { |
1031 public: | 1035 public: |
1032 explicit PreParserFactory(void* unused_value_factory) {} | 1036 explicit PreParserFactory(Isolate* isolate, void* unused_value_factory) {} |
1033 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 1037 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
1034 int pos) { | 1038 int pos) { |
1035 return PreParserExpression::Default(); | 1039 return PreParserExpression::Default(); |
1036 } | 1040 } |
1037 PreParserExpression NewNumberLiteral(double number, | 1041 PreParserExpression NewNumberLiteral(double number, |
1038 int pos) { | 1042 int pos) { |
1039 return PreParserExpression::Default(); | 1043 return PreParserExpression::Default(); |
1040 } | 1044 } |
1041 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 1045 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
1042 PreParserIdentifier js_flags, | 1046 PreParserIdentifier js_flags, |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1487 public: | 1491 public: |
1488 typedef PreParserIdentifier Identifier; | 1492 typedef PreParserIdentifier Identifier; |
1489 typedef PreParserExpression Expression; | 1493 typedef PreParserExpression Expression; |
1490 typedef PreParserStatement Statement; | 1494 typedef PreParserStatement Statement; |
1491 | 1495 |
1492 enum PreParseResult { | 1496 enum PreParseResult { |
1493 kPreParseStackOverflow, | 1497 kPreParseStackOverflow, |
1494 kPreParseSuccess | 1498 kPreParseSuccess |
1495 }; | 1499 }; |
1496 | 1500 |
1497 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) | 1501 PreParser(Isolate* isolate, Scanner* scanner, ParserRecorder* log, |
1498 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, | 1502 uintptr_t stack_limit) |
1499 this) {} | 1503 : ParserBase<PreParserTraits>(isolate, NULL, scanner, stack_limit, NULL, |
1504 log, this) {} | |
1500 | 1505 |
1501 // Pre-parse the program from the character stream; returns true on | 1506 // Pre-parse the program from the character stream; returns true on |
1502 // success (even if parsing failed, the pre-parse data successfully | 1507 // success (even if parsing failed, the pre-parse data successfully |
1503 // captured the syntax error), and false if a stack-overflow happened | 1508 // captured the syntax error), and false if a stack-overflow happened |
1504 // during parsing. | 1509 // during parsing. |
1505 PreParseResult PreParseProgram(int* materialized_literals = 0) { | 1510 PreParseResult PreParseProgram(int* materialized_literals = 0) { |
1506 PreParserScope scope(scope_, SCRIPT_SCOPE); | 1511 PreParserScope scope(scope_, SCRIPT_SCOPE); |
1507 PreParserFactory factory(NULL); | 1512 PreParserFactory factory(NULL, NULL); |
1508 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); | 1513 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); |
1509 bool ok = true; | 1514 bool ok = true; |
1510 int start_position = scanner()->peek_location().beg_pos; | 1515 int start_position = scanner()->peek_location().beg_pos; |
1511 ParseSourceElements(Token::EOS, &ok); | 1516 ParseSourceElements(Token::EOS, &ok); |
1512 if (stack_overflow()) return kPreParseStackOverflow; | 1517 if (stack_overflow()) return kPreParseStackOverflow; |
1513 if (!ok) { | 1518 if (!ok) { |
1514 ReportUnexpectedToken(scanner()->current_token()); | 1519 ReportUnexpectedToken(scanner()->current_token()); |
1515 } else if (scope_->strict_mode() == STRICT) { | 1520 } else if (scope_->strict_mode() == STRICT) { |
1516 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, | 1521 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, |
1517 &ok); | 1522 &ok); |
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2800 default: | 2805 default: |
2801 return expression; | 2806 return expression; |
2802 } | 2807 } |
2803 } | 2808 } |
2804 DCHECK(false); | 2809 DCHECK(false); |
2805 return this->EmptyExpression(); | 2810 return this->EmptyExpression(); |
2806 } | 2811 } |
2807 | 2812 |
2808 | 2813 |
2809 template <class Traits> | 2814 template <class Traits> |
2810 typename ParserBase<Traits>::ExpressionT ParserBase< | 2815 typename ParserBase<Traits>::ExpressionT |
2811 Traits>::ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, | 2816 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, |
2812 bool* ok) { | 2817 ExpressionT params_ast, |
2818 bool* ok) { | |
2813 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); | 2819 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); |
2814 typename Traits::Type::StatementList body; | 2820 typename Traits::Type::StatementList body; |
2815 int num_parameters = -1; | 2821 int num_parameters = -1; |
2816 int materialized_literal_count = -1; | 2822 int materialized_literal_count = -1; |
2817 int expected_property_count = -1; | 2823 int expected_property_count = -1; |
2818 int handler_count = 0; | 2824 int handler_count = 0; |
2819 | 2825 |
2820 { | 2826 { |
2821 typename Traits::Type::Factory function_factory(this->ast_value_factory()); | 2827 typename Traits::Type::Factory function_factory(isolate(), |
2828 this->ast_value_factory()); | |
2822 FunctionState function_state(&function_state_, &scope_, | 2829 FunctionState function_state(&function_state_, &scope_, |
2823 Traits::Type::ptr_to_scope(scope), | 2830 Traits::Type::ptr_to_scope(scope), |
2824 &function_factory); | 2831 &function_factory); |
2825 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 2832 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
2826 num_parameters = Traits::DeclareArrowParametersFromExpression( | 2833 num_parameters = Traits::DeclareArrowParametersFromExpression( |
2827 params_ast, scope_, &dupe_error_loc, ok); | 2834 params_ast, scope_, &dupe_error_loc, ok); |
2828 if (!*ok) { | 2835 if (!*ok) { |
2829 ReportMessageAt( | 2836 ReportMessageAt( |
2830 Scanner::Location(start_pos, scanner()->location().beg_pos), | 2837 Scanner::Location(start_pos, scanner()->location().beg_pos), |
2831 "malformed_arrow_function_parameter_list"); | 2838 "malformed_arrow_function_parameter_list"); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3056 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 3063 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
3057 // Both accessors of the same type. | 3064 // Both accessors of the same type. |
3058 parser()->ReportMessage("accessor_get_set"); | 3065 parser()->ReportMessage("accessor_get_set"); |
3059 } | 3066 } |
3060 *ok = false; | 3067 *ok = false; |
3061 } | 3068 } |
3062 } | 3069 } |
3063 } } // v8::internal | 3070 } } // v8::internal |
3064 | 3071 |
3065 #endif // V8_PREPARSER_H | 3072 #endif // V8_PREPARSER_H |
OLD | NEW |