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