| 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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 // stack overflow. The isolate allows only one pending exception at at time | 642 // stack overflow. The isolate allows only one pending exception at at time |
| 643 // and we want to report the stack overflow later. | 643 // and we want to report the stack overflow later. |
| 644 return; | 644 return; |
| 645 } | 645 } |
| 646 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, | 646 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
| 647 source_location.end_pos, | 647 source_location.end_pos, |
| 648 message, arg, error_type); | 648 message, arg, error_type); |
| 649 } | 649 } |
| 650 | 650 |
| 651 | 651 |
| 652 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { | 652 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) const { |
| 653 const AstRawString* result = | 653 const AstRawString* result = |
| 654 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); | 654 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); |
| 655 DCHECK(result != NULL); | 655 DCHECK(result != NULL); |
| 656 return result; | 656 return result; |
| 657 } | 657 } |
| 658 | 658 |
| 659 | 659 |
| 660 const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) { | 660 const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) const { |
| 661 double double_value = parser_->scanner()->DoubleValue(); | 661 double double_value = parser_->scanner()->DoubleValue(); |
| 662 char array[100]; | 662 char array[100]; |
| 663 const char* string = DoubleToCString(double_value, ArrayVector(array)); | 663 const char* string = DoubleToCString(double_value, ArrayVector(array)); |
| 664 return parser_->ast_value_factory()->GetOneByteString(string); | 664 return parser_->ast_value_factory()->GetOneByteString(string); |
| 665 } | 665 } |
| 666 | 666 |
| 667 | 667 |
| 668 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 668 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) const { |
| 669 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 669 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); |
| 670 } | 670 } |
| 671 | 671 |
| 672 Expression* ParserTraits::ThisExpression(int pos) { | 672 Expression* ParserTraits::ThisExpression(int pos) const { |
| 673 return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(), | 673 return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(), |
| 674 pos, pos + 4, Variable::THIS); | 674 pos, pos + 4, Variable::THIS); |
| 675 } | 675 } |
| 676 | 676 |
| 677 Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, | 677 Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, |
| 678 int pos) { | 678 int pos) const { |
| 679 // this_function[home_object_symbol] | 679 // this_function[home_object_symbol] |
| 680 VariableProxy* this_function_proxy = parser_->NewUnresolved( | 680 VariableProxy* this_function_proxy = parser_->NewUnresolved( |
| 681 parser_->ast_value_factory()->this_function_string(), pos); | 681 parser_->ast_value_factory()->this_function_string(), pos); |
| 682 Expression* home_object_symbol_literal = | 682 Expression* home_object_symbol_literal = |
| 683 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); | 683 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); |
| 684 Expression* home_object = factory->NewProperty( | 684 Expression* home_object = factory->NewProperty( |
| 685 this_function_proxy, home_object_symbol_literal, pos); | 685 this_function_proxy, home_object_symbol_literal, pos); |
| 686 return factory->NewSuperPropertyReference( | 686 return factory->NewSuperPropertyReference( |
| 687 ThisExpression(pos)->AsVariableProxy(), home_object, pos); | 687 ThisExpression(pos)->AsVariableProxy(), home_object, pos); |
| 688 } | 688 } |
| 689 | 689 |
| 690 Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, | 690 Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, |
| 691 int pos) { | 691 int pos) const { |
| 692 VariableProxy* new_target_proxy = parser_->NewUnresolved( | 692 VariableProxy* new_target_proxy = parser_->NewUnresolved( |
| 693 parser_->ast_value_factory()->new_target_string(), pos); | 693 parser_->ast_value_factory()->new_target_string(), pos); |
| 694 VariableProxy* this_function_proxy = parser_->NewUnresolved( | 694 VariableProxy* this_function_proxy = parser_->NewUnresolved( |
| 695 parser_->ast_value_factory()->this_function_string(), pos); | 695 parser_->ast_value_factory()->this_function_string(), pos); |
| 696 return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(), | 696 return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(), |
| 697 new_target_proxy, this_function_proxy, | 697 new_target_proxy, this_function_proxy, |
| 698 pos); | 698 pos); |
| 699 } | 699 } |
| 700 | 700 |
| 701 Expression* ParserTraits::NewTargetExpression(int pos) { | 701 Expression* ParserTraits::NewTargetExpression(int pos) const { |
| 702 static const int kNewTargetStringLength = 10; | 702 static const int kNewTargetStringLength = 10; |
| 703 auto proxy = | 703 auto proxy = |
| 704 parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(), | 704 parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(), |
| 705 pos, pos + kNewTargetStringLength); | 705 pos, pos + kNewTargetStringLength); |
| 706 proxy->set_is_new_target(); | 706 proxy->set_is_new_target(); |
| 707 return proxy; | 707 return proxy; |
| 708 } | 708 } |
| 709 | 709 |
| 710 Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, | 710 Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, |
| 711 int pos) { | 711 int pos) const { |
| 712 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). | 712 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). |
| 713 Zone* zone = parser_->zone(); | 713 Zone* zone = parser_->zone(); |
| 714 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); | 714 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); |
| 715 VariableProxy* generator = factory->NewVariableProxy( | 715 VariableProxy* generator = factory->NewVariableProxy( |
| 716 parser_->function_state_->generator_object_variable()); | 716 parser_->function_state_->generator_object_variable()); |
| 717 args->Add(generator, zone); | 717 args->Add(generator, zone); |
| 718 return factory->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos, | 718 return factory->NewCallRuntime(Runtime::kInlineGeneratorGetInputOrDebugPos, |
| 719 args, pos); | 719 args, pos); |
| 720 } | 720 } |
| 721 | 721 |
| 722 | 722 |
| 723 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, | 723 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, |
| 724 Scanner* scanner, | 724 Scanner* scanner, |
| 725 AstNodeFactory* factory) { | 725 AstNodeFactory* factory) const { |
| 726 switch (token) { | 726 switch (token) { |
| 727 case Token::NULL_LITERAL: | 727 case Token::NULL_LITERAL: |
| 728 return factory->NewNullLiteral(pos); | 728 return factory->NewNullLiteral(pos); |
| 729 case Token::TRUE_LITERAL: | 729 case Token::TRUE_LITERAL: |
| 730 return factory->NewBooleanLiteral(true, pos); | 730 return factory->NewBooleanLiteral(true, pos); |
| 731 case Token::FALSE_LITERAL: | 731 case Token::FALSE_LITERAL: |
| 732 return factory->NewBooleanLiteral(false, pos); | 732 return factory->NewBooleanLiteral(false, pos); |
| 733 case Token::SMI: { | 733 case Token::SMI: { |
| 734 int value = scanner->smi_value(); | 734 int value = scanner->smi_value(); |
| 735 return factory->NewSmiLiteral(value, pos); | 735 return factory->NewSmiLiteral(value, pos); |
| 736 } | 736 } |
| 737 case Token::NUMBER: { | 737 case Token::NUMBER: { |
| 738 bool has_dot = scanner->ContainsDot(); | 738 bool has_dot = scanner->ContainsDot(); |
| 739 double value = scanner->DoubleValue(); | 739 double value = scanner->DoubleValue(); |
| 740 return factory->NewNumberLiteral(value, pos, has_dot); | 740 return factory->NewNumberLiteral(value, pos, has_dot); |
| 741 } | 741 } |
| 742 default: | 742 default: |
| 743 DCHECK(false); | 743 DCHECK(false); |
| 744 } | 744 } |
| 745 return NULL; | 745 return NULL; |
| 746 } | 746 } |
| 747 | 747 |
| 748 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, | 748 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
| 749 int start_position, | 749 int start_position, |
| 750 int end_position, | 750 int end_position, |
| 751 InferName infer) { | 751 InferName infer) const { |
| 752 if (infer == InferName::kYes && parser_->fni_ != NULL) { | 752 if (infer == InferName::kYes && parser_->fni_ != NULL) { |
| 753 parser_->fni_->PushVariableName(name); | 753 parser_->fni_->PushVariableName(name); |
| 754 } | 754 } |
| 755 return parser_->NewUnresolved(name, start_position, end_position); | 755 return parser_->NewUnresolved(name, start_position, end_position); |
| 756 } | 756 } |
| 757 | 757 |
| 758 | 758 |
| 759 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, | 759 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
| 760 AstNodeFactory* factory) { | 760 AstNodeFactory* factory) const { |
| 761 const AstRawString* symbol = GetSymbol(scanner); | 761 const AstRawString* symbol = GetSymbol(scanner); |
| 762 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 762 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
| 763 return factory->NewStringLiteral(symbol, pos); | 763 return factory->NewStringLiteral(symbol, pos); |
| 764 } | 764 } |
| 765 | 765 |
| 766 | 766 |
| 767 Expression* ParserTraits::GetIterator(Expression* iterable, | 767 Expression* ParserTraits::GetIterator(Expression* iterable, |
| 768 AstNodeFactory* factory, int pos) { | 768 AstNodeFactory* factory, int pos) { |
| 769 Expression* iterator_symbol_literal = | 769 Expression* iterator_symbol_literal = |
| 770 factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); | 770 factory->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); |
| 771 Expression* prop = | 771 Expression* prop = |
| 772 factory->NewProperty(iterable, iterator_symbol_literal, pos); | 772 factory->NewProperty(iterable, iterator_symbol_literal, pos); |
| 773 Zone* zone = parser_->zone(); | 773 Zone* zone = parser_->zone(); |
| 774 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); | 774 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); |
| 775 return factory->NewCall(prop, args, pos); | 775 return factory->NewCall(prop, args, pos); |
| 776 } | 776 } |
| 777 | 777 |
| 778 | 778 |
| 779 Literal* ParserTraits::GetLiteralTheHole(int position, | 779 Literal* ParserTraits::GetLiteralTheHole(int position, |
| 780 AstNodeFactory* factory) { | 780 AstNodeFactory* factory) const { |
| 781 return factory->NewTheHoleLiteral(kNoSourcePosition); | 781 return factory->NewTheHoleLiteral(kNoSourcePosition); |
| 782 } | 782 } |
| 783 | 783 |
| 784 | 784 |
| 785 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { | 785 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { |
| 786 return parser_->ParseV8Intrinsic(ok); | 786 return parser_->ParseV8Intrinsic(ok); |
| 787 } | 787 } |
| 788 | 788 |
| 789 | 789 |
| 790 FunctionLiteral* ParserTraits::ParseFunctionLiteral( | 790 FunctionLiteral* ParserTraits::ParseFunctionLiteral( |
| (...skipping 6230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7021 node->Print(Isolate::Current()); | 7021 node->Print(Isolate::Current()); |
| 7022 } | 7022 } |
| 7023 #endif // DEBUG | 7023 #endif // DEBUG |
| 7024 | 7024 |
| 7025 #undef CHECK_OK | 7025 #undef CHECK_OK |
| 7026 #undef CHECK_OK_VOID | 7026 #undef CHECK_OK_VOID |
| 7027 #undef CHECK_FAILED | 7027 #undef CHECK_FAILED |
| 7028 | 7028 |
| 7029 } // namespace internal | 7029 } // namespace internal |
| 7030 } // namespace v8 | 7030 } // namespace v8 |
| OLD | NEW |