Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: src/parsing/preparser.h

Issue 2368083002: [parser] Refactor of ParseClass* and ParseNativeDeclaration (Closed)
Patch Set: The real patch Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 // PreParser doesn't need to store generator variables. 720 // PreParser doesn't need to store generator variables.
721 typedef void Variable; 721 typedef void Variable;
722 722
723 // Return types for traversing functions. 723 // Return types for traversing functions.
724 typedef PreParserIdentifier Identifier; 724 typedef PreParserIdentifier Identifier;
725 typedef PreParserExpression Expression; 725 typedef PreParserExpression Expression;
726 typedef PreParserExpression FunctionLiteral; 726 typedef PreParserExpression FunctionLiteral;
727 typedef PreParserExpression ObjectLiteralProperty; 727 typedef PreParserExpression ObjectLiteralProperty;
728 typedef PreParserExpression ClassLiteralProperty; 728 typedef PreParserExpression ClassLiteralProperty;
729 typedef PreParserExpressionList ExpressionList; 729 typedef PreParserExpressionList ExpressionList;
730 typedef PreParserExpressionList PropertyList; 730 typedef PreParserExpressionList ObjectPropertyList;
731 typedef PreParserExpressionList ClassPropertyList;
731 typedef PreParserFormalParameters FormalParameters; 732 typedef PreParserFormalParameters FormalParameters;
732 typedef PreParserStatement Statement; 733 typedef PreParserStatement Statement;
733 typedef PreParserStatementList StatementList; 734 typedef PreParserStatementList StatementList;
734 typedef PreParserStatement Block; 735 typedef PreParserStatement Block;
735 typedef PreParserStatement BreakableStatement; 736 typedef PreParserStatement BreakableStatement;
736 typedef PreParserStatement IterationStatement; 737 typedef PreParserStatement IterationStatement;
737 738
738 // For constructing objects returned by the traversing functions. 739 // For constructing objects returned by the traversing functions.
739 typedef PreParserFactory Factory; 740 typedef PreParserFactory Factory;
740 741
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, 841 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names,
841 bool default_export, bool* ok); 842 bool default_export, bool* ok);
842 Expression ParseAsyncFunctionExpression(bool* ok); 843 Expression ParseAsyncFunctionExpression(bool* ok);
843 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names,
844 bool default_export, bool* ok);
845 Expression ParseConditionalExpression(bool accept_IN, bool* ok); 844 Expression ParseConditionalExpression(bool accept_IN, bool* ok);
846 Expression ParseObjectLiteral(bool* ok); 845 Expression ParseObjectLiteral(bool* ok);
847 846
848 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 847 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
849 PreParserIdentifier function_name, int pos, 848 PreParserIdentifier function_name, int pos,
850 const PreParserFormalParameters& parameters, FunctionKind kind, 849 const PreParserFormalParameters& parameters, FunctionKind kind,
851 FunctionLiteral::FunctionType function_type, bool* ok); 850 FunctionLiteral::FunctionType function_type, bool* ok);
852 851
853 V8_INLINE LazyParsingResult 852 V8_INLINE LazyParsingResult
854 SkipLazyFunctionBody(int* materialized_literal_count, 853 SkipLazyFunctionBody(int* materialized_literal_count,
855 int* expected_property_count, bool may_abort, bool* ok) { 854 int* expected_property_count, bool may_abort, bool* ok) {
856 UNREACHABLE(); 855 UNREACHABLE();
857 return kLazyParsingComplete; 856 return kLazyParsingComplete;
858 } 857 }
859 Expression ParseFunctionLiteral( 858 Expression ParseFunctionLiteral(
860 Identifier name, Scanner::Location function_name_location, 859 Identifier name, Scanner::Location function_name_location,
861 FunctionNameValidity function_name_validity, FunctionKind kind, 860 FunctionNameValidity function_name_validity, FunctionKind kind,
862 int function_token_pos, FunctionLiteral::FunctionType function_type, 861 int function_token_pos, FunctionLiteral::FunctionType function_type,
863 LanguageMode language_mode, bool* ok); 862 LanguageMode language_mode, bool* ok);
864 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); 863 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok);
865 864
866 PreParserExpression ParseClassLiteral(PreParserIdentifier name,
867 Scanner::Location class_name_location,
868 bool name_is_strict_reserved, int pos,
869 bool* ok);
870
871 struct TemplateLiteralState {}; 865 struct TemplateLiteralState {};
872 866
873 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) { 867 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) {
874 return TemplateLiteralState(); 868 return TemplateLiteralState();
875 } 869 }
876 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, 870 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state,
877 PreParserExpression expression) {} 871 PreParserExpression expression) {}
878 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {} 872 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {}
879 V8_INLINE PreParserExpression CloseTemplateLiteral( 873 V8_INLINE PreParserExpression CloseTemplateLiteral(
880 TemplateLiteralState* state, int start, PreParserExpression tag); 874 TemplateLiteralState* state, int start, PreParserExpression tag);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 V8_INLINE ZoneList<const AstRawString*>* DeclareLabel( 934 V8_INLINE ZoneList<const AstRawString*>* DeclareLabel(
941 ZoneList<const AstRawString*>* labels, PreParserExpression expr, 935 ZoneList<const AstRawString*>* labels, PreParserExpression expr,
942 bool* ok) { 936 bool* ok) {
943 DCHECK(!expr.AsIdentifier().IsEnum()); 937 DCHECK(!expr.AsIdentifier().IsEnum());
944 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait()); 938 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait());
945 DCHECK(is_sloppy(language_mode()) || 939 DCHECK(is_sloppy(language_mode()) ||
946 !IsFutureStrictReserved(expr.AsIdentifier())); 940 !IsFutureStrictReserved(expr.AsIdentifier()));
947 return labels; 941 return labels;
948 } 942 }
949 943
950 V8_INLINE PreParserStatement ParseNativeDeclaration(bool* ok) {
951 UNREACHABLE();
952 return PreParserStatement::Default();
953 }
954
955 // TODO(nikolaos): The preparser currently does not keep track of labels. 944 // TODO(nikolaos): The preparser currently does not keep track of labels.
956 V8_INLINE bool ContainsLabel(ZoneList<const AstRawString*>* labels, 945 V8_INLINE bool ContainsLabel(ZoneList<const AstRawString*>* labels,
957 PreParserIdentifier label) { 946 PreParserIdentifier label) {
958 return false; 947 return false;
959 } 948 }
960 949
961 V8_INLINE PreParserExpression RewriteReturn(PreParserExpression return_value, 950 V8_INLINE PreParserExpression RewriteReturn(PreParserExpression return_value,
962 int pos) { 951 int pos) {
963 return return_value; 952 return return_value;
964 } 953 }
(...skipping 26 matching lines...) Expand all
991 return PreParserStatement::Default(); 980 return PreParserStatement::Default();
992 } 981 }
993 982
994 V8_INLINE PreParserStatement DeclareFunction( 983 V8_INLINE PreParserStatement DeclareFunction(
995 PreParserIdentifier variable_name, PreParserExpression function, int pos, 984 PreParserIdentifier variable_name, PreParserExpression function, int pos,
996 bool is_generator, bool is_async, ZoneList<const AstRawString*>* names, 985 bool is_generator, bool is_async, ZoneList<const AstRawString*>* names,
997 bool* ok) { 986 bool* ok) {
998 return Statement::Default(); 987 return Statement::Default();
999 } 988 }
1000 989
990 V8_INLINE PreParserStatement
991 DeclareClass(PreParserIdentifier variable_name, PreParserExpression value,
992 ZoneList<const AstRawString*>* names, int pos, bool* ok) {
993 return PreParserStatement::Default();
994 }
995 V8_INLINE void DeclareClassVariable(PreParserIdentifier name,
996 Scope* block_scope, ClassInfo* class_info,
997 int 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
1001 V8_INLINE void QueueDestructuringAssignmentForRewriting( 1012 V8_INLINE void QueueDestructuringAssignmentForRewriting(
1002 PreParserExpression assignment) {} 1013 PreParserExpression assignment) {}
1003 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr, 1014 V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr,
1004 bool* ok) {} 1015 bool* ok) {}
1005 1016
1006 // Helper functions for recursive descent. 1017 // Helper functions for recursive descent.
1007 V8_INLINE bool IsEval(PreParserIdentifier identifier) const { 1018 V8_INLINE bool IsEval(PreParserIdentifier identifier) const {
1008 return identifier.IsEval(); 1019 return identifier.IsEval();
1009 } 1020 }
1010 1021
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 PreParserIdentifier* default_string, 1109 PreParserIdentifier* default_string,
1099 PreParserIdentifier* star_default_star_string) {} 1110 PreParserIdentifier* star_default_star_string) {}
1100 1111
1101 // Functions for encapsulating the differences between parsing and preparsing; 1112 // Functions for encapsulating the differences between parsing and preparsing;
1102 // operations interleaved with the recursive descent. 1113 // operations interleaved with the recursive descent.
1103 V8_INLINE static void PushLiteralName(PreParserIdentifier id) {} 1114 V8_INLINE static void PushLiteralName(PreParserIdentifier id) {}
1104 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} 1115 V8_INLINE static void PushVariableName(PreParserIdentifier id) {}
1105 V8_INLINE void PushPropertyName(PreParserExpression expression) {} 1116 V8_INLINE void PushPropertyName(PreParserExpression expression) {}
1106 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} 1117 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {}
1107 V8_INLINE static void InferFunctionName(PreParserExpression expression) {} 1118 V8_INLINE static void InferFunctionName(PreParserExpression expression) {}
1119 V8_INLINE static void Infer() {}
1108 1120
1109 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( 1121 V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
1110 PreParserExpression left, PreParserExpression right) {} 1122 PreParserExpression left, PreParserExpression right) {}
1111 1123
1112 V8_INLINE static PreParserExpression MarkExpressionAsAssigned( 1124 V8_INLINE static PreParserExpression MarkExpressionAsAssigned(
1113 PreParserExpression expression) { 1125 PreParserExpression expression) {
1114 // TODO(marja): To be able to produce the same errors, the preparser needs 1126 // TODO(marja): To be able to produce the same errors, the preparser needs
1115 // to start tracking which expressions are variables and which are assigned. 1127 // to start tracking which expressions are variables and which are assigned.
1116 return expression; 1128 return expression;
1117 } 1129 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 if (scanner()->UnescapedLiteralMatches("use strict", 10)) { 1326 if (scanner()->UnescapedLiteralMatches("use strict", 10)) {
1315 return PreParserExpression::UseStrictStringLiteral(); 1327 return PreParserExpression::UseStrictStringLiteral();
1316 } 1328 }
1317 return PreParserExpression::StringLiteral(); 1329 return PreParserExpression::StringLiteral();
1318 } 1330 }
1319 1331
1320 V8_INLINE PreParserExpressionList NewExpressionList(int size) const { 1332 V8_INLINE PreParserExpressionList NewExpressionList(int size) const {
1321 return PreParserExpressionList(); 1333 return PreParserExpressionList();
1322 } 1334 }
1323 1335
1324 V8_INLINE PreParserExpressionList NewPropertyList(int size) const { 1336 V8_INLINE PreParserExpressionList NewObjectPropertyList(int size) const {
1325 return PreParserExpressionList(); 1337 return PreParserExpressionList();
1326 } 1338 }
1327 1339
1340 V8_INLINE PreParserExpressionList NewClassPropertyList(int size) const {
1341 return PreParserExpressionList();
1342 }
1343
1328 V8_INLINE PreParserStatementList NewStatementList(int size) const { 1344 V8_INLINE PreParserStatementList NewStatementList(int size) const {
1329 return PreParserStatementList(); 1345 return PreParserStatementList();
1330 } 1346 }
1331 1347
1332 PreParserStatementList NewCaseClauseList(int size) { 1348 PreParserStatementList NewCaseClauseList(int size) {
1333 return PreParserStatementList(); 1349 return PreParserStatementList();
1334 } 1350 }
1335 1351
1336 V8_INLINE PreParserExpression 1352 V8_INLINE PreParserExpression
1337 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments, 1353 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 function_state_->NextMaterializedLiteralIndex(); 1476 function_state_->NextMaterializedLiteralIndex();
1461 function_state_->NextMaterializedLiteralIndex(); 1477 function_state_->NextMaterializedLiteralIndex();
1462 } 1478 }
1463 return EmptyExpression(); 1479 return EmptyExpression();
1464 } 1480 }
1465 1481
1466 } // namespace internal 1482 } // namespace internal
1467 } // namespace v8 1483 } // namespace v8
1468 1484
1469 #endif // V8_PARSING_PREPARSER_H 1485 #endif // V8_PARSING_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698