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_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
| 6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | |
| 8 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 9 #include "src/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
| 10 #include "src/parsing/preparse-data.h" | 11 #include "src/parsing/preparse-data.h" |
| 11 | 12 |
| 12 namespace v8 { | 13 namespace v8 { |
| 13 namespace internal { | 14 namespace internal { |
| 14 | 15 |
| 15 // Whereas the Parser generates AST during the recursive descent, | 16 // Whereas the Parser generates AST during the recursive descent, |
| 16 // the PreParser doesn't create a tree. Instead, it passes around minimal | 17 // the PreParser doesn't create a tree. Instead, it passes around minimal |
| 17 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain | 18 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 const AstRawString* string_; | 120 const AstRawString* string_; |
| 120 friend class PreParserExpression; | 121 friend class PreParserExpression; |
| 121 friend class PreParser; | 122 friend class PreParser; |
| 122 friend class PreParserFactory; | 123 friend class PreParserFactory; |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 | 126 |
| 126 class PreParserExpression { | 127 class PreParserExpression { |
| 127 public: | 128 public: |
| 128 PreParserExpression() | 129 PreParserExpression() |
| 129 : code_(TypeField::encode(kEmpty)), identifiers_(nullptr) {} | 130 : code_(TypeField::encode(kEmpty)), variables_(nullptr) {} |
| 130 | 131 |
| 131 static PreParserExpression Empty() { return PreParserExpression(); } | 132 static PreParserExpression Empty() { return PreParserExpression(); } |
| 132 | 133 |
| 133 static PreParserExpression Default( | 134 static PreParserExpression Default( |
| 134 ZoneList<const AstRawString*>* identifiers = nullptr) { | 135 ZoneList<VariableProxy*>* variables = nullptr) { |
| 135 return PreParserExpression(TypeField::encode(kExpression), identifiers); | 136 return PreParserExpression(TypeField::encode(kExpression), variables); |
| 136 } | 137 } |
| 137 | 138 |
| 138 static PreParserExpression Spread(PreParserExpression expression) { | 139 static PreParserExpression Spread(PreParserExpression expression) { |
| 139 return PreParserExpression(TypeField::encode(kSpreadExpression), | 140 return PreParserExpression(TypeField::encode(kSpreadExpression), |
| 140 expression.identifiers_); | 141 expression.variables_); |
| 141 } | 142 } |
| 142 | 143 |
| 143 static PreParserExpression FromIdentifier(PreParserIdentifier id, | 144 static PreParserExpression FromIdentifier(PreParserIdentifier id, |
| 145 VariableProxy* variable, | |
| 144 Zone* zone) { | 146 Zone* zone) { |
| 145 PreParserExpression expression(TypeField::encode(kIdentifierExpression) | | 147 PreParserExpression expression(TypeField::encode(kIdentifierExpression) | |
| 146 IdentifierTypeField::encode(id.type_)); | 148 IdentifierTypeField::encode(id.type_)); |
| 147 expression.AddIdentifier(id.string_, zone); | 149 expression.AddVariable(variable, zone); |
| 148 return expression; | 150 return expression; |
| 149 } | 151 } |
| 150 | 152 |
| 151 static PreParserExpression BinaryOperation(PreParserExpression left, | 153 static PreParserExpression BinaryOperation(PreParserExpression left, |
| 152 Token::Value op, | 154 Token::Value op, |
| 153 PreParserExpression right) { | 155 PreParserExpression right) { |
| 154 return PreParserExpression(TypeField::encode(kExpression)); | 156 return PreParserExpression(TypeField::encode(kExpression)); |
| 155 } | 157 } |
| 156 | 158 |
| 157 static PreParserExpression Assignment( | 159 static PreParserExpression Assignment( |
| 158 ZoneList<const AstRawString*>* identifiers = nullptr) { | 160 ZoneList<VariableProxy*>* variables = nullptr) { |
|
neis
2016/12/12 13:01:36
Can we remove the default value here and below? I
marja
2016/12/12 13:36:46
Done.
| |
| 159 return PreParserExpression(TypeField::encode(kExpression) | | 161 return PreParserExpression(TypeField::encode(kExpression) | |
| 160 ExpressionTypeField::encode(kAssignment), | 162 ExpressionTypeField::encode(kAssignment), |
| 161 identifiers); | 163 variables); |
| 162 } | 164 } |
| 163 | 165 |
| 164 static PreParserExpression ObjectLiteral( | 166 static PreParserExpression ObjectLiteral( |
| 165 ZoneList<const AstRawString*>* identifiers = nullptr) { | 167 ZoneList<VariableProxy*>* variables = nullptr) { |
| 166 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), | 168 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), |
| 167 identifiers); | 169 variables); |
| 168 } | 170 } |
| 169 | 171 |
| 170 static PreParserExpression ArrayLiteral( | 172 static PreParserExpression ArrayLiteral( |
| 171 ZoneList<const AstRawString*>* identifiers = nullptr) { | 173 ZoneList<VariableProxy*>* variables = nullptr) { |
| 172 return PreParserExpression(TypeField::encode(kArrayLiteralExpression), | 174 return PreParserExpression(TypeField::encode(kArrayLiteralExpression), |
| 173 identifiers); | 175 variables); |
| 174 } | 176 } |
| 175 | 177 |
| 176 static PreParserExpression StringLiteral() { | 178 static PreParserExpression StringLiteral() { |
| 177 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); | 179 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); |
| 178 } | 180 } |
| 179 | 181 |
| 180 static PreParserExpression UseStrictStringLiteral() { | 182 static PreParserExpression UseStrictStringLiteral() { |
| 181 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 183 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
| 182 IsUseStrictField::encode(true)); | 184 IsUseStrictField::encode(true)); |
| 183 } | 185 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 kThisExpression, | 342 kThisExpression, |
| 341 kThisPropertyExpression, | 343 kThisPropertyExpression, |
| 342 kPropertyExpression, | 344 kPropertyExpression, |
| 343 kCallExpression, | 345 kCallExpression, |
| 344 kCallEvalExpression, | 346 kCallEvalExpression, |
| 345 kSuperCallReference, | 347 kSuperCallReference, |
| 346 kNoTemplateTagExpression, | 348 kNoTemplateTagExpression, |
| 347 kAssignment | 349 kAssignment |
| 348 }; | 350 }; |
| 349 | 351 |
| 350 explicit PreParserExpression( | 352 explicit PreParserExpression(uint32_t expression_code, |
| 351 uint32_t expression_code, | 353 ZoneList<VariableProxy*>* variables = nullptr) |
| 352 ZoneList<const AstRawString*>* identifiers = nullptr) | 354 : code_(expression_code), variables_(variables) {} |
| 353 : code_(expression_code), identifiers_(identifiers) {} | |
| 354 | 355 |
| 355 void AddIdentifier(const AstRawString* identifier, Zone* zone) { | 356 void AddVariable(VariableProxy* variable, Zone* zone) { |
| 356 if (identifier == nullptr) { | 357 if (variable == nullptr) { |
| 357 return; | 358 return; |
| 358 } | 359 } |
| 359 if (identifiers_ == nullptr) { | 360 if (variables_ == nullptr) { |
| 360 identifiers_ = new (zone) ZoneList<const AstRawString*>(1, zone); | 361 variables_ = new (zone) ZoneList<VariableProxy*>(1, zone); |
| 361 } | 362 } |
| 362 identifiers_->Add(identifier, zone); | 363 variables_->Add(variable, zone); |
| 363 } | 364 } |
| 364 | 365 |
| 365 // The first three bits are for the Type. | 366 // The first three bits are for the Type. |
| 366 typedef BitField<Type, 0, 3> TypeField; | 367 typedef BitField<Type, 0, 3> TypeField; |
| 367 | 368 |
| 368 // The high order bit applies only to nodes which would inherit from the | 369 // The high order bit applies only to nodes which would inherit from the |
| 369 // Expression ASTNode --- This is by necessity, due to the fact that | 370 // Expression ASTNode --- This is by necessity, due to the fact that |
| 370 // Expression nodes may be represented as multiple Types, not exclusively | 371 // Expression nodes may be represented as multiple Types, not exclusively |
| 371 // through kExpression. | 372 // through kExpression. |
| 372 // TODO(caitp, adamk): clean up PreParserExpression bitfields. | 373 // TODO(caitp, adamk): clean up PreParserExpression bitfields. |
| 373 typedef BitField<bool, 31, 1> ParenthesizedField; | 374 typedef BitField<bool, 31, 1> ParenthesizedField; |
| 374 | 375 |
| 375 // The rest of the bits are interpreted depending on the value | 376 // The rest of the bits are interpreted depending on the value |
| 376 // of the Type field, so they can share the storage. | 377 // of the Type field, so they can share the storage. |
| 377 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; | 378 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; |
| 378 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; | 379 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; |
| 379 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField; | 380 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseAsmField; |
| 380 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> | 381 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> |
| 381 IdentifierTypeField; | 382 IdentifierTypeField; |
| 382 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; | 383 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; |
| 383 | 384 |
| 384 uint32_t code_; | 385 uint32_t code_; |
| 385 // If the PreParser is used in the identifier tracking mode, | 386 // If the PreParser is used in the variable tracking mode, PreParserExpression |
| 386 // PreParserExpression accumulates identifiers in that expression. | 387 // accumulates variables in that expression. |
| 387 ZoneList<const AstRawString*>* identifiers_; | 388 ZoneList<VariableProxy*>* variables_; |
| 388 | 389 |
| 389 friend class PreParser; | 390 friend class PreParser; |
| 390 friend class PreParserFactory; | 391 friend class PreParserFactory; |
| 391 template <typename T> | 392 template <typename T> |
| 392 friend class PreParserList; | 393 friend class PreParserList; |
| 393 }; | 394 }; |
| 394 | 395 |
| 395 | 396 |
| 396 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 397 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
| 397 // the like. If the PreParser is used in identifier tracking mode, it needs to | 398 // the like. If the PreParser is used in variable tracking mode, it needs to |
| 398 // build lists of identifiers though. | 399 // build lists of variables though. |
| 399 template <typename T> | 400 template <typename T> |
| 400 class PreParserList { | 401 class PreParserList { |
| 401 public: | 402 public: |
| 402 // These functions make list->Add(some_expression) work (and do nothing). | 403 // These functions make list->Add(some_expression) work (and do nothing). |
| 403 PreParserList() : length_(0), identifiers_(nullptr) {} | 404 PreParserList() : length_(0), variables_(nullptr) {} |
| 404 PreParserList* operator->() { return this; } | 405 PreParserList* operator->() { return this; } |
| 405 void Add(T, Zone* zone); | 406 void Add(T, Zone* zone); |
| 406 int length() const { return length_; } | 407 int length() const { return length_; } |
| 407 static PreParserList Null() { return PreParserList(-1); } | 408 static PreParserList Null() { return PreParserList(-1); } |
| 408 bool IsNull() const { return length_ == -1; } | 409 bool IsNull() const { return length_ == -1; } |
| 409 | 410 |
| 410 private: | 411 private: |
| 411 explicit PreParserList(int n) : length_(n), identifiers_(nullptr) {} | 412 explicit PreParserList(int n) : length_(n), variables_(nullptr) {} |
| 412 int length_; | 413 int length_; |
| 413 ZoneList<const AstRawString*>* identifiers_; | 414 ZoneList<VariableProxy*>* variables_; |
| 414 | 415 |
| 415 friend class PreParser; | 416 friend class PreParser; |
| 416 friend class PreParserFactory; | 417 friend class PreParserFactory; |
| 417 }; | 418 }; |
| 418 | 419 |
| 419 template <> | 420 template <> |
| 420 inline void PreParserList<PreParserExpression>::Add( | 421 inline void PreParserList<PreParserExpression>::Add( |
| 421 PreParserExpression expression, Zone* zone) { | 422 PreParserExpression expression, Zone* zone) { |
| 422 if (expression.identifiers_ != nullptr) { | 423 if (expression.variables_ != nullptr) { |
| 423 DCHECK(FLAG_lazy_inner_functions); | 424 DCHECK(FLAG_lazy_inner_functions); |
| 424 DCHECK(zone != nullptr); | 425 DCHECK(zone != nullptr); |
| 425 if (identifiers_ == nullptr) { | 426 if (variables_ == nullptr) { |
| 426 identifiers_ = new (zone) ZoneList<const AstRawString*>(1, zone); | 427 variables_ = new (zone) ZoneList<VariableProxy*>(1, zone); |
| 427 } | 428 } |
| 428 for (auto identifier : (*expression.identifiers_)) { | 429 for (auto identifier : (*expression.variables_)) { |
| 429 identifiers_->Add(identifier, zone); | 430 variables_->Add(identifier, zone); |
| 430 } | 431 } |
| 431 } | 432 } |
| 432 ++length_; | 433 ++length_; |
| 433 } | 434 } |
| 434 | 435 |
| 435 template <typename T> | 436 template <typename T> |
| 436 void PreParserList<T>::Add(T, Zone* zone) { | 437 void PreParserList<T>::Add(T, Zone* zone) { |
| 437 ++length_; | 438 ++length_; |
| 438 } | 439 } |
| 439 | 440 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 }; | 519 }; |
| 519 | 520 |
| 520 explicit PreParserStatement(Type code) : code_(code) {} | 521 explicit PreParserStatement(Type code) : code_(code) {} |
| 521 Type code_; | 522 Type code_; |
| 522 }; | 523 }; |
| 523 | 524 |
| 524 | 525 |
| 525 class PreParserFactory { | 526 class PreParserFactory { |
| 526 public: | 527 public: |
| 527 explicit PreParserFactory(AstValueFactory* ast_value_factory) | 528 explicit PreParserFactory(AstValueFactory* ast_value_factory) |
| 528 : zone_(ast_value_factory->zone()) {} | 529 : ast_value_factory_(ast_value_factory), |
| 530 zone_(ast_value_factory->zone()) {} | |
| 529 | 531 |
| 530 void set_zone(Zone* zone) { zone_ = zone; } | 532 void set_zone(Zone* zone) { zone_ = zone; } |
| 531 | 533 |
| 532 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 534 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
| 533 int pos) { | 535 int pos) { |
| 534 // This is needed for object literal property names. Property names are | 536 // This is needed for object literal property names. Property names are |
| 535 // normalized to string literals during object literal parsing. | 537 // normalized to string literals during object literal parsing. |
| 536 PreParserExpression expression = PreParserExpression::Default(); | 538 PreParserExpression expression = PreParserExpression::Default(); |
| 537 expression.AddIdentifier(identifier.string_, zone_); | 539 if (identifier.string_ != nullptr) { |
| 540 DCHECK(FLAG_lazy_inner_functions); | |
| 541 AstNodeFactory factory(ast_value_factory_); | |
| 542 factory.set_zone(zone_); | |
| 543 VariableProxy* variable = | |
| 544 factory.NewVariableProxy(identifier.string_, NORMAL_VARIABLE); | |
| 545 expression.AddVariable(variable, zone_); | |
| 546 } | |
|
neis
2016/12/12 13:01:36
Why do we create a variable proxy for a string lit
marja
2016/12/12 13:36:46
Discussed offline: for object literal properties w
| |
| 538 return expression; | 547 return expression; |
| 539 } | 548 } |
| 540 PreParserExpression NewNumberLiteral(double number, | 549 PreParserExpression NewNumberLiteral(double number, |
| 541 int pos) { | 550 int pos) { |
| 542 return PreParserExpression::Default(); | 551 return PreParserExpression::Default(); |
| 543 } | 552 } |
| 544 PreParserExpression NewUndefinedLiteral(int pos) { | 553 PreParserExpression NewUndefinedLiteral(int pos) { |
| 545 return PreParserExpression::Default(); | 554 return PreParserExpression::Default(); |
| 546 } | 555 } |
| 547 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 556 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
| 548 int js_flags, int literal_index, | 557 int js_flags, int literal_index, |
| 549 int pos) { | 558 int pos) { |
| 550 return PreParserExpression::Default(); | 559 return PreParserExpression::Default(); |
| 551 } | 560 } |
| 552 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 561 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
| 553 int first_spread_index, int literal_index, | 562 int first_spread_index, int literal_index, |
| 554 int pos) { | 563 int pos) { |
| 555 return PreParserExpression::ArrayLiteral(values.identifiers_); | 564 return PreParserExpression::ArrayLiteral(values.variables_); |
| 556 } | 565 } |
| 557 PreParserExpression NewClassLiteralProperty(PreParserExpression key, | 566 PreParserExpression NewClassLiteralProperty(PreParserExpression key, |
| 558 PreParserExpression value, | 567 PreParserExpression value, |
| 559 ClassLiteralProperty::Kind kind, | 568 ClassLiteralProperty::Kind kind, |
| 560 bool is_static, | 569 bool is_static, |
| 561 bool is_computed_name) { | 570 bool is_computed_name) { |
| 562 return PreParserExpression::Default(); | 571 return PreParserExpression::Default(); |
| 563 } | 572 } |
| 564 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 573 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
| 565 PreParserExpression value, | 574 PreParserExpression value, |
| 566 ObjectLiteralProperty::Kind kind, | 575 ObjectLiteralProperty::Kind kind, |
| 567 bool is_computed_name) { | 576 bool is_computed_name) { |
| 568 return PreParserExpression::Default(value.identifiers_); | 577 return PreParserExpression::Default(value.variables_); |
| 569 } | 578 } |
| 570 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 579 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
| 571 PreParserExpression value, | 580 PreParserExpression value, |
| 572 bool is_computed_name) { | 581 bool is_computed_name) { |
| 573 return PreParserExpression::Default(value.identifiers_); | 582 return PreParserExpression::Default(value.variables_); |
| 574 } | 583 } |
| 575 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 584 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
| 576 int literal_index, | 585 int literal_index, |
| 577 int boilerplate_properties, | 586 int boilerplate_properties, |
| 578 int pos) { | 587 int pos) { |
| 579 return PreParserExpression::ObjectLiteral(properties.identifiers_); | 588 return PreParserExpression::ObjectLiteral(properties.variables_); |
| 580 } | 589 } |
| 581 PreParserExpression NewVariableProxy(void* variable) { | 590 PreParserExpression NewVariableProxy(void* variable) { |
| 582 return PreParserExpression::Default(); | 591 return PreParserExpression::Default(); |
| 583 } | 592 } |
| 584 PreParserExpression NewProperty(PreParserExpression obj, | 593 PreParserExpression NewProperty(PreParserExpression obj, |
| 585 PreParserExpression key, | 594 PreParserExpression key, |
| 586 int pos) { | 595 int pos) { |
| 587 if (obj.IsThis()) { | 596 if (obj.IsThis()) { |
| 588 return PreParserExpression::ThisProperty(); | 597 return PreParserExpression::ThisProperty(); |
| 589 } | 598 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 604 PreParserExpression right, int pos) { | 613 PreParserExpression right, int pos) { |
| 605 return PreParserExpression::Default(); | 614 return PreParserExpression::Default(); |
| 606 } | 615 } |
| 607 PreParserExpression NewRewritableExpression(PreParserExpression expression) { | 616 PreParserExpression NewRewritableExpression(PreParserExpression expression) { |
| 608 return expression; | 617 return expression; |
| 609 } | 618 } |
| 610 PreParserExpression NewAssignment(Token::Value op, | 619 PreParserExpression NewAssignment(Token::Value op, |
| 611 PreParserExpression left, | 620 PreParserExpression left, |
| 612 PreParserExpression right, | 621 PreParserExpression right, |
| 613 int pos) { | 622 int pos) { |
| 614 // For tracking identifiers for parameters with a default value. | 623 // For tracking variables for parameters with a default value. |
| 615 return PreParserExpression::Assignment(left.identifiers_); | 624 return PreParserExpression::Assignment(left.variables_); |
| 616 } | 625 } |
| 617 PreParserExpression NewYield(PreParserExpression generator_object, | 626 PreParserExpression NewYield(PreParserExpression generator_object, |
| 618 PreParserExpression expression, int pos, | 627 PreParserExpression expression, int pos, |
| 619 Yield::OnException on_exception) { | 628 Yield::OnException on_exception) { |
| 620 return PreParserExpression::Default(); | 629 return PreParserExpression::Default(); |
| 621 } | 630 } |
| 622 PreParserExpression NewConditional(PreParserExpression condition, | 631 PreParserExpression NewConditional(PreParserExpression condition, |
| 623 PreParserExpression then_expression, | 632 PreParserExpression then_expression, |
| 624 PreParserExpression else_expression, | 633 PreParserExpression else_expression, |
| 625 int pos) { | 634 int pos) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 | 751 |
| 743 // Return the object itself as AstVisitor and implement the needed | 752 // Return the object itself as AstVisitor and implement the needed |
| 744 // dummy method right in this class. | 753 // dummy method right in this class. |
| 745 PreParserFactory* visitor() { return this; } | 754 PreParserFactory* visitor() { return this; } |
| 746 int* ast_properties() { | 755 int* ast_properties() { |
| 747 static int dummy = 42; | 756 static int dummy = 42; |
| 748 return &dummy; | 757 return &dummy; |
| 749 } | 758 } |
| 750 | 759 |
| 751 private: | 760 private: |
| 761 AstValueFactory* ast_value_factory_; | |
| 752 Zone* zone_; | 762 Zone* zone_; |
| 753 }; | 763 }; |
| 754 | 764 |
| 755 | 765 |
| 756 struct PreParserFormalParameters : FormalParametersBase { | 766 struct PreParserFormalParameters : FormalParametersBase { |
| 757 struct Parameter : public ZoneObject { | 767 struct Parameter : public ZoneObject { |
| 758 explicit Parameter(PreParserExpression pattern) : pattern(pattern) {} | 768 explicit Parameter(PreParserExpression pattern) : pattern(pattern) {} |
| 759 Parameter** next() { return &next_parameter; } | 769 Parameter** next() { return &next_parameter; } |
| 760 Parameter* const* next() const { return &next_parameter; } | 770 Parameter* const* next() const { return &next_parameter; } |
| 761 PreParserExpression pattern; | 771 PreParserExpression pattern; |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1204 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} | 1214 V8_INLINE static void PushVariableName(PreParserIdentifier id) {} |
| 1205 V8_INLINE void PushPropertyName(PreParserExpression expression) {} | 1215 V8_INLINE void PushPropertyName(PreParserExpression expression) {} |
| 1206 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} | 1216 V8_INLINE void PushEnclosingName(PreParserIdentifier name) {} |
| 1207 V8_INLINE static void AddFunctionForNameInference( | 1217 V8_INLINE static void AddFunctionForNameInference( |
| 1208 PreParserExpression expression) {} | 1218 PreParserExpression expression) {} |
| 1209 V8_INLINE static void InferFunctionName() {} | 1219 V8_INLINE static void InferFunctionName() {} |
| 1210 | 1220 |
| 1211 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( | 1221 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
| 1212 PreParserExpression left, PreParserExpression right) {} | 1222 PreParserExpression left, PreParserExpression right) {} |
| 1213 | 1223 |
| 1214 V8_INLINE static void MarkExpressionAsAssigned( | 1224 V8_INLINE void MarkExpressionAsAssigned(PreParserExpression expression) { |
| 1215 PreParserExpression expression) { | |
| 1216 // TODO(marja): To be able to produce the same errors, the preparser needs | 1225 // TODO(marja): To be able to produce the same errors, the preparser needs |
| 1217 // to start tracking which expressions are variables and which are assigned. | 1226 // to start tracking which expressions are variables and which are assigned. |
|
neis
2016/12/12 13:01:36
Is this TODO now resolved?
marja
2016/12/12 13:36:46
Sadly, no. It's orthogonal-ish. We still only trac
| |
| 1227 if (expression.variables_ != nullptr) { | |
| 1228 DCHECK(FLAG_lazy_inner_functions); | |
| 1229 DCHECK(track_unresolved_variables_); | |
| 1230 for (auto variable : *expression.variables_) { | |
| 1231 variable->set_is_assigned(); | |
| 1232 } | |
| 1233 } | |
| 1218 } | 1234 } |
| 1219 | 1235 |
| 1220 V8_INLINE bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, | 1236 V8_INLINE bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, |
| 1221 PreParserExpression y, | 1237 PreParserExpression y, |
| 1222 Token::Value op, | 1238 Token::Value op, |
| 1223 int pos) { | 1239 int pos) { |
| 1224 return false; | 1240 return false; |
| 1225 } | 1241 } |
| 1226 | 1242 |
| 1227 V8_INLINE PreParserExpression BuildUnaryExpression( | 1243 V8_INLINE PreParserExpression BuildUnaryExpression( |
| 1228 PreParserExpression expression, Token::Value op, int pos) { | 1244 PreParserExpression expression, Token::Value op, int pos) { |
| 1229 return PreParserExpression::Default(); | 1245 return PreParserExpression::Default(); |
| 1230 } | 1246 } |
| 1231 | 1247 |
| 1232 V8_INLINE PreParserExpression BuildIteratorResult(PreParserExpression value, | 1248 V8_INLINE PreParserExpression BuildIteratorResult(PreParserExpression value, |
| 1233 bool done) { | 1249 bool done) { |
| 1234 return PreParserExpression::Default(); | 1250 return PreParserExpression::Default(); |
| 1235 } | 1251 } |
| 1236 | 1252 |
| 1237 V8_INLINE PreParserStatement | 1253 V8_INLINE PreParserStatement |
| 1238 BuildInitializationBlock(DeclarationParsingResult* parsing_result, | 1254 BuildInitializationBlock(DeclarationParsingResult* parsing_result, |
| 1239 ZoneList<const AstRawString*>* names, bool* ok) { | 1255 ZoneList<const AstRawString*>* names, bool* ok) { |
| 1240 return PreParserStatement::Default(); | 1256 return PreParserStatement::Default(); |
| 1241 } | 1257 } |
| 1242 | 1258 |
| 1243 V8_INLINE PreParserStatement | 1259 V8_INLINE PreParserStatement |
| 1244 InitializeForEachStatement(PreParserStatement stmt, PreParserExpression each, | 1260 InitializeForEachStatement(PreParserStatement stmt, PreParserExpression each, |
| 1245 PreParserExpression subject, | 1261 PreParserExpression subject, |
| 1246 PreParserStatement body, int each_keyword_pos) { | 1262 PreParserStatement body, int each_keyword_pos) { |
| 1263 MarkExpressionAsAssigned(each); | |
|
neis
2016/12/12 13:01:36
Maybe reflect this change in the CL description.
marja
2016/12/12 13:36:46
Offline discussion: this falls under the descripti
| |
| 1247 return stmt; | 1264 return stmt; |
| 1248 } | 1265 } |
| 1249 | 1266 |
| 1250 V8_INLINE PreParserStatement RewriteForVarInLegacy(const ForInfo& for_info) { | 1267 V8_INLINE PreParserStatement RewriteForVarInLegacy(const ForInfo& for_info) { |
| 1251 return PreParserStatement::Null(); | 1268 return PreParserStatement::Null(); |
| 1252 } | 1269 } |
| 1253 V8_INLINE void DesugarBindingInForEachStatement( | 1270 V8_INLINE void DesugarBindingInForEachStatement( |
| 1254 ForInfo* for_info, PreParserStatement* body_block, | 1271 ForInfo* for_info, PreParserStatement* body_block, |
| 1255 PreParserExpression* each_variable, bool* ok) {} | 1272 PreParserExpression* each_variable, bool* ok) {} |
| 1256 V8_INLINE PreParserStatement CreateForEachStatementTDZ( | 1273 V8_INLINE PreParserStatement CreateForEachStatementTDZ( |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1467 | 1484 |
| 1468 V8_INLINE void DeclareFormalParameters( | 1485 V8_INLINE void DeclareFormalParameters( |
| 1469 DeclarationScope* scope, | 1486 DeclarationScope* scope, |
| 1470 const ThreadedList<PreParserFormalParameters::Parameter>& parameters) { | 1487 const ThreadedList<PreParserFormalParameters::Parameter>& parameters) { |
| 1471 if (!classifier()->is_simple_parameter_list()) { | 1488 if (!classifier()->is_simple_parameter_list()) { |
| 1472 scope->SetHasNonSimpleParameters(); | 1489 scope->SetHasNonSimpleParameters(); |
| 1473 } | 1490 } |
| 1474 if (track_unresolved_variables_) { | 1491 if (track_unresolved_variables_) { |
| 1475 DCHECK(FLAG_lazy_inner_functions); | 1492 DCHECK(FLAG_lazy_inner_functions); |
| 1476 for (auto parameter : parameters) { | 1493 for (auto parameter : parameters) { |
| 1477 if (parameter->pattern.identifiers_ != nullptr) { | 1494 if (parameter->pattern.variables_ != nullptr) { |
| 1478 for (auto i : *parameter->pattern.identifiers_) { | 1495 for (auto variable : *parameter->pattern.variables_) { |
| 1479 scope->DeclareVariableName(i, VAR); | 1496 scope->DeclareVariableName(variable->raw_name(), VAR); |
| 1480 } | 1497 } |
| 1481 } | 1498 } |
| 1482 } | 1499 } |
| 1483 } | 1500 } |
| 1484 } | 1501 } |
| 1485 | 1502 |
| 1486 V8_INLINE void DeclareArrowFunctionFormalParameters( | 1503 V8_INLINE void DeclareArrowFunctionFormalParameters( |
| 1487 PreParserFormalParameters* parameters, PreParserExpression params, | 1504 PreParserFormalParameters* parameters, PreParserExpression params, |
| 1488 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 1505 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
| 1489 bool* ok) { | 1506 bool* ok) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1504 } | 1521 } |
| 1505 | 1522 |
| 1506 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) { | 1523 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) { |
| 1507 for (int i = 0; i < count; ++i) { | 1524 for (int i = 0; i < count; ++i) { |
| 1508 function_state_->NextMaterializedLiteralIndex(); | 1525 function_state_->NextMaterializedLiteralIndex(); |
| 1509 } | 1526 } |
| 1510 } | 1527 } |
| 1511 | 1528 |
| 1512 V8_INLINE PreParserExpression | 1529 V8_INLINE PreParserExpression |
| 1513 ExpressionListToExpression(PreParserExpressionList args) { | 1530 ExpressionListToExpression(PreParserExpressionList args) { |
| 1514 return PreParserExpression::Default(args.identifiers_); | 1531 return PreParserExpression::Default(args.variables_); |
| 1515 } | 1532 } |
| 1516 | 1533 |
| 1517 V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get, | 1534 V8_INLINE void AddAccessorPrefixToFunctionName(bool is_get, |
| 1518 PreParserExpression function, | 1535 PreParserExpression function, |
| 1519 PreParserIdentifier name) {} | 1536 PreParserIdentifier name) {} |
| 1520 V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property, | 1537 V8_INLINE void SetFunctionNameFromPropertyName(PreParserExpression property, |
| 1521 PreParserIdentifier name) {} | 1538 PreParserIdentifier name) {} |
| 1522 V8_INLINE void SetFunctionNameFromIdentifierRef( | 1539 V8_INLINE void SetFunctionNameFromIdentifierRef( |
| 1523 PreParserExpression value, PreParserExpression identifier) {} | 1540 PreParserExpression value, PreParserExpression identifier) {} |
| 1524 | 1541 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1583 function_state_->NextMaterializedLiteralIndex(); | 1600 function_state_->NextMaterializedLiteralIndex(); |
| 1584 function_state_->NextMaterializedLiteralIndex(); | 1601 function_state_->NextMaterializedLiteralIndex(); |
| 1585 } | 1602 } |
| 1586 return EmptyExpression(); | 1603 return EmptyExpression(); |
| 1587 } | 1604 } |
| 1588 | 1605 |
| 1589 } // namespace internal | 1606 } // namespace internal |
| 1590 } // namespace v8 | 1607 } // namespace v8 |
| 1591 | 1608 |
| 1592 #endif // V8_PARSING_PREPARSER_H | 1609 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |