Chromium Code Reviews| 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/messages.h" | 8 #include "src/messages.h" |
| 9 #include "src/scanner.h" | 9 #include "src/scanner.h" |
| 10 #include "src/token.h" | 10 #include "src/token.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 PatternProductions = | 38 PatternProductions = |
| 39 (BindingPatternProduction | AssignmentPatternProduction), | 39 (BindingPatternProduction | AssignmentPatternProduction), |
| 40 FormalParametersProductions = (DistinctFormalParametersProduction | | 40 FormalParametersProductions = (DistinctFormalParametersProduction | |
| 41 StrictModeFormalParametersProduction | | 41 StrictModeFormalParametersProduction | |
| 42 StrongModeFormalParametersProduction), | 42 StrongModeFormalParametersProduction), |
| 43 StandardProductions = ExpressionProduction | PatternProductions, | 43 StandardProductions = ExpressionProduction | PatternProductions, |
| 44 AllProductions = (StandardProductions | FormalParametersProductions | | 44 AllProductions = (StandardProductions | FormalParametersProductions | |
| 45 ArrowFormalParametersProduction) | 45 ArrowFormalParametersProduction) |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 enum FunctionProperties { NonSimpleParameter = 1 << 0 }; | |
| 49 | |
| 48 ExpressionClassifier() | 50 ExpressionClassifier() |
| 49 : invalid_productions_(0), duplicate_finder_(nullptr) {} | 51 : invalid_productions_(0), |
| 52 function_properties_(0), | |
| 53 duplicate_finder_(nullptr) {} | |
| 50 | 54 |
| 51 explicit ExpressionClassifier(DuplicateFinder* duplicate_finder) | 55 explicit ExpressionClassifier(DuplicateFinder* duplicate_finder) |
| 52 : invalid_productions_(0), duplicate_finder_(duplicate_finder) {} | 56 : invalid_productions_(0), |
| 57 function_properties_(0), | |
| 58 duplicate_finder_(duplicate_finder) {} | |
| 53 | 59 |
| 54 bool is_valid(unsigned productions) const { | 60 bool is_valid(unsigned productions) const { |
| 55 return (invalid_productions_ & productions) == 0; | 61 return (invalid_productions_ & productions) == 0; |
| 56 } | 62 } |
| 57 | 63 |
| 58 DuplicateFinder* duplicate_finder() const { return duplicate_finder_; } | 64 DuplicateFinder* duplicate_finder() const { return duplicate_finder_; } |
| 59 | 65 |
| 60 bool is_valid_expression() const { return is_valid(ExpressionProduction); } | 66 bool is_valid_expression() const { return is_valid(ExpressionProduction); } |
| 61 | 67 |
| 62 bool is_valid_binding_pattern() const { | 68 bool is_valid_binding_pattern() const { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 } | 110 } |
| 105 | 111 |
| 106 const Error& strict_mode_formal_parameter_error() const { | 112 const Error& strict_mode_formal_parameter_error() const { |
| 107 return strict_mode_formal_parameter_error_; | 113 return strict_mode_formal_parameter_error_; |
| 108 } | 114 } |
| 109 | 115 |
| 110 const Error& strong_mode_formal_parameter_error() const { | 116 const Error& strong_mode_formal_parameter_error() const { |
| 111 return strong_mode_formal_parameter_error_; | 117 return strong_mode_formal_parameter_error_; |
| 112 } | 118 } |
| 113 | 119 |
| 120 bool is_simple_parameter_list() const { | |
| 121 return !(function_properties_ & NonSimpleParameter); | |
| 122 } | |
| 123 | |
| 124 void RecordNonSimpleParameter() { | |
| 125 function_properties_ |= NonSimpleParameter; | |
| 126 } | |
| 127 | |
| 114 void RecordExpressionError(const Scanner::Location& loc, | 128 void RecordExpressionError(const Scanner::Location& loc, |
| 115 MessageTemplate::Template message, | 129 MessageTemplate::Template message, |
| 116 const char* arg = nullptr) { | 130 const char* arg = nullptr) { |
| 117 if (!is_valid_expression()) return; | 131 if (!is_valid_expression()) return; |
| 118 invalid_productions_ |= ExpressionProduction; | 132 invalid_productions_ |= ExpressionProduction; |
| 119 expression_error_.location = loc; | 133 expression_error_.location = loc; |
| 120 expression_error_.message = message; | 134 expression_error_.message = message; |
| 121 expression_error_.arg = arg; | 135 expression_error_.arg = arg; |
| 122 } | 136 } |
| 123 | 137 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 strict_mode_formal_parameter_error_ = | 223 strict_mode_formal_parameter_error_ = |
| 210 inner.strict_mode_formal_parameter_error_; | 224 inner.strict_mode_formal_parameter_error_; |
| 211 if (errors & StrongModeFormalParametersProduction) | 225 if (errors & StrongModeFormalParametersProduction) |
| 212 strong_mode_formal_parameter_error_ = | 226 strong_mode_formal_parameter_error_ = |
| 213 inner.strong_mode_formal_parameter_error_; | 227 inner.strong_mode_formal_parameter_error_; |
| 214 } | 228 } |
| 215 | 229 |
| 216 // As an exception to the above, the result continues to be a valid arrow | 230 // As an exception to the above, the result continues to be a valid arrow |
| 217 // formal parameters if the inner expression is a valid binding pattern. | 231 // formal parameters if the inner expression is a valid binding pattern. |
| 218 if (productions & ArrowFormalParametersProduction && | 232 if (productions & ArrowFormalParametersProduction && |
| 219 is_valid_arrow_formal_parameters() && | 233 is_valid_arrow_formal_parameters()) { |
| 220 !inner.is_valid_binding_pattern()) { | 234 // Also copy function properties if expecting an arrow function |
| 221 invalid_productions_ |= ArrowFormalParametersProduction; | 235 // parameter |
|
rossberg
2015/08/24 13:11:08
Nit: period
conradw
2015/08/25 11:31:20
Done.
| |
| 222 arrow_formal_parameters_error_ = inner.binding_pattern_error_; | 236 function_properties_ |= inner.function_properties_; |
| 237 | |
| 238 if (!inner.is_valid_binding_pattern()) { | |
| 239 invalid_productions_ |= ArrowFormalParametersProduction; | |
| 240 arrow_formal_parameters_error_ = inner.binding_pattern_error_; | |
| 241 } | |
| 223 } | 242 } |
| 224 } | 243 } |
| 225 | 244 |
| 226 private: | 245 private: |
| 227 unsigned invalid_productions_; | 246 unsigned invalid_productions_; |
| 247 unsigned function_properties_; | |
| 228 Error expression_error_; | 248 Error expression_error_; |
| 229 Error binding_pattern_error_; | 249 Error binding_pattern_error_; |
| 230 Error assignment_pattern_error_; | 250 Error assignment_pattern_error_; |
| 231 Error arrow_formal_parameters_error_; | 251 Error arrow_formal_parameters_error_; |
| 232 Error duplicate_formal_parameter_error_; | 252 Error duplicate_formal_parameter_error_; |
| 233 Error strict_mode_formal_parameter_error_; | 253 Error strict_mode_formal_parameter_error_; |
| 234 Error strong_mode_formal_parameter_error_; | 254 Error strong_mode_formal_parameter_error_; |
| 235 DuplicateFinder* duplicate_finder_; | 255 DuplicateFinder* duplicate_finder_; |
| 236 }; | 256 }; |
| 237 } | 257 } |
| 238 } // v8::internal | 258 } // v8::internal |
| 239 | 259 |
| 240 #endif // V8_EXPRESSION_CLASSIFIER_H | 260 #endif // V8_EXPRESSION_CLASSIFIER_H |
| OLD | NEW |