| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 ExpressionT ParsePrimaryExpression(bool* ok); | 388 ExpressionT ParsePrimaryExpression(bool* ok); |
| 389 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 389 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
| 390 ExpressionT ParseArrayLiteral(bool* ok); | 390 ExpressionT ParseArrayLiteral(bool* ok); |
| 391 ExpressionT ParseObjectLiteral(bool* ok); | 391 ExpressionT ParseObjectLiteral(bool* ok); |
| 392 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 392 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
| 393 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 393 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 394 ExpressionT ParseYieldExpression(bool* ok); | 394 ExpressionT ParseYieldExpression(bool* ok); |
| 395 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); | 395 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); |
| 396 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 396 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 397 ExpressionT ParseUnaryExpression(bool* ok); |
| 397 | 398 |
| 398 // Used to detect duplicates in object literals. Each of the values | 399 // Used to detect duplicates in object literals. Each of the values |
| 399 // kGetterProperty, kSetterProperty and kValueProperty represents | 400 // kGetterProperty, kSetterProperty and kValueProperty represents |
| 400 // a type of object literal property. When parsing a property, its | 401 // a type of object literal property. When parsing a property, its |
| 401 // type value is stored in the DuplicateFinder for the property name. | 402 // type value is stored in the DuplicateFinder for the property name. |
| 402 // Values are chosen so that having intersection bits means the there is | 403 // Values are chosen so that having intersection bits means the there is |
| 403 // an incompatibility. | 404 // an incompatibility. |
| 404 // I.e., you can add a getter to a property that already has a setter, since | 405 // I.e., you can add a getter to a property that already has a setter, since |
| 405 // kGetterProperty and kSetterProperty doesn't intersect, but not if it | 406 // kGetterProperty and kSetterProperty doesn't intersect, but not if it |
| 406 // already has a getter or a value. Adding the getter to an existing | 407 // already has a getter or a value. Adding the getter to an existing |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 int pos) { | 736 int pos) { |
| 736 return PreParserExpression::Default(); | 737 return PreParserExpression::Default(); |
| 737 } | 738 } |
| 738 | 739 |
| 739 PreParserExpression NewConditional(PreParserExpression condition, | 740 PreParserExpression NewConditional(PreParserExpression condition, |
| 740 PreParserExpression then_expression, | 741 PreParserExpression then_expression, |
| 741 PreParserExpression else_expression, | 742 PreParserExpression else_expression, |
| 742 int pos) { | 743 int pos) { |
| 743 return PreParserExpression::Default(); | 744 return PreParserExpression::Default(); |
| 744 } | 745 } |
| 746 |
| 747 PreParserExpression NewCountOperation(Token::Value op, |
| 748 bool is_prefix, |
| 749 PreParserExpression expression, |
| 750 int pos) { |
| 751 return PreParserExpression::Default(); |
| 752 } |
| 745 }; | 753 }; |
| 746 | 754 |
| 747 | 755 |
| 748 class PreParser; | 756 class PreParser; |
| 749 | 757 |
| 750 class PreParserTraits { | 758 class PreParserTraits { |
| 751 public: | 759 public: |
| 752 struct Type { | 760 struct Type { |
| 753 // TODO(marja): To be removed. The Traits object should contain all the data | 761 // TODO(marja): To be removed. The Traits object should contain all the data |
| 754 // it needs. | 762 // it needs. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // Helper functions for recursive descent. | 795 // Helper functions for recursive descent. |
| 788 static bool IsEvalOrArguments(PreParserIdentifier identifier) { | 796 static bool IsEvalOrArguments(PreParserIdentifier identifier) { |
| 789 return identifier.IsEvalOrArguments(); | 797 return identifier.IsEvalOrArguments(); |
| 790 } | 798 } |
| 791 | 799 |
| 792 // Returns true if the expression is of type "this.foo". | 800 // Returns true if the expression is of type "this.foo". |
| 793 static bool IsThisProperty(PreParserExpression expression) { | 801 static bool IsThisProperty(PreParserExpression expression) { |
| 794 return expression.IsThisProperty(); | 802 return expression.IsThisProperty(); |
| 795 } | 803 } |
| 796 | 804 |
| 805 static bool IsIdentifier(PreParserExpression expression) { |
| 806 return expression.IsIdentifier(); |
| 807 } |
| 808 |
| 797 static bool IsBoilerplateProperty(PreParserExpression property) { | 809 static bool IsBoilerplateProperty(PreParserExpression property) { |
| 798 // PreParser doesn't count boilerplate properties. | 810 // PreParser doesn't count boilerplate properties. |
| 799 return false; | 811 return false; |
| 800 } | 812 } |
| 801 | 813 |
| 802 static bool IsArrayIndex(PreParserIdentifier string, uint32_t* index) { | 814 static bool IsArrayIndex(PreParserIdentifier string, uint32_t* index) { |
| 803 return false; | 815 return false; |
| 804 } | 816 } |
| 805 | 817 |
| 806 // Functions for encapsulating the differences between parsing and preparsing; | 818 // Functions for encapsulating the differences between parsing and preparsing; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 834 void CheckStrictModeLValue(PreParserExpression expression, bool* ok); | 846 void CheckStrictModeLValue(PreParserExpression expression, bool* ok); |
| 835 | 847 |
| 836 bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, | 848 bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, |
| 837 PreParserExpression y, | 849 PreParserExpression y, |
| 838 Token::Value op, | 850 Token::Value op, |
| 839 int pos, | 851 int pos, |
| 840 PreParserFactory* factory) { | 852 PreParserFactory* factory) { |
| 841 return false; | 853 return false; |
| 842 } | 854 } |
| 843 | 855 |
| 856 PreParserExpression BuildUnaryExpression(PreParserExpression expression, |
| 857 Token::Value op, int pos, |
| 858 PreParserFactory* factory) { |
| 859 return PreParserExpression::Default(); |
| 860 } |
| 861 |
| 844 // Reporting errors. | 862 // Reporting errors. |
| 845 void ReportMessageAt(Scanner::Location location, | 863 void ReportMessageAt(Scanner::Location location, |
| 846 const char* message, | 864 const char* message, |
| 847 Vector<const char*> args, | 865 Vector<const char*> args, |
| 848 bool is_reference_error = false); | 866 bool is_reference_error = false); |
| 849 void ReportMessageAt(Scanner::Location location, | 867 void ReportMessageAt(Scanner::Location location, |
| 850 const char* type, | 868 const char* type, |
| 851 const char* name_opt, | 869 const char* name_opt, |
| 852 bool is_reference_error = false); | 870 bool is_reference_error = false); |
| 853 void ReportMessageAt(int start_pos, | 871 void ReportMessageAt(int start_pos, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 // Temporary glue; these functions will move to ParserBase. | 933 // Temporary glue; these functions will move to ParserBase. |
| 916 PreParserExpression ParseV8Intrinsic(bool* ok); | 934 PreParserExpression ParseV8Intrinsic(bool* ok); |
| 917 PreParserExpression ParseFunctionLiteral( | 935 PreParserExpression ParseFunctionLiteral( |
| 918 PreParserIdentifier name, | 936 PreParserIdentifier name, |
| 919 Scanner::Location function_name_location, | 937 Scanner::Location function_name_location, |
| 920 bool name_is_strict_reserved, | 938 bool name_is_strict_reserved, |
| 921 bool is_generator, | 939 bool is_generator, |
| 922 int function_token_position, | 940 int function_token_position, |
| 923 FunctionLiteral::FunctionType type, | 941 FunctionLiteral::FunctionType type, |
| 924 bool* ok); | 942 bool* ok); |
| 925 PreParserExpression ParseUnaryExpression(bool* ok); | 943 PreParserExpression ParsePostfixExpression(bool* ok); |
| 926 | 944 |
| 927 private: | 945 private: |
| 928 PreParser* pre_parser_; | 946 PreParser* pre_parser_; |
| 929 }; | 947 }; |
| 930 | 948 |
| 931 | 949 |
| 932 // Preparsing checks a JavaScript program and emits preparse-data that helps | 950 // Preparsing checks a JavaScript program and emits preparse-data that helps |
| 933 // a later parsing to be faster. | 951 // a later parsing to be faster. |
| 934 // See preparse-data-format.h for the data format. | 952 // See preparse-data-format.h for the data format. |
| 935 | 953 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 Statement ParseReturnStatement(bool* ok); | 1097 Statement ParseReturnStatement(bool* ok); |
| 1080 Statement ParseWithStatement(bool* ok); | 1098 Statement ParseWithStatement(bool* ok); |
| 1081 Statement ParseSwitchStatement(bool* ok); | 1099 Statement ParseSwitchStatement(bool* ok); |
| 1082 Statement ParseDoWhileStatement(bool* ok); | 1100 Statement ParseDoWhileStatement(bool* ok); |
| 1083 Statement ParseWhileStatement(bool* ok); | 1101 Statement ParseWhileStatement(bool* ok); |
| 1084 Statement ParseForStatement(bool* ok); | 1102 Statement ParseForStatement(bool* ok); |
| 1085 Statement ParseThrowStatement(bool* ok); | 1103 Statement ParseThrowStatement(bool* ok); |
| 1086 Statement ParseTryStatement(bool* ok); | 1104 Statement ParseTryStatement(bool* ok); |
| 1087 Statement ParseDebuggerStatement(bool* ok); | 1105 Statement ParseDebuggerStatement(bool* ok); |
| 1088 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 1106 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
| 1089 Expression ParseUnaryExpression(bool* ok); | |
| 1090 Expression ParsePostfixExpression(bool* ok); | 1107 Expression ParsePostfixExpression(bool* ok); |
| 1091 Expression ParseLeftHandSideExpression(bool* ok); | 1108 Expression ParseLeftHandSideExpression(bool* ok); |
| 1092 Expression ParseMemberExpression(bool* ok); | 1109 Expression ParseMemberExpression(bool* ok); |
| 1093 Expression ParseMemberExpressionContinuation(PreParserExpression expression, | 1110 Expression ParseMemberExpressionContinuation(PreParserExpression expression, |
| 1094 bool* ok); | 1111 bool* ok); |
| 1095 Expression ParseMemberWithNewPrefixesExpression(bool* ok); | 1112 Expression ParseMemberWithNewPrefixesExpression(bool* ok); |
| 1096 Expression ParseObjectLiteral(bool* ok); | 1113 Expression ParseObjectLiteral(bool* ok); |
| 1097 Expression ParseV8Intrinsic(bool* ok); | 1114 Expression ParseV8Intrinsic(bool* ok); |
| 1098 | 1115 |
| 1099 Expression ParseFunctionLiteral( | 1116 Expression ParseFunctionLiteral( |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 } else { | 1788 } else { |
| 1772 // We have a "normal" binary operation. | 1789 // We have a "normal" binary operation. |
| 1773 x = factory()->NewBinaryOperation(op, x, y, pos); | 1790 x = factory()->NewBinaryOperation(op, x, y, pos); |
| 1774 } | 1791 } |
| 1775 } | 1792 } |
| 1776 } | 1793 } |
| 1777 return x; | 1794 return x; |
| 1778 } | 1795 } |
| 1779 | 1796 |
| 1780 | 1797 |
| 1798 template <class Traits> |
| 1799 typename ParserBase<Traits>::ExpressionT |
| 1800 ParserBase<Traits>::ParseUnaryExpression(bool* ok) { |
| 1801 // UnaryExpression :: |
| 1802 // PostfixExpression |
| 1803 // 'delete' UnaryExpression |
| 1804 // 'void' UnaryExpression |
| 1805 // 'typeof' UnaryExpression |
| 1806 // '++' UnaryExpression |
| 1807 // '--' UnaryExpression |
| 1808 // '+' UnaryExpression |
| 1809 // '-' UnaryExpression |
| 1810 // '~' UnaryExpression |
| 1811 // '!' UnaryExpression |
| 1812 |
| 1813 Token::Value op = peek(); |
| 1814 if (Token::IsUnaryOp(op)) { |
| 1815 op = Next(); |
| 1816 int pos = position(); |
| 1817 ExpressionT expression = ParseUnaryExpression(CHECK_OK); |
| 1818 |
| 1819 // "delete identifier" is a syntax error in strict mode. |
| 1820 if (op == Token::DELETE && strict_mode() == STRICT && |
| 1821 this->IsIdentifier(expression)) { |
| 1822 ReportMessage("strict_delete", Vector<const char*>::empty()); |
| 1823 *ok = false; |
| 1824 return this->EmptyExpression(); |
| 1825 } |
| 1826 |
| 1827 // Allow Traits do rewrite the expression. |
| 1828 return this->BuildUnaryExpression(expression, op, pos, factory()); |
| 1829 } else if (Token::IsCountOp(op)) { |
| 1830 op = Next(); |
| 1831 Scanner::Location lhs_location = scanner()->peek_location(); |
| 1832 ExpressionT expression = ParseUnaryExpression(CHECK_OK); |
| 1833 if (!this->IsValidLeftHandSide(expression)) { |
| 1834 ReportMessageAt(lhs_location, "invalid_lhs_in_prefix_op", true); |
| 1835 *ok = false; |
| 1836 return this->EmptyExpression(); |
| 1837 } |
| 1838 |
| 1839 if (strict_mode() == STRICT) { |
| 1840 // Prefix expression operand in strict mode may not be eval or arguments. |
| 1841 this->CheckStrictModeLValue(expression, CHECK_OK); |
| 1842 } |
| 1843 this->MarkExpressionAsLValue(expression); |
| 1844 |
| 1845 return factory()->NewCountOperation(op, |
| 1846 true /* prefix */, |
| 1847 expression, |
| 1848 position()); |
| 1849 |
| 1850 } else { |
| 1851 return this->ParsePostfixExpression(ok); |
| 1852 } |
| 1853 } |
| 1854 |
| 1855 |
| 1781 #undef CHECK_OK | 1856 #undef CHECK_OK |
| 1782 #undef CHECK_OK_CUSTOM | 1857 #undef CHECK_OK_CUSTOM |
| 1783 | 1858 |
| 1784 | 1859 |
| 1785 template <typename Traits> | 1860 template <typename Traits> |
| 1786 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 1861 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
| 1787 Token::Value property, | 1862 Token::Value property, |
| 1788 PropertyKind type, | 1863 PropertyKind type, |
| 1789 bool* ok) { | 1864 bool* ok) { |
| 1790 int old; | 1865 int old; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1811 "accessor_get_set"); | 1886 "accessor_get_set"); |
| 1812 } | 1887 } |
| 1813 *ok = false; | 1888 *ok = false; |
| 1814 } | 1889 } |
| 1815 } | 1890 } |
| 1816 | 1891 |
| 1817 | 1892 |
| 1818 } } // v8::internal | 1893 } } // v8::internal |
| 1819 | 1894 |
| 1820 #endif // V8_PREPARSER_H | 1895 #endif // V8_PREPARSER_H |
| OLD | NEW |