OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); | 341 typename Traits::Type::Expression ParsePrimaryExpression(bool* ok); |
342 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); | 342 typename Traits::Type::Expression ParseExpression(bool accept_IN, bool* ok); |
343 typename Traits::Type::Expression ParseArrayLiteral(bool* ok); | 343 typename Traits::Type::Expression ParseArrayLiteral(bool* ok); |
344 typename Traits::Type::Expression ParseObjectLiteral(bool* ok); | 344 typename Traits::Type::Expression ParseObjectLiteral(bool* ok); |
345 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 345 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
346 typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN, | 346 typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN, |
347 bool* ok); | 347 bool* ok); |
348 typename Traits::Type::Expression ParseYieldExpression(bool* ok); | 348 typename Traits::Type::Expression ParseYieldExpression(bool* ok); |
349 typename Traits::Type::Expression ParseConditionalExpression(bool accept_IN, | 349 typename Traits::Type::Expression ParseConditionalExpression(bool accept_IN, |
350 bool* ok); | 350 bool* ok); |
| 351 typename Traits::Type::Expression ParseBinaryExpression(int prec, |
| 352 bool accept_IN, |
| 353 bool* ok); |
351 | 354 |
352 // Used to detect duplicates in object literals. Each of the values | 355 // Used to detect duplicates in object literals. Each of the values |
353 // kGetterProperty, kSetterProperty and kValueProperty represents | 356 // kGetterProperty, kSetterProperty and kValueProperty represents |
354 // a type of object literal property. When parsing a property, its | 357 // a type of object literal property. When parsing a property, its |
355 // type value is stored in the DuplicateFinder for the property name. | 358 // type value is stored in the DuplicateFinder for the property name. |
356 // Values are chosen so that having intersection bits means the there is | 359 // Values are chosen so that having intersection bits means the there is |
357 // an incompatibility. | 360 // an incompatibility. |
358 // I.e., you can add a getter to a property that already has a setter, since | 361 // I.e., you can add a getter to a property that already has a setter, since |
359 // kGetterProperty and kSetterProperty doesn't intersect, but not if it | 362 // kGetterProperty and kSetterProperty doesn't intersect, but not if it |
360 // already has a getter or a value. Adding the getter to an existing | 363 // already has a getter or a value. Adding the getter to an existing |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 class PreParserFactory { | 617 class PreParserFactory { |
615 public: | 618 public: |
616 explicit PreParserFactory(void* extra_param) {} | 619 explicit PreParserFactory(void* extra_param) {} |
617 | 620 |
618 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 621 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
619 PreParserIdentifier js_flags, | 622 PreParserIdentifier js_flags, |
620 int literal_index, | 623 int literal_index, |
621 int pos) { | 624 int pos) { |
622 return PreParserExpression::Default(); | 625 return PreParserExpression::Default(); |
623 } | 626 } |
| 627 PreParserExpression NewUnaryOperation(Token::Value op, |
| 628 PreParserExpression expression, |
| 629 int pos) { |
| 630 return PreParserExpression::Default(); |
| 631 } |
624 PreParserExpression NewBinaryOperation(Token::Value op, | 632 PreParserExpression NewBinaryOperation(Token::Value op, |
625 PreParserExpression left, | 633 PreParserExpression left, |
626 PreParserExpression right, int pos) { | 634 PreParserExpression right, int pos) { |
627 return PreParserExpression::Default(); | 635 return PreParserExpression::Default(); |
628 } | 636 } |
| 637 PreParserExpression NewCompareOperation(Token::Value op, |
| 638 PreParserExpression left, |
| 639 PreParserExpression right, int pos) { |
| 640 return PreParserExpression::Default(); |
| 641 } |
629 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 642 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
630 int literal_index, | 643 int literal_index, |
631 int pos) { | 644 int pos) { |
632 return PreParserExpression::Default(); | 645 return PreParserExpression::Default(); |
633 } | 646 } |
634 | 647 |
635 PreParserExpression NewObjectLiteralProperty(bool is_getter, | 648 PreParserExpression NewObjectLiteralProperty(bool is_getter, |
636 PreParserExpression value, | 649 PreParserExpression value, |
637 int pos) { | 650 int pos) { |
638 return PreParserExpression::Default(); | 651 return PreParserExpression::Default(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 PreParserExpression expression) { | 780 PreParserExpression expression) { |
768 // TODO(marja): To be able to produce the same errors, the preparser needs | 781 // TODO(marja): To be able to produce the same errors, the preparser needs |
769 // to start tracking which expressions are variables and which are lvalues. | 782 // to start tracking which expressions are variables and which are lvalues. |
770 return expression; | 783 return expression; |
771 } | 784 } |
772 | 785 |
773 // Checks LHS expression for assignment and prefix/postfix increment/decrement | 786 // Checks LHS expression for assignment and prefix/postfix increment/decrement |
774 // in strict mode. | 787 // in strict mode. |
775 void CheckStrictModeLValue(PreParserExpression expression, bool* ok); | 788 void CheckStrictModeLValue(PreParserExpression expression, bool* ok); |
776 | 789 |
| 790 bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, |
| 791 PreParserExpression y, |
| 792 Token::Value op, |
| 793 int pos, |
| 794 PreParserFactory* factory) { |
| 795 return false; |
| 796 } |
777 | 797 |
778 // Reporting errors. | 798 // Reporting errors. |
779 void ReportMessageAt(Scanner::Location location, | 799 void ReportMessageAt(Scanner::Location location, |
780 const char* message, | 800 const char* message, |
781 Vector<const char*> args); | 801 Vector<const char*> args); |
782 void ReportMessageAt(Scanner::Location location, | 802 void ReportMessageAt(Scanner::Location location, |
783 const char* type, | 803 const char* type, |
784 const char* name_opt); | 804 const char* name_opt); |
785 void ReportMessageAt(int start_pos, | 805 void ReportMessageAt(int start_pos, |
786 int end_pos, | 806 int end_pos, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 // Temporary glue; these functions will move to ParserBase. | 866 // Temporary glue; these functions will move to ParserBase. |
847 PreParserExpression ParseV8Intrinsic(bool* ok); | 867 PreParserExpression ParseV8Intrinsic(bool* ok); |
848 PreParserExpression ParseFunctionLiteral( | 868 PreParserExpression ParseFunctionLiteral( |
849 PreParserIdentifier name, | 869 PreParserIdentifier name, |
850 Scanner::Location function_name_location, | 870 Scanner::Location function_name_location, |
851 bool name_is_strict_reserved, | 871 bool name_is_strict_reserved, |
852 bool is_generator, | 872 bool is_generator, |
853 int function_token_position, | 873 int function_token_position, |
854 FunctionLiteral::FunctionType type, | 874 FunctionLiteral::FunctionType type, |
855 bool* ok); | 875 bool* ok); |
856 PreParserExpression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 876 PreParserExpression ParseUnaryExpression(bool* ok); |
857 | 877 |
858 private: | 878 private: |
859 PreParser* pre_parser_; | 879 PreParser* pre_parser_; |
860 }; | 880 }; |
861 | 881 |
862 | 882 |
863 // Preparsing checks a JavaScript program and emits preparse-data that helps | 883 // Preparsing checks a JavaScript program and emits preparse-data that helps |
864 // a later parsing to be faster. | 884 // a later parsing to be faster. |
865 // See preparse-data-format.h for the data format. | 885 // See preparse-data-format.h for the data format. |
866 | 886 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 Statement ParseReturnStatement(bool* ok); | 1032 Statement ParseReturnStatement(bool* ok); |
1013 Statement ParseWithStatement(bool* ok); | 1033 Statement ParseWithStatement(bool* ok); |
1014 Statement ParseSwitchStatement(bool* ok); | 1034 Statement ParseSwitchStatement(bool* ok); |
1015 Statement ParseDoWhileStatement(bool* ok); | 1035 Statement ParseDoWhileStatement(bool* ok); |
1016 Statement ParseWhileStatement(bool* ok); | 1036 Statement ParseWhileStatement(bool* ok); |
1017 Statement ParseForStatement(bool* ok); | 1037 Statement ParseForStatement(bool* ok); |
1018 Statement ParseThrowStatement(bool* ok); | 1038 Statement ParseThrowStatement(bool* ok); |
1019 Statement ParseTryStatement(bool* ok); | 1039 Statement ParseTryStatement(bool* ok); |
1020 Statement ParseDebuggerStatement(bool* ok); | 1040 Statement ParseDebuggerStatement(bool* ok); |
1021 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 1041 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
1022 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | |
1023 Expression ParseUnaryExpression(bool* ok); | 1042 Expression ParseUnaryExpression(bool* ok); |
1024 Expression ParsePostfixExpression(bool* ok); | 1043 Expression ParsePostfixExpression(bool* ok); |
1025 Expression ParseLeftHandSideExpression(bool* ok); | 1044 Expression ParseLeftHandSideExpression(bool* ok); |
1026 Expression ParseMemberExpression(bool* ok); | 1045 Expression ParseMemberExpression(bool* ok); |
1027 Expression ParseMemberExpressionContinuation(PreParserExpression expression, | 1046 Expression ParseMemberExpressionContinuation(PreParserExpression expression, |
1028 bool* ok); | 1047 bool* ok); |
1029 Expression ParseMemberWithNewPrefixesExpression(bool* ok); | 1048 Expression ParseMemberWithNewPrefixesExpression(bool* ok); |
1030 Expression ParseObjectLiteral(bool* ok); | 1049 Expression ParseObjectLiteral(bool* ok); |
1031 Expression ParseV8Intrinsic(bool* ok); | 1050 Expression ParseV8Intrinsic(bool* ok); |
1032 | 1051 |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 // section 11.12, page 58. | 1699 // section 11.12, page 58. |
1681 typename Traits::Type::Expression left = | 1700 typename Traits::Type::Expression left = |
1682 ParseAssignmentExpression(true, CHECK_OK); | 1701 ParseAssignmentExpression(true, CHECK_OK); |
1683 Expect(Token::COLON, CHECK_OK); | 1702 Expect(Token::COLON, CHECK_OK); |
1684 typename Traits::Type::Expression right = | 1703 typename Traits::Type::Expression right = |
1685 ParseAssignmentExpression(accept_IN, CHECK_OK); | 1704 ParseAssignmentExpression(accept_IN, CHECK_OK); |
1686 return factory()->NewConditional(expression, left, right, pos); | 1705 return factory()->NewConditional(expression, left, right, pos); |
1687 } | 1706 } |
1688 | 1707 |
1689 | 1708 |
| 1709 // Precedence >= 4 |
| 1710 template <class Traits> |
| 1711 typename Traits::Type::Expression |
| 1712 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { |
| 1713 ASSERT(prec >= 4); |
| 1714 typename Traits::Type::Expression x = this->ParseUnaryExpression(CHECK_OK); |
| 1715 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
| 1716 // prec1 >= 4 |
| 1717 while (Precedence(peek(), accept_IN) == prec1) { |
| 1718 Token::Value op = Next(); |
| 1719 int pos = position(); |
| 1720 typename Traits::Type::Expression y = |
| 1721 ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); |
| 1722 |
| 1723 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, |
| 1724 factory())) { |
| 1725 continue; |
| 1726 } |
| 1727 |
| 1728 // For now we distinguish between comparisons and other binary |
| 1729 // operations. (We could combine the two and get rid of this |
| 1730 // code and AST node eventually.) |
| 1731 if (Token::IsCompareOp(op)) { |
| 1732 // We have a comparison. |
| 1733 Token::Value cmp = op; |
| 1734 switch (op) { |
| 1735 case Token::NE: cmp = Token::EQ; break; |
| 1736 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; |
| 1737 default: break; |
| 1738 } |
| 1739 x = factory()->NewCompareOperation(cmp, x, y, pos); |
| 1740 if (cmp != op) { |
| 1741 // The comparison was negated - add a NOT. |
| 1742 x = factory()->NewUnaryOperation(Token::NOT, x, pos); |
| 1743 } |
| 1744 |
| 1745 } else { |
| 1746 // We have a "normal" binary operation. |
| 1747 x = factory()->NewBinaryOperation(op, x, y, pos); |
| 1748 } |
| 1749 } |
| 1750 } |
| 1751 return x; |
| 1752 } |
| 1753 |
| 1754 |
1690 #undef CHECK_OK | 1755 #undef CHECK_OK |
1691 #undef CHECK_OK_CUSTOM | 1756 #undef CHECK_OK_CUSTOM |
1692 | 1757 |
1693 | 1758 |
1694 template <typename Traits> | 1759 template <typename Traits> |
1695 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 1760 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
1696 Token::Value property, | 1761 Token::Value property, |
1697 PropertyKind type, | 1762 PropertyKind type, |
1698 bool* ok) { | 1763 bool* ok) { |
1699 int old; | 1764 int old; |
(...skipping 22 matching lines...) Expand all Loading... |
1722 "accessor_get_set"); | 1787 "accessor_get_set"); |
1723 } | 1788 } |
1724 *ok = false; | 1789 *ok = false; |
1725 } | 1790 } |
1726 } | 1791 } |
1727 | 1792 |
1728 | 1793 |
1729 } } // v8::internal | 1794 } } // v8::internal |
1730 | 1795 |
1731 #endif // V8_PREPARSER_H | 1796 #endif // V8_PREPARSER_H |
OLD | NEW |