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