| 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 namespace v8 { | 38 namespace v8 { |
| 39 namespace internal { | 39 namespace internal { |
| 40 | 40 |
| 41 // Common base class shared between parser and pre-parser. | 41 // Common base class shared between parser and pre-parser. |
| 42 template <typename Traits> | 42 template <typename Traits> |
| 43 class ParserBase : public Traits { | 43 class ParserBase : public Traits { |
| 44 public: | 44 public: |
| 45 ParserBase(Scanner* scanner, uintptr_t stack_limit, | 45 ParserBase(Scanner* scanner, uintptr_t stack_limit, |
| 46 v8::Extension* extension, | 46 v8::Extension* extension, |
| 47 ParserRecorder* log, |
| 47 typename Traits::Type::Zone* zone, | 48 typename Traits::Type::Zone* zone, |
| 48 typename Traits::Type::Parser this_object) | 49 typename Traits::Type::Parser this_object) |
| 49 : Traits(this_object), | 50 : Traits(this_object), |
| 50 parenthesized_function_(false), | 51 parenthesized_function_(false), |
| 51 scope_(NULL), | 52 scope_(NULL), |
| 52 function_state_(NULL), | 53 function_state_(NULL), |
| 53 extension_(extension), | 54 extension_(extension), |
| 54 fni_(NULL), | 55 fni_(NULL), |
| 56 log_(log), |
| 55 scanner_(scanner), | 57 scanner_(scanner), |
| 56 stack_limit_(stack_limit), | 58 stack_limit_(stack_limit), |
| 57 stack_overflow_(false), | 59 stack_overflow_(false), |
| 58 allow_lazy_(false), | 60 allow_lazy_(false), |
| 59 allow_natives_syntax_(false), | 61 allow_natives_syntax_(false), |
| 60 allow_generators_(false), | 62 allow_generators_(false), |
| 61 allow_for_of_(false), | 63 allow_for_of_(false), |
| 62 zone_(zone) { } | 64 zone_(zone) { } |
| 63 | 65 |
| 64 // Getters that indicate whether certain syntactical constructs are | 66 // Getters that indicate whether certain syntactical constructs are |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // If true, the next (and immediately following) function literal is | 403 // If true, the next (and immediately following) function literal is |
| 402 // preceded by a parenthesis. | 404 // preceded by a parenthesis. |
| 403 // Heuristically that means that the function will be called immediately, | 405 // Heuristically that means that the function will be called immediately, |
| 404 // so never lazily compile it. | 406 // so never lazily compile it. |
| 405 bool parenthesized_function_; | 407 bool parenthesized_function_; |
| 406 | 408 |
| 407 typename Traits::Type::Scope* scope_; // Scope stack. | 409 typename Traits::Type::Scope* scope_; // Scope stack. |
| 408 FunctionState* function_state_; // Function state stack. | 410 FunctionState* function_state_; // Function state stack. |
| 409 v8::Extension* extension_; | 411 v8::Extension* extension_; |
| 410 FuncNameInferrer* fni_; | 412 FuncNameInferrer* fni_; |
| 413 ParserRecorder* log_; |
| 411 | 414 |
| 412 private: | 415 private: |
| 413 Scanner* scanner_; | 416 Scanner* scanner_; |
| 414 uintptr_t stack_limit_; | 417 uintptr_t stack_limit_; |
| 415 bool stack_overflow_; | 418 bool stack_overflow_; |
| 416 | 419 |
| 417 bool allow_lazy_; | 420 bool allow_lazy_; |
| 418 bool allow_natives_syntax_; | 421 bool allow_natives_syntax_; |
| 419 bool allow_generators_; | 422 bool allow_generators_; |
| 420 bool allow_for_of_; | 423 bool allow_for_of_; |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 class PreParser : public ParserBase<PreParserTraits> { | 806 class PreParser : public ParserBase<PreParserTraits> { |
| 804 public: | 807 public: |
| 805 typedef PreParserIdentifier Identifier; | 808 typedef PreParserIdentifier Identifier; |
| 806 typedef PreParserExpression Expression; | 809 typedef PreParserExpression Expression; |
| 807 | 810 |
| 808 enum PreParseResult { | 811 enum PreParseResult { |
| 809 kPreParseStackOverflow, | 812 kPreParseStackOverflow, |
| 810 kPreParseSuccess | 813 kPreParseSuccess |
| 811 }; | 814 }; |
| 812 | 815 |
| 813 PreParser(Scanner* scanner, | 816 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) |
| 814 ParserRecorder* log, | 817 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, |
| 815 uintptr_t stack_limit) | 818 this) {} |
| 816 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, NULL, this), | |
| 817 log_(log) {} | |
| 818 | 819 |
| 819 // Pre-parse the program from the character stream; returns true on | 820 // Pre-parse the program from the character stream; returns true on |
| 820 // success (even if parsing failed, the pre-parse data successfully | 821 // success (even if parsing failed, the pre-parse data successfully |
| 821 // captured the syntax error), and false if a stack-overflow happened | 822 // captured the syntax error), and false if a stack-overflow happened |
| 822 // during parsing. | 823 // during parsing. |
| 823 PreParseResult PreParseProgram() { | 824 PreParseResult PreParseProgram() { |
| 824 PreParserScope scope(scope_, GLOBAL_SCOPE); | 825 PreParserScope scope(scope_, GLOBAL_SCOPE); |
| 825 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); | 826 FunctionState top_scope(&function_state_, &scope_, &scope, NULL); |
| 826 bool ok = true; | 827 bool ok = true; |
| 827 int start_position = scanner()->peek_location().beg_pos; | 828 int start_position = scanner()->peek_location().beg_pos; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 FunctionLiteral::FunctionType function_type, | 971 FunctionLiteral::FunctionType function_type, |
| 971 bool* ok); | 972 bool* ok); |
| 972 void ParseLazyFunctionLiteralBody(bool* ok); | 973 void ParseLazyFunctionLiteralBody(bool* ok); |
| 973 | 974 |
| 974 // Logs the currently parsed literal as a symbol in the preparser data. | 975 // Logs the currently parsed literal as a symbol in the preparser data. |
| 975 void LogSymbol(); | 976 void LogSymbol(); |
| 976 // Log the currently parsed string literal. | 977 // Log the currently parsed string literal. |
| 977 Expression GetStringSymbol(); | 978 Expression GetStringSymbol(); |
| 978 | 979 |
| 979 bool CheckInOrOf(bool accept_OF); | 980 bool CheckInOrOf(bool accept_OF); |
| 980 | |
| 981 ParserRecorder* log_; | |
| 982 }; | 981 }; |
| 983 | 982 |
| 984 | 983 |
| 985 template<class Traits> | 984 template<class Traits> |
| 986 ParserBase<Traits>::FunctionState::FunctionState( | 985 ParserBase<Traits>::FunctionState::FunctionState( |
| 987 FunctionState** function_state_stack, | 986 FunctionState** function_state_stack, |
| 988 typename Traits::Type::Scope** scope_stack, | 987 typename Traits::Type::Scope** scope_stack, |
| 989 typename Traits::Type::Scope* scope, | 988 typename Traits::Type::Scope* scope, |
| 990 typename Traits::Type::Zone* extra_param) | 989 typename Traits::Type::Zone* extra_param) |
| 991 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), | 990 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 "accessor_get_set"); | 1540 "accessor_get_set"); |
| 1542 } | 1541 } |
| 1543 *ok = false; | 1542 *ok = false; |
| 1544 } | 1543 } |
| 1545 } | 1544 } |
| 1546 | 1545 |
| 1547 | 1546 |
| 1548 } } // v8::internal | 1547 } } // v8::internal |
| 1549 | 1548 |
| 1550 #endif // V8_PREPARSER_H | 1549 #endif // V8_PREPARSER_H |
| OLD | NEW |