| 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 20 matching lines...) Expand all Loading... |
| 31 #include "func-name-inferrer.h" | 31 #include "func-name-inferrer.h" |
| 32 #include "hashmap.h" | 32 #include "hashmap.h" |
| 33 #include "scopes.h" | 33 #include "scopes.h" |
| 34 #include "token.h" | 34 #include "token.h" |
| 35 #include "scanner.h" | 35 #include "scanner.h" |
| 36 #include "v8.h" | 36 #include "v8.h" |
| 37 | 37 |
| 38 namespace v8 { | 38 namespace v8 { |
| 39 namespace internal { | 39 namespace internal { |
| 40 | 40 |
| 41 class FastParserThread; |
| 42 |
| 41 // Common base class shared between parser and pre-parser. Traits encapsulate | 43 // Common base class shared between parser and pre-parser. Traits encapsulate |
| 42 // the differences between Parser and PreParser: | 44 // the differences between Parser and PreParser: |
| 43 | 45 |
| 44 // - Return types: For example, Parser functions return Expression* and | 46 // - Return types: For example, Parser functions return Expression* and |
| 45 // PreParser functions return PreParserExpression. | 47 // PreParser functions return PreParserExpression. |
| 46 | 48 |
| 47 // - Creating parse tree nodes: Parser generates an AST during the recursive | 49 // - Creating parse tree nodes: Parser generates an AST during the recursive |
| 48 // descent. PreParser doesn't create a tree. Instead, it passes around minimal | 50 // descent. PreParser doesn't create a tree. Instead, it passes around minimal |
| 49 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain | 51 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain |
| 50 // just enough data for the upper layer functions. PreParserFactory is | 52 // just enough data for the upper layer functions. PreParserFactory is |
| (...skipping 29 matching lines...) Expand all Loading... |
| 80 | 82 |
| 81 template <typename Traits> | 83 template <typename Traits> |
| 82 class ParserBase : public Traits { | 84 class ParserBase : public Traits { |
| 83 public: | 85 public: |
| 84 // Shorten type names defined by Traits. | 86 // Shorten type names defined by Traits. |
| 85 typedef typename Traits::Type::Expression ExpressionT; | 87 typedef typename Traits::Type::Expression ExpressionT; |
| 86 typedef typename Traits::Type::Identifier IdentifierT; | 88 typedef typename Traits::Type::Identifier IdentifierT; |
| 87 | 89 |
| 88 ParserBase(Scanner* scanner, uintptr_t stack_limit, | 90 ParserBase(Scanner* scanner, uintptr_t stack_limit, |
| 89 v8::Extension* extension, | 91 v8::Extension* extension, |
| 92 FastParserThread* thread, |
| 90 ParserRecorder* log, | 93 ParserRecorder* log, |
| 91 typename Traits::Type::Zone* zone, | 94 typename Traits::Type::Zone* zone, |
| 92 typename Traits::Type::Parser this_object) | 95 typename Traits::Type::Parser this_object) |
| 93 : Traits(this_object), | 96 : Traits(this_object), |
| 94 parenthesized_function_(false), | 97 parenthesized_function_(false), |
| 95 scope_(NULL), | 98 scope_(NULL), |
| 96 function_state_(NULL), | 99 function_state_(NULL), |
| 97 extension_(extension), | 100 extension_(extension), |
| 98 fni_(NULL), | 101 fni_(NULL), |
| 99 log_(log), | 102 log_(log), |
| 100 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 103 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
| 104 thread_(thread), |
| 101 scanner_(scanner), | 105 scanner_(scanner), |
| 102 stack_limit_(stack_limit), | 106 stack_limit_(stack_limit), |
| 103 stack_overflow_(false), | 107 stack_overflow_(false), |
| 104 allow_lazy_(false), | 108 allow_lazy_(false), |
| 105 allow_natives_syntax_(false), | 109 allow_natives_syntax_(false), |
| 106 allow_generators_(false), | 110 allow_generators_(false), |
| 107 allow_for_of_(false), | 111 allow_for_of_(false), |
| 108 zone_(zone) { } | 112 zone_(zone) { } |
| 109 | 113 |
| 110 // Getters that indicate whether certain syntactical constructs are | 114 // Getters that indicate whether certain syntactical constructs are |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 // Heuristically that means that the function will be called immediately, | 495 // Heuristically that means that the function will be called immediately, |
| 492 // so never lazily compile it. | 496 // so never lazily compile it. |
| 493 bool parenthesized_function_; | 497 bool parenthesized_function_; |
| 494 | 498 |
| 495 typename Traits::Type::Scope* scope_; // Scope stack. | 499 typename Traits::Type::Scope* scope_; // Scope stack. |
| 496 FunctionState* function_state_; // Function state stack. | 500 FunctionState* function_state_; // Function state stack. |
| 497 v8::Extension* extension_; | 501 v8::Extension* extension_; |
| 498 FuncNameInferrer* fni_; | 502 FuncNameInferrer* fni_; |
| 499 ParserRecorder* log_; | 503 ParserRecorder* log_; |
| 500 Mode mode_; | 504 Mode mode_; |
| 505 FastParserThread* thread_; |
| 501 | 506 |
| 502 private: | 507 private: |
| 503 Scanner* scanner_; | 508 Scanner* scanner_; |
| 504 uintptr_t stack_limit_; | 509 uintptr_t stack_limit_; |
| 505 bool stack_overflow_; | 510 bool stack_overflow_; |
| 506 | 511 |
| 507 bool allow_lazy_; | 512 bool allow_lazy_; |
| 508 bool allow_natives_syntax_; | 513 bool allow_natives_syntax_; |
| 509 bool allow_generators_; | 514 bool allow_generators_; |
| 510 bool allow_for_of_; | 515 bool allow_for_of_; |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 class PreParser : public ParserBase<PreParserTraits> { | 1033 class PreParser : public ParserBase<PreParserTraits> { |
| 1029 public: | 1034 public: |
| 1030 typedef PreParserIdentifier Identifier; | 1035 typedef PreParserIdentifier Identifier; |
| 1031 typedef PreParserExpression Expression; | 1036 typedef PreParserExpression Expression; |
| 1032 | 1037 |
| 1033 enum PreParseResult { | 1038 enum PreParseResult { |
| 1034 kPreParseStackOverflow, | 1039 kPreParseStackOverflow, |
| 1035 kPreParseSuccess | 1040 kPreParseSuccess |
| 1036 }; | 1041 }; |
| 1037 | 1042 |
| 1038 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) | 1043 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit, |
| 1039 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, | 1044 FastParserThread* thread) |
| 1040 this) {} | 1045 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, thread, log, |
| 1046 NULL, this) {} |
| 1041 | 1047 |
| 1042 // Pre-parse the program from the character stream; returns true on | 1048 // Pre-parse the program from the character stream; returns true on |
| 1043 // success (even if parsing failed, the pre-parse data successfully | 1049 // success (even if parsing failed, the pre-parse data successfully |
| 1044 // captured the syntax error), and false if a stack-overflow happened | 1050 // captured the syntax error), and false if a stack-overflow happened |
| 1045 // during parsing. | 1051 // during parsing. |
| 1046 PreParseResult PreParseProgram() { | 1052 PreParseResult PreParseProgram() { |
| 1047 PreParserScope scope(scope_, GLOBAL_SCOPE); | 1053 PreParserScope scope(scope_, GLOBAL_SCOPE); |
| 1048 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); | 1054 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); |
| 1049 bool ok = true; | 1055 bool ok = true; |
| 1050 int start_position = scanner()->peek_location().beg_pos; | 1056 int start_position = scanner()->peek_location().beg_pos; |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2172 "accessor_get_set"); | 2178 "accessor_get_set"); |
| 2173 } | 2179 } |
| 2174 *ok = false; | 2180 *ok = false; |
| 2175 } | 2181 } |
| 2176 } | 2182 } |
| 2177 | 2183 |
| 2178 | 2184 |
| 2179 } } // v8::internal | 2185 } } // v8::internal |
| 2180 | 2186 |
| 2181 #endif // V8_PREPARSER_H | 2187 #endif // V8_PREPARSER_H |
| OLD | NEW |