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 24 matching lines...) Expand all Loading... |
35 namespace v8 { | 35 namespace v8 { |
36 namespace internal { | 36 namespace internal { |
37 | 37 |
38 // Common base class shared between parser and pre-parser. | 38 // Common base class shared between parser and pre-parser. |
39 template <typename Traits> | 39 template <typename Traits> |
40 class ParserBase : public Traits { | 40 class ParserBase : public Traits { |
41 public: | 41 public: |
42 ParserBase(Scanner* scanner, uintptr_t stack_limit, | 42 ParserBase(Scanner* scanner, uintptr_t stack_limit, |
43 typename Traits::ParserType this_object) | 43 typename Traits::ParserType this_object) |
44 : Traits(this_object), | 44 : Traits(this_object), |
| 45 parenthesized_function_(false), |
45 scanner_(scanner), | 46 scanner_(scanner), |
46 stack_limit_(stack_limit), | 47 stack_limit_(stack_limit), |
47 stack_overflow_(false), | 48 stack_overflow_(false), |
48 allow_lazy_(false), | 49 allow_lazy_(false), |
49 allow_natives_syntax_(false), | 50 allow_natives_syntax_(false), |
50 allow_generators_(false), | 51 allow_generators_(false), |
51 allow_for_of_(false) { } | 52 allow_for_of_(false) { } |
52 | 53 |
53 // Getters that indicate whether certain syntactical constructs are | 54 // Getters that indicate whether certain syntactical constructs are |
54 // allowed to be parsed by this instance of the parser. | 55 // allowed to be parsed by this instance of the parser. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 275 } |
275 bool IsAccessorAccessorConflict(PropertyKind type1, PropertyKind type2) { | 276 bool IsAccessorAccessorConflict(PropertyKind type1, PropertyKind type2) { |
276 return ((type1 | type2) & kValueFlag) == 0; | 277 return ((type1 | type2) & kValueFlag) == 0; |
277 } | 278 } |
278 | 279 |
279 ParserBase* parser_; | 280 ParserBase* parser_; |
280 DuplicateFinder finder_; | 281 DuplicateFinder finder_; |
281 LanguageMode language_mode_; | 282 LanguageMode language_mode_; |
282 }; | 283 }; |
283 | 284 |
| 285 // If true, the next (and immediately following) function literal is |
| 286 // preceded by a parenthesis. |
| 287 // Heuristically that means that the function will be called immediately, |
| 288 // so never lazily compile it. |
| 289 bool parenthesized_function_; |
| 290 |
284 private: | 291 private: |
285 Scanner* scanner_; | 292 Scanner* scanner_; |
286 uintptr_t stack_limit_; | 293 uintptr_t stack_limit_; |
287 bool stack_overflow_; | 294 bool stack_overflow_; |
288 | 295 |
289 bool allow_lazy_; | 296 bool allow_lazy_; |
290 bool allow_natives_syntax_; | 297 bool allow_natives_syntax_; |
291 bool allow_generators_; | 298 bool allow_generators_; |
292 bool allow_for_of_; | 299 bool allow_for_of_; |
293 }; | 300 }; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 enum PreParseResult { | 505 enum PreParseResult { |
499 kPreParseStackOverflow, | 506 kPreParseStackOverflow, |
500 kPreParseSuccess | 507 kPreParseSuccess |
501 }; | 508 }; |
502 | 509 |
503 PreParser(Scanner* scanner, | 510 PreParser(Scanner* scanner, |
504 ParserRecorder* log, | 511 ParserRecorder* log, |
505 uintptr_t stack_limit) | 512 uintptr_t stack_limit) |
506 : ParserBase<PreParserTraits>(scanner, stack_limit, this), | 513 : ParserBase<PreParserTraits>(scanner, stack_limit, this), |
507 log_(log), | 514 log_(log), |
508 scope_(NULL), | 515 scope_(NULL) { } |
509 parenthesized_function_(false) { } | |
510 | 516 |
511 ~PreParser() {} | 517 ~PreParser() {} |
512 | 518 |
513 // Pre-parse the program from the character stream; returns true on | 519 // Pre-parse the program from the character stream; returns true on |
514 // success (even if parsing failed, the pre-parse data successfully | 520 // success (even if parsing failed, the pre-parse data successfully |
515 // captured the syntax error), and false if a stack-overflow happened | 521 // captured the syntax error), and false if a stack-overflow happened |
516 // during parsing. | 522 // during parsing. |
517 PreParseResult PreParseProgram() { | 523 PreParseResult PreParseProgram() { |
518 Scope top_scope(&scope_, kTopLevelScope); | 524 Scope top_scope(&scope_, kTopLevelScope); |
519 bool ok = true; | 525 bool ok = true; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 bool is_extended_mode() { | 747 bool is_extended_mode() { |
742 return scope_->language_mode() == EXTENDED_MODE; | 748 return scope_->language_mode() == EXTENDED_MODE; |
743 } | 749 } |
744 | 750 |
745 LanguageMode language_mode() { return scope_->language_mode(); } | 751 LanguageMode language_mode() { return scope_->language_mode(); } |
746 | 752 |
747 bool CheckInOrOf(bool accept_OF); | 753 bool CheckInOrOf(bool accept_OF); |
748 | 754 |
749 ParserRecorder* log_; | 755 ParserRecorder* log_; |
750 Scope* scope_; | 756 Scope* scope_; |
751 bool parenthesized_function_; | |
752 }; | 757 }; |
753 | 758 |
754 | 759 |
755 template<class Traits> | 760 template<class Traits> |
756 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { | 761 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { |
757 // We don't report stack overflows here, to avoid increasing the | 762 // We don't report stack overflows here, to avoid increasing the |
758 // stack depth even further. Instead we report it after parsing is | 763 // stack depth even further. Instead we report it after parsing is |
759 // over, in ParseProgram. | 764 // over, in ParseProgram. |
760 if (token == Token::ILLEGAL && stack_overflow()) { | 765 if (token == Token::ILLEGAL && stack_overflow()) { |
761 return; | 766 return; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 "accessor_get_set"); | 926 "accessor_get_set"); |
922 } | 927 } |
923 *ok = false; | 928 *ok = false; |
924 } | 929 } |
925 } | 930 } |
926 | 931 |
927 | 932 |
928 } } // v8::internal | 933 } } // v8::internal |
929 | 934 |
930 #endif // V8_PREPARSER_H | 935 #endif // V8_PREPARSER_H |
OLD | NEW |