| 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, |
| 44 AsyncBindingPatternProduction = 1 << 11, |
| 43 | 45 |
| 44 ExpressionProductions = | 46 ExpressionProductions = |
| 45 (ExpressionProduction | FormalParameterInitializerProduction | | 47 (ExpressionProduction | FormalParameterInitializerProduction | |
| 46 TailCallExpressionProduction), | 48 TailCallExpressionProduction), |
| 47 PatternProductions = (BindingPatternProduction | | 49 PatternProductions = |
| 48 AssignmentPatternProduction | LetPatternProduction), | 50 (BindingPatternProduction | AssignmentPatternProduction | |
| 51 LetPatternProduction | AsyncBindingPatternProduction), |
| 49 FormalParametersProductions = (DistinctFormalParametersProduction | | 52 FormalParametersProductions = (DistinctFormalParametersProduction | |
| 50 StrictModeFormalParametersProduction), | 53 StrictModeFormalParametersProduction), |
| 51 StandardProductions = ExpressionProductions | PatternProductions, | 54 StandardProductions = ExpressionProductions | PatternProductions, |
| 52 AllProductions = | 55 AllProductions = |
| 53 (StandardProductions | FormalParametersProductions | | 56 (StandardProductions | FormalParametersProductions | |
| 54 ArrowFormalParametersProduction | CoverInitializedNameProduction) | 57 ArrowFormalParametersProduction | CoverInitializedNameProduction | |
| 58 AsyncArrowFormalParametersProduction | AsyncBindingPatternProduction) |
| 55 }; | 59 }; |
| 56 | 60 |
| 57 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; | 61 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; |
| 58 | 62 |
| 59 explicit ExpressionClassifier(const Traits* t) | 63 explicit ExpressionClassifier(const Traits* t) |
| 60 : zone_(t->zone()), | 64 : zone_(t->zone()), |
| 61 non_patterns_to_rewrite_(t->GetNonPatternList()), | 65 non_patterns_to_rewrite_(t->GetNonPatternList()), |
| 62 invalid_productions_(0), | 66 invalid_productions_(0), |
| 63 function_properties_(0), | 67 function_properties_(0), |
| 64 duplicate_finder_(nullptr) { | 68 duplicate_finder_(nullptr) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 109 } |
| 106 | 110 |
| 107 // Note: callers should also check | 111 // Note: callers should also check |
| 108 // is_valid_formal_parameter_list_without_duplicates(). | 112 // is_valid_formal_parameter_list_without_duplicates(). |
| 109 bool is_valid_strict_mode_formal_parameters() const { | 113 bool is_valid_strict_mode_formal_parameters() const { |
| 110 return is_valid(StrictModeFormalParametersProduction); | 114 return is_valid(StrictModeFormalParametersProduction); |
| 111 } | 115 } |
| 112 | 116 |
| 113 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } | 117 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } |
| 114 | 118 |
| 119 bool is_valid_async_arrow_formal_parameters() const { |
| 120 return is_valid(AsyncArrowFormalParametersProduction); |
| 121 } |
| 122 |
| 123 bool is_valid_async_binding_pattern() const { |
| 124 return is_valid(AsyncBindingPatternProduction); |
| 125 } |
| 126 |
| 115 const Error& expression_error() const { return expression_error_; } | 127 const Error& expression_error() const { return expression_error_; } |
| 116 | 128 |
| 117 const Error& formal_parameter_initializer_error() const { | 129 const Error& formal_parameter_initializer_error() const { |
| 118 return formal_parameter_initializer_error_; | 130 return formal_parameter_initializer_error_; |
| 119 } | 131 } |
| 120 | 132 |
| 121 const Error& binding_pattern_error() const { return binding_pattern_error_; } | 133 const Error& binding_pattern_error() const { return binding_pattern_error_; } |
| 122 | 134 |
| 123 const Error& assignment_pattern_error() const { | 135 const Error& assignment_pattern_error() const { |
| 124 return assignment_pattern_error_; | 136 return assignment_pattern_error_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 144 const Error& cover_initialized_name_error() const { | 156 const Error& cover_initialized_name_error() const { |
| 145 return cover_initialized_name_error_; | 157 return cover_initialized_name_error_; |
| 146 } | 158 } |
| 147 | 159 |
| 148 bool has_tail_call_expression() const { | 160 bool has_tail_call_expression() const { |
| 149 return !is_valid(TailCallExpressionProduction); | 161 return !is_valid(TailCallExpressionProduction); |
| 150 } | 162 } |
| 151 const Error& tail_call_expression_error() const { | 163 const Error& tail_call_expression_error() const { |
| 152 return tail_call_expression_error_; | 164 return tail_call_expression_error_; |
| 153 } | 165 } |
| 166 const Error& async_arrow_formal_parameters_error() const { |
| 167 return async_arrow_formal_parameters_error_; |
| 168 } |
| 169 |
| 170 const Error& async_binding_pattern_error() const { |
| 171 return async_binding_pattern_error_; |
| 172 } |
| 154 | 173 |
| 155 bool is_simple_parameter_list() const { | 174 bool is_simple_parameter_list() const { |
| 156 return !(function_properties_ & NonSimpleParameter); | 175 return !(function_properties_ & NonSimpleParameter); |
| 157 } | 176 } |
| 158 | 177 |
| 159 void RecordNonSimpleParameter() { | 178 void RecordNonSimpleParameter() { |
| 160 function_properties_ |= NonSimpleParameter; | 179 function_properties_ |= NonSimpleParameter; |
| 161 } | 180 } |
| 162 | 181 |
| 163 void RecordExpressionError(const Scanner::Location& loc, | 182 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, | 240 void RecordArrowFormalParametersError(const Scanner::Location& loc, |
| 222 MessageTemplate::Template message, | 241 MessageTemplate::Template message, |
| 223 const char* arg = nullptr) { | 242 const char* arg = nullptr) { |
| 224 if (!is_valid_arrow_formal_parameters()) return; | 243 if (!is_valid_arrow_formal_parameters()) return; |
| 225 invalid_productions_ |= ArrowFormalParametersProduction; | 244 invalid_productions_ |= ArrowFormalParametersProduction; |
| 226 arrow_formal_parameters_error_.location = loc; | 245 arrow_formal_parameters_error_.location = loc; |
| 227 arrow_formal_parameters_error_.message = message; | 246 arrow_formal_parameters_error_.message = message; |
| 228 arrow_formal_parameters_error_.arg = arg; | 247 arrow_formal_parameters_error_.arg = arg; |
| 229 } | 248 } |
| 230 | 249 |
| 250 void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc, |
| 251 MessageTemplate::Template message, |
| 252 const char* arg = nullptr) { |
| 253 if (!is_valid_async_arrow_formal_parameters()) return; |
| 254 invalid_productions_ |= AsyncArrowFormalParametersProduction; |
| 255 async_arrow_formal_parameters_error_.location = loc; |
| 256 async_arrow_formal_parameters_error_.message = message; |
| 257 async_arrow_formal_parameters_error_.arg = arg; |
| 258 } |
| 259 |
| 260 void RecordAsyncBindingPatternError(const Scanner::Location& loc, |
| 261 MessageTemplate::Template message, |
| 262 const char* arg = nullptr) { |
| 263 if (!is_valid_async_binding_pattern()) return; |
| 264 invalid_productions_ |= AsyncBindingPatternProduction; |
| 265 async_binding_pattern_error_.location = loc; |
| 266 async_binding_pattern_error_.message = message; |
| 267 async_binding_pattern_error_.arg = arg; |
| 268 } |
| 269 |
| 231 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { | 270 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { |
| 232 if (!is_valid_formal_parameter_list_without_duplicates()) return; | 271 if (!is_valid_formal_parameter_list_without_duplicates()) return; |
| 233 invalid_productions_ |= DistinctFormalParametersProduction; | 272 invalid_productions_ |= DistinctFormalParametersProduction; |
| 234 duplicate_formal_parameter_error_.location = loc; | 273 duplicate_formal_parameter_error_.location = loc; |
| 235 duplicate_formal_parameter_error_.message = MessageTemplate::kParamDupe; | 274 duplicate_formal_parameter_error_.message = MessageTemplate::kParamDupe; |
| 236 duplicate_formal_parameter_error_.arg = nullptr; | 275 duplicate_formal_parameter_error_.arg = nullptr; |
| 237 } | 276 } |
| 238 | 277 |
| 239 // Record a binding that would be invalid in strict mode. Confusingly this | 278 // Record a binding that would be invalid in strict mode. Confusingly this |
| 240 // is not the same as StrictFormalParameterList, which simply forbids | 279 // 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_; | 358 inner->duplicate_formal_parameter_error_; |
| 320 if (errors & StrictModeFormalParametersProduction) | 359 if (errors & StrictModeFormalParametersProduction) |
| 321 strict_mode_formal_parameter_error_ = | 360 strict_mode_formal_parameter_error_ = |
| 322 inner->strict_mode_formal_parameter_error_; | 361 inner->strict_mode_formal_parameter_error_; |
| 323 if (errors & LetPatternProduction) | 362 if (errors & LetPatternProduction) |
| 324 let_pattern_error_ = inner->let_pattern_error_; | 363 let_pattern_error_ = inner->let_pattern_error_; |
| 325 if (errors & CoverInitializedNameProduction) | 364 if (errors & CoverInitializedNameProduction) |
| 326 cover_initialized_name_error_ = inner->cover_initialized_name_error_; | 365 cover_initialized_name_error_ = inner->cover_initialized_name_error_; |
| 327 if (errors & TailCallExpressionProduction) | 366 if (errors & TailCallExpressionProduction) |
| 328 tail_call_expression_error_ = inner->tail_call_expression_error_; | 367 tail_call_expression_error_ = inner->tail_call_expression_error_; |
| 368 if (errors & AsyncArrowFormalParametersProduction) |
| 369 async_arrow_formal_parameters_error_ = |
| 370 inner->async_arrow_formal_parameters_error_; |
| 371 if (errors & AsyncBindingPatternProduction) |
| 372 async_binding_pattern_error_ = inner->async_binding_pattern_error_; |
| 329 } | 373 } |
| 330 | 374 |
| 331 // As an exception to the above, the result continues to be a valid arrow | 375 // 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. | 376 // formal parameters if the inner expression is a valid binding pattern. |
| 333 if (productions & ArrowFormalParametersProduction && | 377 if (productions & ArrowFormalParametersProduction && |
| 334 is_valid_arrow_formal_parameters()) { | 378 is_valid_arrow_formal_parameters()) { |
| 335 // Also copy function properties if expecting an arrow function | 379 // Also copy function properties if expecting an arrow function |
| 336 // parameter. | 380 // parameter. |
| 337 function_properties_ |= inner->function_properties_; | 381 function_properties_ |= inner->function_properties_; |
| 338 | 382 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 366 Error expression_error_; | 410 Error expression_error_; |
| 367 Error formal_parameter_initializer_error_; | 411 Error formal_parameter_initializer_error_; |
| 368 Error binding_pattern_error_; | 412 Error binding_pattern_error_; |
| 369 Error assignment_pattern_error_; | 413 Error assignment_pattern_error_; |
| 370 Error arrow_formal_parameters_error_; | 414 Error arrow_formal_parameters_error_; |
| 371 Error duplicate_formal_parameter_error_; | 415 Error duplicate_formal_parameter_error_; |
| 372 Error strict_mode_formal_parameter_error_; | 416 Error strict_mode_formal_parameter_error_; |
| 373 Error let_pattern_error_; | 417 Error let_pattern_error_; |
| 374 Error cover_initialized_name_error_; | 418 Error cover_initialized_name_error_; |
| 375 Error tail_call_expression_error_; | 419 Error tail_call_expression_error_; |
| 420 Error async_arrow_formal_parameters_error_; |
| 421 Error async_binding_pattern_error_; |
| 376 DuplicateFinder* duplicate_finder_; | 422 DuplicateFinder* duplicate_finder_; |
| 377 }; | 423 }; |
| 378 | 424 |
| 379 | 425 |
| 380 } // namespace internal | 426 } // namespace internal |
| 381 } // namespace v8 | 427 } // namespace v8 |
| 382 | 428 |
| 383 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 429 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
| OLD | NEW |