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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 isolate_(isolate), | 83 isolate_(isolate), |
84 zone_(zone), | 84 zone_(zone), |
85 scanner_(scanner), | 85 scanner_(scanner), |
86 stack_overflow_(false), | 86 stack_overflow_(false), |
87 allow_lazy_(false), | 87 allow_lazy_(false), |
88 allow_natives_(false), | 88 allow_natives_(false), |
89 allow_harmony_arrow_functions_(false), | 89 allow_harmony_arrow_functions_(false), |
90 allow_harmony_object_literals_(false), | 90 allow_harmony_object_literals_(false), |
91 allow_harmony_sloppy_(false), | 91 allow_harmony_sloppy_(false), |
92 allow_harmony_computed_property_names_(false), | 92 allow_harmony_computed_property_names_(false), |
93 allow_harmony_rest_params_(false) {} | 93 allow_harmony_rest_params_(false), |
| 94 allow_strong_mode_(false) {} |
94 | 95 |
95 // Getters that indicate whether certain syntactical constructs are | 96 // Getters that indicate whether certain syntactical constructs are |
96 // allowed to be parsed by this instance of the parser. | 97 // allowed to be parsed by this instance of the parser. |
97 bool allow_lazy() const { return allow_lazy_; } | 98 bool allow_lazy() const { return allow_lazy_; } |
98 bool allow_natives() const { return allow_natives_; } | 99 bool allow_natives() const { return allow_natives_; } |
99 bool allow_harmony_arrow_functions() const { | 100 bool allow_harmony_arrow_functions() const { |
100 return allow_harmony_arrow_functions_; | 101 return allow_harmony_arrow_functions_; |
101 } | 102 } |
102 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } | 103 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } |
103 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } | 104 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } |
104 bool allow_harmony_numeric_literals() const { | 105 bool allow_harmony_numeric_literals() const { |
105 return scanner()->HarmonyNumericLiterals(); | 106 return scanner()->HarmonyNumericLiterals(); |
106 } | 107 } |
107 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } | 108 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } |
108 bool allow_harmony_object_literals() const { | 109 bool allow_harmony_object_literals() const { |
109 return allow_harmony_object_literals_; | 110 return allow_harmony_object_literals_; |
110 } | 111 } |
111 bool allow_harmony_templates() const { return scanner()->HarmonyTemplates(); } | 112 bool allow_harmony_templates() const { return scanner()->HarmonyTemplates(); } |
112 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } | 113 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } |
113 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } | 114 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } |
114 bool allow_harmony_computed_property_names() const { | 115 bool allow_harmony_computed_property_names() const { |
115 return allow_harmony_computed_property_names_; | 116 return allow_harmony_computed_property_names_; |
116 } | 117 } |
117 bool allow_harmony_rest_params() const { | 118 bool allow_harmony_rest_params() const { |
118 return allow_harmony_rest_params_; | 119 return allow_harmony_rest_params_; |
119 } | 120 } |
120 | 121 |
| 122 bool allow_strong_mode() const { return allow_strong_mode_; } |
| 123 |
121 // Setters that determine whether certain syntactical constructs are | 124 // Setters that determine whether certain syntactical constructs are |
122 // allowed to be parsed by this instance of the parser. | 125 // allowed to be parsed by this instance of the parser. |
123 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } | 126 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } |
124 void set_allow_natives(bool allow) { allow_natives_ = allow; } | 127 void set_allow_natives(bool allow) { allow_natives_ = allow; } |
125 void set_allow_harmony_arrow_functions(bool allow) { | 128 void set_allow_harmony_arrow_functions(bool allow) { |
126 allow_harmony_arrow_functions_ = allow; | 129 allow_harmony_arrow_functions_ = allow; |
127 } | 130 } |
128 void set_allow_harmony_modules(bool allow) { | 131 void set_allow_harmony_modules(bool allow) { |
129 scanner()->SetHarmonyModules(allow); | 132 scanner()->SetHarmonyModules(allow); |
130 } | 133 } |
(...skipping 17 matching lines...) Expand all Loading... |
148 } | 151 } |
149 void set_allow_harmony_unicode(bool allow) { | 152 void set_allow_harmony_unicode(bool allow) { |
150 scanner()->SetHarmonyUnicode(allow); | 153 scanner()->SetHarmonyUnicode(allow); |
151 } | 154 } |
152 void set_allow_harmony_computed_property_names(bool allow) { | 155 void set_allow_harmony_computed_property_names(bool allow) { |
153 allow_harmony_computed_property_names_ = allow; | 156 allow_harmony_computed_property_names_ = allow; |
154 } | 157 } |
155 void set_allow_harmony_rest_params(bool allow) { | 158 void set_allow_harmony_rest_params(bool allow) { |
156 allow_harmony_rest_params_ = allow; | 159 allow_harmony_rest_params_ = allow; |
157 } | 160 } |
| 161 void set_allow_strong_mode(bool allow) { allow_strong_mode_ = allow; } |
158 | 162 |
159 protected: | 163 protected: |
160 enum AllowEvalOrArgumentsAsIdentifier { | 164 enum AllowEvalOrArgumentsAsIdentifier { |
161 kAllowEvalOrArguments, | 165 kAllowEvalOrArguments, |
162 kDontAllowEvalOrArguments | 166 kDontAllowEvalOrArguments |
163 }; | 167 }; |
164 | 168 |
165 enum Mode { | 169 enum Mode { |
166 PARSE_LAZILY, | 170 PARSE_LAZILY, |
167 PARSE_EAGERLY | 171 PARSE_EAGERLY |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 Scanner* scanner_; | 631 Scanner* scanner_; |
628 bool stack_overflow_; | 632 bool stack_overflow_; |
629 | 633 |
630 bool allow_lazy_; | 634 bool allow_lazy_; |
631 bool allow_natives_; | 635 bool allow_natives_; |
632 bool allow_harmony_arrow_functions_; | 636 bool allow_harmony_arrow_functions_; |
633 bool allow_harmony_object_literals_; | 637 bool allow_harmony_object_literals_; |
634 bool allow_harmony_sloppy_; | 638 bool allow_harmony_sloppy_; |
635 bool allow_harmony_computed_property_names_; | 639 bool allow_harmony_computed_property_names_; |
636 bool allow_harmony_rest_params_; | 640 bool allow_harmony_rest_params_; |
| 641 bool allow_strong_mode_; |
637 }; | 642 }; |
638 | 643 |
639 | 644 |
640 class PreParserIdentifier { | 645 class PreParserIdentifier { |
641 public: | 646 public: |
642 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 647 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
643 static PreParserIdentifier Default() { | 648 static PreParserIdentifier Default() { |
644 return PreParserIdentifier(kUnknownIdentifier); | 649 return PreParserIdentifier(kUnknownIdentifier); |
645 } | 650 } |
646 static PreParserIdentifier Eval() { | 651 static PreParserIdentifier Eval() { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 IsValidArrowParamListField::encode(valid_arrow_param_list)); | 752 IsValidArrowParamListField::encode(valid_arrow_param_list)); |
748 } | 753 } |
749 | 754 |
750 static PreParserExpression EmptyArrowParamList() { | 755 static PreParserExpression EmptyArrowParamList() { |
751 // Any expression for which IsValidArrowParamList() returns true | 756 // Any expression for which IsValidArrowParamList() returns true |
752 // will work here. | 757 // will work here. |
753 return FromIdentifier(PreParserIdentifier::Default()); | 758 return FromIdentifier(PreParserIdentifier::Default()); |
754 } | 759 } |
755 | 760 |
756 static PreParserExpression StringLiteral() { | 761 static PreParserExpression StringLiteral() { |
757 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 762 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); |
758 IsUseStrictField::encode(false)); | |
759 } | 763 } |
760 | 764 |
761 static PreParserExpression UseStrictStringLiteral() { | 765 static PreParserExpression UseStrictStringLiteral() { |
762 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 766 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
763 IsUseStrictField::encode(true)); | 767 IsUseStrictField::encode(true)); |
764 } | 768 } |
765 | 769 |
| 770 static PreParserExpression UseStrongStringLiteral() { |
| 771 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
| 772 IsUseStrongField::encode(true)); |
| 773 } |
| 774 |
766 static PreParserExpression This() { | 775 static PreParserExpression This() { |
767 return PreParserExpression(TypeField::encode(kExpression) | | 776 return PreParserExpression(TypeField::encode(kExpression) | |
768 ExpressionTypeField::encode(kThisExpression)); | 777 ExpressionTypeField::encode(kThisExpression)); |
769 } | 778 } |
770 | 779 |
771 static PreParserExpression Super() { | 780 static PreParserExpression Super() { |
772 return PreParserExpression(TypeField::encode(kExpression) | | 781 return PreParserExpression(TypeField::encode(kExpression) | |
773 ExpressionTypeField::encode(kSuperExpression)); | 782 ExpressionTypeField::encode(kSuperExpression)); |
774 } | 783 } |
775 | 784 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 | 816 |
808 bool IsStringLiteral() const { | 817 bool IsStringLiteral() const { |
809 return TypeField::decode(code_) == kStringLiteralExpression; | 818 return TypeField::decode(code_) == kStringLiteralExpression; |
810 } | 819 } |
811 | 820 |
812 bool IsUseStrictLiteral() const { | 821 bool IsUseStrictLiteral() const { |
813 return TypeField::decode(code_) == kStringLiteralExpression && | 822 return TypeField::decode(code_) == kStringLiteralExpression && |
814 IsUseStrictField::decode(code_); | 823 IsUseStrictField::decode(code_); |
815 } | 824 } |
816 | 825 |
| 826 bool IsUseStrongLiteral() const { |
| 827 return TypeField::decode(code_) == kStringLiteralExpression && |
| 828 IsUseStrongField::decode(code_); |
| 829 } |
| 830 |
817 bool IsThis() const { | 831 bool IsThis() const { |
818 return TypeField::decode(code_) == kExpression && | 832 return TypeField::decode(code_) == kExpression && |
819 ExpressionTypeField::decode(code_) == kThisExpression; | 833 ExpressionTypeField::decode(code_) == kThisExpression; |
820 } | 834 } |
821 | 835 |
822 bool IsThisProperty() const { | 836 bool IsThisProperty() const { |
823 return TypeField::decode(code_) == kExpression && | 837 return TypeField::decode(code_) == kExpression && |
824 ExpressionTypeField::decode(code_) == kThisPropertyExpression; | 838 ExpressionTypeField::decode(code_) == kThisPropertyExpression; |
825 } | 839 } |
826 | 840 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 | 929 |
916 // The first four bits are for the Type and Parenthesization. | 930 // The first four bits are for the Type and Parenthesization. |
917 typedef BitField<Type, 0, 2> TypeField; | 931 typedef BitField<Type, 0, 2> TypeField; |
918 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; | 932 typedef BitField<Parenthesization, TypeField::kNext, 2> ParenthesizationField; |
919 | 933 |
920 // The rest of the bits are interpreted depending on the value | 934 // The rest of the bits are interpreted depending on the value |
921 // of the Type field, so they can share the storage. | 935 // of the Type field, so they can share the storage. |
922 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> | 936 typedef BitField<ExpressionType, ParenthesizationField::kNext, 3> |
923 ExpressionTypeField; | 937 ExpressionTypeField; |
924 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; | 938 typedef BitField<bool, ParenthesizationField::kNext, 1> IsUseStrictField; |
| 939 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; |
925 typedef BitField<bool, ParenthesizationField::kNext, 1> | 940 typedef BitField<bool, ParenthesizationField::kNext, 1> |
926 IsValidArrowParamListField; | 941 IsValidArrowParamListField; |
927 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> | 942 typedef BitField<PreParserIdentifier::Type, ParenthesizationField::kNext, 10> |
928 IdentifierTypeField; | 943 IdentifierTypeField; |
929 | 944 |
930 uint32_t code_; | 945 uint32_t code_; |
931 }; | 946 }; |
932 | 947 |
933 | 948 |
934 // PreParserExpressionList doesn't actually store the expressions because | 949 // PreParserExpressionList doesn't actually store the expressions because |
(...skipping 21 matching lines...) Expand all Loading... |
956 } | 971 } |
957 | 972 |
958 // Creates expression statement from expression. | 973 // Creates expression statement from expression. |
959 // Preserves being an unparenthesized string literal, possibly | 974 // Preserves being an unparenthesized string literal, possibly |
960 // "use strict". | 975 // "use strict". |
961 static PreParserStatement ExpressionStatement( | 976 static PreParserStatement ExpressionStatement( |
962 PreParserExpression expression) { | 977 PreParserExpression expression) { |
963 if (expression.IsUseStrictLiteral()) { | 978 if (expression.IsUseStrictLiteral()) { |
964 return PreParserStatement(kUseStrictExpressionStatement); | 979 return PreParserStatement(kUseStrictExpressionStatement); |
965 } | 980 } |
| 981 if (expression.IsUseStrongLiteral()) { |
| 982 return PreParserStatement(kUseStrongExpressionStatement); |
| 983 } |
966 if (expression.IsStringLiteral()) { | 984 if (expression.IsStringLiteral()) { |
967 return PreParserStatement(kStringLiteralExpressionStatement); | 985 return PreParserStatement(kStringLiteralExpressionStatement); |
968 } | 986 } |
969 return Default(); | 987 return Default(); |
970 } | 988 } |
971 | 989 |
972 bool IsStringLiteral() { | 990 bool IsStringLiteral() { |
973 return code_ == kStringLiteralExpressionStatement; | 991 return code_ == kStringLiteralExpressionStatement; |
974 } | 992 } |
975 | 993 |
976 bool IsUseStrictLiteral() { | 994 bool IsUseStrictLiteral() { |
977 return code_ == kUseStrictExpressionStatement; | 995 return code_ == kUseStrictExpressionStatement; |
978 } | 996 } |
979 | 997 |
| 998 bool IsUseStrongLiteral() { return code_ == kUseStrongExpressionStatement; } |
| 999 |
980 bool IsFunctionDeclaration() { | 1000 bool IsFunctionDeclaration() { |
981 return code_ == kFunctionDeclaration; | 1001 return code_ == kFunctionDeclaration; |
982 } | 1002 } |
983 | 1003 |
984 private: | 1004 private: |
985 enum Type { | 1005 enum Type { |
986 kUnknownStatement, | 1006 kUnknownStatement, |
987 kStringLiteralExpressionStatement, | 1007 kStringLiteralExpressionStatement, |
988 kUseStrictExpressionStatement, | 1008 kUseStrictExpressionStatement, |
| 1009 kUseStrongExpressionStatement, |
989 kFunctionDeclaration | 1010 kFunctionDeclaration |
990 }; | 1011 }; |
991 | 1012 |
992 explicit PreParserStatement(Type code) : code_(code) {} | 1013 explicit PreParserStatement(Type code) : code_(code) {} |
993 Type code_; | 1014 Type code_; |
994 }; | 1015 }; |
995 | 1016 |
996 | 1017 |
997 | 1018 |
998 // PreParserStatementList doesn't actually store the statements because | 1019 // PreParserStatementList doesn't actually store the statements because |
(...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3076 *ok = false; | 3097 *ok = false; |
3077 return; | 3098 return; |
3078 } | 3099 } |
3079 has_seen_constructor_ = true; | 3100 has_seen_constructor_ = true; |
3080 return; | 3101 return; |
3081 } | 3102 } |
3082 } | 3103 } |
3083 } } // v8::internal | 3104 } } // v8::internal |
3084 | 3105 |
3085 #endif // V8_PREPARSER_H | 3106 #endif // V8_PREPARSER_H |
OLD | NEW |