Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
| 6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 DCHECK(is_generator()); | 231 DCHECK(is_generator()); |
| 232 generator_object_variable_ = variable; | 232 generator_object_variable_ = variable; |
| 233 } | 233 } |
| 234 typename Traits::Type::GeneratorVariable* generator_object_variable() | 234 typename Traits::Type::GeneratorVariable* generator_object_variable() |
| 235 const { | 235 const { |
| 236 return generator_object_variable_; | 236 return generator_object_variable_; |
| 237 } | 237 } |
| 238 | 238 |
| 239 typename Traits::Type::Factory* factory() { return factory_; } | 239 typename Traits::Type::Factory* factory() { return factory_; } |
| 240 | 240 |
| 241 const List<DestructuringAssignment>& destructuring_assignments_to_rewrite() | 241 const ZoneList<DestructuringAssignment>& |
| 242 const { | 242 destructuring_assignments_to_rewrite() const { |
| 243 return destructuring_assignments_to_rewrite_; | 243 return destructuring_assignments_to_rewrite_; |
| 244 } | 244 } |
| 245 | 245 |
| 246 List<ExpressionT>& expressions_in_tail_position() { | 246 ZoneList<typename ExpressionClassifier::Error>* GetReportedErrorList() { |
| 247 return &reported_errors_; | |
| 248 } | |
| 249 | |
| 250 ZoneList<ExpressionT>& expressions_in_tail_position() { | |
| 247 return expressions_in_tail_position_; | 251 return expressions_in_tail_position_; |
| 248 } | 252 } |
| 249 void AddExpressionInTailPosition(ExpressionT expression) { | 253 void AddExpressionInTailPosition(ExpressionT expression) { |
| 250 if (collect_expressions_in_tail_position_) { | 254 if (collect_expressions_in_tail_position_) { |
| 251 expressions_in_tail_position_.Add(expression); | 255 expressions_in_tail_position_.Add(expression, scope()->zone()); |
| 252 } | 256 } |
| 253 } | 257 } |
| 254 | 258 |
| 255 bool collect_expressions_in_tail_position() const { | 259 bool collect_expressions_in_tail_position() const { |
| 256 return collect_expressions_in_tail_position_; | 260 return collect_expressions_in_tail_position_; |
| 257 } | 261 } |
| 258 void set_collect_expressions_in_tail_position(bool collect) { | 262 void set_collect_expressions_in_tail_position(bool collect) { |
| 259 collect_expressions_in_tail_position_ = collect; | 263 collect_expressions_in_tail_position_ = collect; |
| 260 } | 264 } |
| 261 | 265 |
| 262 ZoneList<ExpressionT>* non_patterns_to_rewrite() { | 266 ZoneList<ExpressionT>* non_patterns_to_rewrite() { |
| 263 return &non_patterns_to_rewrite_; | 267 return &non_patterns_to_rewrite_; |
| 264 } | 268 } |
| 265 | 269 |
| 266 private: | 270 private: |
| 267 void AddDestructuringAssignment(DestructuringAssignment pair) { | 271 void AddDestructuringAssignment(DestructuringAssignment pair) { |
| 268 destructuring_assignments_to_rewrite_.Add(pair); | 272 destructuring_assignments_to_rewrite_.Add(pair, scope()->zone()); |
| 269 } | 273 } |
| 270 | 274 |
| 271 V8_INLINE Scope* scope() { return *scope_stack_; } | 275 V8_INLINE Scope* scope() { return *scope_stack_; } |
| 272 | 276 |
| 273 void AddNonPatternForRewriting(ExpressionT expr) { | 277 void AddNonPatternForRewriting(ExpressionT expr) { |
| 274 non_patterns_to_rewrite_.Add(expr, (*scope_stack_)->zone()); | 278 non_patterns_to_rewrite_.Add(expr, scope()->zone()); |
| 275 } | 279 } |
| 276 | 280 |
| 277 // Used to assign an index to each literal that needs materialization in | 281 // Used to assign an index to each literal that needs materialization in |
| 278 // the function. Includes regexp literals, and boilerplate for object and | 282 // the function. Includes regexp literals, and boilerplate for object and |
| 279 // array literals. | 283 // array literals. |
| 280 int next_materialized_literal_index_; | 284 int next_materialized_literal_index_; |
| 281 | 285 |
| 282 // Properties count estimation. | 286 // Properties count estimation. |
| 283 int expected_property_count_; | 287 int expected_property_count_; |
| 284 | 288 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 295 // For generators, this variable may hold the generator object. It variable | 299 // For generators, this variable may hold the generator object. It variable |
| 296 // is used by yield expressions and return statements. It is not necessary | 300 // is used by yield expressions and return statements. It is not necessary |
| 297 // for generator functions to have this variable set. | 301 // for generator functions to have this variable set. |
| 298 Variable* generator_object_variable_; | 302 Variable* generator_object_variable_; |
| 299 | 303 |
| 300 FunctionState** function_state_stack_; | 304 FunctionState** function_state_stack_; |
| 301 FunctionState* outer_function_state_; | 305 FunctionState* outer_function_state_; |
| 302 Scope** scope_stack_; | 306 Scope** scope_stack_; |
| 303 Scope* outer_scope_; | 307 Scope* outer_scope_; |
| 304 | 308 |
| 305 List<DestructuringAssignment> destructuring_assignments_to_rewrite_; | 309 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; |
| 306 List<ExpressionT> expressions_in_tail_position_; | 310 ZoneList<ExpressionT> non_patterns_to_rewrite_; |
| 311 ZoneList<typename ExpressionClassifier::Error> reported_errors_; | |
| 312 ZoneList<ExpressionT> expressions_in_tail_position_; | |
| 307 bool collect_expressions_in_tail_position_; | 313 bool collect_expressions_in_tail_position_; |
| 308 ZoneList<ExpressionT> non_patterns_to_rewrite_; | |
| 309 | 314 |
| 310 typename Traits::Type::Factory* factory_; | 315 typename Traits::Type::Factory* factory_; |
| 311 | 316 |
| 312 friend class ParserTraits; | 317 friend class ParserTraits; |
| 313 friend class PreParserTraits; | 318 friend class PreParserTraits; |
| 314 friend class Checkpoint; | 319 friend class Checkpoint; |
| 315 }; | 320 }; |
| 316 | 321 |
| 317 // Annoyingly, arrow functions first parse as comma expressions, then when we | 322 // Annoyingly, arrow functions first parse as comma expressions, then when we |
| 318 // see the => we have to go back and reinterpret the arguments as being formal | 323 // see the => we have to go back and reinterpret the arguments as being formal |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 expected_property_count_(0), | 965 expected_property_count_(0), |
| 961 this_location_(Scanner::Location::invalid()), | 966 this_location_(Scanner::Location::invalid()), |
| 962 return_location_(Scanner::Location::invalid()), | 967 return_location_(Scanner::Location::invalid()), |
| 963 super_location_(Scanner::Location::invalid()), | 968 super_location_(Scanner::Location::invalid()), |
| 964 kind_(kind), | 969 kind_(kind), |
| 965 generator_object_variable_(NULL), | 970 generator_object_variable_(NULL), |
| 966 function_state_stack_(function_state_stack), | 971 function_state_stack_(function_state_stack), |
| 967 outer_function_state_(*function_state_stack), | 972 outer_function_state_(*function_state_stack), |
| 968 scope_stack_(scope_stack), | 973 scope_stack_(scope_stack), |
| 969 outer_scope_(*scope_stack), | 974 outer_scope_(*scope_stack), |
| 975 destructuring_assignments_to_rewrite_(16, scope->zone()), | |
| 976 non_patterns_to_rewrite_(0, scope->zone()), | |
| 977 reported_errors_(16, scope->zone()), | |
| 978 expressions_in_tail_position_(4, scope->zone()), | |
| 970 collect_expressions_in_tail_position_(true), | 979 collect_expressions_in_tail_position_(true), |
| 971 non_patterns_to_rewrite_(0, scope->zone()), | |
| 972 factory_(factory) { | 980 factory_(factory) { |
| 973 *scope_stack_ = scope; | 981 *scope_stack_ = scope; |
| 974 *function_state_stack = this; | 982 *function_state_stack = this; |
| 975 } | 983 } |
| 976 | 984 |
| 977 | 985 |
| 978 template <class Traits> | 986 template <class Traits> |
| 979 ParserBase<Traits>::FunctionState::~FunctionState() { | 987 ParserBase<Traits>::FunctionState::~FunctionState() { |
| 980 *scope_stack_ = outer_scope_; | 988 *scope_stack_ = outer_scope_; |
| 981 *function_state_stack_ = outer_function_state_; | 989 *function_state_stack_ = outer_function_state_; |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1459 if (peek() == Token::ELLIPSIS) { | 1467 if (peek() == Token::ELLIPSIS) { |
| 1460 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only | 1468 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only |
| 1461 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a | 1469 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a |
| 1462 // valid expression or binding pattern. | 1470 // valid expression or binding pattern. |
| 1463 ExpressionUnexpectedToken(classifier); | 1471 ExpressionUnexpectedToken(classifier); |
| 1464 BindingPatternUnexpectedToken(classifier); | 1472 BindingPatternUnexpectedToken(classifier); |
| 1465 Consume(Token::ELLIPSIS); | 1473 Consume(Token::ELLIPSIS); |
| 1466 seen_rest = is_rest = true; | 1474 seen_rest = is_rest = true; |
| 1467 } | 1475 } |
| 1468 int pos = position(), expr_pos = peek_position(); | 1476 int pos = position(), expr_pos = peek_position(); |
| 1477 ExpressionClassifier binding_classifier(this); | |
| 1469 ExpressionT right = this->ParseAssignmentExpression( | 1478 ExpressionT right = this->ParseAssignmentExpression( |
| 1470 accept_IN, &binding_classifier, CHECK_OK); | 1479 accept_IN, &binding_classifier, CHECK_OK); |
| 1471 classifier->Accumulate(&binding_classifier, | 1480 classifier->Accumulate(&binding_classifier, |
| 1472 ExpressionClassifier::AllProductions); | 1481 ExpressionClassifier::AllProductions); |
| 1473 if (is_rest) { | 1482 if (is_rest) { |
| 1474 if (!this->IsIdentifier(right) && !IsValidPattern(right)) { | 1483 if (!this->IsIdentifier(right) && !IsValidPattern(right)) { |
| 1475 classifier->RecordArrowFormalParametersError( | 1484 classifier->RecordArrowFormalParametersError( |
| 1476 Scanner::Location(pos, scanner()->location().end_pos), | 1485 Scanner::Location(pos, scanner()->location().end_pos), |
| 1477 MessageTemplate::kInvalidRestParameter); | 1486 MessageTemplate::kInvalidRestParameter); |
| 1478 } | 1487 } |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1971 ParserBase<Traits>::Checkpoint checkpoint(this); | 1980 ParserBase<Traits>::Checkpoint checkpoint(this); |
| 1972 ExpressionClassifier arrow_formals_classifier(this, | 1981 ExpressionClassifier arrow_formals_classifier(this, |
| 1973 classifier->duplicate_finder()); | 1982 classifier->duplicate_finder()); |
| 1974 bool parenthesized_formals = peek() == Token::LPAREN; | 1983 bool parenthesized_formals = peek() == Token::LPAREN; |
| 1975 if (!parenthesized_formals) { | 1984 if (!parenthesized_formals) { |
| 1976 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 1985 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
| 1977 } | 1986 } |
| 1978 ExpressionT expression = this->ParseConditionalExpression( | 1987 ExpressionT expression = this->ParseConditionalExpression( |
| 1979 accept_IN, &arrow_formals_classifier, CHECK_OK); | 1988 accept_IN, &arrow_formals_classifier, CHECK_OK); |
| 1980 if (peek() == Token::ARROW) { | 1989 if (peek() == Token::ARROW) { |
| 1981 classifier->RecordPatternError(scanner()->peek_location(), | 1990 typename ExpressionClassifier::Error e1 = |
| 1982 MessageTemplate::kUnexpectedToken, | 1991 ExpressionClassifier::BindingPatternError( |
|
caitp (gmail)
2016/02/18 17:04:09
A thought I had on this duplication:
A BindingPat
nickie
2016/02/19 08:56:31
I'm sorry, I'm not confident enough to talk about
| |
| 1983 Token::String(Token::ARROW)); | 1992 scanner()->peek_location(), MessageTemplate::kUnexpectedToken, |
| 1993 Token::String(Token::ARROW)); | |
| 1994 typename ExpressionClassifier::Error e2 = | |
| 1995 ExpressionClassifier::AssignmentPatternError( | |
| 1996 scanner()->peek_location(), MessageTemplate::kUnexpectedToken, | |
| 1997 Token::String(Token::ARROW)); | |
| 1984 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, | 1998 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
| 1985 parenthesized_formals, CHECK_OK); | 1999 parenthesized_formals, CHECK_OK); |
| 1986 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); | 2000 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); |
| 1987 Scope* scope = | 2001 Scope* scope = |
| 1988 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); | 2002 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); |
| 1989 // Because the arrow's parameters were parsed in the outer scope, any | 2003 // Because the arrow's parameters were parsed in the outer scope, any |
| 1990 // usage flags that might have been triggered there need to be copied | 2004 // usage flags that might have been triggered there need to be copied |
| 1991 // to the arrow scope. | 2005 // to the arrow scope. |
| 1992 scope_->PropagateUsageFlagsToScope(scope); | 2006 scope_->PropagateUsageFlagsToScope(scope); |
| 1993 FormalParametersT parameters(scope); | 2007 FormalParametersT parameters(scope); |
| 1994 if (!arrow_formals_classifier.is_simple_parameter_list()) { | 2008 if (!arrow_formals_classifier.is_simple_parameter_list()) { |
| 1995 scope->SetHasNonSimpleParameters(); | 2009 scope->SetHasNonSimpleParameters(); |
| 1996 parameters.is_simple = false; | 2010 parameters.is_simple = false; |
| 1997 } | 2011 } |
| 1998 | 2012 |
| 1999 checkpoint.Restore(¶meters.materialized_literals_count); | 2013 checkpoint.Restore(¶meters.materialized_literals_count); |
| 2000 | 2014 |
| 2001 scope->set_start_position(lhs_beg_pos); | 2015 scope->set_start_position(lhs_beg_pos); |
| 2002 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2016 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
| 2003 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, | 2017 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, |
| 2004 &duplicate_loc, CHECK_OK); | 2018 &duplicate_loc, CHECK_OK); |
| 2005 if (duplicate_loc.IsValid()) { | 2019 if (duplicate_loc.IsValid()) { |
| 2006 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2020 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
| 2007 duplicate_loc); | 2021 duplicate_loc); |
| 2008 } | 2022 } |
| 2009 expression = this->ParseArrowFunctionLiteral( | 2023 expression = this->ParseArrowFunctionLiteral( |
| 2010 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); | 2024 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); |
| 2025 arrow_formals_classifier.Discard(); | |
| 2026 classifier->RecordBindingPatternError(e1); | |
| 2027 classifier->RecordAssignmentPatternError(e2); | |
| 2011 | 2028 |
| 2012 if (fni_ != nullptr) fni_->Infer(); | 2029 if (fni_ != nullptr) fni_->Infer(); |
| 2013 | 2030 |
| 2014 return expression; | 2031 return expression; |
| 2015 } | 2032 } |
| 2016 | 2033 |
| 2017 if (this->IsValidReferenceExpression(expression)) { | 2034 if (this->IsValidReferenceExpression(expression)) { |
| 2018 arrow_formals_classifier.ForgiveAssignmentPatternError(); | 2035 arrow_formals_classifier.ForgiveAssignmentPatternError(); |
| 2019 } | 2036 } |
| 2020 | 2037 |
| (...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3362 has_seen_constructor_ = true; | 3379 has_seen_constructor_ = true; |
| 3363 return; | 3380 return; |
| 3364 } | 3381 } |
| 3365 } | 3382 } |
| 3366 | 3383 |
| 3367 | 3384 |
| 3368 } // namespace internal | 3385 } // namespace internal |
| 3369 } // namespace v8 | 3386 } // namespace v8 |
| 3370 | 3387 |
| 3371 #endif // V8_PARSING_PARSER_BASE_H | 3388 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |