| 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/messages.h" | 8 #include "src/messages.h" |
| 9 #include "src/scanner.h" | 9 #include "src/scanner.h" |
| 10 #include "src/token.h" | 10 #include "src/token.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 message(MessageTemplate::kNone), | 21 message(MessageTemplate::kNone), |
| 22 arg(nullptr) {} | 22 arg(nullptr) {} |
| 23 | 23 |
| 24 Scanner::Location location; | 24 Scanner::Location location; |
| 25 MessageTemplate::Template message; | 25 MessageTemplate::Template message; |
| 26 const char* arg; | 26 const char* arg; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 enum TargetProduction { | 29 enum TargetProduction { |
| 30 ExpressionProduction = 1 << 0, | 30 ExpressionProduction = 1 << 0, |
| 31 BindingPatternProduction = 1 << 1, | 31 FormalParameterInitializerProduction = 1 << 1, |
| 32 AssignmentPatternProduction = 1 << 2, | 32 BindingPatternProduction = 1 << 2, |
| 33 DistinctFormalParametersProduction = 1 << 3, | 33 AssignmentPatternProduction = 1 << 3, |
| 34 StrictModeFormalParametersProduction = 1 << 4, | 34 DistinctFormalParametersProduction = 1 << 4, |
| 35 StrongModeFormalParametersProduction = 1 << 5, | 35 StrictModeFormalParametersProduction = 1 << 5, |
| 36 ArrowFormalParametersProduction = 1 << 6, | 36 StrongModeFormalParametersProduction = 1 << 6, |
| 37 ArrowFormalParametersProduction = 1 << 7, |
| 37 | 38 |
| 39 ExpressionProductions = |
| 40 (ExpressionProduction | FormalParameterInitializerProduction), |
| 38 PatternProductions = | 41 PatternProductions = |
| 39 (BindingPatternProduction | AssignmentPatternProduction), | 42 (BindingPatternProduction | AssignmentPatternProduction), |
| 40 FormalParametersProductions = (DistinctFormalParametersProduction | | 43 FormalParametersProductions = (DistinctFormalParametersProduction | |
| 41 StrictModeFormalParametersProduction | | 44 StrictModeFormalParametersProduction | |
| 42 StrongModeFormalParametersProduction), | 45 StrongModeFormalParametersProduction), |
| 43 StandardProductions = ExpressionProduction | PatternProductions, | 46 StandardProductions = ExpressionProductions | PatternProductions, |
| 44 AllProductions = (StandardProductions | FormalParametersProductions | | 47 AllProductions = (StandardProductions | FormalParametersProductions | |
| 45 ArrowFormalParametersProduction) | 48 ArrowFormalParametersProduction) |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; | 51 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; |
| 49 | 52 |
| 50 ExpressionClassifier() | 53 ExpressionClassifier() |
| 51 : invalid_productions_(0), | 54 : invalid_productions_(0), |
| 52 function_properties_(0), | 55 function_properties_(0), |
| 53 duplicate_finder_(nullptr) {} | 56 duplicate_finder_(nullptr) {} |
| 54 | 57 |
| 55 explicit ExpressionClassifier(DuplicateFinder* duplicate_finder) | 58 explicit ExpressionClassifier(DuplicateFinder* duplicate_finder) |
| 56 : invalid_productions_(0), | 59 : invalid_productions_(0), |
| 57 function_properties_(0), | 60 function_properties_(0), |
| 58 duplicate_finder_(duplicate_finder) {} | 61 duplicate_finder_(duplicate_finder) {} |
| 59 | 62 |
| 60 bool is_valid(unsigned productions) const { | 63 bool is_valid(unsigned productions) const { |
| 61 return (invalid_productions_ & productions) == 0; | 64 return (invalid_productions_ & productions) == 0; |
| 62 } | 65 } |
| 63 | 66 |
| 64 DuplicateFinder* duplicate_finder() const { return duplicate_finder_; } | 67 DuplicateFinder* duplicate_finder() const { return duplicate_finder_; } |
| 65 | 68 |
| 66 bool is_valid_expression() const { return is_valid(ExpressionProduction); } | 69 bool is_valid_expression() const { return is_valid(ExpressionProduction); } |
| 67 | 70 |
| 71 bool is_valid_formal_parameter_initializer() const { |
| 72 return is_valid(FormalParameterInitializerProduction); |
| 73 } |
| 74 |
| 68 bool is_valid_binding_pattern() const { | 75 bool is_valid_binding_pattern() const { |
| 69 return is_valid(BindingPatternProduction); | 76 return is_valid(BindingPatternProduction); |
| 70 } | 77 } |
| 71 | 78 |
| 72 bool is_valid_assignment_pattern() const { | 79 bool is_valid_assignment_pattern() const { |
| 73 return is_valid(AssignmentPatternProduction); | 80 return is_valid(AssignmentPatternProduction); |
| 74 } | 81 } |
| 75 | 82 |
| 76 bool is_valid_arrow_formal_parameters() const { | 83 bool is_valid_arrow_formal_parameters() const { |
| 77 return is_valid(ArrowFormalParametersProduction); | 84 return is_valid(ArrowFormalParametersProduction); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 } | 95 } |
| 89 | 96 |
| 90 // Note: callers should also check is_valid_strict_mode_formal_parameters() | 97 // Note: callers should also check is_valid_strict_mode_formal_parameters() |
| 91 // and is_valid_formal_parameter_list_without_duplicates(). | 98 // and is_valid_formal_parameter_list_without_duplicates(). |
| 92 bool is_valid_strong_mode_formal_parameters() const { | 99 bool is_valid_strong_mode_formal_parameters() const { |
| 93 return is_valid(StrongModeFormalParametersProduction); | 100 return is_valid(StrongModeFormalParametersProduction); |
| 94 } | 101 } |
| 95 | 102 |
| 96 const Error& expression_error() const { return expression_error_; } | 103 const Error& expression_error() const { return expression_error_; } |
| 97 | 104 |
| 105 const Error& formal_parameter_initializer_error() const { |
| 106 return formal_parameter_initializer_error_; |
| 107 } |
| 108 |
| 98 const Error& binding_pattern_error() const { return binding_pattern_error_; } | 109 const Error& binding_pattern_error() const { return binding_pattern_error_; } |
| 99 | 110 |
| 100 const Error& assignment_pattern_error() const { | 111 const Error& assignment_pattern_error() const { |
| 101 return assignment_pattern_error_; | 112 return assignment_pattern_error_; |
| 102 } | 113 } |
| 103 | 114 |
| 104 const Error& arrow_formal_parameters_error() const { | 115 const Error& arrow_formal_parameters_error() const { |
| 105 return arrow_formal_parameters_error_; | 116 return arrow_formal_parameters_error_; |
| 106 } | 117 } |
| 107 | 118 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 128 void RecordExpressionError(const Scanner::Location& loc, | 139 void RecordExpressionError(const Scanner::Location& loc, |
| 129 MessageTemplate::Template message, | 140 MessageTemplate::Template message, |
| 130 const char* arg = nullptr) { | 141 const char* arg = nullptr) { |
| 131 if (!is_valid_expression()) return; | 142 if (!is_valid_expression()) return; |
| 132 invalid_productions_ |= ExpressionProduction; | 143 invalid_productions_ |= ExpressionProduction; |
| 133 expression_error_.location = loc; | 144 expression_error_.location = loc; |
| 134 expression_error_.message = message; | 145 expression_error_.message = message; |
| 135 expression_error_.arg = arg; | 146 expression_error_.arg = arg; |
| 136 } | 147 } |
| 137 | 148 |
| 149 void RecordFormalParameterInitializerError(const Scanner::Location& loc, |
| 150 MessageTemplate::Template message, |
| 151 const char* arg = nullptr) { |
| 152 if (!is_valid_formal_parameter_initializer()) return; |
| 153 invalid_productions_ |= FormalParameterInitializerProduction; |
| 154 formal_parameter_initializer_error_.location = loc; |
| 155 formal_parameter_initializer_error_.message = message; |
| 156 formal_parameter_initializer_error_.arg = arg; |
| 157 } |
| 158 |
| 138 void RecordBindingPatternError(const Scanner::Location& loc, | 159 void RecordBindingPatternError(const Scanner::Location& loc, |
| 139 MessageTemplate::Template message, | 160 MessageTemplate::Template message, |
| 140 const char* arg = nullptr) { | 161 const char* arg = nullptr) { |
| 141 if (!is_valid_binding_pattern()) return; | 162 if (!is_valid_binding_pattern()) return; |
| 142 invalid_productions_ |= BindingPatternProduction; | 163 invalid_productions_ |= BindingPatternProduction; |
| 143 binding_pattern_error_.location = loc; | 164 binding_pattern_error_.location = loc; |
| 144 binding_pattern_error_.message = message; | 165 binding_pattern_error_.message = message; |
| 145 binding_pattern_error_.arg = arg; | 166 binding_pattern_error_.arg = arg; |
| 146 } | 167 } |
| 147 | 168 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 if (non_arrow_inner_invalid_productions == 0) return; | 226 if (non_arrow_inner_invalid_productions == 0) return; |
| 206 unsigned non_arrow_productions = | 227 unsigned non_arrow_productions = |
| 207 productions & ~ArrowFormalParametersProduction; | 228 productions & ~ArrowFormalParametersProduction; |
| 208 unsigned errors = | 229 unsigned errors = |
| 209 non_arrow_productions & non_arrow_inner_invalid_productions; | 230 non_arrow_productions & non_arrow_inner_invalid_productions; |
| 210 errors &= ~invalid_productions_; | 231 errors &= ~invalid_productions_; |
| 211 if (errors != 0) { | 232 if (errors != 0) { |
| 212 invalid_productions_ |= errors; | 233 invalid_productions_ |= errors; |
| 213 if (errors & ExpressionProduction) | 234 if (errors & ExpressionProduction) |
| 214 expression_error_ = inner.expression_error_; | 235 expression_error_ = inner.expression_error_; |
| 236 if (errors & FormalParameterInitializerProduction) |
| 237 formal_parameter_initializer_error_ = |
| 238 inner.formal_parameter_initializer_error_; |
| 215 if (errors & BindingPatternProduction) | 239 if (errors & BindingPatternProduction) |
| 216 binding_pattern_error_ = inner.binding_pattern_error_; | 240 binding_pattern_error_ = inner.binding_pattern_error_; |
| 217 if (errors & AssignmentPatternProduction) | 241 if (errors & AssignmentPatternProduction) |
| 218 assignment_pattern_error_ = inner.assignment_pattern_error_; | 242 assignment_pattern_error_ = inner.assignment_pattern_error_; |
| 219 if (errors & DistinctFormalParametersProduction) | 243 if (errors & DistinctFormalParametersProduction) |
| 220 duplicate_formal_parameter_error_ = | 244 duplicate_formal_parameter_error_ = |
| 221 inner.duplicate_formal_parameter_error_; | 245 inner.duplicate_formal_parameter_error_; |
| 222 if (errors & StrictModeFormalParametersProduction) | 246 if (errors & StrictModeFormalParametersProduction) |
| 223 strict_mode_formal_parameter_error_ = | 247 strict_mode_formal_parameter_error_ = |
| 224 inner.strict_mode_formal_parameter_error_; | 248 inner.strict_mode_formal_parameter_error_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 239 invalid_productions_ |= ArrowFormalParametersProduction; | 263 invalid_productions_ |= ArrowFormalParametersProduction; |
| 240 arrow_formal_parameters_error_ = inner.binding_pattern_error_; | 264 arrow_formal_parameters_error_ = inner.binding_pattern_error_; |
| 241 } | 265 } |
| 242 } | 266 } |
| 243 } | 267 } |
| 244 | 268 |
| 245 private: | 269 private: |
| 246 unsigned invalid_productions_; | 270 unsigned invalid_productions_; |
| 247 unsigned function_properties_; | 271 unsigned function_properties_; |
| 248 Error expression_error_; | 272 Error expression_error_; |
| 273 Error formal_parameter_initializer_error_; |
| 249 Error binding_pattern_error_; | 274 Error binding_pattern_error_; |
| 250 Error assignment_pattern_error_; | 275 Error assignment_pattern_error_; |
| 251 Error arrow_formal_parameters_error_; | 276 Error arrow_formal_parameters_error_; |
| 252 Error duplicate_formal_parameter_error_; | 277 Error duplicate_formal_parameter_error_; |
| 253 Error strict_mode_formal_parameter_error_; | 278 Error strict_mode_formal_parameter_error_; |
| 254 Error strong_mode_formal_parameter_error_; | 279 Error strong_mode_formal_parameter_error_; |
| 255 DuplicateFinder* duplicate_finder_; | 280 DuplicateFinder* duplicate_finder_; |
| 256 }; | 281 }; |
| 257 } | 282 } |
| 258 } // v8::internal | 283 } // v8::internal |
| 259 | 284 |
| 260 #endif // V8_EXPRESSION_CLASSIFIER_H | 285 #endif // V8_EXPRESSION_CLASSIFIER_H |
| OLD | NEW |