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

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: Rebased onto ToT 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
« no previous file with comments | « src/pattern-rewriter.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 684 }
685 685
686 enum TargetProduction { 686 enum TargetProduction {
687 ExpressionProduction = 1 << 0, 687 ExpressionProduction = 1 << 0,
688 BindingPatternProduction = 1 << 1, 688 BindingPatternProduction = 1 << 1,
689 AssignmentPatternProduction = 1 << 2, 689 AssignmentPatternProduction = 1 << 2,
690 FormalParametersProduction = 1 << 3, 690 FormalParametersProduction = 1 << 3,
691 ArrowFormalParametersProduction = 1 << 4, 691 ArrowFormalParametersProduction = 1 << 4,
692 StandardProductions = (ExpressionProduction | BindingPatternProduction | 692 StandardProductions = (ExpressionProduction | BindingPatternProduction |
693 AssignmentPatternProduction), 693 AssignmentPatternProduction),
694 PatternProductions =
695 BindingPatternProduction | AssignmentPatternProduction,
694 AllProductions = (StandardProductions | FormalParametersProduction | 696 AllProductions = (StandardProductions | FormalParametersProduction |
695 ArrowFormalParametersProduction) 697 ArrowFormalParametersProduction),
696 }; 698 };
697 699
698 void Accumulate(const ExpressionClassifier& inner, 700 void Accumulate(const ExpressionClassifier& inner,
699 unsigned productions = StandardProductions) { 701 unsigned productions = StandardProductions) {
700 if (productions & ExpressionProduction && is_valid_expression()) { 702 if (productions & ExpressionProduction && is_valid_expression()) {
701 expression_error_ = inner.expression_error_; 703 expression_error_ = inner.expression_error_;
702 } 704 }
703 if (productions & BindingPatternProduction && 705 if (productions & BindingPatternProduction &&
704 is_valid_binding_pattern()) { 706 is_valid_binding_pattern()) {
705 binding_pattern_error_ = inner.binding_pattern_error_; 707 binding_pattern_error_ = inner.binding_pattern_error_;
(...skipping 17 matching lines...) Expand all
723 } 725 }
724 } 726 }
725 if (productions & ArrowFormalParametersProduction && 727 if (productions & ArrowFormalParametersProduction &&
726 is_valid_arrow_formal_parameters()) { 728 is_valid_arrow_formal_parameters()) {
727 // The result continues to be a valid arrow formal parameters if the 729 // The result continues to be a valid arrow formal parameters if the
728 // inner expression is a valid binding pattern. 730 // inner expression is a valid binding pattern.
729 arrow_formal_parameters_error_ = inner.binding_pattern_error_; 731 arrow_formal_parameters_error_ = inner.binding_pattern_error_;
730 } 732 }
731 } 733 }
732 734
735 void AccumulateReclassifyingAsPattern(const ExpressionClassifier& inner) {
736 Accumulate(inner, AllProductions & ~PatternProductions);
737 if (!inner.is_valid_expression()) {
738 if (is_valid_binding_pattern()) {
739 binding_pattern_error_ = inner.expression_error();
740 }
741 if (is_valid_assignment_pattern()) {
742 assignment_pattern_error_ = inner.expression_error();
743 }
744 }
745 }
746
733 private: 747 private:
734 Error expression_error_; 748 Error expression_error_;
735 Error binding_pattern_error_; 749 Error binding_pattern_error_;
736 Error assignment_pattern_error_; 750 Error assignment_pattern_error_;
737 Error arrow_formal_parameters_error_; 751 Error arrow_formal_parameters_error_;
738 Error duplicate_formal_parameter_error_; 752 Error duplicate_formal_parameter_error_;
739 Error strict_mode_formal_parameter_error_; 753 Error strict_mode_formal_parameter_error_;
740 Error strong_mode_formal_parameter_error_; 754 Error strong_mode_formal_parameter_error_;
741 }; 755 };
742 756
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 MessageTemplate::kUnexpectedToken, 810 MessageTemplate::kUnexpectedToken,
797 Token::String(scanner()->current_token())); 811 Token::String(scanner()->current_token()));
798 *ok = false; 812 *ok = false;
799 } 813 }
800 } else if (!classifier->is_valid_arrow_formal_parameters()) { 814 } else if (!classifier->is_valid_arrow_formal_parameters()) {
801 ReportClassifierError(classifier->arrow_formal_parameters_error()); 815 ReportClassifierError(classifier->arrow_formal_parameters_error());
802 *ok = false; 816 *ok = false;
803 } 817 }
804 } 818 }
805 819
820 void ExpressionUnexpectedToken(ExpressionClassifier* classifier) {
821 classifier->RecordExpressionError(scanner()->peek_location(),
822 MessageTemplate::kUnexpectedToken,
823 Token::String(peek()));
824 }
825
806 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { 826 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) {
807 classifier->RecordBindingPatternError(scanner()->peek_location(), 827 classifier->RecordBindingPatternError(scanner()->peek_location(),
808 MessageTemplate::kUnexpectedToken, 828 MessageTemplate::kUnexpectedToken,
809 Token::String(peek())); 829 Token::String(peek()));
810 } 830 }
811 831
812 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) { 832 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) {
813 classifier->RecordArrowFormalParametersError( 833 classifier->RecordArrowFormalParametersError(
814 scanner()->peek_location(), MessageTemplate::kUnexpectedToken, 834 scanner()->peek_location(), MessageTemplate::kUnexpectedToken,
815 Token::String(peek())); 835 Token::String(peek()));
(...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 return factory()->NewObjectLiteralProperty( 2690 return factory()->NewObjectLiteralProperty(
2671 name_expression, value, 2691 name_expression, value,
2672 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, 2692 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER,
2673 is_static, *is_computed_name); 2693 is_static, *is_computed_name);
2674 2694
2675 } else if (!in_class && allow_harmony_object_literals_ && 2695 } else if (!in_class && allow_harmony_object_literals_ &&
2676 Token::IsIdentifier(name_token, language_mode(), 2696 Token::IsIdentifier(name_token, language_mode(),
2677 this->is_generator())) { 2697 this->is_generator())) {
2678 DCHECK(!*is_computed_name); 2698 DCHECK(!*is_computed_name);
2679 DCHECK(!is_static); 2699 DCHECK(!is_static);
2680 value = this->ExpressionFromIdentifier(name, next_beg_pos, next_end_pos, 2700
2681 scope_, factory()); 2701 ExpressionT lhs = this->ExpressionFromIdentifier(
2702 name, next_beg_pos, next_end_pos, scope_, factory());
2703 if (peek() == Token::ASSIGN) {
2704 this->ExpressionUnexpectedToken(classifier);
2705 Consume(Token::ASSIGN);
2706 ExpressionClassifier rhs_classifier;
2707 ExpressionT rhs = this->ParseAssignmentExpression(
2708 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2709 classifier->AccumulateReclassifyingAsPattern(rhs_classifier);
2710 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
2711 RelocInfo::kNoPosition);
2712 } else {
2713 value = lhs;
2714 }
2682 return factory()->NewObjectLiteralProperty( 2715 return factory()->NewObjectLiteralProperty(
2683 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false); 2716 name_expression, value, ObjectLiteralProperty::COMPUTED, false, false);
2684 2717
2685 } else { 2718 } else {
2686 Token::Value next = Next(); 2719 Token::Value next = Next();
2687 ReportUnexpectedToken(next); 2720 ReportUnexpectedToken(next);
2688 *ok = false; 2721 *ok = false;
2689 return this->EmptyObjectLiteralProperty(); 2722 return this->EmptyObjectLiteralProperty();
2690 } 2723 }
2691 2724
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2893 if (!allow_harmony_destructuring()) { 2926 if (!allow_harmony_destructuring()) {
2894 BindingPatternUnexpectedToken(classifier); 2927 BindingPatternUnexpectedToken(classifier);
2895 } 2928 }
2896 2929
2897 expression = this->CheckAndRewriteReferenceExpression( 2930 expression = this->CheckAndRewriteReferenceExpression(
2898 expression, lhs_location, MessageTemplate::kInvalidLhsInAssignment, 2931 expression, lhs_location, MessageTemplate::kInvalidLhsInAssignment,
2899 CHECK_OK); 2932 CHECK_OK);
2900 expression = this->MarkExpressionAsAssigned(expression); 2933 expression = this->MarkExpressionAsAssigned(expression);
2901 2934
2902 Token::Value op = Next(); // Get assignment operator. 2935 Token::Value op = Next(); // Get assignment operator.
2936 if (op != Token::ASSIGN) {
2937 classifier->RecordBindingPatternError(scanner()->location(),
2938 MessageTemplate::kUnexpectedToken,
2939 Token::String(op));
2940 }
2903 int pos = position(); 2941 int pos = position();
2942
2943 ExpressionClassifier rhs_classifier;
2904 ExpressionT right = 2944 ExpressionT right =
2905 this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); 2945 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
2946 classifier->AccumulateReclassifyingAsPattern(rhs_classifier);
2906 2947
2907 // TODO(1231235): We try to estimate the set of properties set by 2948 // TODO(1231235): We try to estimate the set of properties set by
2908 // constructors. We define a new property whenever there is an 2949 // constructors. We define a new property whenever there is an
2909 // assignment to a property of 'this'. We should probably only add 2950 // assignment to a property of 'this'. We should probably only add
2910 // properties if we haven't seen them before. Otherwise we'll 2951 // properties if we haven't seen them before. Otherwise we'll
2911 // probably overestimate the number of properties. 2952 // probably overestimate the number of properties.
2912 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { 2953 if (op == Token::ASSIGN && this->IsThisProperty(expression)) {
2913 function_state_->AddProperty(); 2954 function_state_->AddProperty();
2914 } 2955 }
2915 2956
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
3964 *ok = false; 4005 *ok = false;
3965 return; 4006 return;
3966 } 4007 }
3967 has_seen_constructor_ = true; 4008 has_seen_constructor_ = true;
3968 return; 4009 return;
3969 } 4010 }
3970 } 4011 }
3971 } } // v8::internal 4012 } } // v8::internal
3972 4013
3973 #endif // V8_PREPARSER_H 4014 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/pattern-rewriter.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698