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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 template <> | 593 template <> |
601 struct ParserTypes<PreParser> { | 594 struct ParserTypes<PreParser> { |
602 typedef ParserBase<PreParser> Base; | 595 typedef ParserBase<PreParser> Base; |
603 typedef PreParser Impl; | 596 typedef PreParser Impl; |
604 | 597 |
605 // PreParser doesn't need to store generator variables. | 598 // PreParser doesn't need to store generator variables. |
606 typedef void GeneratorVariable; | 599 typedef void GeneratorVariable; |
607 | 600 |
608 typedef int AstProperties; | 601 typedef int AstProperties; |
609 | 602 |
610 typedef v8::internal::ExpressionClassifier<ParserTypes<PreParser>> | |
611 ExpressionClassifier; | |
612 | |
613 // Return types for traversing functions. | 603 // Return types for traversing functions. |
614 typedef PreParserIdentifier Identifier; | 604 typedef PreParserIdentifier Identifier; |
615 typedef PreParserExpression Expression; | 605 typedef PreParserExpression Expression; |
616 typedef PreParserExpression YieldExpression; | 606 typedef PreParserExpression YieldExpression; |
617 typedef PreParserExpression FunctionLiteral; | 607 typedef PreParserExpression FunctionLiteral; |
618 typedef PreParserExpression ClassLiteral; | 608 typedef PreParserExpression ClassLiteral; |
619 typedef PreParserExpression Literal; | 609 typedef PreParserExpression Literal; |
620 typedef PreParserExpression ObjectLiteralProperty; | 610 typedef PreParserExpression ObjectLiteralProperty; |
621 typedef PreParserExpressionList ExpressionList; | 611 typedef PreParserExpressionList ExpressionList; |
622 typedef PreParserExpressionList PropertyList; | 612 typedef PreParserExpressionList PropertyList; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 UNREACHABLE(); | 770 UNREACHABLE(); |
781 } | 771 } |
782 Expression ParseFunctionLiteral( | 772 Expression ParseFunctionLiteral( |
783 Identifier name, Scanner::Location function_name_location, | 773 Identifier name, Scanner::Location function_name_location, |
784 FunctionNameValidity function_name_validity, FunctionKind kind, | 774 FunctionNameValidity function_name_validity, FunctionKind kind, |
785 int function_token_pos, FunctionLiteral::FunctionType function_type, | 775 int function_token_pos, FunctionLiteral::FunctionType function_type, |
786 LanguageMode language_mode, bool* ok); | 776 LanguageMode language_mode, bool* ok); |
787 void ParseLazyFunctionLiteralBody(bool* ok, | 777 void ParseLazyFunctionLiteralBody(bool* ok, |
788 Scanner::BookmarkScope* bookmark = nullptr); | 778 Scanner::BookmarkScope* bookmark = nullptr); |
789 | 779 |
790 PreParserExpression ParseClassLiteral(ExpressionClassifier* classifier, | 780 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
791 PreParserIdentifier name, | |
792 Scanner::Location class_name_location, | 781 Scanner::Location class_name_location, |
793 bool name_is_strict_reserved, int pos, | 782 bool name_is_strict_reserved, int pos, |
794 bool* ok); | 783 bool* ok); |
795 | 784 |
796 struct TemplateLiteralState {}; | 785 struct TemplateLiteralState {}; |
797 | 786 |
798 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { | 787 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { |
799 return TemplateLiteralState(); | 788 return TemplateLiteralState(); |
800 } | 789 } |
801 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, | 790 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, |
802 PreParserExpression expression) {} | 791 PreParserExpression expression) {} |
803 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {} | 792 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {} |
804 V8_INLINE PreParserExpression CloseTemplateLiteral( | 793 V8_INLINE PreParserExpression CloseTemplateLiteral( |
805 TemplateLiteralState* state, int start, PreParserExpression tag); | 794 TemplateLiteralState* state, int start, PreParserExpression tag); |
806 V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 795 V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
807 | 796 |
808 V8_INLINE void MarkCollectedTailCallExpressions() {} | 797 V8_INLINE void MarkCollectedTailCallExpressions() {} |
809 V8_INLINE void MarkTailPosition(PreParserExpression expression) {} | 798 V8_INLINE void MarkTailPosition(PreParserExpression expression) {} |
810 | 799 |
811 void ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, | 800 void ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, |
812 bool accept_IN, | 801 bool accept_IN, |
813 ExpressionClassifier* classifier, | |
814 int pos, bool* ok); | 802 int pos, bool* ok); |
815 | 803 |
816 V8_INLINE PreParserExpressionList | 804 V8_INLINE PreParserExpressionList |
817 PrepareSpreadArguments(PreParserExpressionList list) { | 805 PrepareSpreadArguments(PreParserExpressionList list) { |
818 return list; | 806 return list; |
819 } | 807 } |
820 | 808 |
821 V8_INLINE PreParserExpression SpreadCall(PreParserExpression function, | 809 V8_INLINE PreParserExpression SpreadCall(PreParserExpression function, |
822 PreParserExpressionList args, | 810 PreParserExpressionList args, |
823 int pos); | 811 int pos); |
(...skipping 15 matching lines...) Expand all Loading... |
839 | 827 |
840 V8_INLINE PreParserExpression | 828 V8_INLINE PreParserExpression |
841 RewriteAwaitExpression(PreParserExpression value, int pos) { | 829 RewriteAwaitExpression(PreParserExpression value, int pos) { |
842 return value; | 830 return value; |
843 } | 831 } |
844 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, | 832 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, |
845 PreParserExpression expression, | 833 PreParserExpression expression, |
846 int pos) { | 834 int pos) { |
847 return PreParserExpression::Default(); | 835 return PreParserExpression::Default(); |
848 } | 836 } |
849 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok) { | 837 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } |
850 ValidateExpression(classifier, ok); | |
851 } | |
852 | 838 |
853 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 839 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
854 PreParserExpression assignment) {} | 840 PreParserExpression assignment) {} |
855 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, | 841 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, |
856 bool* ok) {} | 842 bool* ok) {} |
857 | 843 |
858 // Helper functions for recursive descent. | 844 // Helper functions for recursive descent. |
859 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { | 845 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { |
860 return identifier.IsEval(); | 846 return identifier.IsEval(); |
861 } | 847 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 | 1085 |
1100 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, | 1086 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, |
1101 PreParserExpression pattern, | 1087 PreParserExpression pattern, |
1102 PreParserExpression initializer, | 1088 PreParserExpression initializer, |
1103 int initializer_end_position, | 1089 int initializer_end_position, |
1104 bool is_rest) { | 1090 bool is_rest) { |
1105 ++parameters->arity; | 1091 ++parameters->arity; |
1106 } | 1092 } |
1107 | 1093 |
1108 V8_INLINE void DeclareFormalParameter(DeclarationScope* scope, | 1094 V8_INLINE void DeclareFormalParameter(DeclarationScope* scope, |
1109 PreParserIdentifier parameter, | 1095 PreParserIdentifier parameter) { |
1110 ExpressionClassifier* classifier) { | 1096 if (!classifier()->is_simple_parameter_list()) { |
1111 if (!classifier->is_simple_parameter_list()) { | |
1112 scope->SetHasNonSimpleParameters(); | 1097 scope->SetHasNonSimpleParameters(); |
1113 } | 1098 } |
1114 } | 1099 } |
1115 | 1100 |
1116 V8_INLINE void ParseArrowFunctionFormalParameterList( | 1101 V8_INLINE void ParseArrowFunctionFormalParameterList( |
1117 PreParserFormalParameters* parameters, PreParserExpression params, | 1102 PreParserFormalParameters* parameters, PreParserExpression params, |
1118 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 1103 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
1119 const Scope::Snapshot& scope_snapshot, bool* ok) { | 1104 const Scope::Snapshot& scope_snapshot, bool* ok) { |
1120 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect | 1105 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect |
1121 // parameter | 1106 // parameter |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 function_state_->NextMaterializedLiteralIndex(); | 1187 function_state_->NextMaterializedLiteralIndex(); |
1203 function_state_->NextMaterializedLiteralIndex(); | 1188 function_state_->NextMaterializedLiteralIndex(); |
1204 } | 1189 } |
1205 return EmptyExpression(); | 1190 return EmptyExpression(); |
1206 } | 1191 } |
1207 | 1192 |
1208 } // namespace internal | 1193 } // namespace internal |
1209 } // namespace v8 | 1194 } // namespace v8 |
1210 | 1195 |
1211 #endif // V8_PARSING_PREPARSER_H | 1196 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |