| 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 18 matching lines...) Expand all Loading... |
| 29 const char* arg; | 29 const char* arg; |
| 30 }; | 30 }; |
| 31 | 31 |
| 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 StrongModeFormalParametersProduction = 1 << 6, | 39 ArrowFormalParametersProduction = 1 << 6, |
| 40 ArrowFormalParametersProduction = 1 << 7, | 40 LetPatternProduction = 1 << 7, |
| 41 LetPatternProduction = 1 << 8, | 41 CoverInitializedNameProduction = 1 << 8, |
| 42 CoverInitializedNameProduction = 1 << 9, | |
| 43 | 42 |
| 44 ExpressionProductions = | 43 ExpressionProductions = |
| 45 (ExpressionProduction | FormalParameterInitializerProduction), | 44 (ExpressionProduction | FormalParameterInitializerProduction), |
| 46 PatternProductions = (BindingPatternProduction | | 45 PatternProductions = (BindingPatternProduction | |
| 47 AssignmentPatternProduction | LetPatternProduction), | 46 AssignmentPatternProduction | LetPatternProduction), |
| 48 FormalParametersProductions = (DistinctFormalParametersProduction | | 47 FormalParametersProductions = (DistinctFormalParametersProduction | |
| 49 StrictModeFormalParametersProduction | | 48 StrictModeFormalParametersProduction), |
| 50 StrongModeFormalParametersProduction), | |
| 51 StandardProductions = ExpressionProductions | PatternProductions, | 49 StandardProductions = ExpressionProductions | PatternProductions, |
| 52 AllProductions = | 50 AllProductions = |
| 53 (StandardProductions | FormalParametersProductions | | 51 (StandardProductions | FormalParametersProductions | |
| 54 ArrowFormalParametersProduction | CoverInitializedNameProduction) | 52 ArrowFormalParametersProduction | CoverInitializedNameProduction) |
| 55 }; | 53 }; |
| 56 | 54 |
| 57 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; | 55 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; |
| 58 | 56 |
| 59 explicit ExpressionClassifier(const Traits* t) | 57 explicit ExpressionClassifier(const Traits* t) |
| 60 : zone_(t->zone()), | 58 : zone_(t->zone()), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 bool is_valid_formal_parameter_list_without_duplicates() const { | 101 bool is_valid_formal_parameter_list_without_duplicates() const { |
| 104 return is_valid(DistinctFormalParametersProduction); | 102 return is_valid(DistinctFormalParametersProduction); |
| 105 } | 103 } |
| 106 | 104 |
| 107 // Note: callers should also check | 105 // Note: callers should also check |
| 108 // is_valid_formal_parameter_list_without_duplicates(). | 106 // is_valid_formal_parameter_list_without_duplicates(). |
| 109 bool is_valid_strict_mode_formal_parameters() const { | 107 bool is_valid_strict_mode_formal_parameters() const { |
| 110 return is_valid(StrictModeFormalParametersProduction); | 108 return is_valid(StrictModeFormalParametersProduction); |
| 111 } | 109 } |
| 112 | 110 |
| 113 // Note: callers should also check is_valid_strict_mode_formal_parameters() | |
| 114 // and is_valid_formal_parameter_list_without_duplicates(). | |
| 115 bool is_valid_strong_mode_formal_parameters() const { | |
| 116 return is_valid(StrongModeFormalParametersProduction); | |
| 117 } | |
| 118 | |
| 119 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } | 111 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } |
| 120 | 112 |
| 121 const Error& expression_error() const { return expression_error_; } | 113 const Error& expression_error() const { return expression_error_; } |
| 122 | 114 |
| 123 const Error& formal_parameter_initializer_error() const { | 115 const Error& formal_parameter_initializer_error() const { |
| 124 return formal_parameter_initializer_error_; | 116 return formal_parameter_initializer_error_; |
| 125 } | 117 } |
| 126 | 118 |
| 127 const Error& binding_pattern_error() const { return binding_pattern_error_; } | 119 const Error& binding_pattern_error() const { return binding_pattern_error_; } |
| 128 | 120 |
| 129 const Error& assignment_pattern_error() const { | 121 const Error& assignment_pattern_error() const { |
| 130 return assignment_pattern_error_; | 122 return assignment_pattern_error_; |
| 131 } | 123 } |
| 132 | 124 |
| 133 const Error& arrow_formal_parameters_error() const { | 125 const Error& arrow_formal_parameters_error() const { |
| 134 return arrow_formal_parameters_error_; | 126 return arrow_formal_parameters_error_; |
| 135 } | 127 } |
| 136 | 128 |
| 137 const Error& duplicate_formal_parameter_error() const { | 129 const Error& duplicate_formal_parameter_error() const { |
| 138 return duplicate_formal_parameter_error_; | 130 return duplicate_formal_parameter_error_; |
| 139 } | 131 } |
| 140 | 132 |
| 141 const Error& strict_mode_formal_parameter_error() const { | 133 const Error& strict_mode_formal_parameter_error() const { |
| 142 return strict_mode_formal_parameter_error_; | 134 return strict_mode_formal_parameter_error_; |
| 143 } | 135 } |
| 144 | 136 |
| 145 const Error& strong_mode_formal_parameter_error() const { | |
| 146 return strong_mode_formal_parameter_error_; | |
| 147 } | |
| 148 | |
| 149 const Error& let_pattern_error() const { return let_pattern_error_; } | 137 const Error& let_pattern_error() const { return let_pattern_error_; } |
| 150 | 138 |
| 151 bool has_cover_initialized_name() const { | 139 bool has_cover_initialized_name() const { |
| 152 return !is_valid(CoverInitializedNameProduction); | 140 return !is_valid(CoverInitializedNameProduction); |
| 153 } | 141 } |
| 154 const Error& cover_initialized_name_error() const { | 142 const Error& cover_initialized_name_error() const { |
| 155 return cover_initialized_name_error_; | 143 return cover_initialized_name_error_; |
| 156 } | 144 } |
| 157 | 145 |
| 158 bool is_simple_parameter_list() const { | 146 bool is_simple_parameter_list() const { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 void RecordStrictModeFormalParameterError(const Scanner::Location& loc, | 233 void RecordStrictModeFormalParameterError(const Scanner::Location& loc, |
| 246 MessageTemplate::Template message, | 234 MessageTemplate::Template message, |
| 247 const char* arg = nullptr) { | 235 const char* arg = nullptr) { |
| 248 if (!is_valid_strict_mode_formal_parameters()) return; | 236 if (!is_valid_strict_mode_formal_parameters()) return; |
| 249 invalid_productions_ |= StrictModeFormalParametersProduction; | 237 invalid_productions_ |= StrictModeFormalParametersProduction; |
| 250 strict_mode_formal_parameter_error_.location = loc; | 238 strict_mode_formal_parameter_error_.location = loc; |
| 251 strict_mode_formal_parameter_error_.message = message; | 239 strict_mode_formal_parameter_error_.message = message; |
| 252 strict_mode_formal_parameter_error_.arg = arg; | 240 strict_mode_formal_parameter_error_.arg = arg; |
| 253 } | 241 } |
| 254 | 242 |
| 255 void RecordStrongModeFormalParameterError(const Scanner::Location& loc, | |
| 256 MessageTemplate::Template message, | |
| 257 const char* arg = nullptr) { | |
| 258 if (!is_valid_strong_mode_formal_parameters()) return; | |
| 259 invalid_productions_ |= StrongModeFormalParametersProduction; | |
| 260 strong_mode_formal_parameter_error_.location = loc; | |
| 261 strong_mode_formal_parameter_error_.message = message; | |
| 262 strong_mode_formal_parameter_error_.arg = arg; | |
| 263 } | |
| 264 | |
| 265 void RecordLetPatternError(const Scanner::Location& loc, | 243 void RecordLetPatternError(const Scanner::Location& loc, |
| 266 MessageTemplate::Template message, | 244 MessageTemplate::Template message, |
| 267 const char* arg = nullptr) { | 245 const char* arg = nullptr) { |
| 268 if (!is_valid_let_pattern()) return; | 246 if (!is_valid_let_pattern()) return; |
| 269 invalid_productions_ |= LetPatternProduction; | 247 invalid_productions_ |= LetPatternProduction; |
| 270 let_pattern_error_.location = loc; | 248 let_pattern_error_.location = loc; |
| 271 let_pattern_error_.message = message; | 249 let_pattern_error_.message = message; |
| 272 let_pattern_error_.arg = arg; | 250 let_pattern_error_.arg = arg; |
| 273 } | 251 } |
| 274 | 252 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 if (errors & BindingPatternProduction) | 294 if (errors & BindingPatternProduction) |
| 317 binding_pattern_error_ = inner->binding_pattern_error_; | 295 binding_pattern_error_ = inner->binding_pattern_error_; |
| 318 if (errors & AssignmentPatternProduction) | 296 if (errors & AssignmentPatternProduction) |
| 319 assignment_pattern_error_ = inner->assignment_pattern_error_; | 297 assignment_pattern_error_ = inner->assignment_pattern_error_; |
| 320 if (errors & DistinctFormalParametersProduction) | 298 if (errors & DistinctFormalParametersProduction) |
| 321 duplicate_formal_parameter_error_ = | 299 duplicate_formal_parameter_error_ = |
| 322 inner->duplicate_formal_parameter_error_; | 300 inner->duplicate_formal_parameter_error_; |
| 323 if (errors & StrictModeFormalParametersProduction) | 301 if (errors & StrictModeFormalParametersProduction) |
| 324 strict_mode_formal_parameter_error_ = | 302 strict_mode_formal_parameter_error_ = |
| 325 inner->strict_mode_formal_parameter_error_; | 303 inner->strict_mode_formal_parameter_error_; |
| 326 if (errors & StrongModeFormalParametersProduction) | |
| 327 strong_mode_formal_parameter_error_ = | |
| 328 inner->strong_mode_formal_parameter_error_; | |
| 329 if (errors & LetPatternProduction) | 304 if (errors & LetPatternProduction) |
| 330 let_pattern_error_ = inner->let_pattern_error_; | 305 let_pattern_error_ = inner->let_pattern_error_; |
| 331 if (errors & CoverInitializedNameProduction) | 306 if (errors & CoverInitializedNameProduction) |
| 332 cover_initialized_name_error_ = inner->cover_initialized_name_error_; | 307 cover_initialized_name_error_ = inner->cover_initialized_name_error_; |
| 333 } | 308 } |
| 334 | 309 |
| 335 // As an exception to the above, the result continues to be a valid arrow | 310 // As an exception to the above, the result continues to be a valid arrow |
| 336 // formal parameters if the inner expression is a valid binding pattern. | 311 // formal parameters if the inner expression is a valid binding pattern. |
| 337 if (productions & ArrowFormalParametersProduction && | 312 if (productions & ArrowFormalParametersProduction && |
| 338 is_valid_arrow_formal_parameters()) { | 313 is_valid_arrow_formal_parameters()) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 365 int non_pattern_begin_; | 340 int non_pattern_begin_; |
| 366 unsigned invalid_productions_; | 341 unsigned invalid_productions_; |
| 367 unsigned function_properties_; | 342 unsigned function_properties_; |
| 368 Error expression_error_; | 343 Error expression_error_; |
| 369 Error formal_parameter_initializer_error_; | 344 Error formal_parameter_initializer_error_; |
| 370 Error binding_pattern_error_; | 345 Error binding_pattern_error_; |
| 371 Error assignment_pattern_error_; | 346 Error assignment_pattern_error_; |
| 372 Error arrow_formal_parameters_error_; | 347 Error arrow_formal_parameters_error_; |
| 373 Error duplicate_formal_parameter_error_; | 348 Error duplicate_formal_parameter_error_; |
| 374 Error strict_mode_formal_parameter_error_; | 349 Error strict_mode_formal_parameter_error_; |
| 375 Error strong_mode_formal_parameter_error_; | |
| 376 Error let_pattern_error_; | 350 Error let_pattern_error_; |
| 377 Error cover_initialized_name_error_; | 351 Error cover_initialized_name_error_; |
| 378 DuplicateFinder* duplicate_finder_; | 352 DuplicateFinder* duplicate_finder_; |
| 379 }; | 353 }; |
| 380 | 354 |
| 381 | 355 |
| 382 } // namespace internal | 356 } // namespace internal |
| 383 } // namespace v8 | 357 } // namespace v8 |
| 384 | 358 |
| 385 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 359 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
| OLD | NEW |