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