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/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 }; | 29 }; |
30 | 30 |
31 enum TargetProduction { | 31 enum TargetProduction { |
32 ExpressionProduction = 1 << 0, | 32 ExpressionProduction = 1 << 0, |
33 BindingPatternProduction = 1 << 1, | 33 BindingPatternProduction = 1 << 1, |
34 AssignmentPatternProduction = 1 << 2, | 34 AssignmentPatternProduction = 1 << 2, |
35 DistinctFormalParametersProduction = 1 << 3, | 35 DistinctFormalParametersProduction = 1 << 3, |
36 StrictModeFormalParametersProduction = 1 << 4, | 36 StrictModeFormalParametersProduction = 1 << 4, |
37 StrongModeFormalParametersProduction = 1 << 5, | 37 StrongModeFormalParametersProduction = 1 << 5, |
38 ArrowFormalParametersProduction = 1 << 6, | 38 ArrowFormalParametersProduction = 1 << 6, |
39 // Unlike the others; see note in RecordArrowFormalParametersWithRest. | |
40 ArrowFormalParametersWithRestProduction = 1 << 7, | |
Dmitry Lomov (no reviews)
2015/06/10 11:04:41
I am not too happy about this irregularity. We aro
wingo
2015/06/10 13:21:10
Done.
| |
39 | 41 |
40 PatternProductions = | 42 PatternProductions = |
41 (BindingPatternProduction | AssignmentPatternProduction), | 43 (BindingPatternProduction | AssignmentPatternProduction), |
42 FormalParametersProductions = (DistinctFormalParametersProduction | | 44 FormalParametersProductions = (DistinctFormalParametersProduction | |
43 StrictModeFormalParametersProduction | | 45 StrictModeFormalParametersProduction | |
44 StrongModeFormalParametersProduction), | 46 StrongModeFormalParametersProduction), |
45 StandardProductions = ExpressionProduction | PatternProductions, | 47 StandardProductions = ExpressionProduction | PatternProductions, |
46 AllProductions = (StandardProductions | FormalParametersProductions | | 48 AllProductions = (StandardProductions | FormalParametersProductions | |
47 ArrowFormalParametersProduction) | 49 ArrowFormalParametersProduction) |
48 }; | 50 }; |
(...skipping 17 matching lines...) Expand all Loading... | |
66 } | 68 } |
67 | 69 |
68 bool is_valid_assignment_pattern() const { | 70 bool is_valid_assignment_pattern() const { |
69 return is_valid(AssignmentPatternProduction); | 71 return is_valid(AssignmentPatternProduction); |
70 } | 72 } |
71 | 73 |
72 bool is_valid_arrow_formal_parameters() const { | 74 bool is_valid_arrow_formal_parameters() const { |
73 return is_valid(ArrowFormalParametersProduction); | 75 return is_valid(ArrowFormalParametersProduction); |
74 } | 76 } |
75 | 77 |
78 bool is_arrow_formal_parameters_with_rest() const { | |
79 return (invalid_productions_ & ArrowFormalParametersWithRestProduction) != | |
80 0; | |
81 } | |
82 | |
76 bool is_valid_formal_parameter_list_without_duplicates() const { | 83 bool is_valid_formal_parameter_list_without_duplicates() const { |
77 return is_valid(DistinctFormalParametersProduction); | 84 return is_valid(DistinctFormalParametersProduction); |
78 } | 85 } |
79 | 86 |
80 // Note: callers should also check | 87 // Note: callers should also check |
81 // is_valid_formal_parameter_list_without_duplicates(). | 88 // is_valid_formal_parameter_list_without_duplicates(). |
82 bool is_valid_strict_mode_formal_parameters() const { | 89 bool is_valid_strict_mode_formal_parameters() const { |
83 return is_valid(StrictModeFormalParametersProduction); | 90 return is_valid(StrictModeFormalParametersProduction); |
84 } | 91 } |
85 | 92 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 void RecordArrowFormalParametersError(const Scanner::Location& loc, | 153 void RecordArrowFormalParametersError(const Scanner::Location& loc, |
147 MessageTemplate::Template message, | 154 MessageTemplate::Template message, |
148 const char* arg = nullptr) { | 155 const char* arg = nullptr) { |
149 if (!is_valid_arrow_formal_parameters()) return; | 156 if (!is_valid_arrow_formal_parameters()) return; |
150 invalid_productions_ |= ArrowFormalParametersProduction; | 157 invalid_productions_ |= ArrowFormalParametersProduction; |
151 arrow_formal_parameters_error_.location = loc; | 158 arrow_formal_parameters_error_.location = loc; |
152 arrow_formal_parameters_error_.message = message; | 159 arrow_formal_parameters_error_.message = message; |
153 arrow_formal_parameters_error_.arg = arg; | 160 arrow_formal_parameters_error_.arg = arg; |
154 } | 161 } |
155 | 162 |
163 void RecordArrowFormalParametersWithRest() { | |
164 // Unlike the other TargetProduction flags, | |
165 // ArrowFormalParametersWithRestProduction indicates the presence of a rest | |
166 // parameter, not the presence of an error. It doesn't propagate out via | |
167 // Accumulate() either, and doesn't have an associated location. | |
168 invalid_productions_ |= ArrowFormalParametersWithRestProduction; | |
169 } | |
170 | |
156 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { | 171 void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { |
157 if (!is_valid_formal_parameter_list_without_duplicates()) return; | 172 if (!is_valid_formal_parameter_list_without_duplicates()) return; |
158 invalid_productions_ |= DistinctFormalParametersProduction; | 173 invalid_productions_ |= DistinctFormalParametersProduction; |
159 duplicate_formal_parameter_error_.location = loc; | 174 duplicate_formal_parameter_error_.location = loc; |
160 duplicate_formal_parameter_error_.message = | 175 duplicate_formal_parameter_error_.message = |
161 MessageTemplate::kStrictParamDupe; | 176 MessageTemplate::kStrictParamDupe; |
162 duplicate_formal_parameter_error_.arg = nullptr; | 177 duplicate_formal_parameter_error_.arg = nullptr; |
163 } | 178 } |
164 | 179 |
165 // Record a binding that would be invalid in strict mode. Confusingly this | 180 // Record a binding that would be invalid in strict mode. Confusingly this |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 Error arrow_formal_parameters_error_; | 261 Error arrow_formal_parameters_error_; |
247 Error duplicate_formal_parameter_error_; | 262 Error duplicate_formal_parameter_error_; |
248 Error strict_mode_formal_parameter_error_; | 263 Error strict_mode_formal_parameter_error_; |
249 Error strong_mode_formal_parameter_error_; | 264 Error strong_mode_formal_parameter_error_; |
250 DuplicateFinder* duplicate_finder_; | 265 DuplicateFinder* duplicate_finder_; |
251 }; | 266 }; |
252 } | 267 } |
253 } // v8::internal | 268 } // v8::internal |
254 | 269 |
255 #endif // V8_EXPRESSION_CLASSIFIER_H | 270 #endif // V8_EXPRESSION_CLASSIFIER_H |
OLD | NEW |