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_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 21 matching lines...) Expand all Loading... |
32 enum TargetProduction { | 32 enum TargetProduction { |
33 ExpressionProduction = 1 << 0, | 33 ExpressionProduction = 1 << 0, |
34 FormalParameterInitializerProduction = 1 << 1, | 34 FormalParameterInitializerProduction = 1 << 1, |
35 BindingPatternProduction = 1 << 2, | 35 BindingPatternProduction = 1 << 2, |
36 AssignmentPatternProduction = 1 << 3, | 36 AssignmentPatternProduction = 1 << 3, |
37 DistinctFormalParametersProduction = 1 << 4, | 37 DistinctFormalParametersProduction = 1 << 4, |
38 StrictModeFormalParametersProduction = 1 << 5, | 38 StrictModeFormalParametersProduction = 1 << 5, |
39 ArrowFormalParametersProduction = 1 << 6, | 39 ArrowFormalParametersProduction = 1 << 6, |
40 LetPatternProduction = 1 << 7, | 40 LetPatternProduction = 1 << 7, |
41 CoverInitializedNameProduction = 1 << 8, | 41 CoverInitializedNameProduction = 1 << 8, |
| 42 AsyncArrowFormalParametersProduction = 1 << 9, |
42 | 43 |
43 ExpressionProductions = | 44 ExpressionProductions = |
44 (ExpressionProduction | FormalParameterInitializerProduction), | 45 (ExpressionProduction | FormalParameterInitializerProduction), |
45 PatternProductions = (BindingPatternProduction | | 46 PatternProductions = (BindingPatternProduction | |
46 AssignmentPatternProduction | LetPatternProduction), | 47 AssignmentPatternProduction | LetPatternProduction), |
47 FormalParametersProductions = (DistinctFormalParametersProduction | | 48 FormalParametersProductions = (DistinctFormalParametersProduction | |
48 StrictModeFormalParametersProduction), | 49 StrictModeFormalParametersProduction), |
49 StandardProductions = ExpressionProductions | PatternProductions, | 50 StandardProductions = ExpressionProductions | PatternProductions, |
50 AllProductions = | 51 AllProductions = |
51 (StandardProductions | FormalParametersProductions | | 52 (StandardProductions | FormalParametersProductions | |
52 ArrowFormalParametersProduction | CoverInitializedNameProduction) | 53 ArrowFormalParametersProduction | CoverInitializedNameProduction | |
| 54 AsyncArrowFormalParametersProduction) |
53 }; | 55 }; |
54 | 56 |
55 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; | 57 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; |
56 | 58 |
57 explicit ExpressionClassifier(const Traits* t) | 59 explicit ExpressionClassifier(const Traits* t) |
58 : zone_(t->zone()), | 60 : zone_(t->zone()), |
59 non_patterns_to_rewrite_(t->GetNonPatternList()), | 61 non_patterns_to_rewrite_(t->GetNonPatternList()), |
60 invalid_productions_(0), | 62 invalid_productions_(0), |
61 function_properties_(0), | 63 function_properties_(0), |
62 duplicate_finder_(nullptr) { | 64 duplicate_finder_(nullptr) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 105 } |
104 | 106 |
105 // Note: callers should also check | 107 // Note: callers should also check |
106 // is_valid_formal_parameter_list_without_duplicates(). | 108 // is_valid_formal_parameter_list_without_duplicates(). |
107 bool is_valid_strict_mode_formal_parameters() const { | 109 bool is_valid_strict_mode_formal_parameters() const { |
108 return is_valid(StrictModeFormalParametersProduction); | 110 return is_valid(StrictModeFormalParametersProduction); |
109 } | 111 } |
110 | 112 |
111 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } | 113 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } |
112 | 114 |
| 115 bool is_valid_async_arrow_formal_parameters() const { |
| 116 return is_valid(AsyncArrowFormalParametersProduction); |
| 117 } |
| 118 |
113 const Error& expression_error() const { return expression_error_; } | 119 const Error& expression_error() const { return expression_error_; } |
114 | 120 |
115 const Error& formal_parameter_initializer_error() const { | 121 const Error& formal_parameter_initializer_error() const { |
116 return formal_parameter_initializer_error_; | 122 return formal_parameter_initializer_error_; |
117 } | 123 } |
118 | 124 |
119 const Error& binding_pattern_error() const { return binding_pattern_error_; } | 125 const Error& binding_pattern_error() const { return binding_pattern_error_; } |
120 | 126 |
121 const Error& assignment_pattern_error() const { | 127 const Error& assignment_pattern_error() const { |
122 return assignment_pattern_error_; | 128 return assignment_pattern_error_; |
(...skipping 13 matching lines...) Expand all Loading... |
136 | 142 |
137 const Error& let_pattern_error() const { return let_pattern_error_; } | 143 const Error& let_pattern_error() const { return let_pattern_error_; } |
138 | 144 |
139 bool has_cover_initialized_name() const { | 145 bool has_cover_initialized_name() const { |
140 return !is_valid(CoverInitializedNameProduction); | 146 return !is_valid(CoverInitializedNameProduction); |
141 } | 147 } |
142 const Error& cover_initialized_name_error() const { | 148 const Error& cover_initialized_name_error() const { |
143 return cover_initialized_name_error_; | 149 return cover_initialized_name_error_; |
144 } | 150 } |
145 | 151 |
| 152 const Error& async_arrow_formal_parameters_error() const { |
| 153 return async_arrow_formal_parameters_error_; |
| 154 } |
| 155 |
146 bool is_simple_parameter_list() const { | 156 bool is_simple_parameter_list() const { |
147 return !(function_properties_ & NonSimpleParameter); | 157 return !(function_properties_ & NonSimpleParameter); |
148 } | 158 } |
149 | 159 |
150 void RecordNonSimpleParameter() { | 160 void RecordNonSimpleParameter() { |
151 function_properties_ |= NonSimpleParameter; | 161 function_properties_ |= NonSimpleParameter; |
152 } | 162 } |
153 | 163 |
154 void RecordExpressionError(const Scanner::Location& loc, | 164 void RecordExpressionError(const Scanner::Location& loc, |
155 MessageTemplate::Template message, | 165 MessageTemplate::Template message, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 void RecordArrowFormalParametersError(const Scanner::Location& loc, | 222 void RecordArrowFormalParametersError(const Scanner::Location& loc, |
213 MessageTemplate::Template message, | 223 MessageTemplate::Template message, |
214 const char* arg = nullptr) { | 224 const char* arg = nullptr) { |
215 if (!is_valid_arrow_formal_parameters()) return; | 225 if (!is_valid_arrow_formal_parameters()) return; |
216 invalid_productions_ |= ArrowFormalParametersProduction; | 226 invalid_productions_ |= ArrowFormalParametersProduction; |
217 arrow_formal_parameters_error_.location = loc; | 227 arrow_formal_parameters_error_.location = loc; |
218 arrow_formal_parameters_error_.message = message; | 228 arrow_formal_parameters_error_.message = message; |
219 arrow_formal_parameters_error_.arg = arg; | 229 arrow_formal_parameters_error_.arg = arg; |
220 } | 230 } |
221 | 231 |
| 232 void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc, |
| 233 MessageTemplate::Template message, |
| 234 const char* arg = nullptr) { |
| 235 if (!is_valid_async_arrow_formal_parameters()) return; |
| 236 invalid_productions_ |= AsyncArrowFormalParametersProduction; |
| 237 async_arrow_formal_parameters_error_.location = loc; |
| 238 async_arrow_formal_parameters_error_.message = message; |
| 239 async_arrow_formal_parameters_error_.arg = arg; |
| 240 } |
| 241 |
222 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { | 242 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { |
223 if (!is_valid_formal_parameter_list_without_duplicates()) return; | 243 if (!is_valid_formal_parameter_list_without_duplicates()) return; |
224 invalid_productions_ |= DistinctFormalParametersProduction; | 244 invalid_productions_ |= DistinctFormalParametersProduction; |
225 duplicate_formal_parameter_error_.location = loc; | 245 duplicate_formal_parameter_error_.location = loc; |
226 duplicate_formal_parameter_error_.message = MessageTemplate::kParamDupe; | 246 duplicate_formal_parameter_error_.message = MessageTemplate::kParamDupe; |
227 duplicate_formal_parameter_error_.arg = nullptr; | 247 duplicate_formal_parameter_error_.arg = nullptr; |
228 } | 248 } |
229 | 249 |
230 // Record a binding that would be invalid in strict mode. Confusingly this | 250 // Record a binding that would be invalid in strict mode. Confusingly this |
231 // is not the same as StrictFormalParameterList, which simply forbids | 251 // is not the same as StrictFormalParameterList, which simply forbids |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 if (errors & DistinctFormalParametersProduction) | 318 if (errors & DistinctFormalParametersProduction) |
299 duplicate_formal_parameter_error_ = | 319 duplicate_formal_parameter_error_ = |
300 inner->duplicate_formal_parameter_error_; | 320 inner->duplicate_formal_parameter_error_; |
301 if (errors & StrictModeFormalParametersProduction) | 321 if (errors & StrictModeFormalParametersProduction) |
302 strict_mode_formal_parameter_error_ = | 322 strict_mode_formal_parameter_error_ = |
303 inner->strict_mode_formal_parameter_error_; | 323 inner->strict_mode_formal_parameter_error_; |
304 if (errors & LetPatternProduction) | 324 if (errors & LetPatternProduction) |
305 let_pattern_error_ = inner->let_pattern_error_; | 325 let_pattern_error_ = inner->let_pattern_error_; |
306 if (errors & CoverInitializedNameProduction) | 326 if (errors & CoverInitializedNameProduction) |
307 cover_initialized_name_error_ = inner->cover_initialized_name_error_; | 327 cover_initialized_name_error_ = inner->cover_initialized_name_error_; |
| 328 if (errors & AsyncArrowFormalParametersProduction) |
| 329 async_arrow_formal_parameters_error_ = |
| 330 inner->async_arrow_formal_parameters_error_; |
308 } | 331 } |
309 | 332 |
310 // As an exception to the above, the result continues to be a valid arrow | 333 // As an exception to the above, the result continues to be a valid arrow |
311 // formal parameters if the inner expression is a valid binding pattern. | 334 // formal parameters if the inner expression is a valid binding pattern. |
312 if (productions & ArrowFormalParametersProduction && | 335 if (productions & ArrowFormalParametersProduction && |
313 is_valid_arrow_formal_parameters()) { | 336 is_valid_arrow_formal_parameters()) { |
314 // Also copy function properties if expecting an arrow function | 337 // Also copy function properties if expecting an arrow function |
315 // parameter. | 338 // parameter. |
316 function_properties_ |= inner->function_properties_; | 339 function_properties_ |= inner->function_properties_; |
317 | 340 |
(...skipping 24 matching lines...) Expand all Loading... |
342 unsigned function_properties_; | 365 unsigned function_properties_; |
343 Error expression_error_; | 366 Error expression_error_; |
344 Error formal_parameter_initializer_error_; | 367 Error formal_parameter_initializer_error_; |
345 Error binding_pattern_error_; | 368 Error binding_pattern_error_; |
346 Error assignment_pattern_error_; | 369 Error assignment_pattern_error_; |
347 Error arrow_formal_parameters_error_; | 370 Error arrow_formal_parameters_error_; |
348 Error duplicate_formal_parameter_error_; | 371 Error duplicate_formal_parameter_error_; |
349 Error strict_mode_formal_parameter_error_; | 372 Error strict_mode_formal_parameter_error_; |
350 Error let_pattern_error_; | 373 Error let_pattern_error_; |
351 Error cover_initialized_name_error_; | 374 Error cover_initialized_name_error_; |
| 375 Error async_arrow_formal_parameters_error_; |
352 DuplicateFinder* duplicate_finder_; | 376 DuplicateFinder* duplicate_finder_; |
353 }; | 377 }; |
354 | 378 |
355 | 379 |
356 } // namespace internal | 380 } // namespace internal |
357 } // namespace v8 | 381 } // namespace v8 |
358 | 382 |
359 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 383 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
OLD | NEW |