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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 // PreParser doesn't need to store generator variables. | 721 // PreParser doesn't need to store generator variables. |
722 typedef void Variable; | 722 typedef void Variable; |
723 | 723 |
724 // Return types for traversing functions. | 724 // Return types for traversing functions. |
725 typedef PreParserIdentifier Identifier; | 725 typedef PreParserIdentifier Identifier; |
726 typedef PreParserExpression Expression; | 726 typedef PreParserExpression Expression; |
727 typedef PreParserExpression FunctionLiteral; | 727 typedef PreParserExpression FunctionLiteral; |
728 typedef PreParserExpression ObjectLiteralProperty; | 728 typedef PreParserExpression ObjectLiteralProperty; |
729 typedef PreParserExpression ClassLiteralProperty; | 729 typedef PreParserExpression ClassLiteralProperty; |
730 typedef PreParserExpressionList ExpressionList; | 730 typedef PreParserExpressionList ExpressionList; |
731 typedef PreParserExpressionList ObjectPropertyList; | 731 typedef PreParserExpressionList PropertyList; |
732 typedef PreParserExpressionList ClassPropertyList; | |
733 typedef PreParserFormalParameters FormalParameters; | 732 typedef PreParserFormalParameters FormalParameters; |
734 typedef PreParserStatement Statement; | 733 typedef PreParserStatement Statement; |
735 typedef PreParserStatementList StatementList; | 734 typedef PreParserStatementList StatementList; |
736 typedef PreParserStatement Block; | 735 typedef PreParserStatement Block; |
737 typedef PreParserStatement BreakableStatement; | 736 typedef PreParserStatement BreakableStatement; |
738 typedef PreParserStatement IterationStatement; | 737 typedef PreParserStatement IterationStatement; |
739 | 738 |
740 // For constructing objects returned by the traversing functions. | 739 // For constructing objects returned by the traversing functions. |
741 typedef PreParserFactory Factory; | 740 typedef PreParserFactory Factory; |
742 | 741 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 // These types form an algebra over syntactic categories that is just | 830 // These types form an algebra over syntactic categories that is just |
832 // rich enough to let us recognize and propagate the constructs that | 831 // rich enough to let us recognize and propagate the constructs that |
833 // are either being counted in the preparser data, or is important | 832 // are either being counted in the preparser data, or is important |
834 // to throw the correct syntax error exceptions. | 833 // to throw the correct syntax error exceptions. |
835 | 834 |
836 // All ParseXXX functions take as the last argument an *ok parameter | 835 // All ParseXXX functions take as the last argument an *ok parameter |
837 // which is set to false if parsing failed; it is unchanged otherwise. | 836 // which is set to false if parsing failed; it is unchanged otherwise. |
838 // By making the 'exception handling' explicit, we are forced to check | 837 // By making the 'exception handling' explicit, we are forced to check |
839 // for failure at the call sites. | 838 // for failure at the call sites. |
840 Statement ParseFunctionDeclaration(bool* ok); | 839 Statement ParseFunctionDeclaration(bool* ok); |
| 840 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| 841 bool default_export, bool* ok); |
841 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 842 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
842 Expression ParseObjectLiteral(bool* ok); | 843 Expression ParseObjectLiteral(bool* ok); |
843 | 844 |
844 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 845 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
845 PreParserIdentifier function_name, int pos, | 846 PreParserIdentifier function_name, int pos, |
846 const PreParserFormalParameters& parameters, FunctionKind kind, | 847 const PreParserFormalParameters& parameters, FunctionKind kind, |
847 FunctionLiteral::FunctionType function_type, bool* ok); | 848 FunctionLiteral::FunctionType function_type, bool* ok); |
848 | 849 |
849 V8_INLINE LazyParsingResult SkipLazyFunctionBody( | 850 V8_INLINE LazyParsingResult SkipLazyFunctionBody( |
850 int* materialized_literal_count, int* expected_property_count, | 851 int* materialized_literal_count, int* expected_property_count, |
851 bool track_unresolved_variables, bool may_abort, bool* ok) { | 852 bool track_unresolved_variables, bool may_abort, bool* ok) { |
852 UNREACHABLE(); | 853 UNREACHABLE(); |
853 return kLazyParsingComplete; | 854 return kLazyParsingComplete; |
854 } | 855 } |
855 Expression ParseFunctionLiteral( | 856 Expression ParseFunctionLiteral( |
856 Identifier name, Scanner::Location function_name_location, | 857 Identifier name, Scanner::Location function_name_location, |
857 FunctionNameValidity function_name_validity, FunctionKind kind, | 858 FunctionNameValidity function_name_validity, FunctionKind kind, |
858 int function_token_pos, FunctionLiteral::FunctionType function_type, | 859 int function_token_pos, FunctionLiteral::FunctionType function_type, |
859 LanguageMode language_mode, bool* ok); | 860 LanguageMode language_mode, bool* ok); |
860 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); | 861 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); |
861 | 862 |
| 863 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
| 864 Scanner::Location class_name_location, |
| 865 bool name_is_strict_reserved, int pos, |
| 866 bool* ok); |
| 867 |
862 struct TemplateLiteralState {}; | 868 struct TemplateLiteralState {}; |
863 | 869 |
864 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { | 870 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { |
865 return TemplateLiteralState(); | 871 return TemplateLiteralState(); |
866 } | 872 } |
867 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, | 873 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, |
868 PreParserExpression expression) {} | 874 PreParserExpression expression) {} |
869 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {} | 875 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {} |
870 V8_INLINE PreParserExpression CloseTemplateLiteral( | 876 V8_INLINE PreParserExpression CloseTemplateLiteral( |
871 TemplateLiteralState* state, int start, PreParserExpression tag); | 877 TemplateLiteralState* state, int start, PreParserExpression tag); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 V8_INLINE ZoneList<const AstRawString*>* DeclareLabel( | 939 V8_INLINE ZoneList<const AstRawString*>* DeclareLabel( |
934 ZoneList<const AstRawString*>* labels, PreParserExpression expr, | 940 ZoneList<const AstRawString*>* labels, PreParserExpression expr, |
935 bool* ok) { | 941 bool* ok) { |
936 DCHECK(!expr.AsIdentifier().IsEnum()); | 942 DCHECK(!expr.AsIdentifier().IsEnum()); |
937 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait()); | 943 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait()); |
938 DCHECK(is_sloppy(language_mode()) || | 944 DCHECK(is_sloppy(language_mode()) || |
939 !IsFutureStrictReserved(expr.AsIdentifier())); | 945 !IsFutureStrictReserved(expr.AsIdentifier())); |
940 return labels; | 946 return labels; |
941 } | 947 } |
942 | 948 |
| 949 V8_INLINE PreParserStatement ParseNativeDeclaration(bool* ok) { |
| 950 UNREACHABLE(); |
| 951 return PreParserStatement::Default(); |
| 952 } |
| 953 |
943 // TODO(nikolaos): The preparser currently does not keep track of labels. | 954 // TODO(nikolaos): The preparser currently does not keep track of labels. |
944 V8_INLINE bool ContainsLabel(ZoneList<const AstRawString*>* labels, | 955 V8_INLINE bool ContainsLabel(ZoneList<const AstRawString*>* labels, |
945 PreParserIdentifier label) { | 956 PreParserIdentifier label) { |
946 return false; | 957 return false; |
947 } | 958 } |
948 | 959 |
949 V8_INLINE PreParserExpression RewriteReturn(PreParserExpression return_value, | 960 V8_INLINE PreParserExpression RewriteReturn(PreParserExpression return_value, |
950 int pos) { | 961 int pos) { |
951 return return_value; | 962 return return_value; |
952 } | 963 } |
(...skipping 26 matching lines...) Expand all Loading... |
979 return PreParserStatement::Default(); | 990 return PreParserStatement::Default(); |
980 } | 991 } |
981 | 992 |
982 V8_INLINE PreParserStatement DeclareFunction( | 993 V8_INLINE PreParserStatement DeclareFunction( |
983 PreParserIdentifier variable_name, PreParserExpression function, int pos, | 994 PreParserIdentifier variable_name, PreParserExpression function, int pos, |
984 bool is_generator, bool is_async, ZoneList<const AstRawString*>* names, | 995 bool is_generator, bool is_async, ZoneList<const AstRawString*>* names, |
985 bool* ok) { | 996 bool* ok) { |
986 return Statement::Default(); | 997 return Statement::Default(); |
987 } | 998 } |
988 | 999 |
989 V8_INLINE PreParserStatement | |
990 DeclareClass(PreParserIdentifier variable_name, PreParserExpression value, | |
991 ZoneList<const AstRawString*>* names, int class_token_pos, | |
992 int end_pos, bool* ok) { | |
993 return PreParserStatement::Default(); | |
994 } | |
995 V8_INLINE void DeclareClassVariable(PreParserIdentifier name, | |
996 Scope* block_scope, ClassInfo* class_info, | |
997 int class_token_pos, bool* ok) {} | |
998 V8_INLINE void DeclareClassProperty(PreParserIdentifier class_name, | |
999 PreParserExpression property, | |
1000 ClassInfo* class_info, bool* ok) {} | |
1001 V8_INLINE PreParserExpression RewriteClassLiteral(PreParserIdentifier name, | |
1002 ClassInfo* class_info, | |
1003 int pos, bool* ok) { | |
1004 return PreParserExpression::Default(); | |
1005 } | |
1006 | |
1007 V8_INLINE PreParserStatement DeclareNative(PreParserIdentifier name, int pos, | |
1008 bool* ok) { | |
1009 return PreParserStatement::Default(); | |
1010 } | |
1011 | |
1012 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 1000 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
1013 PreParserExpression assignment) {} | 1001 PreParserExpression assignment) {} |
1014 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, | 1002 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, |
1015 bool* ok) {} | 1003 bool* ok) {} |
1016 | 1004 |
1017 // Helper functions for recursive descent. | 1005 // Helper functions for recursive descent. |
1018 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { | 1006 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { |
1019 return identifier.IsEval(); | 1007 return identifier.IsEval(); |
1020 } | 1008 } |
1021 | 1009 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 V8_INLINE static void GetDefaultStrings( | 1096 V8_INLINE static void GetDefaultStrings( |
1109 PreParserIdentifier* default_string, | 1097 PreParserIdentifier* default_string, |
1110 PreParserIdentifier* star_default_star_string) {} | 1098 PreParserIdentifier* star_default_star_string) {} |
1111 | 1099 |
1112 // Functions for encapsulating the differences between parsing and preparsing; | 1100 // Functions for encapsulating the differences between parsing and preparsing; |
1113 // operations interleaved with the recursive descent. | 1101 // operations interleaved with the recursive descent. |
1114 V8_INLINE static void PushLiteralName(PreParserIdentifier id) {} | 1102 V8_INLINE static void PushLiteralName(PreParserIdentifier id) {} |
1115 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} | 1103 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} |
1116 V8_INLINE void PushPropertyName(PreParserExpression expression) {} | 1104 V8_INLINE void PushPropertyName(PreParserExpression expression) {} |
1117 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} | 1105 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} |
1118 V8_INLINE static void AddFunctionForNameInference( | 1106 V8_INLINE static void InferFunctionName(PreParserExpression expression) {} |
1119 PreParserExpression expression) {} | |
1120 V8_INLINE static void InferFunctionName() {} | |
1121 | 1107 |
1122 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( | 1108 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
1123 PreParserExpression left, PreParserExpression right) {} | 1109 PreParserExpression left, PreParserExpression right) {} |
1124 | 1110 |
1125 V8_INLINE static PreParserExpression MarkExpressionAsAssigned( | 1111 V8_INLINE static PreParserExpression MarkExpressionAsAssigned( |
1126 PreParserExpression expression) { | 1112 PreParserExpression expression) { |
1127 // TODO(marja): To be able to produce the same errors, the preparser needs | 1113 // TODO(marja): To be able to produce the same errors, the preparser needs |
1128 // to start tracking which expressions are variables and which are assigned. | 1114 // to start tracking which expressions are variables and which are assigned. |
1129 return expression; | 1115 return expression; |
1130 } | 1116 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 if (scanner()->UnescapedLiteralMatches("use strict", 10)) { | 1311 if (scanner()->UnescapedLiteralMatches("use strict", 10)) { |
1326 return PreParserExpression::UseStrictStringLiteral(); | 1312 return PreParserExpression::UseStrictStringLiteral(); |
1327 } | 1313 } |
1328 return PreParserExpression::StringLiteral(); | 1314 return PreParserExpression::StringLiteral(); |
1329 } | 1315 } |
1330 | 1316 |
1331 V8_INLINE PreParserExpressionList NewExpressionList(int size) const { | 1317 V8_INLINE PreParserExpressionList NewExpressionList(int size) const { |
1332 return PreParserExpressionList(); | 1318 return PreParserExpressionList(); |
1333 } | 1319 } |
1334 | 1320 |
1335 V8_INLINE PreParserExpressionList NewObjectPropertyList(int size) const { | 1321 V8_INLINE PreParserExpressionList NewPropertyList(int size) const { |
1336 return PreParserExpressionList(); | 1322 return PreParserExpressionList(); |
1337 } | 1323 } |
1338 | 1324 |
1339 V8_INLINE PreParserExpressionList NewClassPropertyList(int size) const { | |
1340 return PreParserExpressionList(); | |
1341 } | |
1342 | |
1343 V8_INLINE PreParserStatementList NewStatementList(int size) const { | 1325 V8_INLINE PreParserStatementList NewStatementList(int size) const { |
1344 return PreParserStatementList(); | 1326 return PreParserStatementList(); |
1345 } | 1327 } |
1346 | 1328 |
1347 PreParserStatementList NewCaseClauseList(int size) { | 1329 PreParserStatementList NewCaseClauseList(int size) { |
1348 return PreParserStatementList(); | 1330 return PreParserStatementList(); |
1349 } | 1331 } |
1350 | 1332 |
1351 V8_INLINE PreParserExpression | 1333 V8_INLINE PreParserExpression |
1352 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments, | 1334 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 function_state_->NextMaterializedLiteralIndex(); | 1457 function_state_->NextMaterializedLiteralIndex(); |
1476 function_state_->NextMaterializedLiteralIndex(); | 1458 function_state_->NextMaterializedLiteralIndex(); |
1477 } | 1459 } |
1478 return EmptyExpression(); | 1460 return EmptyExpression(); |
1479 } | 1461 } |
1480 | 1462 |
1481 } // namespace internal | 1463 } // namespace internal |
1482 } // namespace v8 | 1464 } // namespace v8 |
1483 | 1465 |
1484 #endif // V8_PARSING_PREPARSER_H | 1466 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |