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

Side by Side Diff: src/preparser.h

Issue 1146683002: [destructuring] Implement initializers in patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
OLDNEW
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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 675 }
676 676
677 enum TargetProduction { 677 enum TargetProduction {
678 ExpressionProduction = 1 << 0, 678 ExpressionProduction = 1 << 0,
679 BindingPatternProduction = 1 << 1, 679 BindingPatternProduction = 1 << 1,
680 AssignmentPatternProduction = 1 << 2, 680 AssignmentPatternProduction = 1 << 2,
681 FormalParametersProduction = 1 << 3, 681 FormalParametersProduction = 1 << 3,
682 ArrowFormalParametersProduction = 1 << 4, 682 ArrowFormalParametersProduction = 1 << 4,
683 StandardProductions = (ExpressionProduction | BindingPatternProduction | 683 StandardProductions = (ExpressionProduction | BindingPatternProduction |
684 AssignmentPatternProduction), 684 AssignmentPatternProduction),
685 PatternProductions =
686 BindingPatternProduction | AssignmentPatternProduction,
685 AllProductions = (StandardProductions | FormalParametersProduction | 687 AllProductions = (StandardProductions | FormalParametersProduction |
686 ArrowFormalParametersProduction) 688 ArrowFormalParametersProduction),
687 }; 689 };
688 690
689 void Accumulate(const ExpressionClassifier& inner, 691 void Accumulate(const ExpressionClassifier& inner,
690 unsigned productions = StandardProductions) { 692 unsigned productions = StandardProductions) {
691 if (productions & ExpressionProduction && is_valid_expression()) { 693 if (productions & ExpressionProduction && is_valid_expression()) {
692 expression_error_ = inner.expression_error_; 694 expression_error_ = inner.expression_error_;
693 } 695 }
694 if (productions & BindingPatternProduction && 696 if (productions & BindingPatternProduction &&
695 is_valid_binding_pattern()) { 697 is_valid_binding_pattern()) {
696 binding_pattern_error_ = inner.binding_pattern_error_; 698 binding_pattern_error_ = inner.binding_pattern_error_;
(...skipping 17 matching lines...) Expand all
714 } 716 }
715 } 717 }
716 if (productions & ArrowFormalParametersProduction && 718 if (productions & ArrowFormalParametersProduction &&
717 is_valid_arrow_formal_parameters()) { 719 is_valid_arrow_formal_parameters()) {
718 // The result continues to be a valid arrow formal parameters if the 720 // The result continues to be a valid arrow formal parameters if the
719 // inner expression is a valid binding pattern. 721 // inner expression is a valid binding pattern.
720 arrow_formal_parameters_error_ = inner.binding_pattern_error_; 722 arrow_formal_parameters_error_ = inner.binding_pattern_error_;
721 } 723 }
722 } 724 }
723 725
726 void AccumulateReclassifyingAsPattern(const ExpressionClassifier& inner) {
727 Accumulate(inner, AllProductions & ~PatternProductions);
728 if (!inner.is_valid_expression()) {
729 if (is_valid_binding_pattern()) {
730 binding_pattern_error_ = inner.expression_error();
731 }
732 if (is_valid_assignment_pattern()) {
733 assignment_pattern_error_ = inner.expression_error();
734 }
735 }
736 }
737
724 private: 738 private:
725 Error expression_error_; 739 Error expression_error_;
726 Error binding_pattern_error_; 740 Error binding_pattern_error_;
727 Error assignment_pattern_error_; 741 Error assignment_pattern_error_;
728 Error arrow_formal_parameters_error_; 742 Error arrow_formal_parameters_error_;
729 Error duplicate_formal_parameter_error_; 743 Error duplicate_formal_parameter_error_;
730 Error strict_mode_formal_parameter_error_; 744 Error strict_mode_formal_parameter_error_;
731 Error strong_mode_formal_parameter_error_; 745 Error strong_mode_formal_parameter_error_;
732 }; 746 };
733 747
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 Traits::ReportMessageAt(scanner()->location(), "unexpected_token", 800 Traits::ReportMessageAt(scanner()->location(), "unexpected_token",
787 Token::String(scanner()->current_token())); 801 Token::String(scanner()->current_token()));
788 *ok = false; 802 *ok = false;
789 } 803 }
790 } else if (!classifier->is_valid_arrow_formal_parameters()) { 804 } else if (!classifier->is_valid_arrow_formal_parameters()) {
791 ReportClassifierError(classifier->arrow_formal_parameters_error()); 805 ReportClassifierError(classifier->arrow_formal_parameters_error());
792 *ok = false; 806 *ok = false;
793 } 807 }
794 } 808 }
795 809
810 void ExpressionUnexpectedToken(ExpressionClassifier* classifier) {
811 classifier->RecordExpressionError(
812 scanner()->peek_location(), "unexpected_token", Token::String(peek()));
813 }
814
796 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { 815 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) {
797 classifier->RecordBindingPatternError( 816 classifier->RecordBindingPatternError(
798 scanner()->peek_location(), "unexpected_token", Token::String(peek())); 817 scanner()->peek_location(), "unexpected_token", Token::String(peek()));
799 } 818 }
800 819
801 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) { 820 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) {
802 classifier->RecordArrowFormalParametersError( 821 classifier->RecordArrowFormalParametersError(
803 scanner()->peek_location(), "unexpected_token", Token::String(peek())); 822 scanner()->peek_location(), "unexpected_token", Token::String(peek()));
804 } 823 }
805 824
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 return factory()->NewObjectLiteralProperty( 2664 return factory()->NewObjectLiteralProperty(
2646 name_expression, value, 2665 name_expression, value,
2647 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, 2666 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER,
2648 is_static, *is_computed_name); 2667 is_static, *is_computed_name);
2649 2668
2650 } else if (!in_class && allow_harmony_object_literals_ && 2669 } else if (!in_class && allow_harmony_object_literals_ &&
2651 Token::IsIdentifier(name_token, language_mode(), 2670 Token::IsIdentifier(name_token, language_mode(),
2652 this->is_generator())) { 2671 this->is_generator())) {
2653 DCHECK(!*is_computed_name); 2672 DCHECK(!*is_computed_name);
2654 DCHECK(!is_static); 2673 DCHECK(!is_static);
2655 value = this->ExpressionFromIdentifier(name, next_beg_pos, next_end_pos, 2674
2656 scope_, factory()); 2675 ExpressionT lhs = this->ExpressionFromIdentifier(
2676 name, next_beg_pos, next_end_pos, scope_, factory());
2677 if (peek() == Token::ASSIGN) {
2678 this->ExpressionUnexpectedToken(classifier);
2679 Consume(Token::ASSIGN);
2680 ExpressionClassifier rhs_classifier;
2681 ExpressionT rhs = this->ParseAssignmentExpression(
2682 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2683 classifier->AccumulateReclassifyingAsPattern(rhs_classifier);
2684 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
2685 RelocInfo::kNoPosition);
2686 } else {
2687 value = lhs;
2688 }
2657 return factory()->NewObjectLiteralProperty( 2689 return factory()->NewObjectLiteralProperty(
2658 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false); 2690 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false);
2659 2691
2660 } else { 2692 } else {
2661 Token::Value next = Next(); 2693 Token::Value next = Next();
2662 ReportUnexpectedToken(next); 2694 ReportUnexpectedToken(next);
2663 *ok = false; 2695 *ok = false;
2664 return this->EmptyObjectLiteralProperty(); 2696 return this->EmptyObjectLiteralProperty();
2665 } 2697 }
2666 2698
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2866 2898
2867 if (!allow_harmony_destructuring()) { 2899 if (!allow_harmony_destructuring()) {
2868 BindingPatternUnexpectedToken(classifier); 2900 BindingPatternUnexpectedToken(classifier);
2869 } 2901 }
2870 2902
2871 expression = this->CheckAndRewriteReferenceExpression( 2903 expression = this->CheckAndRewriteReferenceExpression(
2872 expression, lhs_location, "invalid_lhs_in_assignment", CHECK_OK); 2904 expression, lhs_location, "invalid_lhs_in_assignment", CHECK_OK);
2873 expression = this->MarkExpressionAsAssigned(expression); 2905 expression = this->MarkExpressionAsAssigned(expression);
2874 2906
2875 Token::Value op = Next(); // Get assignment operator. 2907 Token::Value op = Next(); // Get assignment operator.
2908 if (op != Token::ASSIGN) {
2909 classifier->RecordBindingPatternError(
arv (Not doing code reviews) 2015/05/18 14:36:20 Just curious... Is the reason why you are not doin
Dmitry Lomov (no reviews) 2015/05/18 17:31:22 Yes.
2910 scanner()->location(), "unexpected_token", Token::String(op));
2911 }
2876 int pos = position(); 2912 int pos = position();
2913
2914 ExpressionClassifier rhs_classifier;
2877 ExpressionT right = 2915 ExpressionT right =
2878 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); 2916 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
2917 classifier->AccumulateReclassifyingAsPattern(rhs_classifier);
2879 2918
2880 // TODO(1231235): We try to estimate the set of properties set by 2919 // TODO(1231235): We try to estimate the set of properties set by
2881 // constructors. We define a new property whenever there is an 2920 // constructors. We define a new property whenever there is an
2882 // assignment to a property of 'this'. We should probably only add 2921 // assignment to a property of 'this'. We should probably only add
2883 // properties if we haven't seen them before. Otherwise we'll 2922 // properties if we haven't seen them before. Otherwise we'll
2884 // probably overestimate the number of properties. 2923 // probably overestimate the number of properties.
2885 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { 2924 if (op == Token::ASSIGN && this->IsThisProperty(expression)) {
2886 function_state_->AddProperty(); 2925 function_state_->AddProperty();
2887 } 2926 }
2888 2927
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
3923 *ok = false; 3962 *ok = false;
3924 return; 3963 return;
3925 } 3964 }
3926 has_seen_constructor_ = true; 3965 has_seen_constructor_ = true;
3927 return; 3966 return;
3928 } 3967 }
3929 } 3968 }
3930 } } // v8::internal 3969 } } // v8::internal
3931 3970
3932 #endif // V8_PREPARSER_H 3971 #endif // V8_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698