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/bailout-reason.h" | |
10 #include "src/base/hashmap.h" | |
11 #include "src/messages.h" | |
12 #include "src/parsing/expression-classifier.h" | |
13 #include "src/parsing/func-name-inferrer.h" | |
14 #include "src/parsing/parser-base.h" | 9 #include "src/parsing/parser-base.h" |
15 #include "src/parsing/scanner.h" | |
16 #include "src/parsing/token.h" | |
17 | 10 |
18 namespace v8 { | 11 namespace v8 { |
19 namespace internal { | 12 namespace internal { |
20 | 13 |
21 // Whereas the Parser generates AST during the recursive descent, | 14 // Whereas the Parser generates AST during the recursive descent, |
22 // the PreParser doesn't create a tree. Instead, it passes around minimal | 15 // the PreParser doesn't create a tree. Instead, it passes around minimal |
23 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain | 16 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain |
24 // just enough data for the upper layer functions. PreParserFactory is | 17 // just enough data for the upper layer functions. PreParserFactory is |
25 // responsible for creating these dummy objects. It provides a similar kind of | 18 // responsible for creating these dummy objects. It provides a similar kind of |
26 // interface as AstNodeFactory, so ParserBase doesn't need to care which one is | 19 // interface as AstNodeFactory, so ParserBase doesn't need to care which one is |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 template <> | 588 template <> |
596 struct ParserTypes<PreParser> { | 589 struct ParserTypes<PreParser> { |
597 typedef ParserBase<PreParser> Base; | 590 typedef ParserBase<PreParser> Base; |
598 typedef PreParser Impl; | 591 typedef PreParser Impl; |
599 | 592 |
600 // PreParser doesn't need to store generator variables. | 593 // PreParser doesn't need to store generator variables. |
601 typedef void GeneratorVariable; | 594 typedef void GeneratorVariable; |
602 | 595 |
603 typedef int AstProperties; | 596 typedef int AstProperties; |
604 | 597 |
605 typedef v8::internal::ExpressionClassifier<ParserTypes<PreParser>> | |
606 ExpressionClassifier; | |
607 | |
608 // Return types for traversing functions. | 598 // Return types for traversing functions. |
609 typedef PreParserIdentifier Identifier; | 599 typedef PreParserIdentifier Identifier; |
610 typedef PreParserExpression Expression; | 600 typedef PreParserExpression Expression; |
611 typedef PreParserExpression YieldExpression; | 601 typedef PreParserExpression YieldExpression; |
612 typedef PreParserExpression FunctionLiteral; | 602 typedef PreParserExpression FunctionLiteral; |
613 typedef PreParserExpression ClassLiteral; | 603 typedef PreParserExpression ClassLiteral; |
614 typedef PreParserExpression Literal; | 604 typedef PreParserExpression Literal; |
615 typedef PreParserExpression ObjectLiteralProperty; | 605 typedef PreParserExpression ObjectLiteralProperty; |
616 typedef PreParserExpressionList ExpressionList; | 606 typedef PreParserExpressionList ExpressionList; |
617 typedef PreParserExpressionList PropertyList; | 607 typedef PreParserExpressionList PropertyList; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 UNREACHABLE(); | 765 UNREACHABLE(); |
776 } | 766 } |
777 Expression ParseFunctionLiteral( | 767 Expression ParseFunctionLiteral( |
778 Identifier name, Scanner::Location function_name_location, | 768 Identifier name, Scanner::Location function_name_location, |
779 FunctionNameValidity function_name_validity, FunctionKind kind, | 769 FunctionNameValidity function_name_validity, FunctionKind kind, |
780 int function_token_pos, FunctionLiteral::FunctionType function_type, | 770 int function_token_pos, FunctionLiteral::FunctionType function_type, |
781 LanguageMode language_mode, bool* ok); | 771 LanguageMode language_mode, bool* ok); |
782 void ParseLazyFunctionLiteralBody(bool* ok, | 772 void ParseLazyFunctionLiteralBody(bool* ok, |
783 Scanner::BookmarkScope* bookmark = nullptr); | 773 Scanner::BookmarkScope* bookmark = nullptr); |
784 | 774 |
785 PreParserExpression ParseClassLiteral(ExpressionClassifier* classifier, | 775 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
786 PreParserIdentifier name, | |
787 Scanner::Location class_name_location, | 776 Scanner::Location class_name_location, |
788 bool name_is_strict_reserved, int pos, | 777 bool name_is_strict_reserved, int pos, |
789 bool* ok); | 778 bool* ok); |
790 | 779 |
791 struct TemplateLiteralState {}; | 780 struct TemplateLiteralState {}; |
792 | 781 |
793 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { | 782 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { |
794 return TemplateLiteralState(); | 783 return TemplateLiteralState(); |
795 } | 784 } |
796 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, | 785 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, |
797 PreParserExpression expression) {} | 786 PreParserExpression expression) {} |
798 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {} | 787 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {} |
799 V8_INLINE PreParserExpression CloseTemplateLiteral( | 788 V8_INLINE PreParserExpression CloseTemplateLiteral( |
800 TemplateLiteralState* state, int start, PreParserExpression tag); | 789 TemplateLiteralState* state, int start, PreParserExpression tag); |
801 V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 790 V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
802 | 791 |
803 V8_INLINE void MarkCollectedTailCallExpressions() {} | 792 V8_INLINE void MarkCollectedTailCallExpressions() {} |
804 V8_INLINE void MarkTailPosition(PreParserExpression expression) {} | 793 V8_INLINE void MarkTailPosition(PreParserExpression expression) {} |
805 | 794 |
806 void ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, | 795 void ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, |
807 bool accept_IN, | 796 bool accept_IN, |
808 ExpressionClassifier* classifier, | |
809 int pos, bool* ok); | 797 int pos, bool* ok); |
810 | 798 |
811 V8_INLINE PreParserExpressionList | 799 V8_INLINE PreParserExpressionList |
812 PrepareSpreadArguments(PreParserExpressionList list) { | 800 PrepareSpreadArguments(PreParserExpressionList list) { |
813 return list; | 801 return list; |
814 } | 802 } |
815 | 803 |
816 V8_INLINE PreParserExpression SpreadCall(PreParserExpression function, | 804 V8_INLINE PreParserExpression SpreadCall(PreParserExpression function, |
817 PreParserExpressionList args, | 805 PreParserExpressionList args, |
818 int pos); | 806 int pos); |
(...skipping 15 matching lines...) Expand all Loading... |
834 | 822 |
835 V8_INLINE PreParserExpression | 823 V8_INLINE PreParserExpression |
836 RewriteAwaitExpression(PreParserExpression value, int pos) { | 824 RewriteAwaitExpression(PreParserExpression value, int pos) { |
837 return value; | 825 return value; |
838 } | 826 } |
839 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, | 827 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, |
840 PreParserExpression expression, | 828 PreParserExpression expression, |
841 int pos) { | 829 int pos) { |
842 return PreParserExpression::Default(); | 830 return PreParserExpression::Default(); |
843 } | 831 } |
844 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok) { | 832 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } |
845 ValidateExpression(classifier, ok); | |
846 } | |
847 | 833 |
848 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 834 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
849 PreParserExpression assignment) {} | 835 PreParserExpression assignment) {} |
850 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, | 836 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, |
851 bool* ok) {} | 837 bool* ok) {} |
852 | 838 |
853 // Helper functions for recursive descent. | 839 // Helper functions for recursive descent. |
854 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { | 840 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { |
855 return identifier.IsEval(); | 841 return identifier.IsEval(); |
856 } | 842 } |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 | 1076 |
1091 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, | 1077 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, |
1092 PreParserExpression pattern, | 1078 PreParserExpression pattern, |
1093 PreParserExpression initializer, | 1079 PreParserExpression initializer, |
1094 int initializer_end_position, | 1080 int initializer_end_position, |
1095 bool is_rest) { | 1081 bool is_rest) { |
1096 ++parameters->arity; | 1082 ++parameters->arity; |
1097 } | 1083 } |
1098 | 1084 |
1099 V8_INLINE void DeclareFormalParameter(DeclarationScope* scope, | 1085 V8_INLINE void DeclareFormalParameter(DeclarationScope* scope, |
1100 PreParserIdentifier parameter, | 1086 PreParserIdentifier parameter) { |
1101 ExpressionClassifier* classifier) { | 1087 if (!classifier()->is_simple_parameter_list()) { |
1102 if (!classifier->is_simple_parameter_list()) { | |
1103 scope->SetHasNonSimpleParameters(); | 1088 scope->SetHasNonSimpleParameters(); |
1104 } | 1089 } |
1105 } | 1090 } |
1106 | 1091 |
1107 V8_INLINE void ParseArrowFunctionFormalParameterList( | 1092 V8_INLINE void ParseArrowFunctionFormalParameterList( |
1108 PreParserFormalParameters* parameters, PreParserExpression params, | 1093 PreParserFormalParameters* parameters, PreParserExpression params, |
1109 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 1094 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
1110 const Scope::Snapshot& scope_snapshot, bool* ok) { | 1095 const Scope::Snapshot& scope_snapshot, bool* ok) { |
1111 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect | 1096 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect |
1112 // parameter | 1097 // parameter |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 function_state_->NextMaterializedLiteralIndex(); | 1178 function_state_->NextMaterializedLiteralIndex(); |
1194 function_state_->NextMaterializedLiteralIndex(); | 1179 function_state_->NextMaterializedLiteralIndex(); |
1195 } | 1180 } |
1196 return EmptyExpression(); | 1181 return EmptyExpression(); |
1197 } | 1182 } |
1198 | 1183 |
1199 } // namespace internal | 1184 } // namespace internal |
1200 } // namespace v8 | 1185 } // namespace v8 |
1201 | 1186 |
1202 #endif // V8_PARSING_PREPARSER_H | 1187 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |