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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 ParseErrorType t = kSyntaxError) | 48 ParseErrorType t = kSyntaxError) |
49 : location(loc), message(msg), kind(k), type(t), arg(a) {} | 49 : location(loc), message(msg), kind(k), type(t), arg(a) {} |
50 | 50 |
51 Scanner::Location location; | 51 Scanner::Location location; |
52 MessageTemplate::Template message : 26; | 52 MessageTemplate::Template message : 26; |
53 unsigned kind : 4; | 53 unsigned kind : 4; |
54 ParseErrorType type : 2; | 54 ParseErrorType type : 2; |
55 const char* arg; | 55 const char* arg; |
56 }; | 56 }; |
57 | 57 |
58 // clang-format off | |
58 enum TargetProduction : unsigned { | 59 enum TargetProduction : unsigned { |
59 #define DEFINE_PRODUCTION(NAME, CODE) NAME = 1 << CODE, | 60 #define DEFINE_PRODUCTION(NAME, CODE) NAME = 1 << CODE, |
60 ERROR_CODES(DEFINE_PRODUCTION) | 61 ERROR_CODES(DEFINE_PRODUCTION) |
61 #undef DEFINE_PRODUCTION | 62 #undef DEFINE_PRODUCTION |
62 | 63 |
63 ExpressionProductions = | 64 #define DEFINE_ALL_PRODUCTIONS(NAME, CODE) NAME | |
64 (ExpressionProduction | FormalParameterInitializerProduction | | 65 AllProductions = ERROR_CODES(DEFINE_ALL_PRODUCTIONS) /* | */ 0 |
65 TailCallExpressionProduction), | 66 #undef DEFINE_ALL_PRODUCTIONS |
66 PatternProductions = (BindingPatternProduction | | |
67 AssignmentPatternProduction | LetPatternProduction), | |
68 FormalParametersProductions = (DistinctFormalParametersProduction | | |
69 StrictModeFormalParametersProduction), | |
70 AllProductions = | |
71 (ExpressionProductions | PatternProductions | | |
72 FormalParametersProductions | ArrowFormalParametersProduction | | |
73 ObjectLiteralProduction | AsyncArrowFormalParametersProduction) | |
74 }; | 67 }; |
68 // clang-format on | |
75 | 69 |
76 enum FunctionProperties : unsigned { | 70 enum FunctionProperties : unsigned { |
77 NonSimpleParameter = 1 << 0 | 71 NonSimpleParameter = 1 << 0 |
78 }; | 72 }; |
79 | 73 |
80 explicit ExpressionClassifier(const Traits* t) | 74 explicit ExpressionClassifier(const Traits* t) |
81 : zone_(t->zone()), | 75 : zone_(t->zone()), |
82 non_patterns_to_rewrite_(t->GetNonPatternList()), | 76 non_patterns_to_rewrite_(t->GetNonPatternList()), |
83 reported_errors_(t->GetReportedErrorList()), | 77 reported_errors_(t->GetReportedErrorList()), |
84 duplicate_finder_(nullptr), | 78 duplicate_finder_(nullptr), |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 reported_errors_->at(reported_errors_end_-1).kind = | 368 reported_errors_->at(reported_errors_end_-1).kind = |
375 kArrowFormalParametersProduction; | 369 kArrowFormalParametersProduction; |
376 } | 370 } |
377 } | 371 } |
378 } | 372 } |
379 reported_errors_->Rewind(reported_errors_end_); | 373 reported_errors_->Rewind(reported_errors_end_); |
380 inner->reported_errors_begin_ = inner->reported_errors_end_ = | 374 inner->reported_errors_begin_ = inner->reported_errors_end_ = |
381 reported_errors_end_; | 375 reported_errors_end_; |
382 } | 376 } |
383 | 377 |
378 // Accumulate errors that can be arbitrarily deep in an expression. | |
379 // These correspond to the ECMAScript spec's 'Contains' operation | |
380 // on productions. This includes: | |
381 // | |
382 // - YieldExpression is disallowed in arrow parameters in a generator. | |
383 // - AwaitExpression is disallowed in arrow parameters in an async function. | |
384 // - AwaitExpression is disallowed in async arrow parameters. | |
385 // | |
386 void AccumulateFormalParameterContainmentErrors(ExpressionClassifier* inner) { | |
nickie
2016/08/25 10:48:00
I'm not sure I understand entirely the logic of V8
adamk
2016/08/25 15:46:27
Agreed that I don't know of good guidelines for wh
| |
387 Accumulate(inner, FormalParameterInitializerProduction | | |
388 AsyncArrowFormalParametersProduction); | |
389 } | |
390 | |
384 V8_INLINE int GetNonPatternBegin() const { return non_pattern_begin_; } | 391 V8_INLINE int GetNonPatternBegin() const { return non_pattern_begin_; } |
385 | 392 |
386 V8_INLINE void Discard() { | 393 V8_INLINE void Discard() { |
387 if (reported_errors_end_ == reported_errors_->length()) { | 394 if (reported_errors_end_ == reported_errors_->length()) { |
388 reported_errors_->Rewind(reported_errors_begin_); | 395 reported_errors_->Rewind(reported_errors_begin_); |
389 reported_errors_end_ = reported_errors_begin_; | 396 reported_errors_end_ = reported_errors_begin_; |
390 } | 397 } |
391 DCHECK_EQ(reported_errors_begin_, reported_errors_end_); | 398 DCHECK_EQ(reported_errors_begin_, reported_errors_end_); |
392 DCHECK_LE(non_pattern_begin_, non_patterns_to_rewrite_->length()); | 399 DCHECK_LE(non_pattern_begin_, non_patterns_to_rewrite_->length()); |
393 non_patterns_to_rewrite_->Rewind(non_pattern_begin_); | 400 non_patterns_to_rewrite_->Rewind(non_pattern_begin_); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 }; | 466 }; |
460 | 467 |
461 | 468 |
462 #undef ERROR_CODES | 469 #undef ERROR_CODES |
463 | 470 |
464 | 471 |
465 } // namespace internal | 472 } // namespace internal |
466 } // namespace v8 | 473 } // namespace v8 |
467 | 474 |
468 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 475 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
OLD | NEW |