| 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/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 IsValidArrowParamListField::encode(valid_arrow_param_list)); | 747 IsValidArrowParamListField::encode(valid_arrow_param_list)); |
| 748 } | 748 } |
| 749 | 749 |
| 750 static PreParserExpression EmptyArrowParamList() { | 750 static PreParserExpression EmptyArrowParamList() { |
| 751 // Any expression for which IsValidArrowParamList() returns true | 751 // Any expression for which IsValidArrowParamList() returns true |
| 752 // will work here. | 752 // will work here. |
| 753 return FromIdentifier(PreParserIdentifier::Default()); | 753 return FromIdentifier(PreParserIdentifier::Default()); |
| 754 } | 754 } |
| 755 | 755 |
| 756 static PreParserExpression StringLiteral() { | 756 static PreParserExpression StringLiteral() { |
| 757 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 757 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); |
| 758 IsUseStrictField::encode(false)); | |
| 759 } | 758 } |
| 760 | 759 |
| 761 static PreParserExpression UseStrictStringLiteral() { | 760 static PreParserExpression UseStrictStringLiteral() { |
| 762 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 761 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
| 763 IsUseStrictField::encode(true)); | 762 IsUseStrictField::encode(true)); |
| 764 } | 763 } |
| 765 | 764 |
| 765 static PreParserExpression UseSanityStringLiteral() { |
| 766 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
| 767 IsUseSanityField::encode(true)); |
| 768 } |
| 769 |
| 766 static PreParserExpression This() { | 770 static PreParserExpression This() { |
| 767 return PreParserExpression(TypeField::encode(kExpression) | | 771 return PreParserExpression(TypeField::encode(kExpression) | |
| 768 ExpressionTypeField::encode(kThisExpression)); | 772 ExpressionTypeField::encode(kThisExpression)); |
| 769 } | 773 } |
| 770 | 774 |
| 771 static PreParserExpression Super() { | 775 static PreParserExpression Super() { |
| 772 return PreParserExpression(TypeField::encode(kExpression) | | 776 return PreParserExpression(TypeField::encode(kExpression) | |
| 773 ExpressionTypeField::encode(kSuperExpression)); | 777 ExpressionTypeField::encode(kSuperExpression)); |
| 774 } | 778 } |
| 775 | 779 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 | 811 |
| 808 bool IsStringLiteral() const { | 812 bool IsStringLiteral() const { |
| 809 return TypeField::decode(code_) == kStringLiteralExpression; | 813 return TypeField::decode(code_) == kStringLiteralExpression; |
| 810 } | 814 } |
| 811 | 815 |
| 812 bool IsUseStrictLiteral() const { | 816 bool IsUseStrictLiteral() const { |
| 813 return TypeField::decode(code_) == kStringLiteralExpression && | 817 return TypeField::decode(code_) == kStringLiteralExpression && |
| 814 IsUseStrictField::decode(code_); | 818 IsUseStrictField::decode(code_); |
| 815 } | 819 } |
| 816 | 820 |
| 821 bool IsUseSanityLiteral() const { |
| 822 return TypeField::decode(code_) == kStringLiteralExpression && |
| 823 IsUseSanityField::decode(code_); |
| 824 } |
| 825 |
| 817 bool IsThis() const { | 826 bool IsThis() const { |
| 818 return TypeField::decode(code_) == kExpression && | 827 return TypeField::decode(code_) == kExpression && |
| 819 ExpressionTypeField::decode(code_) == kThisExpression; | 828 ExpressionTypeField::decode(code_) == kThisExpression; |
| 820 } | 829 } |
| 821 | 830 |
| 822 bool IsThisProperty() const { | 831 bool IsThisProperty() const { |
| 823 return TypeField::decode(code_) == kExpression && | 832 return TypeField::decode(code_) == kExpression && |
| 824 ExpressionTypeField::decode(code_) == kThisPropertyExpression; | 833 ExpressionTypeField::decode(code_) == kThisPropertyExpression; |
| 825 } | 834 } |
| 826 | 835 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 | 924 |
| 916 // The first four bits are for the Type and Parenthesization. | 925 // The first four bits are for the Type and Parenthesization. |
| 917 typedef BitField<Type, 0, 2> TypeField; | 926 typedef BitField<Type, 0, 2> TypeField; |
| 918 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; | 927 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; |
| 919 | 928 |
| 920 // The rest of the bits are interpreted depending on the value | 929 // The rest of the bits are interpreted depending on the value |
| 921 // of the Type field, so they can share the storage. | 930 // of the Type field, so they can share the storage. |
| 922 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> | 931 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> |
| 923 ExpressionTypeField; | 932 ExpressionTypeField; |
| 924 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; | 933 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; |
| 934 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseSanityField; |
| 925 typedef BitField<bool, ParenthesizationField::kNext, 1> | 935 typedef BitField<bool, ParenthesizationField::kNext, 1> |
| 926 IsValidArrowParamListField; | 936 IsValidArrowParamListField; |
| 927 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> | 937 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> |
| 928 IdentifierTypeField; | 938 IdentifierTypeField; |
| 929 | 939 |
| 930 uint32_t code_; | 940 uint32_t code_; |
| 931 }; | 941 }; |
| 932 | 942 |
| 933 | 943 |
| 934 // PreParserExpressionList doesn't actually store the expressions because | 944 // PreParserExpressionList doesn't actually store the expressions because |
| (...skipping 21 matching lines...) Expand all Loading... |
| 956 } | 966 } |
| 957 | 967 |
| 958 // Creates expression statement from expression. | 968 // Creates expression statement from expression. |
| 959 // Preserves being an unparenthesized string literal, possibly | 969 // Preserves being an unparenthesized string literal, possibly |
| 960 // "use strict". | 970 // "use strict". |
| 961 static PreParserStatement ExpressionStatement( | 971 static PreParserStatement ExpressionStatement( |
| 962 PreParserExpression expression) { | 972 PreParserExpression expression) { |
| 963 if (expression.IsUseStrictLiteral()) { | 973 if (expression.IsUseStrictLiteral()) { |
| 964 return PreParserStatement(kUseStrictExpressionStatement); | 974 return PreParserStatement(kUseStrictExpressionStatement); |
| 965 } | 975 } |
| 976 if (expression.IsUseSanityLiteral()) { |
| 977 return PreParserStatement(kUseSanityExpressionStatement); |
| 978 } |
| 966 if (expression.IsStringLiteral()) { | 979 if (expression.IsStringLiteral()) { |
| 967 return PreParserStatement(kStringLiteralExpressionStatement); | 980 return PreParserStatement(kStringLiteralExpressionStatement); |
| 968 } | 981 } |
| 969 return Default(); | 982 return Default(); |
| 970 } | 983 } |
| 971 | 984 |
| 972 bool IsStringLiteral() { | 985 bool IsStringLiteral() { |
| 973 return code_ == kStringLiteralExpressionStatement; | 986 return code_ == kStringLiteralExpressionStatement; |
| 974 } | 987 } |
| 975 | 988 |
| 976 bool IsUseStrictLiteral() { | 989 bool IsUseStrictLiteral() { |
| 977 return code_ == kUseStrictExpressionStatement; | 990 return code_ == kUseStrictExpressionStatement; |
| 978 } | 991 } |
| 979 | 992 |
| 993 bool IsUseSanityLiteral() { return code_ == kUseSanityExpressionStatement; } |
| 994 |
| 980 bool IsFunctionDeclaration() { | 995 bool IsFunctionDeclaration() { |
| 981 return code_ == kFunctionDeclaration; | 996 return code_ == kFunctionDeclaration; |
| 982 } | 997 } |
| 983 | 998 |
| 984 private: | 999 private: |
| 985 enum Type { | 1000 enum Type { |
| 986 kUnknownStatement, | 1001 kUnknownStatement, |
| 987 kStringLiteralExpressionStatement, | 1002 kStringLiteralExpressionStatement, |
| 988 kUseStrictExpressionStatement, | 1003 kUseStrictExpressionStatement, |
| 1004 kUseSanityExpressionStatement, |
| 989 kFunctionDeclaration | 1005 kFunctionDeclaration |
| 990 }; | 1006 }; |
| 991 | 1007 |
| 992 explicit PreParserStatement(Type code) : code_(code) {} | 1008 explicit PreParserStatement(Type code) : code_(code) {} |
| 993 Type code_; | 1009 Type code_; |
| 994 }; | 1010 }; |
| 995 | 1011 |
| 996 | 1012 |
| 997 | 1013 |
| 998 // PreParserStatementList doesn't actually store the statements because | 1014 // PreParserStatementList doesn't actually store the statements because |
| (...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3076 *ok = false; | 3092 *ok = false; |
| 3077 return; | 3093 return; |
| 3078 } | 3094 } |
| 3079 has_seen_constructor_ = true; | 3095 has_seen_constructor_ = true; |
| 3080 return; | 3096 return; |
| 3081 } | 3097 } |
| 3082 } | 3098 } |
| 3083 } } // v8::internal | 3099 } } // v8::internal |
| 3084 | 3100 |
| 3085 #endif // V8_PREPARSER_H | 3101 #endif // V8_PREPARSER_H |
| OLD | NEW |