| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 304 } |
| 305 | 305 |
| 306 void RecordTailCallExpressionError(const Scanner::Location& loc, | 306 void RecordTailCallExpressionError(const Scanner::Location& loc, |
| 307 MessageTemplate::Template message, | 307 MessageTemplate::Template message, |
| 308 const char* arg = nullptr) { | 308 const char* arg = nullptr) { |
| 309 if (has_tail_call_expression()) return; | 309 if (has_tail_call_expression()) return; |
| 310 invalid_productions_ |= TailCallExpressionProduction; | 310 invalid_productions_ |= TailCallExpressionProduction; |
| 311 Add(Error(loc, message, kTailCallExpressionProduction, arg)); | 311 Add(Error(loc, message, kTailCallExpressionProduction, arg)); |
| 312 } | 312 } |
| 313 | 313 |
| 314 void ForgiveObjectLiteralError() { | |
| 315 if (!(invalid_productions_ & ObjectLiteralProduction)) return; | |
| 316 Error& e = reported_error(kObjectLiteralProduction); | |
| 317 e.kind = kUnusedError; | |
| 318 invalid_productions_ &= ~ObjectLiteralProduction; | |
| 319 } | |
| 320 | |
| 321 void ForgiveAssignmentPatternError() { | |
| 322 if (!(invalid_productions_ & AssignmentPatternProduction)) return; | |
| 323 Error& e = reported_error(kAssignmentPatternProduction); | |
| 324 e.kind = kUnusedError; | |
| 325 invalid_productions_ &= ~AssignmentPatternProduction; | |
| 326 } | |
| 327 | |
| 328 void Accumulate(ExpressionClassifier* inner, unsigned productions, | 314 void Accumulate(ExpressionClassifier* inner, unsigned productions, |
| 329 bool merge_non_patterns = true) { | 315 bool merge_non_patterns = true) { |
| 330 DCHECK_EQ(inner->reported_errors_, reported_errors_); | 316 DCHECK_EQ(inner->reported_errors_, reported_errors_); |
| 331 DCHECK_EQ(inner->reported_errors_begin_, reported_errors_end_); | 317 DCHECK_EQ(inner->reported_errors_begin_, reported_errors_end_); |
| 332 DCHECK_EQ(inner->reported_errors_end_, reported_errors_->length()); | 318 DCHECK_EQ(inner->reported_errors_end_, reported_errors_->length()); |
| 333 if (merge_non_patterns) MergeNonPatterns(inner); | 319 if (merge_non_patterns) MergeNonPatterns(inner); |
| 334 // Propagate errors from inner, but don't overwrite already recorded | 320 // Propagate errors from inner, but don't overwrite already recorded |
| 335 // errors. | 321 // errors. |
| 336 unsigned non_arrow_inner_invalid_productions = | 322 unsigned non_arrow_inner_invalid_productions = |
| 337 inner->invalid_productions_ & ~ArrowFormalParametersProduction; | 323 inner->invalid_productions_ & ~ArrowFormalParametersProduction; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 DCHECK_LE(non_pattern_begin_, non_patterns_to_rewrite_->length()); | 392 DCHECK_LE(non_pattern_begin_, non_patterns_to_rewrite_->length()); |
| 407 non_patterns_to_rewrite_->Rewind(non_pattern_begin_); | 393 non_patterns_to_rewrite_->Rewind(non_pattern_begin_); |
| 408 } | 394 } |
| 409 | 395 |
| 410 V8_INLINE void MergeNonPatterns(ExpressionClassifier* inner) { | 396 V8_INLINE void MergeNonPatterns(ExpressionClassifier* inner) { |
| 411 DCHECK_LE(non_pattern_begin_, inner->non_pattern_begin_); | 397 DCHECK_LE(non_pattern_begin_, inner->non_pattern_begin_); |
| 412 inner->non_pattern_begin_ = inner->non_patterns_to_rewrite_->length(); | 398 inner->non_pattern_begin_ = inner->non_patterns_to_rewrite_->length(); |
| 413 } | 399 } |
| 414 | 400 |
| 415 private: | 401 private: |
| 416 V8_INLINE Error& reported_error(ErrorKind kind) const { | 402 V8_INLINE const Error& reported_error(ErrorKind kind) const { |
| 417 if (invalid_productions_ & (1 << kind)) { | 403 if (invalid_productions_ & (1 << kind)) { |
| 418 for (int i = reported_errors_begin_; i < reported_errors_end_; i++) { | 404 for (int i = reported_errors_begin_; i < reported_errors_end_; i++) { |
| 419 if (reported_errors_->at(i).kind == kind) | 405 if (reported_errors_->at(i).kind == kind) |
| 420 return reported_errors_->at(i); | 406 return reported_errors_->at(i); |
| 421 } | 407 } |
| 422 UNREACHABLE(); | 408 UNREACHABLE(); |
| 423 } | 409 } |
| 424 // We should only be looking for an error when we know that one has | 410 // We should only be looking for an error when we know that one has |
| 425 // been reported. But we're not... So this is to make sure we have | 411 // been reported. But we're not... So this is to make sure we have |
| 426 // the same behaviour. | 412 // the same behaviour. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 }; | 459 }; |
| 474 | 460 |
| 475 | 461 |
| 476 #undef ERROR_CODES | 462 #undef ERROR_CODES |
| 477 | 463 |
| 478 | 464 |
| 479 } // namespace internal | 465 } // namespace internal |
| 480 } // namespace v8 | 466 } // namespace v8 |
| 481 | 467 |
| 482 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 468 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
| OLD | NEW |