| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 static PreParserExpression Default() { | 130 static PreParserExpression Default() { |
| 131 return PreParserExpression(TypeField::encode(kExpression)); | 131 return PreParserExpression(TypeField::encode(kExpression)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 static PreParserExpression Spread(PreParserExpression expression) { | 134 static PreParserExpression Spread(PreParserExpression expression) { |
| 135 return PreParserExpression(TypeField::encode(kSpreadExpression)); | 135 return PreParserExpression(TypeField::encode(kSpreadExpression)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 static PreParserExpression FromIdentifier(PreParserIdentifier id) { | 138 static PreParserExpression FromIdentifier(PreParserIdentifier id) { |
| 139 return PreParserExpression(TypeField::encode(kIdentifierExpression) | | 139 return PreParserExpression(TypeField::encode(kIdentifierExpression) | |
| 140 IdentifierTypeField::encode(id.type_)); | 140 IdentifierTypeField::encode(id.type_), |
| 141 id.string_); |
| 141 } | 142 } |
| 142 | 143 |
| 143 static PreParserExpression BinaryOperation(PreParserExpression left, | 144 static PreParserExpression BinaryOperation(PreParserExpression left, |
| 144 Token::Value op, | 145 Token::Value op, |
| 145 PreParserExpression right) { | 146 PreParserExpression right) { |
| 146 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); | 147 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); |
| 147 } | 148 } |
| 148 | 149 |
| 149 static PreParserExpression Assignment() { | 150 static PreParserExpression Assignment() { |
| 150 return PreParserExpression(TypeField::encode(kExpression) | | 151 return PreParserExpression(TypeField::encode(kExpression) | |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 kThisExpression, | 337 kThisExpression, |
| 337 kThisPropertyExpression, | 338 kThisPropertyExpression, |
| 338 kPropertyExpression, | 339 kPropertyExpression, |
| 339 kCallExpression, | 340 kCallExpression, |
| 340 kCallEvalExpression, | 341 kCallEvalExpression, |
| 341 kSuperCallReference, | 342 kSuperCallReference, |
| 342 kNoTemplateTagExpression, | 343 kNoTemplateTagExpression, |
| 343 kAssignment | 344 kAssignment |
| 344 }; | 345 }; |
| 345 | 346 |
| 346 explicit PreParserExpression(uint32_t expression_code) | 347 explicit PreParserExpression(uint32_t expression_code, |
| 347 : code_(expression_code) {} | 348 const AstRawString* string = nullptr) |
| 349 : code_(expression_code), string_(string) {} |
| 348 | 350 |
| 349 // The first three bits are for the Type. | 351 // The first three bits are for the Type. |
| 350 typedef BitField<Type, 0, 3> TypeField; | 352 typedef BitField<Type, 0, 3> TypeField; |
| 351 | 353 |
| 352 // The high order bit applies only to nodes which would inherit from the | 354 // The high order bit applies only to nodes which would inherit from the |
| 353 // Expression ASTNode --- This is by necessity, due to the fact that | 355 // Expression ASTNode --- This is by necessity, due to the fact that |
| 354 // Expression nodes may be represented as multiple Types, not exclusively | 356 // Expression nodes may be represented as multiple Types, not exclusively |
| 355 // through kExpression. | 357 // through kExpression. |
| 356 // TODO(caitp, adamk): clean up PreParserExpression bitfields. | 358 // TODO(caitp, adamk): clean up PreParserExpression bitfields. |
| 357 typedef BitField<bool, 31, 1> ParenthesizedField; | 359 typedef BitField<bool, 31, 1> ParenthesizedField; |
| 358 | 360 |
| 359 // The rest of the bits are interpreted depending on the value | 361 // The rest of the bits are interpreted depending on the value |
| 360 // of the Type field, so they can share the storage. | 362 // of the Type field, so they can share the storage. |
| 361 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; | 363 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; |
| 362 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; | 364 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; |
| 363 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField; | 365 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField; |
| 364 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> | 366 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> |
| 365 IdentifierTypeField; | 367 IdentifierTypeField; |
| 366 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; | 368 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; |
| 367 | 369 |
| 368 uint32_t code_; | 370 uint32_t code_; |
| 371 // Non-nullptr if the expression is one identifier. |
| 372 const AstRawString* string_; |
| 373 |
| 374 friend class PreParser; |
| 369 }; | 375 }; |
| 370 | 376 |
| 371 | 377 |
| 372 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 378 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
| 373 // the like. | 379 // the like. |
| 374 template <typename T> | 380 template <typename T> |
| 375 class PreParserList { | 381 class PreParserList { |
| 376 public: | 382 public: |
| 377 // These functions make list->Add(some_expression) work (and do nothing). | 383 // These functions make list->Add(some_expression) work (and do nothing). |
| 378 PreParserList() : length_(0) {} | 384 PreParserList() : length_(0) {} |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 PreParserStatement block, | 921 PreParserStatement block, |
| 916 PreParserExpression return_value, | 922 PreParserExpression return_value, |
| 917 bool* ok) {} | 923 bool* ok) {} |
| 918 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, | 924 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, |
| 919 PreParserExpression expression, | 925 PreParserExpression expression, |
| 920 int pos) { | 926 int pos) { |
| 921 return PreParserExpression::Default(); | 927 return PreParserExpression::Default(); |
| 922 } | 928 } |
| 923 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } | 929 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } |
| 924 | 930 |
| 925 V8_INLINE void DeclareAndInitializeVariables( | 931 void DeclareAndInitializeVariables( |
| 926 PreParserStatement block, | 932 PreParserStatement block, |
| 927 const DeclarationDescriptor* declaration_descriptor, | 933 const DeclarationDescriptor* declaration_descriptor, |
| 928 const DeclarationParsingResult::Declaration* declaration, | 934 const DeclarationParsingResult::Declaration* declaration, |
| 929 ZoneList<const AstRawString*>* names, bool* ok) {} | 935 ZoneList<const AstRawString*>* names, bool* ok); |
| 936 |
| 930 V8_INLINE ZoneList<const AstRawString*>* DeclareLabel( | 937 V8_INLINE ZoneList<const AstRawString*>* DeclareLabel( |
| 931 ZoneList<const AstRawString*>* labels, PreParserExpression expr, | 938 ZoneList<const AstRawString*>* labels, PreParserExpression expr, |
| 932 bool* ok) { | 939 bool* ok) { |
| 933 DCHECK(!expr.AsIdentifier().IsEnum()); | 940 DCHECK(!expr.AsIdentifier().IsEnum()); |
| 934 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait()); | 941 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait()); |
| 935 DCHECK(is_sloppy(language_mode()) || | 942 DCHECK(is_sloppy(language_mode()) || |
| 936 !IsFutureStrictReserved(expr.AsIdentifier())); | 943 !IsFutureStrictReserved(expr.AsIdentifier())); |
| 937 return labels; | 944 return labels; |
| 938 } | 945 } |
| 939 | 946 |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 function_state_->NextMaterializedLiteralIndex(); | 1479 function_state_->NextMaterializedLiteralIndex(); |
| 1473 function_state_->NextMaterializedLiteralIndex(); | 1480 function_state_->NextMaterializedLiteralIndex(); |
| 1474 } | 1481 } |
| 1475 return EmptyExpression(); | 1482 return EmptyExpression(); |
| 1476 } | 1483 } |
| 1477 | 1484 |
| 1478 } // namespace internal | 1485 } // namespace internal |
| 1479 } // namespace v8 | 1486 } // namespace v8 |
| 1480 | 1487 |
| 1481 #endif // V8_PARSING_PREPARSER_H | 1488 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |