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