Chromium Code Reviews| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 return TypeField::decode(code_) == kBinaryOperationExpression; | 285 return TypeField::decode(code_) == kBinaryOperationExpression; |
| 286 } | 286 } |
| 287 | 287 |
| 288 // Dummy implementation for making expression->somefunc() work in both Parser | 288 // Dummy implementation for making expression->somefunc() work in both Parser |
| 289 // and PreParser. | 289 // and PreParser. |
| 290 PreParserExpression* operator->() { return this; } | 290 PreParserExpression* operator->() { return this; } |
| 291 | 291 |
| 292 // More dummy implementations of things PreParser doesn't need to track: | 292 // More dummy implementations of things PreParser doesn't need to track: |
| 293 void set_index(int index) {} // For YieldExpressions | 293 void set_index(int index) {} // For YieldExpressions |
| 294 void set_should_eager_compile() {} | 294 void set_should_eager_compile() {} |
| 295 void set_should_be_used_once_hint() {} | |
| 295 | 296 |
| 296 int position() const { return kNoSourcePosition; } | 297 int position() const { return kNoSourcePosition; } |
| 297 void set_function_token_position(int position) {} | 298 void set_function_token_position(int position) {} |
| 298 | 299 |
| 299 private: | 300 private: |
| 300 enum Type { | 301 enum Type { |
| 301 kExpression, | 302 kExpression, |
| 302 kIdentifierExpression, | 303 kIdentifierExpression, |
| 303 kStringLiteralExpression, | 304 kStringLiteralExpression, |
| 304 kBinaryOperationExpression, | 305 kBinaryOperationExpression, |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 friend class ParserBase<PreParser>; | 631 friend class ParserBase<PreParser>; |
| 631 friend class v8::internal::ExpressionClassifier<ParserTypes<PreParser>>; | 632 friend class v8::internal::ExpressionClassifier<ParserTypes<PreParser>>; |
| 632 | 633 |
| 633 public: | 634 public: |
| 634 typedef PreParserIdentifier Identifier; | 635 typedef PreParserIdentifier Identifier; |
| 635 typedef PreParserExpression Expression; | 636 typedef PreParserExpression Expression; |
| 636 typedef PreParserStatement Statement; | 637 typedef PreParserStatement Statement; |
| 637 | 638 |
| 638 enum PreParseResult { | 639 enum PreParseResult { |
| 639 kPreParseStackOverflow, | 640 kPreParseStackOverflow, |
| 641 kPreParseAbort, | |
| 640 kPreParseSuccess | 642 kPreParseSuccess |
| 641 }; | 643 }; |
| 642 | 644 |
| 643 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, | 645 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, |
| 644 ParserRecorder* log, uintptr_t stack_limit) | 646 ParserRecorder* log, uintptr_t stack_limit) |
| 645 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, | 647 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, |
| 646 ast_value_factory, log), | 648 ast_value_factory, log), |
| 647 use_counts_(nullptr) {} | 649 use_counts_(nullptr) {} |
| 648 | 650 |
| 649 // Pre-parse the program from the character stream; returns true on | 651 // Pre-parse the program from the character stream; returns true on |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 // Returns a FunctionEntry describing the body of the function in enough | 688 // Returns a FunctionEntry describing the body of the function in enough |
| 687 // detail that it can be lazily compiled. | 689 // detail that it can be lazily compiled. |
| 688 // The scanner is expected to have matched the "function" or "function*" | 690 // The scanner is expected to have matched the "function" or "function*" |
| 689 // keyword and parameters, and have consumed the initial '{'. | 691 // keyword and parameters, and have consumed the initial '{'. |
| 690 // At return, unless an error occurred, the scanner is positioned before the | 692 // At return, unless an error occurred, the scanner is positioned before the |
| 691 // the final '}'. | 693 // the final '}'. |
| 692 PreParseResult PreParseLazyFunction(LanguageMode language_mode, | 694 PreParseResult PreParseLazyFunction(LanguageMode language_mode, |
| 693 FunctionKind kind, | 695 FunctionKind kind, |
| 694 bool has_simple_parameters, | 696 bool has_simple_parameters, |
| 695 bool parsing_module, ParserRecorder* log, | 697 bool parsing_module, ParserRecorder* log, |
| 696 Scanner::BookmarkScope* bookmark, | 698 bool may_abort, int* use_counts); |
| 697 int* use_counts); | |
| 698 | 699 |
| 699 // A dummy function, just useful as an argument to CHECK_OK_CUSTOM. | 700 // A dummy function, just useful as an argument to CHECK_OK_CUSTOM. |
| 700 static void Void() {} | 701 static void Void() {} |
| 701 | 702 |
| 702 private: | 703 private: |
| 703 static const int kLazyParseTrialLimit = 200; | 704 static const int kLazyParseTrialLimit = 200; |
| 704 | 705 |
| 705 // These types form an algebra over syntactic categories that is just | 706 // These types form an algebra over syntactic categories that is just |
| 706 // rich enough to let us recognize and propagate the constructs that | 707 // rich enough to let us recognize and propagate the constructs that |
| 707 // are either being counted in the preparser data, or is important | 708 // are either being counted in the preparser data, or is important |
| 708 // to throw the correct syntax error exceptions. | 709 // to throw the correct syntax error exceptions. |
| 709 | 710 |
| 710 // All ParseXXX functions take as the last argument an *ok parameter | 711 // All ParseXXX functions take as the last argument an *ok parameter |
| 711 // which is set to false if parsing failed; it is unchanged otherwise. | 712 // which is set to false if parsing failed; it is unchanged otherwise. |
| 712 // By making the 'exception handling' explicit, we are forced to check | 713 // By making the 'exception handling' explicit, we are forced to check |
| 713 // for failure at the call sites. | 714 // for failure at the call sites. |
| 714 Statement ParseStatementListItem(bool* ok); | 715 Statement ParseStatementListItem(bool* ok); |
| 715 void ParseStatementList(int end_token, bool* ok, | 716 V8_INLINE bool ParseStatementList(int end_token, bool* ok) { |
| 716 Scanner::BookmarkScope* bookmark = nullptr); | 717 return ParseStatementList(end_token, false, ok); |
|
vogelheim
2016/08/30 16:28:42
If may_abort is set to false, ParseStatementList w
nickie
2016/08/31 13:23:36
Done.
| |
| 718 } | |
| 719 bool ParseStatementList(int end_token, bool may_abort, bool* ok); | |
| 717 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, | 720 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, |
| 718 bool* ok); | 721 bool* ok); |
| 719 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, | 722 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, |
| 720 bool* ok); | 723 bool* ok); |
| 721 Statement ParseScopedStatement(bool legacy, bool* ok); | 724 Statement ParseScopedStatement(bool legacy, bool* ok); |
| 722 Statement ParseHoistableDeclaration(bool* ok); | 725 Statement ParseHoistableDeclaration(bool* ok); |
| 723 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, | 726 Statement ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, |
| 724 bool* ok); | 727 bool* ok); |
| 725 Statement ParseFunctionDeclaration(bool* ok); | 728 Statement ParseFunctionDeclaration(bool* ok); |
| 726 Statement ParseAsyncFunctionDeclaration(bool* ok); | 729 Statement ParseAsyncFunctionDeclaration(bool* ok); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 752 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 755 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
| 753 Expression ParseObjectLiteral(bool* ok); | 756 Expression ParseObjectLiteral(bool* ok); |
| 754 Expression ParseV8Intrinsic(bool* ok); | 757 Expression ParseV8Intrinsic(bool* ok); |
| 755 Expression ParseDoExpression(bool* ok); | 758 Expression ParseDoExpression(bool* ok); |
| 756 | 759 |
| 757 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 760 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
| 758 PreParserIdentifier function_name, int pos, | 761 PreParserIdentifier function_name, int pos, |
| 759 const PreParserFormalParameters& parameters, FunctionKind kind, | 762 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 760 FunctionLiteral::FunctionType function_type, bool* ok); | 763 FunctionLiteral::FunctionType function_type, bool* ok); |
| 761 | 764 |
| 762 V8_INLINE void SkipLazyFunctionBody( | 765 V8_INLINE bool SkipLazyFunctionBody(int* materialized_literal_count, |
| 763 int* materialized_literal_count, int* expected_property_count, bool* ok, | 766 int* expected_property_count, |
| 764 Scanner::BookmarkScope* bookmark = nullptr) { | 767 bool may_abort, bool* ok) { |
| 765 UNREACHABLE(); | 768 UNREACHABLE(); |
| 766 } | 769 } |
| 767 Expression ParseFunctionLiteral( | 770 Expression ParseFunctionLiteral( |
| 768 Identifier name, Scanner::Location function_name_location, | 771 Identifier name, Scanner::Location function_name_location, |
| 769 FunctionNameValidity function_name_validity, FunctionKind kind, | 772 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 770 int function_token_pos, FunctionLiteral::FunctionType function_type, | 773 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 771 LanguageMode language_mode, bool* ok); | 774 LanguageMode language_mode, bool* ok); |
| 772 void ParseLazyFunctionLiteralBody(bool* ok, | 775 bool ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); |
| 773 Scanner::BookmarkScope* bookmark = nullptr); | |
| 774 | 776 |
| 775 PreParserExpression ParseClassLiteral(PreParserIdentifier name, | 777 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
| 776 Scanner::Location class_name_location, | 778 Scanner::Location class_name_location, |
| 777 bool name_is_strict_reserved, int pos, | 779 bool name_is_strict_reserved, int pos, |
| 778 bool* ok); | 780 bool* ok); |
| 779 | 781 |
| 780 struct TemplateLiteralState {}; | 782 struct TemplateLiteralState {}; |
| 781 | 783 |
| 782 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { | 784 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { |
| 783 return TemplateLiteralState(); | 785 return TemplateLiteralState(); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 V8_INLINE static PreParserExpression EmptyObjectLiteralProperty() { | 995 V8_INLINE static PreParserExpression EmptyObjectLiteralProperty() { |
| 994 return PreParserExpression::Default(); | 996 return PreParserExpression::Default(); |
| 995 } | 997 } |
| 996 V8_INLINE static PreParserExpression EmptyFunctionLiteral() { | 998 V8_INLINE static PreParserExpression EmptyFunctionLiteral() { |
| 997 return PreParserExpression::Default(); | 999 return PreParserExpression::Default(); |
| 998 } | 1000 } |
| 999 | 1001 |
| 1000 V8_INLINE static PreParserExpressionList NullExpressionList() { | 1002 V8_INLINE static PreParserExpressionList NullExpressionList() { |
| 1001 return PreParserExpressionList(); | 1003 return PreParserExpressionList(); |
| 1002 } | 1004 } |
| 1005 V8_INLINE static PreParserStatementList NullStatementList() { | |
| 1006 return PreParserStatementList(); | |
| 1007 } | |
| 1003 V8_INLINE PreParserIdentifier EmptyIdentifierString() const { | 1008 V8_INLINE PreParserIdentifier EmptyIdentifierString() const { |
| 1004 return PreParserIdentifier::Default(); | 1009 return PreParserIdentifier::Default(); |
| 1005 } | 1010 } |
| 1006 | 1011 |
| 1007 // Odd-ball literal creators. | 1012 // Odd-ball literal creators. |
| 1008 V8_INLINE PreParserExpression GetLiteralTheHole(int position) { | 1013 V8_INLINE PreParserExpression GetLiteralTheHole(int position) { |
| 1009 return PreParserExpression::Default(); | 1014 return PreParserExpression::Default(); |
| 1010 } | 1015 } |
| 1011 | 1016 |
| 1012 // Producing data during the recursive descent. | 1017 // Producing data during the recursive descent. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1178 function_state_->NextMaterializedLiteralIndex(); | 1183 function_state_->NextMaterializedLiteralIndex(); |
| 1179 function_state_->NextMaterializedLiteralIndex(); | 1184 function_state_->NextMaterializedLiteralIndex(); |
| 1180 } | 1185 } |
| 1181 return EmptyExpression(); | 1186 return EmptyExpression(); |
| 1182 } | 1187 } |
| 1183 | 1188 |
| 1184 } // namespace internal | 1189 } // namespace internal |
| 1185 } // namespace v8 | 1190 } // namespace v8 |
| 1186 | 1191 |
| 1187 #endif // V8_PARSING_PREPARSER_H | 1192 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |