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/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 static PreParserIdentifier FutureStrictReserved() { | 603 static PreParserIdentifier FutureStrictReserved() { |
604 return PreParserIdentifier(kFutureStrictReservedIdentifier); | 604 return PreParserIdentifier(kFutureStrictReservedIdentifier); |
605 } | 605 } |
606 static PreParserIdentifier Let() { | 606 static PreParserIdentifier Let() { |
607 return PreParserIdentifier(kLetIdentifier); | 607 return PreParserIdentifier(kLetIdentifier); |
608 } | 608 } |
609 static PreParserIdentifier Yield() { | 609 static PreParserIdentifier Yield() { |
610 return PreParserIdentifier(kYieldIdentifier); | 610 return PreParserIdentifier(kYieldIdentifier); |
611 } | 611 } |
612 bool IsEval() const { return type_ == kEvalIdentifier; } | 612 bool IsEval() const { return type_ == kEvalIdentifier; } |
613 bool IsArguments() const { return type_ == kArgumentsIdentifier; } | 613 bool IsArguments(const AstValueFactory*) const { |
rossberg
2014/09/10 06:33:56
Why is this change necessary when the argument isn
| |
614 return type_ == kArgumentsIdentifier; | |
615 } | |
614 bool IsEvalOrArguments() const { return type_ >= kEvalIdentifier; } | 616 bool IsEvalOrArguments() const { return type_ >= kEvalIdentifier; } |
615 bool IsYield() const { return type_ == kYieldIdentifier; } | 617 bool IsYield() const { return type_ == kYieldIdentifier; } |
616 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } | 618 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } |
617 bool IsFutureStrictReserved() const { | 619 bool IsFutureStrictReserved() const { |
618 return type_ == kFutureStrictReservedIdentifier; | 620 return type_ == kFutureStrictReservedIdentifier; |
619 } | 621 } |
620 bool IsValidStrictVariable() const { return type_ == kUnknownIdentifier; } | 622 bool IsValidStrictVariable() const { return type_ == kUnknownIdentifier; } |
621 | 623 |
622 // Allow identifier->name()[->length()] to work. The preparser | 624 // Allow identifier->name()[->length()] to work. The preparser |
623 // does not need the actual positions/lengths of the identifiers. | 625 // does not need the actual positions/lengths of the identifiers. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 }; | 821 }; |
820 | 822 |
821 explicit PreParserExpression(int expression_code) : code_(expression_code) {} | 823 explicit PreParserExpression(int expression_code) : code_(expression_code) {} |
822 | 824 |
823 V8_INLINE int ArrowParamListBit() const { | 825 V8_INLINE int ArrowParamListBit() const { |
824 if (IsBinaryOperation()) return code_ & kBinaryOperationArrowParamList; | 826 if (IsBinaryOperation()) return code_ & kBinaryOperationArrowParamList; |
825 if (IsIdentifier()) { | 827 if (IsIdentifier()) { |
826 const PreParserIdentifier ident = AsIdentifier(); | 828 const PreParserIdentifier ident = AsIdentifier(); |
827 // A valid identifier can be an arrow function parameter list | 829 // A valid identifier can be an arrow function parameter list |
828 // except for eval, arguments, yield, and reserved keywords. | 830 // except for eval, arguments, yield, and reserved keywords. |
829 if (ident.IsEval() || ident.IsArguments() || ident.IsYield() || | 831 if (ident.IsEval() || ident.IsArguments(nullptr) || ident.IsYield() || |
rossberg
2014/09/10 06:33:56
Unfortunately, we can't use C++11 yet...
| |
830 ident.IsFutureStrictReserved()) | 832 ident.IsFutureStrictReserved()) |
831 return 0; | 833 return 0; |
832 return kBinaryOperationArrowParamList; | 834 return kBinaryOperationArrowParamList; |
833 } | 835 } |
834 return 0; | 836 return 0; |
835 } | 837 } |
836 | 838 |
837 int code_; | 839 int code_; |
838 }; | 840 }; |
839 | 841 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 | 929 |
928 // When PreParser is in use, lazy compilation is already being done, | 930 // When PreParser is in use, lazy compilation is already being done, |
929 // things cannot get lazier than that. | 931 // things cannot get lazier than that. |
930 bool AllowsLazyCompilation() const { return false; } | 932 bool AllowsLazyCompilation() const { return false; } |
931 | 933 |
932 void set_start_position(int position) {} | 934 void set_start_position(int position) {} |
933 void set_end_position(int position) {} | 935 void set_end_position(int position) {} |
934 | 936 |
935 bool IsDeclared(const PreParserIdentifier& identifier) const { return false; } | 937 bool IsDeclared(const PreParserIdentifier& identifier) const { return false; } |
936 void DeclareParameter(const PreParserIdentifier& identifier, VariableMode) {} | 938 void DeclareParameter(const PreParserIdentifier& identifier, VariableMode) {} |
939 void RecordArgumentsUsage() {} | |
940 void RecordThisUsage() {} | |
937 | 941 |
938 // Allow scope->Foo() to work. | 942 // Allow scope->Foo() to work. |
939 PreParserScope* operator->() { return this; } | 943 PreParserScope* operator->() { return this; } |
940 | 944 |
941 private: | 945 private: |
942 ScopeType scope_type_; | 946 ScopeType scope_type_; |
943 StrictMode strict_mode_; | 947 StrictMode strict_mode_; |
944 }; | 948 }; |
945 | 949 |
946 | 950 |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1592 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, | 1596 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, |
1593 bool* ok) { | 1597 bool* ok) { |
1594 Token::Value next = Next(); | 1598 Token::Value next = Next(); |
1595 if (next == Token::IDENTIFIER) { | 1599 if (next == Token::IDENTIFIER) { |
1596 IdentifierT name = this->GetSymbol(scanner()); | 1600 IdentifierT name = this->GetSymbol(scanner()); |
1597 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && | 1601 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && |
1598 strict_mode() == STRICT && this->IsEvalOrArguments(name)) { | 1602 strict_mode() == STRICT && this->IsEvalOrArguments(name)) { |
1599 ReportMessage("strict_eval_arguments"); | 1603 ReportMessage("strict_eval_arguments"); |
1600 *ok = false; | 1604 *ok = false; |
1601 } | 1605 } |
1606 if (name->IsArguments(this->ast_value_factory())) | |
1607 scope_->RecordArgumentsUsage(); | |
1602 return name; | 1608 return name; |
1603 } else if (strict_mode() == SLOPPY && | 1609 } else if (strict_mode() == SLOPPY && |
1604 (next == Token::FUTURE_STRICT_RESERVED_WORD || | 1610 (next == Token::FUTURE_STRICT_RESERVED_WORD || |
1605 (next == Token::LET) || | 1611 (next == Token::LET) || |
1606 (next == Token::YIELD && !is_generator()))) { | 1612 (next == Token::YIELD && !is_generator()))) { |
1607 return this->GetSymbol(scanner()); | 1613 return this->GetSymbol(scanner()); |
1608 } else { | 1614 } else { |
1609 this->ReportUnexpectedToken(next); | 1615 this->ReportUnexpectedToken(next); |
1610 *ok = false; | 1616 *ok = false; |
1611 return Traits::EmptyIdentifier(); | 1617 return Traits::EmptyIdentifier(); |
(...skipping 10 matching lines...) Expand all Loading... | |
1622 *is_strict_reserved = false; | 1628 *is_strict_reserved = false; |
1623 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || | 1629 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || |
1624 next == Token::LET || | 1630 next == Token::LET || |
1625 (next == Token::YIELD && !this->is_generator())) { | 1631 (next == Token::YIELD && !this->is_generator())) { |
1626 *is_strict_reserved = true; | 1632 *is_strict_reserved = true; |
1627 } else { | 1633 } else { |
1628 ReportUnexpectedToken(next); | 1634 ReportUnexpectedToken(next); |
1629 *ok = false; | 1635 *ok = false; |
1630 return Traits::EmptyIdentifier(); | 1636 return Traits::EmptyIdentifier(); |
1631 } | 1637 } |
1632 return this->GetSymbol(scanner()); | 1638 |
1639 IdentifierT name = this->GetSymbol(scanner()); | |
1640 if (name->IsArguments(this->ast_value_factory())) | |
1641 scope_->RecordArgumentsUsage(); | |
1642 return name; | |
1633 } | 1643 } |
1634 | 1644 |
1635 | 1645 |
1636 template <class Traits> | 1646 template <class Traits> |
1637 typename ParserBase<Traits>::IdentifierT | 1647 typename ParserBase<Traits>::IdentifierT |
1638 ParserBase<Traits>::ParseIdentifierName(bool* ok) { | 1648 ParserBase<Traits>::ParseIdentifierName(bool* ok) { |
1639 Token::Value next = Next(); | 1649 Token::Value next = Next(); |
1640 if (next != Token::IDENTIFIER && next != Token::FUTURE_RESERVED_WORD && | 1650 if (next != Token::IDENTIFIER && next != Token::FUTURE_RESERVED_WORD && |
1641 next != Token::LET && next != Token::YIELD && | 1651 next != Token::LET && next != Token::YIELD && |
1642 next != Token::FUTURE_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { | 1652 next != Token::FUTURE_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { |
1643 this->ReportUnexpectedToken(next); | 1653 this->ReportUnexpectedToken(next); |
1644 *ok = false; | 1654 *ok = false; |
1645 return Traits::EmptyIdentifier(); | 1655 return Traits::EmptyIdentifier(); |
1646 } | 1656 } |
1647 return this->GetSymbol(scanner()); | 1657 |
1658 IdentifierT name = this->GetSymbol(scanner()); | |
1659 if (name->IsArguments(this->ast_value_factory())) | |
1660 scope_->RecordArgumentsUsage(); | |
1661 return name; | |
1648 } | 1662 } |
1649 | 1663 |
1650 | 1664 |
1651 template <class Traits> | 1665 template <class Traits> |
1652 typename ParserBase<Traits>::IdentifierT | 1666 typename ParserBase<Traits>::IdentifierT |
1653 ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get, | 1667 ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get, |
1654 bool* is_set, | 1668 bool* is_set, |
1655 bool* ok) { | 1669 bool* ok) { |
1656 IdentifierT result = ParseIdentifierName(ok); | 1670 IdentifierT result = ParseIdentifierName(ok); |
1657 if (!*ok) return Traits::EmptyIdentifier(); | 1671 if (!*ok) return Traits::EmptyIdentifier(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1714 // ObjectLiteral | 1728 // ObjectLiteral |
1715 // RegExpLiteral | 1729 // RegExpLiteral |
1716 // '(' Expression ')' | 1730 // '(' Expression ')' |
1717 | 1731 |
1718 int pos = peek_position(); | 1732 int pos = peek_position(); |
1719 ExpressionT result = this->EmptyExpression(); | 1733 ExpressionT result = this->EmptyExpression(); |
1720 Token::Value token = peek(); | 1734 Token::Value token = peek(); |
1721 switch (token) { | 1735 switch (token) { |
1722 case Token::THIS: { | 1736 case Token::THIS: { |
1723 Consume(Token::THIS); | 1737 Consume(Token::THIS); |
1738 scope_->RecordThisUsage(); | |
1724 result = this->ThisExpression(scope_, factory()); | 1739 result = this->ThisExpression(scope_, factory()); |
1725 break; | 1740 break; |
1726 } | 1741 } |
1727 | 1742 |
1728 case Token::NULL_LITERAL: | 1743 case Token::NULL_LITERAL: |
1729 case Token::TRUE_LITERAL: | 1744 case Token::TRUE_LITERAL: |
1730 case Token::FALSE_LITERAL: | 1745 case Token::FALSE_LITERAL: |
1731 case Token::NUMBER: | 1746 case Token::NUMBER: |
1732 Next(); | 1747 Next(); |
1733 result = this->ExpressionFromLiteral(token, pos, scanner(), factory()); | 1748 result = this->ExpressionFromLiteral(token, pos, scanner(), factory()); |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2661 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2676 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
2662 // Both accessors of the same type. | 2677 // Both accessors of the same type. |
2663 parser()->ReportMessage("accessor_get_set"); | 2678 parser()->ReportMessage("accessor_get_set"); |
2664 } | 2679 } |
2665 *ok = false; | 2680 *ok = false; |
2666 } | 2681 } |
2667 } | 2682 } |
2668 } } // v8::internal | 2683 } } // v8::internal |
2669 | 2684 |
2670 #endif // V8_PREPARSER_H | 2685 #endif // V8_PREPARSER_H |
OLD | NEW |