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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 enum TargetProduction { | 29 enum TargetProduction { |
30 ExpressionProduction = 1 << 0, | 30 ExpressionProduction = 1 << 0, |
31 FormalParameterInitializerProduction = 1 << 1, | 31 FormalParameterInitializerProduction = 1 << 1, |
32 BindingPatternProduction = 1 << 2, | 32 BindingPatternProduction = 1 << 2, |
33 AssignmentPatternProduction = 1 << 3, | 33 AssignmentPatternProduction = 1 << 3, |
34 DistinctFormalParametersProduction = 1 << 4, | 34 DistinctFormalParametersProduction = 1 << 4, |
35 StrictModeFormalParametersProduction = 1 << 5, | 35 StrictModeFormalParametersProduction = 1 << 5, |
36 StrongModeFormalParametersProduction = 1 << 6, | 36 StrongModeFormalParametersProduction = 1 << 6, |
37 ArrowFormalParametersProduction = 1 << 7, | 37 ArrowFormalParametersProduction = 1 << 7, |
| 38 LetPatternProduction = 1 << 8, |
38 | 39 |
39 ExpressionProductions = | 40 ExpressionProductions = |
40 (ExpressionProduction | FormalParameterInitializerProduction), | 41 (ExpressionProduction | FormalParameterInitializerProduction), |
41 PatternProductions = | 42 PatternProductions = (BindingPatternProduction | |
42 (BindingPatternProduction | AssignmentPatternProduction), | 43 AssignmentPatternProduction | LetPatternProduction), |
43 FormalParametersProductions = (DistinctFormalParametersProduction | | 44 FormalParametersProductions = (DistinctFormalParametersProduction | |
44 StrictModeFormalParametersProduction | | 45 StrictModeFormalParametersProduction | |
45 StrongModeFormalParametersProduction), | 46 StrongModeFormalParametersProduction), |
46 StandardProductions = ExpressionProductions | PatternProductions, | 47 StandardProductions = ExpressionProductions | PatternProductions, |
47 AllProductions = (StandardProductions | FormalParametersProductions | | 48 AllProductions = (StandardProductions | FormalParametersProductions | |
48 ArrowFormalParametersProduction) | 49 ArrowFormalParametersProduction) |
49 }; | 50 }; |
50 | 51 |
51 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; | 52 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; |
52 | 53 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 bool is_valid_strict_mode_formal_parameters() const { | 94 bool is_valid_strict_mode_formal_parameters() const { |
94 return is_valid(StrictModeFormalParametersProduction); | 95 return is_valid(StrictModeFormalParametersProduction); |
95 } | 96 } |
96 | 97 |
97 // Note: callers should also check is_valid_strict_mode_formal_parameters() | 98 // Note: callers should also check is_valid_strict_mode_formal_parameters() |
98 // and is_valid_formal_parameter_list_without_duplicates(). | 99 // and is_valid_formal_parameter_list_without_duplicates(). |
99 bool is_valid_strong_mode_formal_parameters() const { | 100 bool is_valid_strong_mode_formal_parameters() const { |
100 return is_valid(StrongModeFormalParametersProduction); | 101 return is_valid(StrongModeFormalParametersProduction); |
101 } | 102 } |
102 | 103 |
| 104 bool is_valid_let_pattern() const { return is_valid(LetPatternProduction); } |
| 105 |
103 const Error& expression_error() const { return expression_error_; } | 106 const Error& expression_error() const { return expression_error_; } |
104 | 107 |
105 const Error& formal_parameter_initializer_error() const { | 108 const Error& formal_parameter_initializer_error() const { |
106 return formal_parameter_initializer_error_; | 109 return formal_parameter_initializer_error_; |
107 } | 110 } |
108 | 111 |
109 const Error& binding_pattern_error() const { return binding_pattern_error_; } | 112 const Error& binding_pattern_error() const { return binding_pattern_error_; } |
110 | 113 |
111 const Error& assignment_pattern_error() const { | 114 const Error& assignment_pattern_error() const { |
112 return assignment_pattern_error_; | 115 return assignment_pattern_error_; |
113 } | 116 } |
114 | 117 |
115 const Error& arrow_formal_parameters_error() const { | 118 const Error& arrow_formal_parameters_error() const { |
116 return arrow_formal_parameters_error_; | 119 return arrow_formal_parameters_error_; |
117 } | 120 } |
118 | 121 |
119 const Error& duplicate_formal_parameter_error() const { | 122 const Error& duplicate_formal_parameter_error() const { |
120 return duplicate_formal_parameter_error_; | 123 return duplicate_formal_parameter_error_; |
121 } | 124 } |
122 | 125 |
123 const Error& strict_mode_formal_parameter_error() const { | 126 const Error& strict_mode_formal_parameter_error() const { |
124 return strict_mode_formal_parameter_error_; | 127 return strict_mode_formal_parameter_error_; |
125 } | 128 } |
126 | 129 |
127 const Error& strong_mode_formal_parameter_error() const { | 130 const Error& strong_mode_formal_parameter_error() const { |
128 return strong_mode_formal_parameter_error_; | 131 return strong_mode_formal_parameter_error_; |
129 } | 132 } |
130 | 133 |
| 134 const Error& let_pattern_error() const { return let_pattern_error_; } |
| 135 |
131 bool is_simple_parameter_list() const { | 136 bool is_simple_parameter_list() const { |
132 return !(function_properties_ & NonSimpleParameter); | 137 return !(function_properties_ & NonSimpleParameter); |
133 } | 138 } |
134 | 139 |
135 void RecordNonSimpleParameter() { | 140 void RecordNonSimpleParameter() { |
136 function_properties_ |= NonSimpleParameter; | 141 function_properties_ |= NonSimpleParameter; |
137 } | 142 } |
138 | 143 |
139 void RecordExpressionError(const Scanner::Location& loc, | 144 void RecordExpressionError(const Scanner::Location& loc, |
140 MessageTemplate::Template message, | 145 MessageTemplate::Template message, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 void RecordStrongModeFormalParameterError(const Scanner::Location& loc, | 215 void RecordStrongModeFormalParameterError(const Scanner::Location& loc, |
211 MessageTemplate::Template message, | 216 MessageTemplate::Template message, |
212 const char* arg = nullptr) { | 217 const char* arg = nullptr) { |
213 if (!is_valid_strong_mode_formal_parameters()) return; | 218 if (!is_valid_strong_mode_formal_parameters()) return; |
214 invalid_productions_ |= StrongModeFormalParametersProduction; | 219 invalid_productions_ |= StrongModeFormalParametersProduction; |
215 strong_mode_formal_parameter_error_.location = loc; | 220 strong_mode_formal_parameter_error_.location = loc; |
216 strong_mode_formal_parameter_error_.message = message; | 221 strong_mode_formal_parameter_error_.message = message; |
217 strong_mode_formal_parameter_error_.arg = arg; | 222 strong_mode_formal_parameter_error_.arg = arg; |
218 } | 223 } |
219 | 224 |
| 225 void RecordLetPatternError(const Scanner::Location& loc, |
| 226 MessageTemplate::Template message, |
| 227 const char* arg = nullptr) { |
| 228 if (!is_valid_let_pattern()) return; |
| 229 invalid_productions_ |= LetPatternProduction; |
| 230 let_pattern_error_.location = loc; |
| 231 let_pattern_error_.message = message; |
| 232 let_pattern_error_.arg = arg; |
| 233 } |
| 234 |
220 void Accumulate(const ExpressionClassifier& inner, | 235 void Accumulate(const ExpressionClassifier& inner, |
221 unsigned productions = StandardProductions) { | 236 unsigned productions = StandardProductions) { |
222 // Propagate errors from inner, but don't overwrite already recorded | 237 // Propagate errors from inner, but don't overwrite already recorded |
223 // errors. | 238 // errors. |
224 unsigned non_arrow_inner_invalid_productions = | 239 unsigned non_arrow_inner_invalid_productions = |
225 inner.invalid_productions_ & ~ArrowFormalParametersProduction; | 240 inner.invalid_productions_ & ~ArrowFormalParametersProduction; |
226 if (non_arrow_inner_invalid_productions == 0) return; | 241 if (non_arrow_inner_invalid_productions == 0) return; |
227 unsigned non_arrow_productions = | 242 unsigned non_arrow_productions = |
228 productions & ~ArrowFormalParametersProduction; | 243 productions & ~ArrowFormalParametersProduction; |
229 unsigned errors = | 244 unsigned errors = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 unsigned invalid_productions_; | 285 unsigned invalid_productions_; |
271 unsigned function_properties_; | 286 unsigned function_properties_; |
272 Error expression_error_; | 287 Error expression_error_; |
273 Error formal_parameter_initializer_error_; | 288 Error formal_parameter_initializer_error_; |
274 Error binding_pattern_error_; | 289 Error binding_pattern_error_; |
275 Error assignment_pattern_error_; | 290 Error assignment_pattern_error_; |
276 Error arrow_formal_parameters_error_; | 291 Error arrow_formal_parameters_error_; |
277 Error duplicate_formal_parameter_error_; | 292 Error duplicate_formal_parameter_error_; |
278 Error strict_mode_formal_parameter_error_; | 293 Error strict_mode_formal_parameter_error_; |
279 Error strong_mode_formal_parameter_error_; | 294 Error strong_mode_formal_parameter_error_; |
| 295 Error let_pattern_error_; |
280 DuplicateFinder* duplicate_finder_; | 296 DuplicateFinder* duplicate_finder_; |
281 }; | 297 }; |
282 | 298 |
283 } // namespace internal | 299 } // namespace internal |
284 } // namespace v8 | 300 } // namespace v8 |
285 | 301 |
286 #endif // V8_EXPRESSION_CLASSIFIER_H | 302 #endif // V8_EXPRESSION_CLASSIFIER_H |
OLD | NEW |