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

Side by Side Diff: src/parsing/expression-classifier.h

Issue 1994643002: Simpler implementation of expression classifiers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@nickie-1708193003-class-rev
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 e.kind = kUnusedError; 365 e.kind = kUnusedError;
366 } 366 }
367 367
368 void Accumulate(ExpressionClassifier* inner, 368 void Accumulate(ExpressionClassifier* inner,
369 unsigned productions = StandardProductions, 369 unsigned productions = StandardProductions,
370 bool merge_non_patterns = true) { 370 bool merge_non_patterns = true) {
371 DCHECK_EQ(inner->reported_errors_, reported_errors_); 371 DCHECK_EQ(inner->reported_errors_, reported_errors_);
372 DCHECK_EQ(inner->reported_errors_begin_, reported_errors_end_); 372 DCHECK_EQ(inner->reported_errors_begin_, reported_errors_end_);
373 DCHECK_EQ(inner->reported_errors_end_, reported_errors_->length()); 373 DCHECK_EQ(inner->reported_errors_end_, reported_errors_->length());
374 if (merge_non_patterns) MergeNonPatterns(inner); 374 if (merge_non_patterns) MergeNonPatterns(inner);
375 // Propagate errors from inner, but don't overwrite already recorded 375 // Propagate errors from inner, excluding arrow formal parameters.
376 // errors. 376 unsigned errors = inner->invalid_productions_ & productions &
377 unsigned non_arrow_inner_invalid_productions = 377 ~ArrowFormalParametersProduction;
378 inner->invalid_productions_ & ~ArrowFormalParametersProduction;
379 int next = inner->reported_errors_begin_;
380 if (non_arrow_inner_invalid_productions) {
381 unsigned non_arrow_productions =
382 productions & ~ArrowFormalParametersProduction;
383 unsigned errors =
384 non_arrow_productions & non_arrow_inner_invalid_productions;
385 errors &= ~invalid_productions_;
386 378
387 // As an exception to the above, the result continues to be a valid arrow 379 // If there's nothing to add, the inner classifier's array can be dropped.
388 // formal parameters if the inner expression is a valid binding pattern. 380 if (errors & ~invalid_productions_) {
nickie 2016/05/18 17:32:41 In this if-then-else, the condition is reversed.
389 if (productions & ArrowFormalParametersProduction && 381 reported_errors_->Rewind(reported_errors_end_);
caitp (gmail) 2016/05/18 15:23:21 All this does is set the ring buffer's length_ to
390 is_valid_arrow_formal_parameters()) { 382 } else {
391 // Also copy function properties if expecting an arrow function 383 invalid_productions_ |= errors;
392 // parameter. 384 reported_errors_end_ = inner->reported_errors_end_;
393 function_properties_ |= inner->function_properties_; 385 }
394 386
395 if (!inner->is_valid_binding_pattern()) 387 // As an exception to error propagation, the result continues to be valid
396 errors |= ArrowFormalParametersProduction; 388 // as arrow formal parameters if the inner expression is a valid binding
397 } 389 // pattern.
398 390 if (productions & ArrowFormalParametersProduction &&
399 if (errors != 0) { 391 is_valid_arrow_formal_parameters()) {
400 invalid_productions_ |= errors; 392 // Also copy function properties if expecting an arrow function
401 int arrow_index = inner->reported_errors_end_; 393 // parameter.
402 for (int i = inner->reported_errors_begin_; 394 function_properties_ |= inner->function_properties_;
403 i < inner->reported_errors_end_; i++) { 395 if (!inner->is_valid_binding_pattern()) {
404 if (reported_errors_->at(i).kind == kUnusedError || 396 invalid_productions_ |= ArrowFormalParametersProduction;
405 reported_errors_->at(i).kind == kArrowFormalParametersProduction) 397 Add(inner->reported_error(kBindingPatternProduction));
406 continue;
407 if (errors & (1 << reported_errors_->at(i).kind))
408 Move(next++, i);
409 if (reported_errors_->at(i).kind == kBindingPatternProduction &&
410 errors & ArrowFormalParametersProduction) {
411 if (next <= i) {
412 Move(next, i);
413 reported_errors_->at(next++).kind =
414 kArrowFormalParametersProduction;
415 } else {
416 DCHECK_EQ(next, i+1);
417 arrow_index = i;
418 }
419 }
420 }
421 if (arrow_index < inner->reported_errors_end_) {
422 Add(reported_errors_->at(arrow_index));
423 reported_errors_->at(next++).kind = kArrowFormalParametersProduction;
424 }
425 } 398 }
426 } 399 }
427 DCHECK_EQ(reported_errors_end_, next); 400 inner->reported_errors_begin_ = inner->reported_errors_end_ =
428 reported_errors_->Rewind(next); 401 reported_errors_end_;
429 inner->reported_errors_begin_ = inner->reported_errors_end_ = next;
430 } 402 }
431 403
432 V8_INLINE int GetNonPatternBegin() const { return non_pattern_begin_; } 404 V8_INLINE int GetNonPatternBegin() const { return non_pattern_begin_; }
433 405
434 V8_INLINE void Discard() { 406 V8_INLINE void Discard() {
435 if (reported_errors_end_ == reported_errors_->length()) { 407 if (reported_errors_end_ == reported_errors_->length()) {
436 reported_errors_->Rewind(reported_errors_begin_); 408 reported_errors_->Rewind(reported_errors_begin_);
437 reported_errors_end_ = reported_errors_begin_; 409 reported_errors_end_ = reported_errors_begin_;
438 } 410 }
439 DCHECK_EQ(reported_errors_begin_, reported_errors_end_); 411 DCHECK_EQ(reported_errors_begin_, reported_errors_end_);
(...skipping 20 matching lines...) Expand all
460 static Error none; 432 static Error none;
461 return none; 433 return none;
462 } 434 }
463 435
464 V8_INLINE void Add(const Error& e) { 436 V8_INLINE void Add(const Error& e) {
465 DCHECK_EQ(reported_errors_end_, reported_errors_->length()); 437 DCHECK_EQ(reported_errors_end_, reported_errors_->length());
466 reported_errors_->Add(e, zone_); 438 reported_errors_->Add(e, zone_);
467 reported_errors_end_++; 439 reported_errors_end_++;
468 } 440 }
469 441
470 V8_INLINE void Move(int next, int i) {
471 DCHECK_EQ(reported_errors_end_, next);
472 DCHECK_LE(next, i);
473 DCHECK_LT(i, reported_errors_->length());
474 if (next < i) reported_errors_->at(next++) = reported_errors_->at(i);
475 reported_errors_end_++;
476 }
477
478 Zone* zone_; 442 Zone* zone_;
479 ZoneList<typename Traits::Type::Expression>* non_patterns_to_rewrite_; 443 ZoneList<typename Traits::Type::Expression>* non_patterns_to_rewrite_;
480 int non_pattern_begin_; 444 int non_pattern_begin_;
481 unsigned invalid_productions_ : 14; 445 unsigned invalid_productions_ : 14;
482 unsigned function_properties_ : 2; 446 unsigned function_properties_ : 2;
483 ZoneList<Error>* reported_errors_; 447 ZoneList<Error>* reported_errors_;
484 int reported_errors_begin_; 448 int reported_errors_begin_;
485 int reported_errors_end_; 449 int reported_errors_end_;
486 DuplicateFinder* duplicate_finder_; 450 DuplicateFinder* duplicate_finder_;
487 }; 451 };
488 452
489 453
490 #undef ERROR_CODES 454 #undef ERROR_CODES
491 455
492 456
493 } // namespace internal 457 } // namespace internal
494 } // namespace v8 458 } // namespace v8
495 459
496 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H 460 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698