| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 | 105 |
| 106 class PreParser { | 106 class PreParser { |
| 107 public: | 107 public: |
| 108 enum PreParseResult { | 108 enum PreParseResult { |
| 109 kPreParseStackOverflow, | 109 kPreParseStackOverflow, |
| 110 kPreParseSuccess | 110 kPreParseSuccess |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 |
| 114 PreParser(i::Scanner* scanner, |
| 115 i::ParserRecorder* log, |
| 116 uintptr_t stack_limit, |
| 117 bool allow_lazy, |
| 118 bool allow_natives_syntax) |
| 119 : scanner_(scanner), |
| 120 log_(log), |
| 121 scope_(NULL), |
| 122 stack_limit_(stack_limit), |
| 123 strict_mode_violation_location_(i::Scanner::Location::invalid()), |
| 124 strict_mode_violation_type_(NULL), |
| 125 stack_overflow_(false), |
| 126 allow_lazy_(allow_lazy), |
| 127 allow_natives_syntax_(allow_natives_syntax), |
| 128 parenthesized_function_(false), |
| 129 harmony_scoping_(scanner->HarmonyScoping()) { } |
| 130 |
| 113 ~PreParser() {} | 131 ~PreParser() {} |
| 114 | 132 |
| 115 // Pre-parse the program from the character stream; returns true on | 133 // Pre-parse the program from the character stream; returns true on |
| 116 // success (even if parsing failed, the pre-parse data successfully | 134 // success (even if parsing failed, the pre-parse data successfully |
| 117 // captured the syntax error), and false if a stack-overflow happened | 135 // captured the syntax error), and false if a stack-overflow happened |
| 118 // during parsing. | 136 // during parsing. |
| 119 static PreParseResult PreParseProgram(i::Scanner* scanner, | 137 static PreParseResult PreParseProgram(i::Scanner* scanner, |
| 120 i::ParserRecorder* log, | 138 i::ParserRecorder* log, |
| 121 int flags, | 139 int flags, |
| 122 uintptr_t stack_limit) { | 140 uintptr_t stack_limit) { |
| 123 bool allow_lazy = (flags & i::kAllowLazy) != 0; | 141 bool allow_lazy = (flags & i::kAllowLazy) != 0; |
| 124 bool allow_natives_syntax = (flags & i::kAllowNativesSyntax) != 0; | 142 bool allow_natives_syntax = (flags & i::kAllowNativesSyntax) != 0; |
| 125 return PreParser(scanner, log, stack_limit, | 143 return PreParser(scanner, log, stack_limit, |
| 126 allow_lazy, allow_natives_syntax).PreParse(); | 144 allow_lazy, allow_natives_syntax).PreParse(); |
| 127 } | 145 } |
| 128 | 146 |
| 147 // Parses a single function literal, from the opening parentheses before |
| 148 // parameters to the closing brace after the body. |
| 149 // Returns a FunctionEntry describing the body of the funciton in enough |
| 150 // detail that it can be lazily compiled. |
| 151 // The scanner is expected to have matched the "function" keyword and |
| 152 // parameters, and have consumed the initial '{'. |
| 153 // At return, unless an error occured, the scanner is positioned before the |
| 154 // the final '}'. |
| 155 PreParseResult PreParseLazyFunction(i::LanguageMode mode, |
| 156 i::ParserRecorder* log); |
| 157 |
| 129 private: | 158 private: |
| 130 // Used to detect duplicates in object literals. Each of the values | 159 // Used to detect duplicates in object literals. Each of the values |
| 131 // kGetterProperty, kSetterProperty and kValueProperty represents | 160 // kGetterProperty, kSetterProperty and kValueProperty represents |
| 132 // a type of object literal property. When parsing a property, its | 161 // a type of object literal property. When parsing a property, its |
| 133 // type value is stored in the DuplicateFinder for the property name. | 162 // type value is stored in the DuplicateFinder for the property name. |
| 134 // Values are chosen so that having intersection bits means the there is | 163 // Values are chosen so that having intersection bits means the there is |
| 135 // an incompatibility. | 164 // an incompatibility. |
| 136 // I.e., you can add a getter to a property that already has a setter, since | 165 // I.e., you can add a getter to a property that already has a setter, since |
| 137 // kGetterProperty and kSetterProperty doesn't intersect, but not if it | 166 // kGetterProperty and kSetterProperty doesn't intersect, but not if it |
| 138 // already has a getter or a value. Adding the getter to an existing | 167 // already has a getter or a value. Adding the getter to an existing |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 private: | 472 private: |
| 444 Scope** const variable_; | 473 Scope** const variable_; |
| 445 Scope* const prev_; | 474 Scope* const prev_; |
| 446 const ScopeType type_; | 475 const ScopeType type_; |
| 447 int materialized_literal_count_; | 476 int materialized_literal_count_; |
| 448 int expected_properties_; | 477 int expected_properties_; |
| 449 int with_nesting_count_; | 478 int with_nesting_count_; |
| 450 i::LanguageMode language_mode_; | 479 i::LanguageMode language_mode_; |
| 451 }; | 480 }; |
| 452 | 481 |
| 453 // Private constructor only used in PreParseProgram. | |
| 454 PreParser(i::Scanner* scanner, | |
| 455 i::ParserRecorder* log, | |
| 456 uintptr_t stack_limit, | |
| 457 bool allow_lazy, | |
| 458 bool allow_natives_syntax) | |
| 459 : scanner_(scanner), | |
| 460 log_(log), | |
| 461 scope_(NULL), | |
| 462 stack_limit_(stack_limit), | |
| 463 strict_mode_violation_location_(i::Scanner::Location::invalid()), | |
| 464 strict_mode_violation_type_(NULL), | |
| 465 stack_overflow_(false), | |
| 466 allow_lazy_(allow_lazy), | |
| 467 allow_natives_syntax_(allow_natives_syntax), | |
| 468 parenthesized_function_(false), | |
| 469 harmony_scoping_(scanner->HarmonyScoping()) { } | |
| 470 | |
| 471 // Preparse the program. Only called in PreParseProgram after creating | 482 // Preparse the program. Only called in PreParseProgram after creating |
| 472 // the instance. | 483 // the instance. |
| 473 PreParseResult PreParse() { | 484 PreParseResult PreParse() { |
| 474 Scope top_scope(&scope_, kTopLevelScope); | 485 Scope top_scope(&scope_, kTopLevelScope); |
| 475 bool ok = true; | 486 bool ok = true; |
| 476 int start_position = scanner_->peek_location().beg_pos; | 487 int start_position = scanner_->peek_location().beg_pos; |
| 477 ParseSourceElements(i::Token::EOS, &ok); | 488 ParseSourceElements(i::Token::EOS, &ok); |
| 478 if (stack_overflow_) return kPreParseStackOverflow; | 489 if (stack_overflow_) return kPreParseStackOverflow; |
| 479 if (!ok) { | 490 if (!ok) { |
| 480 ReportUnexpectedToken(scanner_->current_token()); | 491 ReportUnexpectedToken(scanner_->current_token()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 Expression ParseMemberExpression(bool* ok); | 551 Expression ParseMemberExpression(bool* ok); |
| 541 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok); | 552 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok); |
| 542 Expression ParsePrimaryExpression(bool* ok); | 553 Expression ParsePrimaryExpression(bool* ok); |
| 543 Expression ParseArrayLiteral(bool* ok); | 554 Expression ParseArrayLiteral(bool* ok); |
| 544 Expression ParseObjectLiteral(bool* ok); | 555 Expression ParseObjectLiteral(bool* ok); |
| 545 Expression ParseRegExpLiteral(bool seen_equal, bool* ok); | 556 Expression ParseRegExpLiteral(bool seen_equal, bool* ok); |
| 546 Expression ParseV8Intrinsic(bool* ok); | 557 Expression ParseV8Intrinsic(bool* ok); |
| 547 | 558 |
| 548 Arguments ParseArguments(bool* ok); | 559 Arguments ParseArguments(bool* ok); |
| 549 Expression ParseFunctionLiteral(bool* ok); | 560 Expression ParseFunctionLiteral(bool* ok); |
| 561 void ParseLazyFunctionLiteralBody(bool* ok); |
| 550 | 562 |
| 551 Identifier ParseIdentifier(bool* ok); | 563 Identifier ParseIdentifier(bool* ok); |
| 552 Identifier ParseIdentifierName(bool* ok); | 564 Identifier ParseIdentifierName(bool* ok); |
| 553 Identifier ParseIdentifierNameOrGetOrSet(bool* is_get, | 565 Identifier ParseIdentifierNameOrGetOrSet(bool* is_get, |
| 554 bool* is_set, | 566 bool* is_set, |
| 555 bool* ok); | 567 bool* ok); |
| 556 | 568 |
| 557 // Logs the currently parsed literal as a symbol in the preparser data. | 569 // Logs the currently parsed literal as a symbol in the preparser data. |
| 558 void LogSymbol(); | 570 void LogSymbol(); |
| 559 // Log the currently parsed identifier. | 571 // Log the currently parsed identifier. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 const char* strict_mode_violation_type_; | 647 const char* strict_mode_violation_type_; |
| 636 bool stack_overflow_; | 648 bool stack_overflow_; |
| 637 bool allow_lazy_; | 649 bool allow_lazy_; |
| 638 bool allow_natives_syntax_; | 650 bool allow_natives_syntax_; |
| 639 bool parenthesized_function_; | 651 bool parenthesized_function_; |
| 640 bool harmony_scoping_; | 652 bool harmony_scoping_; |
| 641 }; | 653 }; |
| 642 } } // v8::preparser | 654 } } // v8::preparser |
| 643 | 655 |
| 644 #endif // V8_PREPARSER_H | 656 #endif // V8_PREPARSER_H |
| OLD | NEW |