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

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

Issue 1168643005: [es6] parse destructuring assignment (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase + Bunch of tests + Nits fixed Created 5 years, 6 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 | src/messages.h » ('j') | src/preparser.h » ('J')
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_EXPRESSION_CLASSIFIER_H 5 #ifndef V8_EXPRESSION_CLASSIFIER_H
6 #define V8_EXPRESSION_CLASSIFIER_H 6 #define V8_EXPRESSION_CLASSIFIER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 30 matching lines...) Expand all
41 (BindingPatternProduction | AssignmentPatternProduction), 41 (BindingPatternProduction | AssignmentPatternProduction),
42 FormalParametersProductions = (DistinctFormalParametersProduction | 42 FormalParametersProductions = (DistinctFormalParametersProduction |
43 StrictModeFormalParametersProduction | 43 StrictModeFormalParametersProduction |
44 StrongModeFormalParametersProduction), 44 StrongModeFormalParametersProduction),
45 StandardProductions = ExpressionProduction | PatternProductions, 45 StandardProductions = ExpressionProduction | PatternProductions,
46 AllProductions = (StandardProductions | FormalParametersProductions | 46 AllProductions = (StandardProductions | FormalParametersProductions |
47 ArrowFormalParametersProduction) 47 ArrowFormalParametersProduction)
48 }; 48 };
49 49
50 ExpressionClassifier() 50 ExpressionClassifier()
51 : invalid_productions_(0), duplicate_finder_(nullptr) {} 51 : lhs_type_(TARGET_NONE),
52 assigned_(false),
53 invalid_productions_(0),
54 duplicate_finder_(nullptr) {}
52 55
53 explicit ExpressionClassifier(DuplicateFinder* duplicate_finder) 56 explicit ExpressionClassifier(DuplicateFinder* duplicate_finder)
54 : invalid_productions_(0), duplicate_finder_(duplicate_finder) {} 57 : lhs_type_(TARGET_NONE),
58 assigned_(false),
59 invalid_productions_(0),
60 duplicate_finder_(duplicate_finder) {}
61
62 enum AssignmentTargetType {
63 TARGET_NONE = 0,
64
65 // IdentifierReference
66 TARGET_IDENTIFIER,
67
68 // MemberExpression . <property name>
69 // MemberExpression [<property name>]
70 TARGET_PROPERTY,
71
72 // MemberExpression ( arguments )
73 // new MemberExpression ( arguments )
74 // MemberExpression TemplateLiteral
75 TARGET_CALL,
76
77 // this
78 // Literal
79 // ArrayLiteral
80 // ObjectLiteral
81 // FunctionExpression
82 // ClassExpression
83 // GeneratorExpression
84 // RegularExpressionLiteral
85 // TemplateLiteral
86 // CoverParenthesizedExpressionAndArrowParameterList
87 TARGET_PRIMARY,
88
89 // UnaryExpression
90 // MultiplicativeExpression
91 // AdditiveExpression
92 // ShiftExpression
93 // RelationalExpression
94 // EqualityExpression
95 // BitwiseANDExpression
96 // BitwiseXORExpression
97 // BitwiseORExpression
98 // LogicalANDExpression
99 // LogicalORExpression
100 // ConditionalExpression
101 // AssignmentExpression
102 // ... Pretty much any binary operator
103 UNACCEPTABLE_TARGET,
104
105 // BindingPattern
106 TARGET_PATTERN
107 };
108
109 inline AssignmentTargetType AssignmentTarget() const { return lhs_type_; }
110
111 inline void AppendAssignmentTarget(AssignmentTargetType type) {
112 if (lhs_type_ == UNACCEPTABLE_TARGET) return;
113 lhs_type_ = type;
114 }
115
116 inline void ReportInvalidSimpleAssignmentTarget() {
117 lhs_type_ = UNACCEPTABLE_TARGET;
118 }
119
120 inline bool IsValidSimpleAssignmentTarget() const {
121 // Only identifiers and properties are valid targets.
122 return lhs_type_ == TARGET_IDENTIFIER || lhs_type_ == TARGET_PROPERTY;
123 }
124
125 inline bool IsPatternAssignmentElement() const {
126 // Any AssignmentElement for which IsValidSimpleAssignmentTarget is false.
127 // Used for nested AssignmentPatterns
128 return lhs_type_ == TARGET_PATTERN && is_valid_assignment_pattern();
129 }
130
131 inline bool IsValidPattern() const { return lhs_type_ == TARGET_PATTERN; }
132
133 inline bool IsAssigned() const { return assigned_; }
134
135 void set_assigned() { assigned_ = true; }
136
137 bool is_destructuring_assignment() const {
138 return IsValidPattern() && IsAssigned();
139 }
140
55 141
56 bool is_valid(unsigned productions) const { 142 bool is_valid(unsigned productions) const {
57 return (invalid_productions_ & productions) == 0; 143 return (invalid_productions_ & productions) == 0;
58 } 144 }
59 145
60 DuplicateFinder* duplicate_finder() const { return duplicate_finder_; } 146 DuplicateFinder* duplicate_finder() const { return duplicate_finder_; }
61 147
62 bool is_valid_expression() const { return is_valid(ExpressionProduction); } 148 bool is_valid_expression() const { return is_valid(ExpressionProduction); }
63 149
64 bool is_valid_binding_pattern() const { 150 bool is_valid_binding_pattern() const {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 void RecordStrongModeFormalParameterError(const Scanner::Location& loc, 264 void RecordStrongModeFormalParameterError(const Scanner::Location& loc,
179 MessageTemplate::Template message, 265 MessageTemplate::Template message,
180 const char* arg = nullptr) { 266 const char* arg = nullptr) {
181 if (!is_valid_strong_mode_formal_parameters()) return; 267 if (!is_valid_strong_mode_formal_parameters()) return;
182 invalid_productions_ |= StrongModeFormalParametersProduction; 268 invalid_productions_ |= StrongModeFormalParametersProduction;
183 strong_mode_formal_parameter_error_.location = loc; 269 strong_mode_formal_parameter_error_.location = loc;
184 strong_mode_formal_parameter_error_.message = message; 270 strong_mode_formal_parameter_error_.message = message;
185 strong_mode_formal_parameter_error_.arg = arg; 271 strong_mode_formal_parameter_error_.arg = arg;
186 } 272 }
187 273
274 void AccumulateValidSimpleAssignmentTarget(
275 const ExpressionClassifier& inner) {
276 if (lhs_type_ != UNACCEPTABLE_TARGET) {
277 lhs_type_ = inner.lhs_type_;
278 }
279 }
280
281
188 void Accumulate(const ExpressionClassifier& inner, 282 void Accumulate(const ExpressionClassifier& inner,
189 unsigned productions = StandardProductions) { 283 unsigned productions = StandardProductions) {
190 // Propagate errors from inner, but don't overwrite already recorded 284 // Propagate errors from inner, but don't overwrite already recorded
191 // errors. 285 // errors.
192 unsigned non_arrow_inner_invalid_productions = 286 unsigned non_arrow_inner_invalid_productions =
193 inner.invalid_productions_ & ~ArrowFormalParametersProduction; 287 inner.invalid_productions_ & ~ArrowFormalParametersProduction;
194 if (non_arrow_inner_invalid_productions == 0) return; 288 if (non_arrow_inner_invalid_productions == 0) return;
195 unsigned non_arrow_productions = 289 unsigned non_arrow_productions =
196 productions & ~ArrowFormalParametersProduction; 290 productions & ~ArrowFormalParametersProduction;
197 unsigned errors = 291 unsigned errors =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (is_valid_binding_pattern()) { 326 if (is_valid_binding_pattern()) {
233 binding_pattern_error_ = inner.expression_error(); 327 binding_pattern_error_ = inner.expression_error();
234 } 328 }
235 if (is_valid_assignment_pattern()) { 329 if (is_valid_assignment_pattern()) {
236 assignment_pattern_error_ = inner.expression_error(); 330 assignment_pattern_error_ = inner.expression_error();
237 } 331 }
238 } 332 }
239 } 333 }
240 334
241 private: 335 private:
336 AssignmentTargetType lhs_type_;
337 bool assigned_;
242 unsigned invalid_productions_; 338 unsigned invalid_productions_;
243 Error expression_error_; 339 Error expression_error_;
244 Error binding_pattern_error_; 340 Error binding_pattern_error_;
245 Error assignment_pattern_error_; 341 Error assignment_pattern_error_;
246 Error arrow_formal_parameters_error_; 342 Error arrow_formal_parameters_error_;
247 Error duplicate_formal_parameter_error_; 343 Error duplicate_formal_parameter_error_;
248 Error strict_mode_formal_parameter_error_; 344 Error strict_mode_formal_parameter_error_;
249 Error strong_mode_formal_parameter_error_; 345 Error strong_mode_formal_parameter_error_;
250 DuplicateFinder* duplicate_finder_; 346 DuplicateFinder* duplicate_finder_;
251 }; 347 };
252 } 348 }
253 } // v8::internal 349 } // v8::internal
254 350
255 #endif // V8_EXPRESSION_CLASSIFIER_H 351 #endif // V8_EXPRESSION_CLASSIFIER_H
OLDNEW
« no previous file with comments | « no previous file | src/messages.h » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698