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

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

Issue 1841543003: [esnext] implement frontend changes for async/await proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove pointless line from scanner Created 4 years, 7 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/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 static PreParserIdentifier Constructor() { 55 static PreParserIdentifier Constructor() {
56 return PreParserIdentifier(kConstructorIdentifier); 56 return PreParserIdentifier(kConstructorIdentifier);
57 } 57 }
58 static PreParserIdentifier Enum() { 58 static PreParserIdentifier Enum() {
59 return PreParserIdentifier(kEnumIdentifier); 59 return PreParserIdentifier(kEnumIdentifier);
60 } 60 }
61 static PreParserIdentifier Await() { 61 static PreParserIdentifier Await() {
62 return PreParserIdentifier(kAwaitIdentifier); 62 return PreParserIdentifier(kAwaitIdentifier);
63 } 63 }
64 static PreParserIdentifier Async() {
65 return PreParserIdentifier(kAsyncIdentifier);
66 }
64 bool IsEval() const { return type_ == kEvalIdentifier; } 67 bool IsEval() const { return type_ == kEvalIdentifier; }
65 bool IsArguments() const { return type_ == kArgumentsIdentifier; } 68 bool IsArguments() const { return type_ == kArgumentsIdentifier; }
66 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); } 69 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); }
67 bool IsUndefined() const { return type_ == kUndefinedIdentifier; } 70 bool IsUndefined() const { return type_ == kUndefinedIdentifier; }
68 bool IsLet() const { return type_ == kLetIdentifier; } 71 bool IsLet() const { return type_ == kLetIdentifier; }
69 bool IsStatic() const { return type_ == kStaticIdentifier; } 72 bool IsStatic() const { return type_ == kStaticIdentifier; }
70 bool IsYield() const { return type_ == kYieldIdentifier; } 73 bool IsYield() const { return type_ == kYieldIdentifier; }
71 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } 74 bool IsPrototype() const { return type_ == kPrototypeIdentifier; }
72 bool IsConstructor() const { return type_ == kConstructorIdentifier; } 75 bool IsConstructor() const { return type_ == kConstructorIdentifier; }
73 bool IsEnum() const { return type_ == kEnumIdentifier; } 76 bool IsEnum() const { return type_ == kEnumIdentifier; }
74 bool IsAwait() const { return type_ == kAwaitIdentifier; } 77 bool IsAwait() const { return type_ == kAwaitIdentifier; }
78 bool IsAsync() const { return type_ == kAsyncIdentifier; }
75 bool IsFutureStrictReserved() const { 79 bool IsFutureStrictReserved() const {
76 return type_ == kFutureStrictReservedIdentifier || 80 return type_ == kFutureStrictReservedIdentifier ||
77 type_ == kLetIdentifier || type_ == kStaticIdentifier || 81 type_ == kLetIdentifier || type_ == kStaticIdentifier ||
78 type_ == kYieldIdentifier; 82 type_ == kYieldIdentifier;
79 } 83 }
80 84
81 // Allow identifier->name()[->length()] to work. The preparser 85 // Allow identifier->name()[->length()] to work. The preparser
82 // does not need the actual positions/lengths of the identifiers. 86 // does not need the actual positions/lengths of the identifiers.
83 const PreParserIdentifier* operator->() const { return this; } 87 const PreParserIdentifier* operator->() const { return this; }
84 const PreParserIdentifier raw_name() const { return *this; } 88 const PreParserIdentifier raw_name() const { return *this; }
85 89
86 int position() const { return 0; } 90 int position() const { return 0; }
87 int length() const { return 0; } 91 int length() const { return 0; }
88 92
89 private: 93 private:
90 enum Type { 94 enum Type {
91 kUnknownIdentifier, 95 kUnknownIdentifier,
92 kFutureReservedIdentifier, 96 kFutureReservedIdentifier,
93 kFutureStrictReservedIdentifier, 97 kFutureStrictReservedIdentifier,
94 kLetIdentifier, 98 kLetIdentifier,
95 kStaticIdentifier, 99 kStaticIdentifier,
96 kYieldIdentifier, 100 kYieldIdentifier,
97 kEvalIdentifier, 101 kEvalIdentifier,
98 kArgumentsIdentifier, 102 kArgumentsIdentifier,
99 kUndefinedIdentifier, 103 kUndefinedIdentifier,
100 kPrototypeIdentifier, 104 kPrototypeIdentifier,
101 kConstructorIdentifier, 105 kConstructorIdentifier,
102 kEnumIdentifier, 106 kEnumIdentifier,
103 kAwaitIdentifier 107 kAwaitIdentifier,
108 kAsyncIdentifier
104 }; 109 };
105 110
106 explicit PreParserIdentifier(Type type) : type_(type) {} 111 explicit PreParserIdentifier(Type type) : type_(type) {}
107 Type type_; 112 Type type_;
108 113
109 friend class PreParserExpression; 114 friend class PreParserExpression;
110 }; 115 };
111 116
112 117
113 class PreParserExpression { 118 class PreParserExpression {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 620
616 // Helper functions for recursive descent. 621 // Helper functions for recursive descent.
617 static bool IsEval(PreParserIdentifier identifier) { 622 static bool IsEval(PreParserIdentifier identifier) {
618 return identifier.IsEval(); 623 return identifier.IsEval();
619 } 624 }
620 625
621 static bool IsArguments(PreParserIdentifier identifier) { 626 static bool IsArguments(PreParserIdentifier identifier) {
622 return identifier.IsArguments(); 627 return identifier.IsArguments();
623 } 628 }
624 629
630 static bool IsAwait(PreParserIdentifier identifier) {
631 return identifier.IsAwait();
632 }
633
634 static bool IsAsync(PreParserIdentifier identifier) {
635 return identifier.IsAsync();
636 }
637
625 static bool IsEvalOrArguments(PreParserIdentifier identifier) { 638 static bool IsEvalOrArguments(PreParserIdentifier identifier) {
626 return identifier.IsEvalOrArguments(); 639 return identifier.IsEvalOrArguments();
627 } 640 }
628 641
629 static bool IsUndefined(PreParserIdentifier identifier) { 642 static bool IsUndefined(PreParserIdentifier identifier) {
630 return identifier.IsUndefined(); 643 return identifier.IsUndefined();
631 } 644 }
632 645
633 static bool IsPrototype(PreParserIdentifier identifier) { 646 static bool IsPrototype(PreParserIdentifier identifier) {
634 return identifier.IsPrototype(); 647 return identifier.IsPrototype();
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 871 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
859 PreParserIdentifier function_name, int pos, 872 PreParserIdentifier function_name, int pos,
860 const PreParserFormalParameters& parameters, FunctionKind kind, 873 const PreParserFormalParameters& parameters, FunctionKind kind,
861 FunctionLiteral::FunctionType function_type, bool* ok); 874 FunctionLiteral::FunctionType function_type, bool* ok);
862 875
863 V8_INLINE void ParseArrowFunctionFormalParameterList( 876 V8_INLINE void ParseArrowFunctionFormalParameterList(
864 PreParserFormalParameters* parameters, 877 PreParserFormalParameters* parameters,
865 PreParserExpression expression, const Scanner::Location& params_loc, 878 PreParserExpression expression, const Scanner::Location& params_loc,
866 Scanner::Location* duplicate_loc, bool* ok); 879 Scanner::Location* duplicate_loc, bool* ok);
867 880
881 V8_INLINE PreParserExpression ParseAsyncFunctionExpression(bool* ok);
882
868 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} 883 void ReindexLiterals(const PreParserFormalParameters& paramaters) {}
869 884
870 struct TemplateLiteralState {}; 885 struct TemplateLiteralState {};
871 886
872 TemplateLiteralState OpenTemplateLiteral(int pos) { 887 TemplateLiteralState OpenTemplateLiteral(int pos) {
873 return TemplateLiteralState(); 888 return TemplateLiteralState();
874 } 889 }
875 void AddTemplateSpan(TemplateLiteralState*, bool) {} 890 void AddTemplateSpan(TemplateLiteralState*, bool) {}
876 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} 891 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {}
877 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, 892 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 945
931 inline void MaterializeUnspreadArgumentsLiterals(int count); 946 inline void MaterializeUnspreadArgumentsLiterals(int count);
932 947
933 inline PreParserExpression SpreadCall(PreParserExpression function, 948 inline PreParserExpression SpreadCall(PreParserExpression function,
934 PreParserExpressionList args, int pos); 949 PreParserExpressionList args, int pos);
935 950
936 inline PreParserExpression SpreadCallNew(PreParserExpression function, 951 inline PreParserExpression SpreadCallNew(PreParserExpression function,
937 PreParserExpressionList args, 952 PreParserExpressionList args,
938 int pos); 953 int pos);
939 954
955 inline PreParserExpression ExpressionListToExpression(
956 PreParserExpressionList args) {
957 return PreParserExpression::Default();
958 }
959
940 inline void RewriteDestructuringAssignments() {} 960 inline void RewriteDestructuringAssignments() {}
941 961
942 inline PreParserExpression RewriteExponentiation(PreParserExpression left, 962 inline PreParserExpression RewriteExponentiation(PreParserExpression left,
943 PreParserExpression right, 963 PreParserExpression right,
944 int pos) { 964 int pos) {
945 return left; 965 return left;
946 } 966 }
947 inline PreParserExpression RewriteAssignExponentiation( 967 inline PreParserExpression RewriteAssignExponentiation(
948 PreParserExpression left, PreParserExpression right, int pos) { 968 PreParserExpression left, PreParserExpression right, int pos) {
949 return left; 969 return left;
950 } 970 }
951 971
952 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {} 972 inline void QueueDestructuringAssignmentForRewriting(PreParserExpression) {}
953 inline void QueueNonPatternForRewriting(PreParserExpression) {} 973 inline void QueueNonPatternForRewriting(PreParserExpression) {}
954 974
955 void SetFunctionNameFromPropertyName(PreParserExpression, 975 void SetFunctionNameFromPropertyName(PreParserExpression,
956 PreParserIdentifier) {} 976 PreParserIdentifier) {}
957 void SetFunctionNameFromIdentifierRef(PreParserExpression, 977 void SetFunctionNameFromIdentifierRef(PreParserExpression,
958 PreParserExpression) {} 978 PreParserExpression) {}
959 979
960 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier, 980 inline void RewriteNonPattern(Type::ExpressionClassifier* classifier,
961 bool* ok); 981 bool* ok);
962 982
983 inline PreParserExpression RewriteAwaitExpression(PreParserExpression value,
984 int pos);
985
963 V8_INLINE Zone* zone() const; 986 V8_INLINE Zone* zone() const;
964 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const; 987 V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const;
965 988
966 inline PreParserExpression RewriteYieldStar( 989 inline PreParserExpression RewriteYieldStar(
967 PreParserExpression generator, PreParserExpression expr, int pos); 990 PreParserExpression generator, PreParserExpression expr, int pos);
968 inline PreParserExpression RewriteInstanceof(PreParserExpression lhs, 991 inline PreParserExpression RewriteInstanceof(PreParserExpression lhs,
969 PreParserExpression rhs, 992 PreParserExpression rhs,
970 int pos); 993 int pos);
971 994
972 private: 995 private:
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 void ParseStatementList(int end_token, bool* ok, 1094 void ParseStatementList(int end_token, bool* ok,
1072 Scanner::BookmarkScope* bookmark = nullptr); 1095 Scanner::BookmarkScope* bookmark = nullptr);
1073 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, 1096 Statement ParseStatement(AllowLabelledFunctionStatement allow_function,
1074 bool* ok); 1097 bool* ok);
1075 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, 1098 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function,
1076 bool* ok); 1099 bool* ok);
1077 Statement ParseScopedStatement(bool legacy, bool* ok); 1100 Statement ParseScopedStatement(bool legacy, bool* ok);
1078 Statement ParseHoistableDeclaration(bool* ok); 1101 Statement ParseHoistableDeclaration(bool* ok);
1079 Statement ParseHoistableDeclaration(int pos, bool is_generator, bool* ok); 1102 Statement ParseHoistableDeclaration(int pos, bool is_generator, bool* ok);
1080 Statement ParseFunctionDeclaration(bool* ok); 1103 Statement ParseFunctionDeclaration(bool* ok);
1104 Statement ParseAsyncFunctionDeclaration(bool* ok);
1105 Expression ParseAsyncFunctionExpression(bool* ok);
1081 Statement ParseClassDeclaration(bool* ok); 1106 Statement ParseClassDeclaration(bool* ok);
1082 Statement ParseBlock(bool* ok); 1107 Statement ParseBlock(bool* ok);
1083 Statement ParseVariableStatement(VariableDeclarationContext var_context, 1108 Statement ParseVariableStatement(VariableDeclarationContext var_context,
1084 bool* ok); 1109 bool* ok);
1085 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, 1110 Statement ParseVariableDeclarations(VariableDeclarationContext var_context,
1086 int* num_decl, bool* is_lexical, 1111 int* num_decl, bool* is_lexical,
1087 bool* is_binding_pattern, 1112 bool* is_binding_pattern,
1088 Scanner::Location* first_initializer_loc, 1113 Scanner::Location* first_initializer_loc,
1089 Scanner::Location* bindings_loc, 1114 Scanner::Location* bindings_loc,
1090 bool* ok); 1115 bool* ok);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 1184
1160 1185
1161 void PreParserTraits::ParseArrowFunctionFormalParameterList( 1186 void PreParserTraits::ParseArrowFunctionFormalParameterList(
1162 PreParserFormalParameters* parameters, 1187 PreParserFormalParameters* parameters,
1163 PreParserExpression params, const Scanner::Location& params_loc, 1188 PreParserExpression params, const Scanner::Location& params_loc,
1164 Scanner::Location* duplicate_loc, bool* ok) { 1189 Scanner::Location* duplicate_loc, bool* ok) {
1165 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter 1190 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter
1166 // lists that are too long. 1191 // lists that are too long.
1167 } 1192 }
1168 1193
1194 PreParserExpression PreParserTraits::ParseAsyncFunctionExpression(bool* ok) {
1195 return pre_parser_->ParseAsyncFunctionExpression(ok);
1196 }
1169 1197
1170 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) { 1198 PreParserExpression PreParserTraits::ParseDoExpression(bool* ok) {
1171 return pre_parser_->ParseDoExpression(ok); 1199 return pre_parser_->ParseDoExpression(ok);
1172 } 1200 }
1173 1201
1174 1202
1175 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, 1203 void PreParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier,
1176 bool* ok) { 1204 bool* ok) {
1177 pre_parser_->ValidateExpression(classifier, ok); 1205 pre_parser_->ValidateExpression(classifier, ok);
1178 } 1206 }
1179 1207
1208 PreParserExpression PreParserTraits::RewriteAwaitExpression(
1209 PreParserExpression value, int pos) {
1210 return value;
1211 }
1180 1212
1181 Zone* PreParserTraits::zone() const { 1213 Zone* PreParserTraits::zone() const {
1182 return pre_parser_->function_state_->scope()->zone(); 1214 return pre_parser_->function_state_->scope()->zone();
1183 } 1215 }
1184 1216
1185 1217
1186 ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const { 1218 ZoneList<PreParserExpression>* PreParserTraits::GetNonPatternList() const {
1187 return pre_parser_->function_state_->non_patterns_to_rewrite(); 1219 return pre_parser_->function_state_->non_patterns_to_rewrite();
1188 } 1220 }
1189 1221
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 const PreParserFormalParameters& parameters, FunctionKind kind, 1256 const PreParserFormalParameters& parameters, FunctionKind kind,
1225 FunctionLiteral::FunctionType function_type, bool* ok) { 1257 FunctionLiteral::FunctionType function_type, bool* ok) {
1226 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, 1258 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters,
1227 kind, function_type, ok); 1259 kind, function_type, ok);
1228 } 1260 }
1229 1261
1230 } // namespace internal 1262 } // namespace internal
1231 } // namespace v8 1263 } // namespace v8
1232 1264
1233 #endif // V8_PARSING_PREPARSER_H 1265 #endif // V8_PARSING_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698