OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 template <typename Traits> | 81 template <typename Traits> |
82 class ParserBase : public Traits { | 82 class ParserBase : public Traits { |
83 public: | 83 public: |
84 // Shorten type names defined by Traits. | 84 // Shorten type names defined by Traits. |
85 typedef typename Traits::Type::Expression ExpressionT; | 85 typedef typename Traits::Type::Expression ExpressionT; |
86 typedef typename Traits::Type::Identifier IdentifierT; | 86 typedef typename Traits::Type::Identifier IdentifierT; |
87 | 87 |
88 ParserBase(Scanner* scanner, uintptr_t stack_limit, | 88 ParserBase(Scanner* scanner, uintptr_t stack_limit, |
89 v8::Extension* extension, | 89 v8::Extension* extension, |
| 90 ParserRecorder* log, |
90 typename Traits::Type::Zone* zone, | 91 typename Traits::Type::Zone* zone, |
91 typename Traits::Type::Parser this_object) | 92 typename Traits::Type::Parser this_object) |
92 : Traits(this_object), | 93 : Traits(this_object), |
93 parenthesized_function_(false), | 94 parenthesized_function_(false), |
94 scope_(NULL), | 95 scope_(NULL), |
95 function_state_(NULL), | 96 function_state_(NULL), |
96 extension_(extension), | 97 extension_(extension), |
97 fni_(NULL), | 98 fni_(NULL), |
| 99 log_(log), |
98 scanner_(scanner), | 100 scanner_(scanner), |
99 stack_limit_(stack_limit), | 101 stack_limit_(stack_limit), |
100 stack_overflow_(false), | 102 stack_overflow_(false), |
101 allow_lazy_(false), | 103 allow_lazy_(false), |
102 allow_natives_syntax_(false), | 104 allow_natives_syntax_(false), |
103 allow_generators_(false), | 105 allow_generators_(false), |
104 allow_for_of_(false), | 106 allow_for_of_(false), |
105 zone_(zone) { } | 107 zone_(zone) { } |
106 | 108 |
107 // Getters that indicate whether certain syntactical constructs are | 109 // Getters that indicate whether certain syntactical constructs are |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 // If true, the next (and immediately following) function literal is | 452 // If true, the next (and immediately following) function literal is |
451 // preceded by a parenthesis. | 453 // preceded by a parenthesis. |
452 // Heuristically that means that the function will be called immediately, | 454 // Heuristically that means that the function will be called immediately, |
453 // so never lazily compile it. | 455 // so never lazily compile it. |
454 bool parenthesized_function_; | 456 bool parenthesized_function_; |
455 | 457 |
456 typename Traits::Type::Scope* scope_; // Scope stack. | 458 typename Traits::Type::Scope* scope_; // Scope stack. |
457 FunctionState* function_state_; // Function state stack. | 459 FunctionState* function_state_; // Function state stack. |
458 v8::Extension* extension_; | 460 v8::Extension* extension_; |
459 FuncNameInferrer* fni_; | 461 FuncNameInferrer* fni_; |
| 462 ParserRecorder* log_; |
460 | 463 |
461 private: | 464 private: |
462 Scanner* scanner_; | 465 Scanner* scanner_; |
463 uintptr_t stack_limit_; | 466 uintptr_t stack_limit_; |
464 bool stack_overflow_; | 467 bool stack_overflow_; |
465 | 468 |
466 bool allow_lazy_; | 469 bool allow_lazy_; |
467 bool allow_natives_syntax_; | 470 bool allow_natives_syntax_; |
468 bool allow_generators_; | 471 bool allow_generators_; |
469 bool allow_for_of_; | 472 bool allow_for_of_; |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 class PreParser : public ParserBase<PreParserTraits> { | 944 class PreParser : public ParserBase<PreParserTraits> { |
942 public: | 945 public: |
943 typedef PreParserIdentifier Identifier; | 946 typedef PreParserIdentifier Identifier; |
944 typedef PreParserExpression Expression; | 947 typedef PreParserExpression Expression; |
945 | 948 |
946 enum PreParseResult { | 949 enum PreParseResult { |
947 kPreParseStackOverflow, | 950 kPreParseStackOverflow, |
948 kPreParseSuccess | 951 kPreParseSuccess |
949 }; | 952 }; |
950 | 953 |
951 PreParser(Scanner* scanner, | 954 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) |
952 ParserRecorder* log, | 955 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, |
953 uintptr_t stack_limit) | 956 this) {} |
954 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, NULL, this), | |
955 log_(log) {} | |
956 | 957 |
957 // Pre-parse the program from the character stream; returns true on | 958 // Pre-parse the program from the character stream; returns true on |
958 // success (even if parsing failed, the pre-parse data successfully | 959 // success (even if parsing failed, the pre-parse data successfully |
959 // captured the syntax error), and false if a stack-overflow happened | 960 // captured the syntax error), and false if a stack-overflow happened |
960 // during parsing. | 961 // during parsing. |
961 PreParseResult PreParseProgram() { | 962 PreParseResult PreParseProgram() { |
962 PreParserScope scope(scope_, GLOBAL_SCOPE); | 963 PreParserScope scope(scope_, GLOBAL_SCOPE); |
963 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); | 964 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); |
964 bool ok = true; | 965 bool ok = true; |
965 int start_position = scanner()->peek_location().beg_pos; | 966 int start_position = scanner()->peek_location().beg_pos; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 FunctionLiteral::FunctionType function_type, | 1105 FunctionLiteral::FunctionType function_type, |
1105 bool* ok); | 1106 bool* ok); |
1106 void ParseLazyFunctionLiteralBody(bool* ok); | 1107 void ParseLazyFunctionLiteralBody(bool* ok); |
1107 | 1108 |
1108 // Logs the currently parsed literal as a symbol in the preparser data. | 1109 // Logs the currently parsed literal as a symbol in the preparser data. |
1109 void LogSymbol(); | 1110 void LogSymbol(); |
1110 // Log the currently parsed string literal. | 1111 // Log the currently parsed string literal. |
1111 Expression GetStringSymbol(); | 1112 Expression GetStringSymbol(); |
1112 | 1113 |
1113 bool CheckInOrOf(bool accept_OF); | 1114 bool CheckInOrOf(bool accept_OF); |
1114 | |
1115 ParserRecorder* log_; | |
1116 }; | 1115 }; |
1117 | 1116 |
1118 | |
1119 template<class Traits> | 1117 template<class Traits> |
1120 ParserBase<Traits>::FunctionState::FunctionState( | 1118 ParserBase<Traits>::FunctionState::FunctionState( |
1121 FunctionState** function_state_stack, | 1119 FunctionState** function_state_stack, |
1122 typename Traits::Type::Scope** scope_stack, | 1120 typename Traits::Type::Scope** scope_stack, |
1123 typename Traits::Type::Scope* scope, | 1121 typename Traits::Type::Scope* scope, |
1124 typename Traits::Type::Zone* extra_param) | 1122 typename Traits::Type::Zone* extra_param) |
1125 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), | 1123 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), |
1126 next_handler_index_(0), | 1124 next_handler_index_(0), |
1127 expected_property_count_(0), | 1125 expected_property_count_(0), |
1128 is_generator_(false), | 1126 is_generator_(false), |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 "accessor_get_set"); | 1811 "accessor_get_set"); |
1814 } | 1812 } |
1815 *ok = false; | 1813 *ok = false; |
1816 } | 1814 } |
1817 } | 1815 } |
1818 | 1816 |
1819 | 1817 |
1820 } } // v8::internal | 1818 } } // v8::internal |
1821 | 1819 |
1822 #endif // V8_PREPARSER_H | 1820 #endif // V8_PREPARSER_H |
OLD | NEW |