| 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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 static PreParserIdentifier Yield() { | 620 static PreParserIdentifier Yield() { |
| 621 return PreParserIdentifier(kYieldIdentifier); | 621 return PreParserIdentifier(kYieldIdentifier); |
| 622 } | 622 } |
| 623 static PreParserIdentifier Prototype() { | 623 static PreParserIdentifier Prototype() { |
| 624 return PreParserIdentifier(kPrototypeIdentifier); | 624 return PreParserIdentifier(kPrototypeIdentifier); |
| 625 } | 625 } |
| 626 static PreParserIdentifier Constructor() { | 626 static PreParserIdentifier Constructor() { |
| 627 return PreParserIdentifier(kConstructorIdentifier); | 627 return PreParserIdentifier(kConstructorIdentifier); |
| 628 } | 628 } |
| 629 bool IsEval() const { return type_ == kEvalIdentifier; } | 629 bool IsEval() const { return type_ == kEvalIdentifier; } |
| 630 bool IsArguments() const { return type_ == kArgumentsIdentifier; } | 630 bool IsArguments(const AstValueFactory* = NULL) const { |
| 631 return type_ == kArgumentsIdentifier; |
| 632 } |
| 631 bool IsYield() const { return type_ == kYieldIdentifier; } | 633 bool IsYield() const { return type_ == kYieldIdentifier; } |
| 632 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } | 634 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } |
| 633 bool IsConstructor() const { return type_ == kConstructorIdentifier; } | 635 bool IsConstructor() const { return type_ == kConstructorIdentifier; } |
| 634 bool IsEvalOrArguments() const { | 636 bool IsEvalOrArguments() const { |
| 635 return type_ == kEvalIdentifier || type_ == kArgumentsIdentifier; | 637 return type_ == kEvalIdentifier || type_ == kArgumentsIdentifier; |
| 636 } | 638 } |
| 637 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } | 639 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } |
| 638 bool IsFutureStrictReserved() const { | 640 bool IsFutureStrictReserved() const { |
| 639 return type_ == kFutureStrictReservedIdentifier; | 641 return type_ == kFutureStrictReservedIdentifier; |
| 640 } | 642 } |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 | 963 |
| 962 // When PreParser is in use, lazy compilation is already being done, | 964 // When PreParser is in use, lazy compilation is already being done, |
| 963 // things cannot get lazier than that. | 965 // things cannot get lazier than that. |
| 964 bool AllowsLazyCompilation() const { return false; } | 966 bool AllowsLazyCompilation() const { return false; } |
| 965 | 967 |
| 966 void set_start_position(int position) {} | 968 void set_start_position(int position) {} |
| 967 void set_end_position(int position) {} | 969 void set_end_position(int position) {} |
| 968 | 970 |
| 969 bool IsDeclared(const PreParserIdentifier& identifier) const { return false; } | 971 bool IsDeclared(const PreParserIdentifier& identifier) const { return false; } |
| 970 void DeclareParameter(const PreParserIdentifier& identifier, VariableMode) {} | 972 void DeclareParameter(const PreParserIdentifier& identifier, VariableMode) {} |
| 973 void RecordArgumentsUsage() {} |
| 974 void RecordThisUsage() {} |
| 971 | 975 |
| 972 // Allow scope->Foo() to work. | 976 // Allow scope->Foo() to work. |
| 973 PreParserScope* operator->() { return this; } | 977 PreParserScope* operator->() { return this; } |
| 974 | 978 |
| 975 private: | 979 private: |
| 976 ScopeType scope_type_; | 980 ScopeType scope_type_; |
| 977 StrictMode strict_mode_; | 981 StrictMode strict_mode_; |
| 978 }; | 982 }; |
| 979 | 983 |
| 980 | 984 |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, | 1652 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, |
| 1649 bool* ok) { | 1653 bool* ok) { |
| 1650 Token::Value next = Next(); | 1654 Token::Value next = Next(); |
| 1651 if (next == Token::IDENTIFIER) { | 1655 if (next == Token::IDENTIFIER) { |
| 1652 IdentifierT name = this->GetSymbol(scanner()); | 1656 IdentifierT name = this->GetSymbol(scanner()); |
| 1653 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && | 1657 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && |
| 1654 strict_mode() == STRICT && this->IsEvalOrArguments(name)) { | 1658 strict_mode() == STRICT && this->IsEvalOrArguments(name)) { |
| 1655 ReportMessage("strict_eval_arguments"); | 1659 ReportMessage("strict_eval_arguments"); |
| 1656 *ok = false; | 1660 *ok = false; |
| 1657 } | 1661 } |
| 1662 if (name->IsArguments(this->ast_value_factory())) |
| 1663 scope_->RecordArgumentsUsage(); |
| 1658 return name; | 1664 return name; |
| 1659 } else if (strict_mode() == SLOPPY && | 1665 } else if (strict_mode() == SLOPPY && |
| 1660 (next == Token::FUTURE_STRICT_RESERVED_WORD || | 1666 (next == Token::FUTURE_STRICT_RESERVED_WORD || |
| 1661 (next == Token::LET) || | 1667 (next == Token::LET) || |
| 1662 (next == Token::YIELD && !is_generator()))) { | 1668 (next == Token::YIELD && !is_generator()))) { |
| 1663 return this->GetSymbol(scanner()); | 1669 return this->GetSymbol(scanner()); |
| 1664 } else { | 1670 } else { |
| 1665 this->ReportUnexpectedToken(next); | 1671 this->ReportUnexpectedToken(next); |
| 1666 *ok = false; | 1672 *ok = false; |
| 1667 return Traits::EmptyIdentifier(); | 1673 return Traits::EmptyIdentifier(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1678 *is_strict_reserved = false; | 1684 *is_strict_reserved = false; |
| 1679 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || | 1685 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || |
| 1680 next == Token::LET || | 1686 next == Token::LET || |
| 1681 (next == Token::YIELD && !this->is_generator())) { | 1687 (next == Token::YIELD && !this->is_generator())) { |
| 1682 *is_strict_reserved = true; | 1688 *is_strict_reserved = true; |
| 1683 } else { | 1689 } else { |
| 1684 ReportUnexpectedToken(next); | 1690 ReportUnexpectedToken(next); |
| 1685 *ok = false; | 1691 *ok = false; |
| 1686 return Traits::EmptyIdentifier(); | 1692 return Traits::EmptyIdentifier(); |
| 1687 } | 1693 } |
| 1688 return this->GetSymbol(scanner()); | 1694 |
| 1695 IdentifierT name = this->GetSymbol(scanner()); |
| 1696 if (name->IsArguments(this->ast_value_factory())) |
| 1697 scope_->RecordArgumentsUsage(); |
| 1698 return name; |
| 1689 } | 1699 } |
| 1690 | 1700 |
| 1691 | 1701 |
| 1692 template <class Traits> | 1702 template <class Traits> |
| 1693 typename ParserBase<Traits>::IdentifierT | 1703 typename ParserBase<Traits>::IdentifierT |
| 1694 ParserBase<Traits>::ParseIdentifierName(bool* ok) { | 1704 ParserBase<Traits>::ParseIdentifierName(bool* ok) { |
| 1695 Token::Value next = Next(); | 1705 Token::Value next = Next(); |
| 1696 if (next != Token::IDENTIFIER && next != Token::FUTURE_RESERVED_WORD && | 1706 if (next != Token::IDENTIFIER && next != Token::FUTURE_RESERVED_WORD && |
| 1697 next != Token::LET && next != Token::YIELD && | 1707 next != Token::LET && next != Token::YIELD && |
| 1698 next != Token::FUTURE_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { | 1708 next != Token::FUTURE_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { |
| 1699 this->ReportUnexpectedToken(next); | 1709 this->ReportUnexpectedToken(next); |
| 1700 *ok = false; | 1710 *ok = false; |
| 1701 return Traits::EmptyIdentifier(); | 1711 return Traits::EmptyIdentifier(); |
| 1702 } | 1712 } |
| 1703 return this->GetSymbol(scanner()); | 1713 |
| 1714 IdentifierT name = this->GetSymbol(scanner()); |
| 1715 if (name->IsArguments(this->ast_value_factory())) |
| 1716 scope_->RecordArgumentsUsage(); |
| 1717 return name; |
| 1704 } | 1718 } |
| 1705 | 1719 |
| 1706 | 1720 |
| 1707 template <class Traits> | 1721 template <class Traits> |
| 1708 typename ParserBase<Traits>::IdentifierT | 1722 typename ParserBase<Traits>::IdentifierT |
| 1709 ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get, | 1723 ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get, |
| 1710 bool* is_set, | 1724 bool* is_set, |
| 1711 bool* ok) { | 1725 bool* ok) { |
| 1712 IdentifierT result = ParseIdentifierName(ok); | 1726 IdentifierT result = ParseIdentifierName(ok); |
| 1713 if (!*ok) return Traits::EmptyIdentifier(); | 1727 if (!*ok) return Traits::EmptyIdentifier(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 // RegExpLiteral | 1785 // RegExpLiteral |
| 1772 // ClassLiteral | 1786 // ClassLiteral |
| 1773 // '(' Expression ')' | 1787 // '(' Expression ')' |
| 1774 | 1788 |
| 1775 int pos = peek_position(); | 1789 int pos = peek_position(); |
| 1776 ExpressionT result = this->EmptyExpression(); | 1790 ExpressionT result = this->EmptyExpression(); |
| 1777 Token::Value token = peek(); | 1791 Token::Value token = peek(); |
| 1778 switch (token) { | 1792 switch (token) { |
| 1779 case Token::THIS: { | 1793 case Token::THIS: { |
| 1780 Consume(Token::THIS); | 1794 Consume(Token::THIS); |
| 1795 scope_->RecordThisUsage(); |
| 1781 result = this->ThisExpression(scope_, factory()); | 1796 result = this->ThisExpression(scope_, factory()); |
| 1782 break; | 1797 break; |
| 1783 } | 1798 } |
| 1784 | 1799 |
| 1785 case Token::NULL_LITERAL: | 1800 case Token::NULL_LITERAL: |
| 1786 case Token::TRUE_LITERAL: | 1801 case Token::TRUE_LITERAL: |
| 1787 case Token::FALSE_LITERAL: | 1802 case Token::FALSE_LITERAL: |
| 1788 case Token::NUMBER: | 1803 case Token::NUMBER: |
| 1789 Next(); | 1804 Next(); |
| 1790 result = this->ExpressionFromLiteral(token, pos, scanner(), factory()); | 1805 result = this->ExpressionFromLiteral(token, pos, scanner(), factory()); |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 } | 2633 } |
| 2619 DCHECK(false); | 2634 DCHECK(false); |
| 2620 return this->EmptyExpression(); | 2635 return this->EmptyExpression(); |
| 2621 } | 2636 } |
| 2622 | 2637 |
| 2623 | 2638 |
| 2624 template <class Traits> | 2639 template <class Traits> |
| 2625 typename ParserBase<Traits>::ExpressionT ParserBase< | 2640 typename ParserBase<Traits>::ExpressionT ParserBase< |
| 2626 Traits>::ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, | 2641 Traits>::ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, |
| 2627 bool* ok) { | 2642 bool* ok) { |
| 2628 // TODO(aperez): Change this to use ARROW_SCOPE | 2643 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); |
| 2629 typename Traits::Type::ScopePtr scope = | |
| 2630 this->NewScope(scope_, FUNCTION_SCOPE); | |
| 2631 typename Traits::Type::StatementList body; | 2644 typename Traits::Type::StatementList body; |
| 2632 typename Traits::Type::AstProperties ast_properties; | 2645 typename Traits::Type::AstProperties ast_properties; |
| 2633 BailoutReason dont_optimize_reason = kNoReason; | 2646 BailoutReason dont_optimize_reason = kNoReason; |
| 2634 int num_parameters = -1; | 2647 int num_parameters = -1; |
| 2635 int materialized_literal_count = -1; | 2648 int materialized_literal_count = -1; |
| 2636 int expected_property_count = -1; | 2649 int expected_property_count = -1; |
| 2637 int handler_count = 0; | 2650 int handler_count = 0; |
| 2638 | 2651 |
| 2639 { | 2652 { |
| 2640 FunctionState function_state(&function_state_, &scope_, &scope, zone(), | 2653 FunctionState function_state(&function_state_, &scope_, &scope, zone(), |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2845 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2858 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
| 2846 // Both accessors of the same type. | 2859 // Both accessors of the same type. |
| 2847 parser()->ReportMessage("accessor_get_set"); | 2860 parser()->ReportMessage("accessor_get_set"); |
| 2848 } | 2861 } |
| 2849 *ok = false; | 2862 *ok = false; |
| 2850 } | 2863 } |
| 2851 } | 2864 } |
| 2852 } } // v8::internal | 2865 } } // v8::internal |
| 2853 | 2866 |
| 2854 #endif // V8_PREPARSER_H | 2867 #endif // V8_PREPARSER_H |
| OLD | NEW |