| 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_PARSING_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
| 6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/parsing/parser-base.h" | 9 #include "src/parsing/parser-base.h" |
| 10 | 10 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 return TypeField::decode(code_) == kBinaryOperationExpression; | 289 return TypeField::decode(code_) == kBinaryOperationExpression; |
| 290 } | 290 } |
| 291 | 291 |
| 292 // Dummy implementation for making expression->somefunc() work in both Parser | 292 // Dummy implementation for making expression->somefunc() work in both Parser |
| 293 // and PreParser. | 293 // and PreParser. |
| 294 PreParserExpression* operator->() { return this; } | 294 PreParserExpression* operator->() { return this; } |
| 295 | 295 |
| 296 // More dummy implementations of things PreParser doesn't need to track: | 296 // More dummy implementations of things PreParser doesn't need to track: |
| 297 void set_index(int index) {} // For YieldExpressions | 297 void set_index(int index) {} // For YieldExpressions |
| 298 void set_should_eager_compile() {} | 298 void set_should_eager_compile() {} |
| 299 void set_should_be_used_once_hint() {} |
| 299 | 300 |
| 300 int position() const { return kNoSourcePosition; } | 301 int position() const { return kNoSourcePosition; } |
| 301 void set_function_token_position(int position) {} | 302 void set_function_token_position(int position) {} |
| 302 | 303 |
| 303 private: | 304 private: |
| 304 enum Type { | 305 enum Type { |
| 305 kEmpty, | 306 kEmpty, |
| 306 kExpression, | 307 kExpression, |
| 307 kIdentifierExpression, | 308 kIdentifierExpression, |
| 308 kStringLiteralExpression, | 309 kStringLiteralExpression, |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 friend class ParserBase<PreParser>; | 636 friend class ParserBase<PreParser>; |
| 636 friend class v8::internal::ExpressionClassifier<ParserTypes<PreParser>>; | 637 friend class v8::internal::ExpressionClassifier<ParserTypes<PreParser>>; |
| 637 | 638 |
| 638 public: | 639 public: |
| 639 typedef PreParserIdentifier Identifier; | 640 typedef PreParserIdentifier Identifier; |
| 640 typedef PreParserExpression Expression; | 641 typedef PreParserExpression Expression; |
| 641 typedef PreParserStatement Statement; | 642 typedef PreParserStatement Statement; |
| 642 | 643 |
| 643 enum PreParseResult { | 644 enum PreParseResult { |
| 644 kPreParseStackOverflow, | 645 kPreParseStackOverflow, |
| 646 kPreParseAbort, |
| 645 kPreParseSuccess | 647 kPreParseSuccess |
| 646 }; | 648 }; |
| 647 | 649 |
| 648 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, | 650 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, |
| 649 ParserRecorder* log, uintptr_t stack_limit) | 651 ParserRecorder* log, uintptr_t stack_limit) |
| 650 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, | 652 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, |
| 651 ast_value_factory, log), | 653 ast_value_factory, log), |
| 652 use_counts_(nullptr) {} | 654 use_counts_(nullptr) {} |
| 653 | 655 |
| 654 // Pre-parse the program from the character stream; returns true on | 656 // Pre-parse the program from the character stream; returns true on |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 // Returns a FunctionEntry describing the body of the function in enough | 693 // Returns a FunctionEntry describing the body of the function in enough |
| 692 // detail that it can be lazily compiled. | 694 // detail that it can be lazily compiled. |
| 693 // The scanner is expected to have matched the "function" or "function*" | 695 // The scanner is expected to have matched the "function" or "function*" |
| 694 // keyword and parameters, and have consumed the initial '{'. | 696 // keyword and parameters, and have consumed the initial '{'. |
| 695 // At return, unless an error occurred, the scanner is positioned before the | 697 // At return, unless an error occurred, the scanner is positioned before the |
| 696 // the final '}'. | 698 // the final '}'. |
| 697 PreParseResult PreParseLazyFunction(LanguageMode language_mode, | 699 PreParseResult PreParseLazyFunction(LanguageMode language_mode, |
| 698 FunctionKind kind, | 700 FunctionKind kind, |
| 699 bool has_simple_parameters, | 701 bool has_simple_parameters, |
| 700 bool parsing_module, ParserRecorder* log, | 702 bool parsing_module, ParserRecorder* log, |
| 701 Scanner::BookmarkScope* bookmark, | 703 bool may_abort, int* use_counts); |
| 702 int* use_counts); | |
| 703 | |
| 704 // A dummy function, just useful as an argument to CHECK_OK_CUSTOM. | |
| 705 static void Void() {} | |
| 706 | 704 |
| 707 private: | 705 private: |
| 708 static const int kLazyParseTrialLimit = 200; | 706 static const int kLazyParseTrialLimit = 200; |
| 709 | 707 |
| 710 // These types form an algebra over syntactic categories that is just | 708 // These types form an algebra over syntactic categories that is just |
| 711 // rich enough to let us recognize and propagate the constructs that | 709 // rich enough to let us recognize and propagate the constructs that |
| 712 // are either being counted in the preparser data, or is important | 710 // are either being counted in the preparser data, or is important |
| 713 // to throw the correct syntax error exceptions. | 711 // to throw the correct syntax error exceptions. |
| 714 | 712 |
| 715 // All ParseXXX functions take as the last argument an *ok parameter | 713 // All ParseXXX functions take as the last argument an *ok parameter |
| 716 // which is set to false if parsing failed; it is unchanged otherwise. | 714 // which is set to false if parsing failed; it is unchanged otherwise. |
| 717 // By making the 'exception handling' explicit, we are forced to check | 715 // By making the 'exception handling' explicit, we are forced to check |
| 718 // for failure at the call sites. | 716 // for failure at the call sites. |
| 719 Statement ParseStatementListItem(bool* ok); | 717 Statement ParseStatementListItem(bool* ok); |
| 720 void ParseStatementList(int end_token, bool* ok, | 718 V8_INLINE void ParseStatementList(int end_token, bool* ok) { |
| 721 Scanner::BookmarkScope* bookmark = nullptr); | 719 LazyParsingResult result = ParseStatementList(end_token, false, ok); |
| 720 USE(result); // The result is just used in debug modes. |
| 721 DCHECK_EQ(result, kLazyParsingComplete); |
| 722 } |
| 723 LazyParsingResult ParseStatementList(int end_token, bool may_abort, bool* ok); |
| 722 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, | 724 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, |
| 723 bool* ok); | 725 bool* ok); |
| 724 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, | 726 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, |
| 725 bool* ok); | 727 bool* ok); |
| 726 Statement ParseScopedStatement(bool legacy, bool* ok); | 728 Statement ParseScopedStatement(bool legacy, bool* ok); |
| 727 Statement ParseHoistableDeclaration(bool* ok); | 729 Statement ParseHoistableDeclaration(bool* ok); |
| 728 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, | 730 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, |
| 729 bool* ok); | 731 bool* ok); |
| 730 Statement ParseFunctionDeclaration(bool* ok); | 732 Statement ParseFunctionDeclaration(bool* ok); |
| 731 Statement ParseAsyncFunctionDeclaration(bool* ok); | 733 Statement ParseAsyncFunctionDeclaration(bool* ok); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 757 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 759 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
| 758 Expression ParseObjectLiteral(bool* ok); | 760 Expression ParseObjectLiteral(bool* ok); |
| 759 Expression ParseV8Intrinsic(bool* ok); | 761 Expression ParseV8Intrinsic(bool* ok); |
| 760 Expression ParseDoExpression(bool* ok); | 762 Expression ParseDoExpression(bool* ok); |
| 761 | 763 |
| 762 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 764 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
| 763 PreParserIdentifier function_name, int pos, | 765 PreParserIdentifier function_name, int pos, |
| 764 const PreParserFormalParameters& parameters, FunctionKind kind, | 766 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 765 FunctionLiteral::FunctionType function_type, bool* ok); | 767 FunctionLiteral::FunctionType function_type, bool* ok); |
| 766 | 768 |
| 767 V8_INLINE void SkipLazyFunctionBody( | 769 V8_INLINE LazyParsingResult |
| 768 int* materialized_literal_count, int* expected_property_count, bool* ok, | 770 SkipLazyFunctionBody(int* materialized_literal_count, |
| 769 Scanner::BookmarkScope* bookmark = nullptr) { | 771 int* expected_property_count, bool may_abort, bool* ok) { |
| 770 UNREACHABLE(); | 772 UNREACHABLE(); |
| 773 return kLazyParsingComplete; |
| 771 } | 774 } |
| 772 Expression ParseFunctionLiteral( | 775 Expression ParseFunctionLiteral( |
| 773 Identifier name, Scanner::Location function_name_location, | 776 Identifier name, Scanner::Location function_name_location, |
| 774 FunctionNameValidity function_name_validity, FunctionKind kind, | 777 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 775 int function_token_pos, FunctionLiteral::FunctionType function_type, | 778 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 776 LanguageMode language_mode, bool* ok); | 779 LanguageMode language_mode, bool* ok); |
| 777 void ParseLazyFunctionLiteralBody(bool* ok, | 780 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); |
| 778 Scanner::BookmarkScope* bookmark = nullptr); | |
| 779 | 781 |
| 780 PreParserExpression ParseClassLiteral(PreParserIdentifier name, | 782 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
| 781 Scanner::Location class_name_location, | 783 Scanner::Location class_name_location, |
| 782 bool name_is_strict_reserved, int pos, | 784 bool name_is_strict_reserved, int pos, |
| 783 bool* ok); | 785 bool* ok); |
| 784 | 786 |
| 785 struct TemplateLiteralState {}; | 787 struct TemplateLiteralState {}; |
| 786 | 788 |
| 787 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { | 789 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { |
| 788 return TemplateLiteralState(); | 790 return TemplateLiteralState(); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 return PreParserExpression::Default(); | 1004 return PreParserExpression::Default(); |
| 1003 } | 1005 } |
| 1004 | 1006 |
| 1005 V8_INLINE static bool IsEmptyExpression(PreParserExpression expr) { | 1007 V8_INLINE static bool IsEmptyExpression(PreParserExpression expr) { |
| 1006 return expr.IsEmpty(); | 1008 return expr.IsEmpty(); |
| 1007 } | 1009 } |
| 1008 | 1010 |
| 1009 V8_INLINE static PreParserExpressionList NullExpressionList() { | 1011 V8_INLINE static PreParserExpressionList NullExpressionList() { |
| 1010 return PreParserExpressionList(); | 1012 return PreParserExpressionList(); |
| 1011 } | 1013 } |
| 1014 V8_INLINE static PreParserStatementList NullStatementList() { |
| 1015 return PreParserStatementList(); |
| 1016 } |
| 1012 V8_INLINE PreParserIdentifier EmptyIdentifierString() const { | 1017 V8_INLINE PreParserIdentifier EmptyIdentifierString() const { |
| 1013 return PreParserIdentifier::Default(); | 1018 return PreParserIdentifier::Default(); |
| 1014 } | 1019 } |
| 1015 | 1020 |
| 1016 // Odd-ball literal creators. | 1021 // Odd-ball literal creators. |
| 1017 V8_INLINE PreParserExpression GetLiteralTheHole(int position) { | 1022 V8_INLINE PreParserExpression GetLiteralTheHole(int position) { |
| 1018 return PreParserExpression::Default(); | 1023 return PreParserExpression::Default(); |
| 1019 } | 1024 } |
| 1020 | 1025 |
| 1021 // Producing data during the recursive descent. | 1026 // Producing data during the recursive descent. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 function_state_->NextMaterializedLiteralIndex(); | 1192 function_state_->NextMaterializedLiteralIndex(); |
| 1188 function_state_->NextMaterializedLiteralIndex(); | 1193 function_state_->NextMaterializedLiteralIndex(); |
| 1189 } | 1194 } |
| 1190 return EmptyExpression(); | 1195 return EmptyExpression(); |
| 1191 } | 1196 } |
| 1192 | 1197 |
| 1193 } // namespace internal | 1198 } // namespace internal |
| 1194 } // namespace v8 | 1199 } // namespace v8 |
| 1195 | 1200 |
| 1196 #endif // V8_PARSING_PREPARSER_H | 1201 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |