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 |
16 #define ERROR_CODES(T) \ | 16 #define ERROR_CODES(T) \ |
17 T(ExpressionProduction, 0) \ | 17 T(ExpressionProduction, 0) \ |
18 T(FormalParameterInitializerProduction, 1) \ | 18 T(FormalParameterInitializerProduction, 1) \ |
19 T(BindingPatternProduction, 2) \ | 19 T(BindingPatternProduction, 2) \ |
20 T(AssignmentPatternProduction, 3) \ | 20 T(AssignmentPatternProduction, 3) \ |
21 T(DistinctFormalParametersProduction, 4) \ | 21 T(DistinctFormalParametersProduction, 4) \ |
22 T(StrictModeFormalParametersProduction, 5) \ | 22 T(StrictModeFormalParametersProduction, 5) \ |
23 T(ArrowFormalParametersProduction, 6) \ | 23 T(ArrowFormalParametersProduction, 6) \ |
24 T(LetPatternProduction, 7) \ | 24 T(LetPatternProduction, 7) \ |
25 T(CoverInitializedNameProduction, 8) \ | 25 T(ObjectLiteralProduction, 8) \ |
26 T(TailCallExpressionProduction, 9) \ | 26 T(TailCallExpressionProduction, 9) \ |
27 T(AsyncArrowFormalParametersProduction, 10) \ | 27 T(AsyncArrowFormalParametersProduction, 10) \ |
28 T(AsyncBindingPatternProduction, 11) | 28 T(AsyncBindingPatternProduction, 11) |
29 | 29 |
30 | |
31 template <typename Traits> | 30 template <typename Traits> |
32 class ExpressionClassifier { | 31 class ExpressionClassifier { |
33 public: | 32 public: |
34 enum ErrorKind : unsigned { | 33 enum ErrorKind : unsigned { |
35 #define DEFINE_ERROR_KIND(NAME, CODE) k##NAME = CODE, | 34 #define DEFINE_ERROR_KIND(NAME, CODE) k##NAME = CODE, |
36 ERROR_CODES(DEFINE_ERROR_KIND) | 35 ERROR_CODES(DEFINE_ERROR_KIND) |
37 #undef DEFINE_ERROR_KIND | 36 #undef DEFINE_ERROR_KIND |
38 kUnusedError = 15 // Larger than error codes; should fit in 4 bits | 37 kUnusedError = 15 // Larger than error codes; should fit in 4 bits |
39 }; | 38 }; |
40 | 39 |
(...skipping 26 matching lines...) Expand all Loading... |
67 (ExpressionProduction | FormalParameterInitializerProduction | | 66 (ExpressionProduction | FormalParameterInitializerProduction | |
68 TailCallExpressionProduction), | 67 TailCallExpressionProduction), |
69 PatternProductions = | 68 PatternProductions = |
70 (BindingPatternProduction | AssignmentPatternProduction | | 69 (BindingPatternProduction | AssignmentPatternProduction | |
71 LetPatternProduction | AsyncBindingPatternProduction), | 70 LetPatternProduction | AsyncBindingPatternProduction), |
72 FormalParametersProductions = (DistinctFormalParametersProduction | | 71 FormalParametersProductions = (DistinctFormalParametersProduction | |
73 StrictModeFormalParametersProduction), | 72 StrictModeFormalParametersProduction), |
74 AllProductions = | 73 AllProductions = |
75 (ExpressionProductions | PatternProductions | | 74 (ExpressionProductions | PatternProductions | |
76 FormalParametersProductions | ArrowFormalParametersProduction | | 75 FormalParametersProductions | ArrowFormalParametersProduction | |
77 CoverInitializedNameProduction | AsyncArrowFormalParametersProduction) | 76 ObjectLiteralProduction | AsyncArrowFormalParametersProduction) |
78 }; | 77 }; |
79 | 78 |
80 enum FunctionProperties : unsigned { | 79 enum FunctionProperties : unsigned { |
81 NonSimpleParameter = 1 << 0 | 80 NonSimpleParameter = 1 << 0 |
82 }; | 81 }; |
83 | 82 |
84 explicit ExpressionClassifier(const Traits* t) | 83 explicit ExpressionClassifier(const Traits* t) |
85 : zone_(t->zone()), | 84 : zone_(t->zone()), |
86 non_patterns_to_rewrite_(t->GetNonPatternList()), | 85 non_patterns_to_rewrite_(t->GetNonPatternList()), |
87 reported_errors_(t->GetReportedErrorList()), | 86 reported_errors_(t->GetReportedErrorList()), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 179 } |
181 | 180 |
182 V8_INLINE const Error& strict_mode_formal_parameter_error() const { | 181 V8_INLINE const Error& strict_mode_formal_parameter_error() const { |
183 return reported_error(kStrictModeFormalParametersProduction); | 182 return reported_error(kStrictModeFormalParametersProduction); |
184 } | 183 } |
185 | 184 |
186 V8_INLINE const Error& let_pattern_error() const { | 185 V8_INLINE const Error& let_pattern_error() const { |
187 return reported_error(kLetPatternProduction); | 186 return reported_error(kLetPatternProduction); |
188 } | 187 } |
189 | 188 |
190 V8_INLINE bool has_cover_initialized_name() const { | 189 V8_INLINE bool has_object_literal_error() const { |
191 return !is_valid(CoverInitializedNameProduction); | 190 return !is_valid(ObjectLiteralProduction); |
192 } | 191 } |
193 | 192 |
194 V8_INLINE const Error& cover_initialized_name_error() const { | 193 V8_INLINE const Error& object_literal_error() const { |
195 return reported_error(kCoverInitializedNameProduction); | 194 return reported_error(kObjectLiteralProduction); |
196 } | 195 } |
197 | 196 |
198 V8_INLINE bool has_tail_call_expression() const { | 197 V8_INLINE bool has_tail_call_expression() const { |
199 return !is_valid(TailCallExpressionProduction); | 198 return !is_valid(TailCallExpressionProduction); |
200 } | 199 } |
201 V8_INLINE const Error& tail_call_expression_error() const { | 200 V8_INLINE const Error& tail_call_expression_error() const { |
202 return reported_error(kTailCallExpressionProduction); | 201 return reported_error(kTailCallExpressionProduction); |
203 } | 202 } |
| 203 |
204 V8_INLINE const Error& async_arrow_formal_parameters_error() const { | 204 V8_INLINE const Error& async_arrow_formal_parameters_error() const { |
205 return reported_error(kAsyncArrowFormalParametersProduction); | 205 return reported_error(kAsyncArrowFormalParametersProduction); |
206 } | 206 } |
207 | 207 |
208 V8_INLINE const Error& async_binding_pattern_error() const { | 208 V8_INLINE const Error& async_binding_pattern_error() const { |
209 return reported_error(kAsyncBindingPatternProduction); | 209 return reported_error(kAsyncBindingPatternProduction); |
210 } | 210 } |
211 | 211 |
212 V8_INLINE bool is_simple_parameter_list() const { | 212 V8_INLINE bool is_simple_parameter_list() const { |
213 return !(function_properties_ & NonSimpleParameter); | 213 return !(function_properties_ & NonSimpleParameter); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 void RecordLetPatternError(const Scanner::Location& loc, | 309 void RecordLetPatternError(const Scanner::Location& loc, |
310 MessageTemplate::Template message, | 310 MessageTemplate::Template message, |
311 const char* arg = nullptr) { | 311 const char* arg = nullptr) { |
312 if (!is_valid_let_pattern()) return; | 312 if (!is_valid_let_pattern()) return; |
313 invalid_productions_ |= LetPatternProduction; | 313 invalid_productions_ |= LetPatternProduction; |
314 Add(Error(loc, message, kLetPatternProduction, arg)); | 314 Add(Error(loc, message, kLetPatternProduction, arg)); |
315 } | 315 } |
316 | 316 |
317 void RecordCoverInitializedNameError(const Scanner::Location& loc, | 317 void RecordObjectLiteralError(const Scanner::Location& loc, |
318 MessageTemplate::Template message, | 318 MessageTemplate::Template message, |
319 const char* arg = nullptr) { | 319 const char* arg = nullptr) { |
320 if (has_cover_initialized_name()) return; | 320 if (has_object_literal_error()) return; |
321 invalid_productions_ |= CoverInitializedNameProduction; | 321 invalid_productions_ |= ObjectLiteralProduction; |
322 Add(Error(loc, message, kCoverInitializedNameProduction, arg)); | 322 Add(Error(loc, message, kObjectLiteralProduction, arg)); |
323 } | 323 } |
324 | 324 |
325 void RecordTailCallExpressionError(const Scanner::Location& loc, | 325 void RecordTailCallExpressionError(const Scanner::Location& loc, |
326 MessageTemplate::Template message, | 326 MessageTemplate::Template message, |
327 const char* arg = nullptr) { | 327 const char* arg = nullptr) { |
328 if (has_tail_call_expression()) return; | 328 if (has_tail_call_expression()) return; |
329 invalid_productions_ |= TailCallExpressionProduction; | 329 invalid_productions_ |= TailCallExpressionProduction; |
330 Add(Error(loc, message, kTailCallExpressionProduction, arg)); | 330 Add(Error(loc, message, kTailCallExpressionProduction, arg)); |
331 } | 331 } |
332 | 332 |
333 void ForgiveCoverInitializedNameError() { | 333 void ForgiveObjectLiteralError() { |
334 if (!(invalid_productions_ & CoverInitializedNameProduction)) return; | 334 if (!(invalid_productions_ & ObjectLiteralProduction)) return; |
335 Error& e = reported_error(kCoverInitializedNameProduction); | 335 Error& e = reported_error(kObjectLiteralProduction); |
336 e.kind = kUnusedError; | 336 e.kind = kUnusedError; |
337 invalid_productions_ &= ~CoverInitializedNameProduction; | 337 invalid_productions_ &= ~ObjectLiteralProduction; |
338 } | 338 } |
339 | 339 |
340 void ForgiveAssignmentPatternError() { | 340 void ForgiveAssignmentPatternError() { |
341 if (!(invalid_productions_ & AssignmentPatternProduction)) return; | 341 if (!(invalid_productions_ & AssignmentPatternProduction)) return; |
342 Error& e = reported_error(kAssignmentPatternProduction); | 342 Error& e = reported_error(kAssignmentPatternProduction); |
343 e.kind = kUnusedError; | 343 e.kind = kUnusedError; |
344 invalid_productions_ &= ~AssignmentPatternProduction; | 344 invalid_productions_ &= ~AssignmentPatternProduction; |
345 } | 345 } |
346 | 346 |
347 void Accumulate(ExpressionClassifier* inner, unsigned productions, | 347 void Accumulate(ExpressionClassifier* inner, unsigned productions, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 }; | 492 }; |
493 | 493 |
494 | 494 |
495 #undef ERROR_CODES | 495 #undef ERROR_CODES |
496 | 496 |
497 | 497 |
498 } // namespace internal | 498 } // namespace internal |
499 } // namespace v8 | 499 } // namespace v8 |
500 | 500 |
501 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 501 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
OLD | NEW |