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 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 class DuplicateFinder; | 14 class DuplicateFinder; |
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(TailCallExpressionProduction, 8) \ | 25 T(AsyncArrowFormalParametersProduction, 8) |
26 T(AsyncArrowFormalParametersProduction, 9) | |
27 | 26 |
28 // Expression classifiers serve two purposes: | 27 // Expression classifiers serve two purposes: |
29 // | 28 // |
30 // 1) They keep track of error messages that are pending (and other | 29 // 1) They keep track of error messages that are pending (and other |
31 // related information), waiting for the parser to decide whether | 30 // related information), waiting for the parser to decide whether |
32 // the parsed expression is a pattern or not. | 31 // the parsed expression is a pattern or not. |
33 // 2) They keep track of expressions that may need to be rewritten, if | 32 // 2) They keep track of expressions that may need to be rewritten, if |
34 // the parser decides that they are not patterns. (A different | 33 // the parser decides that they are not patterns. (A different |
35 // mechanism implements the rewriting of patterns.) | 34 // mechanism implements the rewriting of patterns.) |
36 // | 35 // |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 183 } |
185 | 184 |
186 V8_INLINE const Error& strict_mode_formal_parameter_error() const { | 185 V8_INLINE const Error& strict_mode_formal_parameter_error() const { |
187 return reported_error(kStrictModeFormalParametersProduction); | 186 return reported_error(kStrictModeFormalParametersProduction); |
188 } | 187 } |
189 | 188 |
190 V8_INLINE const Error& let_pattern_error() const { | 189 V8_INLINE const Error& let_pattern_error() const { |
191 return reported_error(kLetPatternProduction); | 190 return reported_error(kLetPatternProduction); |
192 } | 191 } |
193 | 192 |
194 V8_INLINE bool has_tail_call_expression() const { | |
195 return !is_valid(TailCallExpressionProduction); | |
196 } | |
197 V8_INLINE const Error& tail_call_expression_error() const { | |
198 return reported_error(kTailCallExpressionProduction); | |
199 } | |
200 | |
201 V8_INLINE const Error& async_arrow_formal_parameters_error() const { | 193 V8_INLINE const Error& async_arrow_formal_parameters_error() const { |
202 return reported_error(kAsyncArrowFormalParametersProduction); | 194 return reported_error(kAsyncArrowFormalParametersProduction); |
203 } | 195 } |
204 | 196 |
205 V8_INLINE bool is_simple_parameter_list() const { | 197 V8_INLINE bool is_simple_parameter_list() const { |
206 return !(function_properties_ & NonSimpleParameter); | 198 return !(function_properties_ & NonSimpleParameter); |
207 } | 199 } |
208 | 200 |
209 V8_INLINE void RecordNonSimpleParameter() { | 201 V8_INLINE void RecordNonSimpleParameter() { |
210 function_properties_ |= NonSimpleParameter; | 202 function_properties_ |= NonSimpleParameter; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 284 } |
293 | 285 |
294 void RecordLetPatternError(const Scanner::Location& loc, | 286 void RecordLetPatternError(const Scanner::Location& loc, |
295 MessageTemplate::Template message, | 287 MessageTemplate::Template message, |
296 const char* arg = nullptr) { | 288 const char* arg = nullptr) { |
297 if (!is_valid_let_pattern()) return; | 289 if (!is_valid_let_pattern()) return; |
298 invalid_productions_ |= LetPatternProduction; | 290 invalid_productions_ |= LetPatternProduction; |
299 Add(Error(loc, message, kLetPatternProduction, arg)); | 291 Add(Error(loc, message, kLetPatternProduction, arg)); |
300 } | 292 } |
301 | 293 |
302 void RecordTailCallExpressionError(const Scanner::Location& loc, | |
303 MessageTemplate::Template message, | |
304 const char* arg = nullptr) { | |
305 if (has_tail_call_expression()) return; | |
306 invalid_productions_ |= TailCallExpressionProduction; | |
307 Add(Error(loc, message, kTailCallExpressionProduction, arg)); | |
308 } | |
309 | |
310 void Accumulate(ExpressionClassifier* inner, unsigned productions, | 294 void Accumulate(ExpressionClassifier* inner, unsigned productions, |
311 bool merge_non_patterns = true) { | 295 bool merge_non_patterns = true) { |
312 DCHECK_EQ(inner->reported_errors_, reported_errors_); | 296 DCHECK_EQ(inner->reported_errors_, reported_errors_); |
313 DCHECK_EQ(inner->reported_errors_begin_, reported_errors_end_); | 297 DCHECK_EQ(inner->reported_errors_begin_, reported_errors_end_); |
314 DCHECK_EQ(inner->reported_errors_end_, reported_errors_->length()); | 298 DCHECK_EQ(inner->reported_errors_end_, reported_errors_->length()); |
315 DCHECK_EQ(inner->non_patterns_to_rewrite_, non_patterns_to_rewrite_); | 299 DCHECK_EQ(inner->non_patterns_to_rewrite_, non_patterns_to_rewrite_); |
316 DCHECK_LE(non_pattern_begin_, inner->non_pattern_begin_); | 300 DCHECK_LE(non_pattern_begin_, inner->non_pattern_begin_); |
317 DCHECK_LE(inner->non_pattern_begin_, non_patterns_to_rewrite_->length()); | 301 DCHECK_LE(inner->non_pattern_begin_, non_patterns_to_rewrite_->length()); |
318 // Merge non-patterns from the inner classifier, or discard them. | 302 // Merge non-patterns from the inner classifier, or discard them. |
319 if (merge_non_patterns) | 303 if (merge_non_patterns) |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 }; | 450 }; |
467 | 451 |
468 | 452 |
469 #undef ERROR_CODES | 453 #undef ERROR_CODES |
470 | 454 |
471 | 455 |
472 } // namespace internal | 456 } // namespace internal |
473 } // namespace v8 | 457 } // namespace v8 |
474 | 458 |
475 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H | 459 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H |
OLD | NEW |