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_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 29 matching lines...) Expand all Loading... |
40 PatternProductions = | 40 PatternProductions = |
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 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; |
| 51 |
50 ExpressionClassifier() | 52 ExpressionClassifier() |
51 : invalid_productions_(0), duplicate_finder_(nullptr) {} | 53 : invalid_productions_(0), |
| 54 function_properties_(0), |
| 55 duplicate_finder_(nullptr) {} |
52 | 56 |
53 explicit ExpressionClassifier(DuplicateFinder* duplicate_finder) | 57 explicit ExpressionClassifier(DuplicateFinder* duplicate_finder) |
54 : invalid_productions_(0), duplicate_finder_(duplicate_finder) {} | 58 : invalid_productions_(0), |
| 59 function_properties_(0), |
| 60 duplicate_finder_(duplicate_finder) {} |
55 | 61 |
56 bool is_valid(unsigned productions) const { | 62 bool is_valid(unsigned productions) const { |
57 return (invalid_productions_ & productions) == 0; | 63 return (invalid_productions_ & productions) == 0; |
58 } | 64 } |
59 | 65 |
60 DuplicateFinder* duplicate_finder() const { return duplicate_finder_; } | 66 DuplicateFinder* duplicate_finder() const { return duplicate_finder_; } |
61 | 67 |
62 bool is_valid_expression() const { return is_valid(ExpressionProduction); } | 68 bool is_valid_expression() const { return is_valid(ExpressionProduction); } |
63 | 69 |
64 bool is_valid_binding_pattern() const { | 70 bool is_valid_binding_pattern() const { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 112 } |
107 | 113 |
108 const Error& strict_mode_formal_parameter_error() const { | 114 const Error& strict_mode_formal_parameter_error() const { |
109 return strict_mode_formal_parameter_error_; | 115 return strict_mode_formal_parameter_error_; |
110 } | 116 } |
111 | 117 |
112 const Error& strong_mode_formal_parameter_error() const { | 118 const Error& strong_mode_formal_parameter_error() const { |
113 return strong_mode_formal_parameter_error_; | 119 return strong_mode_formal_parameter_error_; |
114 } | 120 } |
115 | 121 |
| 122 bool is_simple_parameter_list() const { |
| 123 return !(function_properties_ & NonSimpleParameter); |
| 124 } |
| 125 |
| 126 void RecordNonSimpleParameter() { |
| 127 function_properties_ |= NonSimpleParameter; |
| 128 } |
| 129 |
116 void RecordExpressionError(const Scanner::Location& loc, | 130 void RecordExpressionError(const Scanner::Location& loc, |
117 MessageTemplate::Template message, | 131 MessageTemplate::Template message, |
118 const char* arg = nullptr) { | 132 const char* arg = nullptr) { |
119 if (!is_valid_expression()) return; | 133 if (!is_valid_expression()) return; |
120 invalid_productions_ |= ExpressionProduction; | 134 invalid_productions_ |= ExpressionProduction; |
121 expression_error_.location = loc; | 135 expression_error_.location = loc; |
122 expression_error_.message = message; | 136 expression_error_.message = message; |
123 expression_error_.arg = arg; | 137 expression_error_.arg = arg; |
124 } | 138 } |
125 | 139 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 strict_mode_formal_parameter_error_ = | 225 strict_mode_formal_parameter_error_ = |
212 inner.strict_mode_formal_parameter_error_; | 226 inner.strict_mode_formal_parameter_error_; |
213 if (errors & StrongModeFormalParametersProduction) | 227 if (errors & StrongModeFormalParametersProduction) |
214 strong_mode_formal_parameter_error_ = | 228 strong_mode_formal_parameter_error_ = |
215 inner.strong_mode_formal_parameter_error_; | 229 inner.strong_mode_formal_parameter_error_; |
216 } | 230 } |
217 | 231 |
218 // As an exception to the above, the result continues to be a valid arrow | 232 // As an exception to the above, the result continues to be a valid arrow |
219 // formal parameters if the inner expression is a valid binding pattern. | 233 // formal parameters if the inner expression is a valid binding pattern. |
220 if (productions & ArrowFormalParametersProduction && | 234 if (productions & ArrowFormalParametersProduction && |
221 is_valid_arrow_formal_parameters() && | 235 is_valid_arrow_formal_parameters()) { |
222 !inner.is_valid_binding_pattern()) { | 236 // Also copy function properties if expecting an arrow function |
223 invalid_productions_ |= ArrowFormalParametersProduction; | 237 // parameter |
224 arrow_formal_parameters_error_ = inner.binding_pattern_error_; | 238 function_properties_ |= inner.function_properties_; |
| 239 |
| 240 if (!inner.is_valid_binding_pattern()) { |
| 241 invalid_productions_ |= ArrowFormalParametersProduction; |
| 242 arrow_formal_parameters_error_ = inner.binding_pattern_error_; |
| 243 } |
225 } | 244 } |
226 } | 245 } |
227 | 246 |
228 private: | 247 private: |
229 unsigned invalid_productions_; | 248 unsigned invalid_productions_; |
| 249 unsigned function_properties_; |
230 Error expression_error_; | 250 Error expression_error_; |
231 Error binding_pattern_error_; | 251 Error binding_pattern_error_; |
232 Error assignment_pattern_error_; | 252 Error assignment_pattern_error_; |
233 Error arrow_formal_parameters_error_; | 253 Error arrow_formal_parameters_error_; |
234 Error duplicate_formal_parameter_error_; | 254 Error duplicate_formal_parameter_error_; |
235 Error strict_mode_formal_parameter_error_; | 255 Error strict_mode_formal_parameter_error_; |
236 Error strong_mode_formal_parameter_error_; | 256 Error strong_mode_formal_parameter_error_; |
237 DuplicateFinder* duplicate_finder_; | 257 DuplicateFinder* duplicate_finder_; |
238 }; | 258 }; |
239 } | 259 } |
240 } // v8::internal | 260 } // v8::internal |
241 | 261 |
242 #endif // V8_EXPRESSION_CLASSIFIER_H | 262 #endif // V8_EXPRESSION_CLASSIFIER_H |
OLD | NEW |