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" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 | 15 #define ERROR_CODES(T) \ |
16 #define ERROR_CODES(T) \ | 16 T(ExpressionProduction, 0) \ |
17 T(ExpressionProduction, 0) \ | 17 T(FormalParameterInitializerProduction, 1) \ |
18 T(FormalParameterInitializerProduction, 1) \ | 18 T(BindingPatternProduction, 2) \ |
19 T(BindingPatternProduction, 2) \ | 19 T(AssignmentPatternProduction, 3) \ |
20 T(AssignmentPatternProduction, 3) \ | 20 T(DistinctFormalParametersProduction, 4) \ |
21 T(DistinctFormalParametersProduction, 4) \ | 21 T(StrictModeFormalParametersProduction, 5) \ |
22 T(StrictModeFormalParametersProduction, 5) \ | 22 T(ArrowFormalParametersProduction, 6) \ |
23 T(ArrowFormalParametersProduction, 6) \ | 23 T(LetPatternProduction, 7) \ |
24 T(LetPatternProduction, 7) \ | 24 T(CoverInitializedNameProduction, 8) \ |
25 T(CoverInitializedNameProduction, 8) \ | 25 T(TailCallExpressionProduction, 9) \ |
26 T(TailCallExpressionProduction, 9) \ | 26 T(AsyncArrowFormalParametersProduction, 10) |
27 T(AsyncArrowFormalParametersProduction, 10) \ | |
28 T(AsyncBindingPatternProduction, 11) | |
29 | |
30 | 27 |
31 template <typename Traits> | 28 template <typename Traits> |
32 class ExpressionClassifier { | 29 class ExpressionClassifier { |
33 public: | 30 public: |
34 enum ErrorKind : unsigned { | 31 enum ErrorKind : unsigned { |
35 #define DEFINE_ERROR_KIND(NAME, CODE) k##NAME = CODE, | 32 #define DEFINE_ERROR_KIND(NAME, CODE) k##NAME = CODE, |
36 ERROR_CODES(DEFINE_ERROR_KIND) | 33 ERROR_CODES(DEFINE_ERROR_KIND) |
37 #undef DEFINE_ERROR_KIND | 34 #undef DEFINE_ERROR_KIND |
38 kUnusedError = 15 // Larger than error codes; should fit in 4 bits | 35 kUnusedError = 15 // Larger than error codes; should fit in 4 bits |
39 }; | 36 }; |
(...skipping 19 matching lines...) Expand all Loading... |
59 }; | 56 }; |
60 | 57 |
61 enum TargetProduction : unsigned { | 58 enum TargetProduction : unsigned { |
62 #define DEFINE_PRODUCTION(NAME, CODE) NAME = 1 << CODE, | 59 #define DEFINE_PRODUCTION(NAME, CODE) NAME = 1 << CODE, |
63 ERROR_CODES(DEFINE_PRODUCTION) | 60 ERROR_CODES(DEFINE_PRODUCTION) |
64 #undef DEFINE_PRODUCTION | 61 #undef DEFINE_PRODUCTION |
65 | 62 |
66 ExpressionProductions = | 63 ExpressionProductions = |
67 (ExpressionProduction | FormalParameterInitializerProduction | | 64 (ExpressionProduction | FormalParameterInitializerProduction | |
68 TailCallExpressionProduction), | 65 TailCallExpressionProduction), |
69 PatternProductions = | 66 PatternProductions = (BindingPatternProduction | |
70 (BindingPatternProduction | AssignmentPatternProduction | | 67 AssignmentPatternProduction | LetPatternProduction), |
71 LetPatternProduction | AsyncBindingPatternProduction), | |
72 FormalParametersProductions = (DistinctFormalParametersProduction | | 68 FormalParametersProductions = (DistinctFormalParametersProduction | |
73 StrictModeFormalParametersProduction), | 69 StrictModeFormalParametersProduction), |
74 AllProductions = | 70 AllProductions = |
75 (ExpressionProductions | PatternProductions | | 71 (ExpressionProductions | PatternProductions | |
76 FormalParametersProductions | ArrowFormalParametersProduction | | 72 FormalParametersProductions | ArrowFormalParametersProduction | |
77 CoverInitializedNameProduction | AsyncArrowFormalParametersProduction) | 73 CoverInitializedNameProduction | AsyncArrowFormalParametersProduction) |
78 }; | 74 }; |
79 | 75 |
80 enum FunctionProperties : unsigned { | 76 enum FunctionProperties : unsigned { |
81 NonSimpleParameter = 1 << 0 | 77 NonSimpleParameter = 1 << 0 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 140 } |
145 | 141 |
146 V8_INLINE bool is_valid_let_pattern() const { | 142 V8_INLINE bool is_valid_let_pattern() const { |
147 return is_valid(LetPatternProduction); | 143 return is_valid(LetPatternProduction); |
148 } | 144 } |
149 | 145 |
150 bool is_valid_async_arrow_formal_parameters() const { | 146 bool is_valid_async_arrow_formal_parameters() const { |
151 return is_valid(AsyncArrowFormalParametersProduction); | 147 return is_valid(AsyncArrowFormalParametersProduction); |
152 } | 148 } |
153 | 149 |
154 bool is_valid_async_binding_pattern() const { | |
155 return is_valid(AsyncBindingPatternProduction); | |
156 } | |
157 | |
158 V8_INLINE const Error& expression_error() const { | 150 V8_INLINE const Error& expression_error() const { |
159 return reported_error(kExpressionProduction); | 151 return reported_error(kExpressionProduction); |
160 } | 152 } |
161 | 153 |
162 V8_INLINE const Error& formal_parameter_initializer_error() const { | 154 V8_INLINE const Error& formal_parameter_initializer_error() const { |
163 return reported_error(kFormalParameterInitializerProduction); | 155 return reported_error(kFormalParameterInitializerProduction); |
164 } | 156 } |
165 | 157 |
166 V8_INLINE const Error& binding_pattern_error() const { | 158 V8_INLINE const Error& binding_pattern_error() const { |
167 return reported_error(kBindingPatternProduction); | 159 return reported_error(kBindingPatternProduction); |
(...skipping 30 matching lines...) Expand all Loading... |
198 V8_INLINE bool has_tail_call_expression() const { | 190 V8_INLINE bool has_tail_call_expression() const { |
199 return !is_valid(TailCallExpressionProduction); | 191 return !is_valid(TailCallExpressionProduction); |
200 } | 192 } |
201 V8_INLINE const Error& tail_call_expression_error() const { | 193 V8_INLINE const Error& tail_call_expression_error() const { |
202 return reported_error(kTailCallExpressionProduction); | 194 return reported_error(kTailCallExpressionProduction); |
203 } | 195 } |
204 V8_INLINE const Error& async_arrow_formal_parameters_error() const { | 196 V8_INLINE const Error& async_arrow_formal_parameters_error() const { |
205 return reported_error(kAsyncArrowFormalParametersProduction); | 197 return reported_error(kAsyncArrowFormalParametersProduction); |
206 } | 198 } |
207 | 199 |
208 V8_INLINE const Error& async_binding_pattern_error() const { | |
209 return reported_error(kAsyncBindingPatternProduction); | |
210 } | |
211 | |
212 V8_INLINE bool is_simple_parameter_list() const { | 200 V8_INLINE bool is_simple_parameter_list() const { |
213 return !(function_properties_ & NonSimpleParameter); | 201 return !(function_properties_ & NonSimpleParameter); |
214 } | 202 } |
215 | 203 |
216 V8_INLINE void RecordNonSimpleParameter() { | 204 V8_INLINE void RecordNonSimpleParameter() { |
217 function_properties_ |= NonSimpleParameter; | 205 function_properties_ |= NonSimpleParameter; |
218 } | 206 } |
219 | 207 |
220 void RecordExpressionError(const Scanner::Location& loc, | 208 void RecordExpressionError(const Scanner::Location& loc, |
221 MessageTemplate::Template message, | 209 MessageTemplate::Template message, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 261 } |
274 | 262 |
275 void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc, | 263 void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc, |
276 MessageTemplate::Template message, | 264 MessageTemplate::Template message, |
277 const char* arg = nullptr) { | 265 const char* arg = nullptr) { |
278 if (!is_valid_async_arrow_formal_parameters()) return; | 266 if (!is_valid_async_arrow_formal_parameters()) return; |
279 invalid_productions_ |= AsyncArrowFormalParametersProduction; | 267 invalid_productions_ |= AsyncArrowFormalParametersProduction; |
280 Add(Error(loc, message, kAsyncArrowFormalParametersProduction, arg)); | 268 Add(Error(loc, message, kAsyncArrowFormalParametersProduction, arg)); |
281 } | 269 } |
282 | 270 |
283 void RecordAsyncBindingPatternError(const Scanner::Location& loc, | |
284 MessageTemplate::Template message, | |
285 const char* arg = nullptr) { | |
286 if (!is_valid_async_binding_pattern()) return; | |
287 invalid_productions_ |= AsyncBindingPatternProduction; | |
288 Add(Error(loc, message, kAsyncBindingPatternProduction, arg)); | |
289 } | |
290 | |
291 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { | 271 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { |
292 if (!is_valid_formal_parameter_list_without_duplicates()) return; | 272 if (!is_valid_formal_parameter_list_without_duplicates()) return; |
293 invalid_productions_ |= DistinctFormalParametersProduction; | 273 invalid_productions_ |= DistinctFormalParametersProduction; |
294 Add(Error(loc, MessageTemplate::kParamDupe, | 274 Add(Error(loc, MessageTemplate::kParamDupe, |
295 kDistinctFormalParametersProduction)); | 275 kDistinctFormalParametersProduction)); |
296 } | 276 } |
297 | 277 |
298 // 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 |
299 // is not the same as StrictFormalParameterList, which simply forbids | 279 // is not the same as StrictFormalParameterList, which simply forbids |
300 // duplicate bindings. | 280 // duplicate bindings. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 }; | 472 }; |
493 | 473 |
494 | 474 |
495 #undef ERROR_CODES | 475 #undef ERROR_CODES |
496 | 476 |
497 | 477 |
498 } // namespace internal | 478 } // namespace internal |
499 } // namespace v8 | 479 } // namespace v8 |
500 | 480 |
501 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 481 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
OLD | NEW |