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

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

Issue 2279363002: Remove duplicated code from comma-separated Expression parsing (Closed)
Patch Set: Remove unused message Created 4 years, 3 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/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 explicit PreParserIdentifier(Type type) : type_(type) {} 117 explicit PreParserIdentifier(Type type) : type_(type) {}
118 Type type_; 118 Type type_;
119 119
120 friend class PreParserExpression; 120 friend class PreParserExpression;
121 }; 121 };
122 122
123 123
124 class PreParserExpression { 124 class PreParserExpression {
125 public: 125 public:
126 PreParserExpression() : code_(TypeField::encode(kExpression)) {} 126 PreParserExpression() : code_(TypeField::encode(kEmpty)) {}
127
128 static PreParserExpression Empty() { return PreParserExpression(); }
127 129
128 static PreParserExpression Default() { 130 static PreParserExpression Default() {
129 return PreParserExpression(); 131 return PreParserExpression(TypeField::encode(kExpression));
130 } 132 }
131 133
132 static PreParserExpression Spread(PreParserExpression expression) { 134 static PreParserExpression Spread(PreParserExpression expression) {
133 return PreParserExpression(TypeField::encode(kSpreadExpression)); 135 return PreParserExpression(TypeField::encode(kSpreadExpression));
134 } 136 }
135 137
136 static PreParserExpression FromIdentifier(PreParserIdentifier id) { 138 static PreParserExpression FromIdentifier(PreParserIdentifier id) {
137 return PreParserExpression(TypeField::encode(kIdentifierExpression) | 139 return PreParserExpression(TypeField::encode(kIdentifierExpression) |
138 IdentifierTypeField::encode(id.type_)); 140 IdentifierTypeField::encode(id.type_));
139 } 141 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 TypeField::encode(kExpression) | 201 TypeField::encode(kExpression) |
200 ExpressionTypeField::encode(kSuperCallReference)); 202 ExpressionTypeField::encode(kSuperCallReference));
201 } 203 }
202 204
203 static PreParserExpression NoTemplateTag() { 205 static PreParserExpression NoTemplateTag() {
204 return PreParserExpression( 206 return PreParserExpression(
205 TypeField::encode(kExpression) | 207 TypeField::encode(kExpression) |
206 ExpressionTypeField::encode(kNoTemplateTagExpression)); 208 ExpressionTypeField::encode(kNoTemplateTagExpression));
207 } 209 }
208 210
211 bool IsEmpty() const { return TypeField::decode(code_) == kEmpty; }
212
209 bool IsIdentifier() const { 213 bool IsIdentifier() const {
210 return TypeField::decode(code_) == kIdentifierExpression; 214 return TypeField::decode(code_) == kIdentifierExpression;
211 } 215 }
212 216
213 PreParserIdentifier AsIdentifier() const { 217 PreParserIdentifier AsIdentifier() const {
214 DCHECK(IsIdentifier()); 218 DCHECK(IsIdentifier());
215 return PreParserIdentifier(IdentifierTypeField::decode(code_)); 219 return PreParserIdentifier(IdentifierTypeField::decode(code_));
216 } 220 }
217 221
218 bool IsAssignment() const { 222 bool IsAssignment() const {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 279
276 // At the moment PreParser doesn't track these expression types. 280 // At the moment PreParser doesn't track these expression types.
277 bool IsFunctionLiteral() const { return false; } 281 bool IsFunctionLiteral() const { return false; }
278 bool IsCallNew() const { return false; } 282 bool IsCallNew() const { return false; }
279 283
280 bool IsNoTemplateTag() const { 284 bool IsNoTemplateTag() const {
281 return TypeField::decode(code_) == kExpression && 285 return TypeField::decode(code_) == kExpression &&
282 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression; 286 ExpressionTypeField::decode(code_) == kNoTemplateTagExpression;
283 } 287 }
284 288
285 bool IsSpreadExpression() const { 289 bool IsSpread() const {
286 return TypeField::decode(code_) == kSpreadExpression; 290 return TypeField::decode(code_) == kSpreadExpression;
287 } 291 }
288 292
289 PreParserExpression AsFunctionLiteral() { return *this; } 293 PreParserExpression AsFunctionLiteral() { return *this; }
290 294
291 bool IsBinaryOperation() const { 295 bool IsBinaryOperation() const {
292 return TypeField::decode(code_) == kBinaryOperationExpression; 296 return TypeField::decode(code_) == kBinaryOperationExpression;
293 } 297 }
294 298
295 // Dummy implementation for making expression->somefunc() work in both Parser 299 // Dummy implementation for making expression->somefunc() work in both Parser
296 // and PreParser. 300 // and PreParser.
297 PreParserExpression* operator->() { return this; } 301 PreParserExpression* operator->() { return this; }
298 302
299 // More dummy implementations of things PreParser doesn't need to track: 303 // More dummy implementations of things PreParser doesn't need to track:
300 void set_index(int index) {} // For YieldExpressions 304 void set_index(int index) {} // For YieldExpressions
301 void set_should_eager_compile() {} 305 void set_should_eager_compile() {}
302 306
303 int position() const { return kNoSourcePosition; } 307 int position() const { return kNoSourcePosition; }
304 void set_function_token_position(int position) {} 308 void set_function_token_position(int position) {}
305 309
306 private: 310 private:
307 enum Type { 311 enum Type {
312 kEmpty,
308 kExpression, 313 kExpression,
309 kIdentifierExpression, 314 kIdentifierExpression,
310 kStringLiteralExpression, 315 kStringLiteralExpression,
311 kBinaryOperationExpression, 316 kBinaryOperationExpression,
312 kSpreadExpression, 317 kSpreadExpression,
313 kObjectLiteralExpression, 318 kObjectLiteralExpression,
314 kArrayLiteralExpression 319 kArrayLiteralExpression
315 }; 320 };
316 321
317 enum ExpressionType { 322 enum ExpressionType {
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 const AstRawString* arg, 997 const AstRawString* arg,
993 ParseErrorType error_type = kSyntaxError) { 998 ParseErrorType error_type = kSyntaxError) {
994 UNREACHABLE(); 999 UNREACHABLE();
995 } 1000 }
996 1001
997 // "null" return type creators. 1002 // "null" return type creators.
998 V8_INLINE static PreParserIdentifier EmptyIdentifier() { 1003 V8_INLINE static PreParserIdentifier EmptyIdentifier() {
999 return PreParserIdentifier::Default(); 1004 return PreParserIdentifier::Default();
1000 } 1005 }
1001 V8_INLINE static PreParserExpression EmptyExpression() { 1006 V8_INLINE static PreParserExpression EmptyExpression() {
1002 return PreParserExpression::Default(); 1007 return PreParserExpression::Empty();
1003 } 1008 }
1004 V8_INLINE static PreParserExpression EmptyLiteral() { 1009 V8_INLINE static PreParserExpression EmptyLiteral() {
1005 return PreParserExpression::Default(); 1010 return PreParserExpression::Default();
1006 } 1011 }
1007 V8_INLINE static PreParserExpression EmptyObjectLiteralProperty() { 1012 V8_INLINE static PreParserExpression EmptyObjectLiteralProperty() {
1008 return PreParserExpression::Default(); 1013 return PreParserExpression::Default();
1009 } 1014 }
1010 V8_INLINE static PreParserExpression EmptyFunctionLiteral() { 1015 V8_INLINE static PreParserExpression EmptyFunctionLiteral() {
1011 return PreParserExpression::Default(); 1016 return PreParserExpression::Default();
1012 } 1017 }
1013 1018
1019 V8_INLINE static bool IsEmptyExpression(PreParserExpression expr) {
1020 return expr.IsEmpty();
1021 }
1022
1014 V8_INLINE static PreParserExpressionList NullExpressionList() { 1023 V8_INLINE static PreParserExpressionList NullExpressionList() {
1015 return PreParserExpressionList(); 1024 return PreParserExpressionList();
1016 } 1025 }
1017 V8_INLINE PreParserIdentifier EmptyIdentifierString() const { 1026 V8_INLINE PreParserIdentifier EmptyIdentifierString() const {
1018 return PreParserIdentifier::Default(); 1027 return PreParserIdentifier::Default();
1019 } 1028 }
1020 1029
1021 // Odd-ball literal creators. 1030 // Odd-ball literal creators.
1022 V8_INLINE PreParserExpression GetLiteralTheHole(int position) { 1031 V8_INLINE PreParserExpression GetLiteralTheHole(int position) {
1023 return PreParserExpression::Default(); 1032 return PreParserExpression::Default();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 function_state_->NextMaterializedLiteralIndex(); 1202 function_state_->NextMaterializedLiteralIndex();
1194 function_state_->NextMaterializedLiteralIndex(); 1203 function_state_->NextMaterializedLiteralIndex();
1195 } 1204 }
1196 return EmptyExpression(); 1205 return EmptyExpression();
1197 } 1206 }
1198 1207
1199 } // namespace internal 1208 } // namespace internal
1200 } // namespace v8 1209 } // namespace v8
1201 1210
1202 #endif // V8_PARSING_PREPARSER_H 1211 #endif // V8_PARSING_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698