| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_EXPRESSION_CLASSIFIER_H | 5 #ifndef V8_PARSING_EXPRESSION_CLASSIFIER_H |
| 6 #define V8_PARSING_EXPRESSION_CLASSIFIER_H | 6 #define V8_PARSING_EXPRESSION_CLASSIFIER_H |
| 7 | 7 |
| 8 #include "src/messages.h" | 8 #include "src/messages.h" |
| 9 #include "src/parsing/scanner.h" | 9 #include "src/parsing/scanner.h" |
| 10 #include "src/parsing/token.h" | 10 #include "src/parsing/token.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 ParseErrorType t = kSyntaxError) | 50 ParseErrorType t = kSyntaxError) |
| 51 : location(loc), message(msg), kind(k), type(t), arg(a) {} | 51 : location(loc), message(msg), kind(k), type(t), arg(a) {} |
| 52 | 52 |
| 53 Scanner::Location location; | 53 Scanner::Location location; |
| 54 MessageTemplate::Template message : 26; | 54 MessageTemplate::Template message : 26; |
| 55 unsigned kind : 4; | 55 unsigned kind : 4; |
| 56 ParseErrorType type : 2; | 56 ParseErrorType type : 2; |
| 57 const char* arg; | 57 const char* arg; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 // clang-format off |
| 60 enum TargetProduction : unsigned { | 61 enum TargetProduction : unsigned { |
| 61 #define DEFINE_PRODUCTION(NAME, CODE) NAME = 1 << CODE, | 62 #define DEFINE_PRODUCTION(NAME, CODE) NAME = 1 << CODE, |
| 62 ERROR_CODES(DEFINE_PRODUCTION) | 63 ERROR_CODES(DEFINE_PRODUCTION) |
| 63 #undef DEFINE_PRODUCTION | 64 #undef DEFINE_PRODUCTION |
| 64 | 65 |
| 65 ExpressionProductions = | 66 #define DEFINE_ALL_PRODUCTIONS(NAME, CODE) NAME | |
| 66 (ExpressionProduction | FormalParameterInitializerProduction | | 67 AllProductions = ERROR_CODES(DEFINE_ALL_PRODUCTIONS) /* | */ 0 |
| 67 TailCallExpressionProduction), | 68 #undef DEFINE_ALL_PRODUCTIONS |
| 68 PatternProductions = (BindingPatternProduction | | |
| 69 AssignmentPatternProduction | LetPatternProduction), | |
| 70 FormalParametersProductions = (DistinctFormalParametersProduction | | |
| 71 StrictModeFormalParametersProduction), | |
| 72 AllProductions = | |
| 73 (ExpressionProductions | PatternProductions | | |
| 74 FormalParametersProductions | ArrowFormalParametersProduction | | |
| 75 ObjectLiteralProduction | AsyncArrowFormalParametersProduction) | |
| 76 }; | 69 }; |
| 70 // clang-format on |
| 77 | 71 |
| 78 enum FunctionProperties : unsigned { | 72 enum FunctionProperties : unsigned { |
| 79 NonSimpleParameter = 1 << 0 | 73 NonSimpleParameter = 1 << 0 |
| 80 }; | 74 }; |
| 81 | 75 |
| 82 explicit ExpressionClassifier(const typename Traits::Type::Base* base, | 76 explicit ExpressionClassifier(const typename Traits::Type::Base* base, |
| 83 DuplicateFinder* duplicate_finder = nullptr) | 77 DuplicateFinder* duplicate_finder = nullptr) |
| 84 : zone_(base->impl()->zone()), | 78 : zone_(base->impl()->zone()), |
| 85 non_patterns_to_rewrite_(base->impl()->GetNonPatternList()), | 79 non_patterns_to_rewrite_(base->impl()->GetNonPatternList()), |
| 86 reported_errors_(base->impl()->GetReportedErrorList()), | 80 reported_errors_(base->impl()->GetReportedErrorList()), |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 reported_errors_->at(reported_errors_end_-1).kind = | 360 reported_errors_->at(reported_errors_end_-1).kind = |
| 367 kArrowFormalParametersProduction; | 361 kArrowFormalParametersProduction; |
| 368 } | 362 } |
| 369 } | 363 } |
| 370 } | 364 } |
| 371 reported_errors_->Rewind(reported_errors_end_); | 365 reported_errors_->Rewind(reported_errors_end_); |
| 372 inner->reported_errors_begin_ = inner->reported_errors_end_ = | 366 inner->reported_errors_begin_ = inner->reported_errors_end_ = |
| 373 reported_errors_end_; | 367 reported_errors_end_; |
| 374 } | 368 } |
| 375 | 369 |
| 370 // Accumulate errors that can be arbitrarily deep in an expression. |
| 371 // These correspond to the ECMAScript spec's 'Contains' operation |
| 372 // on productions. This includes: |
| 373 // |
| 374 // - YieldExpression is disallowed in arrow parameters in a generator. |
| 375 // - AwaitExpression is disallowed in arrow parameters in an async function. |
| 376 // - AwaitExpression is disallowed in async arrow parameters. |
| 377 // |
| 378 V8_INLINE void AccumulateFormalParameterContainmentErrors( |
| 379 ExpressionClassifier* inner) { |
| 380 Accumulate(inner, FormalParameterInitializerProduction | |
| 381 AsyncArrowFormalParametersProduction); |
| 382 } |
| 383 |
| 376 V8_INLINE int GetNonPatternBegin() const { return non_pattern_begin_; } | 384 V8_INLINE int GetNonPatternBegin() const { return non_pattern_begin_; } |
| 377 | 385 |
| 378 V8_INLINE void Discard() { | 386 V8_INLINE void Discard() { |
| 379 if (reported_errors_end_ == reported_errors_->length()) { | 387 if (reported_errors_end_ == reported_errors_->length()) { |
| 380 reported_errors_->Rewind(reported_errors_begin_); | 388 reported_errors_->Rewind(reported_errors_begin_); |
| 381 reported_errors_end_ = reported_errors_begin_; | 389 reported_errors_end_ = reported_errors_begin_; |
| 382 } | 390 } |
| 383 DCHECK_EQ(reported_errors_begin_, reported_errors_end_); | 391 DCHECK_EQ(reported_errors_begin_, reported_errors_end_); |
| 384 DCHECK_LE(non_pattern_begin_, non_patterns_to_rewrite_->length()); | 392 DCHECK_LE(non_pattern_begin_, non_patterns_to_rewrite_->length()); |
| 385 non_patterns_to_rewrite_->Rewind(non_pattern_begin_); | 393 non_patterns_to_rewrite_->Rewind(non_pattern_begin_); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 }; | 459 }; |
| 452 | 460 |
| 453 | 461 |
| 454 #undef ERROR_CODES | 462 #undef ERROR_CODES |
| 455 | 463 |
| 456 | 464 |
| 457 } // namespace internal | 465 } // namespace internal |
| 458 } // namespace v8 | 466 } // namespace v8 |
| 459 | 467 |
| 460 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 468 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
| OLD | NEW |