| 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 22 matching lines...) Expand all Loading... |
| 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 TailCallExpressionProduction = 1 << 9, | 42 TailCallExpressionProduction = 1 << 9, |
| 43 AsyncArrowFormalParametersProduction = 1 << 10, |
| 43 | 44 |
| 44 ExpressionProductions = | 45 ExpressionProductions = |
| 45 (ExpressionProduction | FormalParameterInitializerProduction | | 46 (ExpressionProduction | FormalParameterInitializerProduction | |
| 46 TailCallExpressionProduction), | 47 TailCallExpressionProduction), |
| 47 PatternProductions = (BindingPatternProduction | | 48 PatternProductions = (BindingPatternProduction | |
| 48 AssignmentPatternProduction | LetPatternProduction), | 49 AssignmentPatternProduction | LetPatternProduction), |
| 49 FormalParametersProductions = (DistinctFormalParametersProduction | | 50 FormalParametersProductions = (DistinctFormalParametersProduction | |
| 50 StrictModeFormalParametersProduction), | 51 StrictModeFormalParametersProduction), |
| 51 StandardProductions = ExpressionProductions | PatternProductions, | 52 StandardProductions = ExpressionProductions | PatternProductions, |
| 52 AllProductions = | 53 AllProductions = |
| 53 (StandardProductions | FormalParametersProductions | | 54 (StandardProductions | FormalParametersProductions | |
| 54 ArrowFormalParametersProduction | CoverInitializedNameProduction) | 55 ArrowFormalParametersProduction | CoverInitializedNameProduction | |
| 56 AsyncArrowFormalParametersProduction) |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; | 59 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; |
| 58 | 60 |
| 59 explicit ExpressionClassifier(const Traits* t) | 61 explicit ExpressionClassifier(const Traits* t) |
| 60 : zone_(t->zone()), | 62 : zone_(t->zone()), |
| 61 non_patterns_to_rewrite_(t->GetNonPatternList()), | 63 non_patterns_to_rewrite_(t->GetNonPatternList()), |
| 62 invalid_productions_(0), | 64 invalid_productions_(0), |
| 63 function_properties_(0), | 65 function_properties_(0), |
| 64 duplicate_finder_(nullptr) { | 66 duplicate_finder_(nullptr) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 107 } |
| 106 | 108 |
| 107 // Note: callers should also check | 109 // Note: callers should also check |
| 108 // is_valid_formal_parameter_list_without_duplicates(). | 110 // is_valid_formal_parameter_list_without_duplicates(). |
| 109 bool is_valid_strict_mode_formal_parameters() const { | 111 bool is_valid_strict_mode_formal_parameters() const { |
| 110 return is_valid(StrictModeFormalParametersProduction); | 112 return is_valid(StrictModeFormalParametersProduction); |
| 111 } | 113 } |
| 112 | 114 |
| 113 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } | 115 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } |
| 114 | 116 |
| 117 bool is_valid_async_arrow_formal_parameters() const { |
| 118 return is_valid(AsyncArrowFormalParametersProduction); |
| 119 } |
| 120 |
| 115 const Error& expression_error() const { return expression_error_; } | 121 const Error& expression_error() const { return expression_error_; } |
| 116 | 122 |
| 117 const Error& formal_parameter_initializer_error() const { | 123 const Error& formal_parameter_initializer_error() const { |
| 118 return formal_parameter_initializer_error_; | 124 return formal_parameter_initializer_error_; |
| 119 } | 125 } |
| 120 | 126 |
| 121 const Error& binding_pattern_error() const { return binding_pattern_error_; } | 127 const Error& binding_pattern_error() const { return binding_pattern_error_; } |
| 122 | 128 |
| 123 const Error& assignment_pattern_error() const { | 129 const Error& assignment_pattern_error() const { |
| 124 return assignment_pattern_error_; | 130 return assignment_pattern_error_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 144 const Error& cover_initialized_name_error() const { | 150 const Error& cover_initialized_name_error() const { |
| 145 return cover_initialized_name_error_; | 151 return cover_initialized_name_error_; |
| 146 } | 152 } |
| 147 | 153 |
| 148 bool has_tail_call_expression() const { | 154 bool has_tail_call_expression() const { |
| 149 return !is_valid(TailCallExpressionProduction); | 155 return !is_valid(TailCallExpressionProduction); |
| 150 } | 156 } |
| 151 const Error& tail_call_expression_error() const { | 157 const Error& tail_call_expression_error() const { |
| 152 return tail_call_expression_error_; | 158 return tail_call_expression_error_; |
| 153 } | 159 } |
| 160 const Error& async_arrow_formal_parameters_error() const { |
| 161 return async_arrow_formal_parameters_error_; |
| 162 } |
| 154 | 163 |
| 155 bool is_simple_parameter_list() const { | 164 bool is_simple_parameter_list() const { |
| 156 return !(function_properties_ & NonSimpleParameter); | 165 return !(function_properties_ & NonSimpleParameter); |
| 157 } | 166 } |
| 158 | 167 |
| 159 void RecordNonSimpleParameter() { | 168 void RecordNonSimpleParameter() { |
| 160 function_properties_ |= NonSimpleParameter; | 169 function_properties_ |= NonSimpleParameter; |
| 161 } | 170 } |
| 162 | 171 |
| 163 void RecordExpressionError(const Scanner::Location& loc, | 172 void RecordExpressionError(const Scanner::Location& loc, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 void RecordArrowFormalParametersError(const Scanner::Location& loc, | 230 void RecordArrowFormalParametersError(const Scanner::Location& loc, |
| 222 MessageTemplate::Template message, | 231 MessageTemplate::Template message, |
| 223 const char* arg = nullptr) { | 232 const char* arg = nullptr) { |
| 224 if (!is_valid_arrow_formal_parameters()) return; | 233 if (!is_valid_arrow_formal_parameters()) return; |
| 225 invalid_productions_ |= ArrowFormalParametersProduction; | 234 invalid_productions_ |= ArrowFormalParametersProduction; |
| 226 arrow_formal_parameters_error_.location = loc; | 235 arrow_formal_parameters_error_.location = loc; |
| 227 arrow_formal_parameters_error_.message = message; | 236 arrow_formal_parameters_error_.message = message; |
| 228 arrow_formal_parameters_error_.arg = arg; | 237 arrow_formal_parameters_error_.arg = arg; |
| 229 } | 238 } |
| 230 | 239 |
| 240 void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc, |
| 241 MessageTemplate::Template message, |
| 242 const char* arg = nullptr) { |
| 243 if (!is_valid_async_arrow_formal_parameters()) return; |
| 244 invalid_productions_ |= AsyncArrowFormalParametersProduction; |
| 245 async_arrow_formal_parameters_error_.location = loc; |
| 246 async_arrow_formal_parameters_error_.message = message; |
| 247 async_arrow_formal_parameters_error_.arg = arg; |
| 248 } |
| 249 |
| 231 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { | 250 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { |
| 232 if (!is_valid_formal_parameter_list_without_duplicates()) return; | 251 if (!is_valid_formal_parameter_list_without_duplicates()) return; |
| 233 invalid_productions_ |= DistinctFormalParametersProduction; | 252 invalid_productions_ |= DistinctFormalParametersProduction; |
| 234 duplicate_formal_parameter_error_.location = loc; | 253 duplicate_formal_parameter_error_.location = loc; |
| 235 duplicate_formal_parameter_error_.message = MessageTemplate::kParamDupe; | 254 duplicate_formal_parameter_error_.message = MessageTemplate::kParamDupe; |
| 236 duplicate_formal_parameter_error_.arg = nullptr; | 255 duplicate_formal_parameter_error_.arg = nullptr; |
| 237 } | 256 } |
| 238 | 257 |
| 239 // Record a binding that would be invalid in strict mode. Confusingly this | 258 // Record a binding that would be invalid in strict mode. Confusingly this |
| 240 // is not the same as StrictFormalParameterList, which simply forbids | 259 // is not the same as StrictFormalParameterList, which simply forbids |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 inner->duplicate_formal_parameter_error_; | 338 inner->duplicate_formal_parameter_error_; |
| 320 if (errors & StrictModeFormalParametersProduction) | 339 if (errors & StrictModeFormalParametersProduction) |
| 321 strict_mode_formal_parameter_error_ = | 340 strict_mode_formal_parameter_error_ = |
| 322 inner->strict_mode_formal_parameter_error_; | 341 inner->strict_mode_formal_parameter_error_; |
| 323 if (errors & LetPatternProduction) | 342 if (errors & LetPatternProduction) |
| 324 let_pattern_error_ = inner->let_pattern_error_; | 343 let_pattern_error_ = inner->let_pattern_error_; |
| 325 if (errors & CoverInitializedNameProduction) | 344 if (errors & CoverInitializedNameProduction) |
| 326 cover_initialized_name_error_ = inner->cover_initialized_name_error_; | 345 cover_initialized_name_error_ = inner->cover_initialized_name_error_; |
| 327 if (errors & TailCallExpressionProduction) | 346 if (errors & TailCallExpressionProduction) |
| 328 tail_call_expression_error_ = inner->tail_call_expression_error_; | 347 tail_call_expression_error_ = inner->tail_call_expression_error_; |
| 348 if (errors & AsyncArrowFormalParametersProduction) |
| 349 async_arrow_formal_parameters_error_ = |
| 350 inner->async_arrow_formal_parameters_error_; |
| 329 } | 351 } |
| 330 | 352 |
| 331 // As an exception to the above, the result continues to be a valid arrow | 353 // As an exception to the above, the result continues to be a valid arrow |
| 332 // formal parameters if the inner expression is a valid binding pattern. | 354 // formal parameters if the inner expression is a valid binding pattern. |
| 333 if (productions & ArrowFormalParametersProduction && | 355 if (productions & ArrowFormalParametersProduction && |
| 334 is_valid_arrow_formal_parameters()) { | 356 is_valid_arrow_formal_parameters()) { |
| 335 // Also copy function properties if expecting an arrow function | 357 // Also copy function properties if expecting an arrow function |
| 336 // parameter. | 358 // parameter. |
| 337 function_properties_ |= inner->function_properties_; | 359 function_properties_ |= inner->function_properties_; |
| 338 | 360 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 366 Error expression_error_; | 388 Error expression_error_; |
| 367 Error formal_parameter_initializer_error_; | 389 Error formal_parameter_initializer_error_; |
| 368 Error binding_pattern_error_; | 390 Error binding_pattern_error_; |
| 369 Error assignment_pattern_error_; | 391 Error assignment_pattern_error_; |
| 370 Error arrow_formal_parameters_error_; | 392 Error arrow_formal_parameters_error_; |
| 371 Error duplicate_formal_parameter_error_; | 393 Error duplicate_formal_parameter_error_; |
| 372 Error strict_mode_formal_parameter_error_; | 394 Error strict_mode_formal_parameter_error_; |
| 373 Error let_pattern_error_; | 395 Error let_pattern_error_; |
| 374 Error cover_initialized_name_error_; | 396 Error cover_initialized_name_error_; |
| 375 Error tail_call_expression_error_; | 397 Error tail_call_expression_error_; |
| 398 Error async_arrow_formal_parameters_error_; |
| 376 DuplicateFinder* duplicate_finder_; | 399 DuplicateFinder* duplicate_finder_; |
| 377 }; | 400 }; |
| 378 | 401 |
| 379 | 402 |
| 380 } // namespace internal | 403 } // namespace internal |
| 381 } // namespace v8 | 404 } // namespace v8 |
| 382 | 405 |
| 383 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 406 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
| OLD | NEW |