| 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 "func-name-inferrer.h" | 8 #include "func-name-inferrer.h" |
| 9 #include "hashmap.h" | 9 #include "hashmap.h" |
| 10 #include "scopes.h" | 10 #include "scopes.h" |
| 11 #include "token.h" | 11 #include "token.h" |
| 12 #include "scanner.h" | 12 #include "scanner.h" |
| 13 #include "v8.h" | 13 #include "v8.h" |
| 14 | 14 |
| 15 namespace v8 { | 15 namespace v8 { |
| 16 namespace internal { | 16 namespace internal { |
| 17 | 17 |
| 18 class FastParserThread; |
| 19 |
| 18 // Common base class shared between parser and pre-parser. Traits encapsulate | 20 // Common base class shared between parser and pre-parser. Traits encapsulate |
| 19 // the differences between Parser and PreParser: | 21 // the differences between Parser and PreParser: |
| 20 | 22 |
| 21 // - Return types: For example, Parser functions return Expression* and | 23 // - Return types: For example, Parser functions return Expression* and |
| 22 // PreParser functions return PreParserExpression. | 24 // PreParser functions return PreParserExpression. |
| 23 | 25 |
| 24 // - Creating parse tree nodes: Parser generates an AST during the recursive | 26 // - Creating parse tree nodes: Parser generates an AST during the recursive |
| 25 // descent. PreParser doesn't create a tree. Instead, it passes around minimal | 27 // descent. PreParser doesn't create a tree. Instead, it passes around minimal |
| 26 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain | 28 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain |
| 27 // just enough data for the upper layer functions. PreParserFactory is | 29 // just enough data for the upper layer functions. PreParserFactory is |
| (...skipping 29 matching lines...) Expand all Loading... |
| 57 | 59 |
| 58 template <typename Traits> | 60 template <typename Traits> |
| 59 class ParserBase : public Traits { | 61 class ParserBase : public Traits { |
| 60 public: | 62 public: |
| 61 // Shorten type names defined by Traits. | 63 // Shorten type names defined by Traits. |
| 62 typedef typename Traits::Type::Expression ExpressionT; | 64 typedef typename Traits::Type::Expression ExpressionT; |
| 63 typedef typename Traits::Type::Identifier IdentifierT; | 65 typedef typename Traits::Type::Identifier IdentifierT; |
| 64 | 66 |
| 65 ParserBase(Scanner* scanner, uintptr_t stack_limit, | 67 ParserBase(Scanner* scanner, uintptr_t stack_limit, |
| 66 v8::Extension* extension, | 68 v8::Extension* extension, |
| 69 FastParserThread* thread, |
| 67 ParserRecorder* log, | 70 ParserRecorder* log, |
| 68 typename Traits::Type::Zone* zone, | 71 typename Traits::Type::Zone* zone, |
| 69 typename Traits::Type::Parser this_object) | 72 typename Traits::Type::Parser this_object) |
| 70 : Traits(this_object), | 73 : Traits(this_object), |
| 71 parenthesized_function_(false), | 74 parenthesized_function_(false), |
| 72 scope_(NULL), | 75 scope_(NULL), |
| 73 function_state_(NULL), | 76 function_state_(NULL), |
| 74 extension_(extension), | 77 extension_(extension), |
| 75 fni_(NULL), | 78 fni_(NULL), |
| 76 log_(log), | 79 log_(log), |
| 77 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 80 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
| 81 thread_(thread), |
| 78 scanner_(scanner), | 82 scanner_(scanner), |
| 79 stack_limit_(stack_limit), | 83 stack_limit_(stack_limit), |
| 80 stack_overflow_(false), | 84 stack_overflow_(false), |
| 81 allow_lazy_(false), | 85 allow_lazy_(false), |
| 82 allow_natives_syntax_(false), | 86 allow_natives_syntax_(false), |
| 83 allow_generators_(false), | 87 allow_generators_(false), |
| 84 allow_for_of_(false), | 88 allow_for_of_(false), |
| 85 zone_(zone) { } | 89 zone_(zone) { } |
| 86 | 90 |
| 87 // Getters that indicate whether certain syntactical constructs are | 91 // Getters that indicate whether certain syntactical constructs are |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // Heuristically that means that the function will be called immediately, | 471 // Heuristically that means that the function will be called immediately, |
| 468 // so never lazily compile it. | 472 // so never lazily compile it. |
| 469 bool parenthesized_function_; | 473 bool parenthesized_function_; |
| 470 | 474 |
| 471 typename Traits::Type::Scope* scope_; // Scope stack. | 475 typename Traits::Type::Scope* scope_; // Scope stack. |
| 472 FunctionState* function_state_; // Function state stack. | 476 FunctionState* function_state_; // Function state stack. |
| 473 v8::Extension* extension_; | 477 v8::Extension* extension_; |
| 474 FuncNameInferrer* fni_; | 478 FuncNameInferrer* fni_; |
| 475 ParserRecorder* log_; | 479 ParserRecorder* log_; |
| 476 Mode mode_; | 480 Mode mode_; |
| 481 FastParserThread* thread_; |
| 477 | 482 |
| 478 private: | 483 private: |
| 479 Scanner* scanner_; | 484 Scanner* scanner_; |
| 480 uintptr_t stack_limit_; | 485 uintptr_t stack_limit_; |
| 481 bool stack_overflow_; | 486 bool stack_overflow_; |
| 482 | 487 |
| 483 bool allow_lazy_; | 488 bool allow_lazy_; |
| 484 bool allow_natives_syntax_; | 489 bool allow_natives_syntax_; |
| 485 bool allow_generators_; | 490 bool allow_generators_; |
| 486 bool allow_for_of_; | 491 bool allow_for_of_; |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 public: | 1072 public: |
| 1068 typedef PreParserIdentifier Identifier; | 1073 typedef PreParserIdentifier Identifier; |
| 1069 typedef PreParserExpression Expression; | 1074 typedef PreParserExpression Expression; |
| 1070 typedef PreParserStatement Statement; | 1075 typedef PreParserStatement Statement; |
| 1071 | 1076 |
| 1072 enum PreParseResult { | 1077 enum PreParseResult { |
| 1073 kPreParseStackOverflow, | 1078 kPreParseStackOverflow, |
| 1074 kPreParseSuccess | 1079 kPreParseSuccess |
| 1075 }; | 1080 }; |
| 1076 | 1081 |
| 1077 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) | 1082 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit, |
| 1078 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, | 1083 FastParserThread* thread) |
| 1079 this) {} | 1084 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, thread, log, |
| 1085 NULL, this) {} |
| 1080 | 1086 |
| 1081 // Pre-parse the program from the character stream; returns true on | 1087 // Pre-parse the program from the character stream; returns true on |
| 1082 // success (even if parsing failed, the pre-parse data successfully | 1088 // success (even if parsing failed, the pre-parse data successfully |
| 1083 // captured the syntax error), and false if a stack-overflow happened | 1089 // captured the syntax error), and false if a stack-overflow happened |
| 1084 // during parsing. | 1090 // during parsing. |
| 1085 PreParseResult PreParseProgram() { | 1091 PreParseResult PreParseProgram() { |
| 1086 PreParserScope scope(scope_, GLOBAL_SCOPE); | 1092 PreParserScope scope(scope_, GLOBAL_SCOPE); |
| 1087 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); | 1093 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); |
| 1088 bool ok = true; | 1094 bool ok = true; |
| 1089 int start_position = scanner()->peek_location().beg_pos; | 1095 int start_position = scanner()->peek_location().beg_pos; |
| (...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2165 "accessor_get_set"); | 2171 "accessor_get_set"); |
| 2166 } | 2172 } |
| 2167 *ok = false; | 2173 *ok = false; |
| 2168 } | 2174 } |
| 2169 } | 2175 } |
| 2170 | 2176 |
| 2171 | 2177 |
| 2172 } } // v8::internal | 2178 } } // v8::internal |
| 2173 | 2179 |
| 2174 #endif // V8_PREPARSER_H | 2180 #endif // V8_PREPARSER_H |
| OLD | NEW |