Chromium Code Reviews| 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/bailout-reason.h" | 8 #include "src/bailout-reason.h" |
| 9 #include "src/expression-classifier.h" | 9 #include "src/expression-classifier.h" |
| 10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 IdentifierTypeField::encode(id.type_)); | 914 IdentifierTypeField::encode(id.type_)); |
| 915 } | 915 } |
| 916 | 916 |
| 917 static PreParserExpression BinaryOperation(PreParserExpression left, | 917 static PreParserExpression BinaryOperation(PreParserExpression left, |
| 918 Token::Value op, | 918 Token::Value op, |
| 919 PreParserExpression right) { | 919 PreParserExpression right) { |
| 920 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); | 920 return PreParserExpression(TypeField::encode(kBinaryOperationExpression)); |
| 921 } | 921 } |
| 922 | 922 |
| 923 static PreParserExpression StringLiteral() { | 923 static PreParserExpression StringLiteral() { |
| 924 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); | 924 return PreParserExpression(TypeField::encode(kStringLiteral)); |
|
caitp (gmail)
2015/08/17 18:26:12
the `Expression` suffix wasn't really adding anyth
| |
| 925 } | 925 } |
| 926 | 926 |
| 927 static PreParserExpression UseStrictStringLiteral() { | 927 static PreParserExpression UseStrictStringLiteral() { |
| 928 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 928 return PreParserExpression(TypeField::encode(kStringLiteral) | |
| 929 IsUseStrictField::encode(true)); | 929 IsUseStrictField::encode(true)); |
| 930 } | 930 } |
| 931 | 931 |
| 932 static PreParserExpression UseStrongStringLiteral() { | 932 static PreParserExpression UseStrongStringLiteral() { |
| 933 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 933 return PreParserExpression(TypeField::encode(kStringLiteral) | |
| 934 IsUseStrongField::encode(true)); | 934 IsUseStrongField::encode(true)); |
| 935 } | 935 } |
| 936 | 936 |
| 937 static PreParserExpression NumberLiteral() { | |
| 938 return PreParserExpression(TypeField::encode(kNumberLiteral)); | |
|
caitp (gmail)
2015/08/17 18:26:12
Just here for consistency --- might be useful for
| |
| 939 } | |
| 940 | |
| 941 static PreParserExpression ArrayLiteral() { | |
| 942 return PreParserExpression(TypeField::encode(kArrayLiteral)); | |
|
caitp (gmail)
2015/08/17 18:26:12
I have uses for this in destructuring assignment,
| |
| 943 } | |
| 944 | |
| 945 static PreParserExpression ObjectLiteral() { | |
| 946 return PreParserExpression(TypeField::encode(kObjectLiteral)); | |
| 947 } | |
| 948 | |
| 937 static PreParserExpression This() { | 949 static PreParserExpression This() { |
| 938 return PreParserExpression(TypeField::encode(kExpression) | | 950 return PreParserExpression(TypeField::encode(kExpression) | |
| 939 ExpressionTypeField::encode(kThisExpression)); | 951 ExpressionTypeField::encode(kThisExpression)); |
| 940 } | 952 } |
| 941 | 953 |
| 942 static PreParserExpression ThisProperty() { | 954 static PreParserExpression ThisProperty() { |
| 943 return PreParserExpression( | 955 return PreParserExpression( |
| 944 TypeField::encode(kExpression) | | 956 TypeField::encode(kExpression) | |
| 945 ExpressionTypeField::encode(kThisPropertyExpression)); | 957 ExpressionTypeField::encode(kThisPropertyExpression)); |
| 946 } | 958 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 971 bool IsIdentifier() const { | 983 bool IsIdentifier() const { |
| 972 return TypeField::decode(code_) == kIdentifierExpression; | 984 return TypeField::decode(code_) == kIdentifierExpression; |
| 973 } | 985 } |
| 974 | 986 |
| 975 PreParserIdentifier AsIdentifier() const { | 987 PreParserIdentifier AsIdentifier() const { |
| 976 DCHECK(IsIdentifier()); | 988 DCHECK(IsIdentifier()); |
| 977 return PreParserIdentifier(IdentifierTypeField::decode(code_)); | 989 return PreParserIdentifier(IdentifierTypeField::decode(code_)); |
| 978 } | 990 } |
| 979 | 991 |
| 980 bool IsStringLiteral() const { | 992 bool IsStringLiteral() const { |
| 981 return TypeField::decode(code_) == kStringLiteralExpression; | 993 return TypeField::decode(code_) == kStringLiteral; |
| 982 } | 994 } |
| 983 | 995 |
| 984 bool IsUseStrictLiteral() const { | 996 bool IsUseStrictLiteral() const { |
| 985 return TypeField::decode(code_) == kStringLiteralExpression && | 997 return TypeField::decode(code_) == kStringLiteral && |
| 986 IsUseStrictField::decode(code_); | 998 IsUseStrictField::decode(code_); |
| 987 } | 999 } |
| 988 | 1000 |
| 989 bool IsUseStrongLiteral() const { | 1001 bool IsUseStrongLiteral() const { |
| 990 return TypeField::decode(code_) == kStringLiteralExpression && | 1002 return TypeField::decode(code_) == kStringLiteral && |
| 991 IsUseStrongField::decode(code_); | 1003 IsUseStrongField::decode(code_); |
| 992 } | 1004 } |
| 993 | 1005 |
| 1006 bool IsNumberLiteral() const { | |
| 1007 return TypeField::decode(code_) == kNumberLiteral; | |
| 1008 } | |
| 1009 | |
| 1010 bool IsArrayLiteral() const { | |
| 1011 return TypeField::decode(code_) == kArrayLiteral; | |
| 1012 } | |
| 1013 | |
| 1014 bool IsObjectLiteral() const { | |
| 1015 return TypeField::decode(code_) == kObjectLiteral; | |
| 1016 } | |
| 1017 | |
| 994 bool IsThis() const { | 1018 bool IsThis() const { |
| 995 return TypeField::decode(code_) == kExpression && | 1019 return TypeField::decode(code_) == kExpression && |
| 996 ExpressionTypeField::decode(code_) == kThisExpression; | 1020 ExpressionTypeField::decode(code_) == kThisExpression; |
| 997 } | 1021 } |
| 998 | 1022 |
| 999 bool IsThisProperty() const { | 1023 bool IsThisProperty() const { |
| 1000 return TypeField::decode(code_) == kExpression && | 1024 return TypeField::decode(code_) == kExpression && |
| 1001 ExpressionTypeField::decode(code_) == kThisPropertyExpression; | 1025 ExpressionTypeField::decode(code_) == kThisPropertyExpression; |
| 1002 } | 1026 } |
| 1003 | 1027 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1048 void set_index(int index) {} // For YieldExpressions | 1072 void set_index(int index) {} // For YieldExpressions |
| 1049 void set_should_eager_compile() {} | 1073 void set_should_eager_compile() {} |
| 1050 | 1074 |
| 1051 int position() const { return RelocInfo::kNoPosition; } | 1075 int position() const { return RelocInfo::kNoPosition; } |
| 1052 void set_function_token_position(int position) {} | 1076 void set_function_token_position(int position) {} |
| 1053 | 1077 |
| 1054 private: | 1078 private: |
| 1055 enum Type { | 1079 enum Type { |
| 1056 kExpression, | 1080 kExpression, |
| 1057 kIdentifierExpression, | 1081 kIdentifierExpression, |
| 1058 kStringLiteralExpression, | 1082 kStringLiteral, |
| 1083 kNumberLiteral, | |
| 1084 kArrayLiteral, | |
| 1085 kObjectLiteral, | |
| 1059 kBinaryOperationExpression, | 1086 kBinaryOperationExpression, |
| 1060 kSpreadExpression | 1087 kSpreadExpression |
| 1061 }; | 1088 }; |
| 1062 | 1089 |
| 1063 enum ExpressionType { | 1090 enum ExpressionType { |
| 1064 kThisExpression, | 1091 kThisExpression, |
| 1065 kThisPropertyExpression, | 1092 kThisPropertyExpression, |
| 1066 kPropertyExpression, | 1093 kPropertyExpression, |
| 1067 kCallExpression, | 1094 kCallExpression, |
| 1068 kSuperCallReference, | 1095 kSuperCallReference, |
| 1069 kNoTemplateTagExpression | 1096 kNoTemplateTagExpression |
| 1070 }; | 1097 }; |
| 1071 | 1098 |
| 1072 explicit PreParserExpression(uint32_t expression_code) | 1099 explicit PreParserExpression(uint32_t expression_code) |
| 1073 : code_(expression_code) {} | 1100 : code_(expression_code) {} |
| 1074 | 1101 |
| 1075 // The first three bits are for the Type. | 1102 // The first three bits are for the Type. |
| 1076 typedef BitField<Type, 0, 3> TypeField; | 1103 typedef BitField<Type, 0, 4> TypeField; |
|
caitp (gmail)
2015/08/17 18:26:11
I guess this doesn't really need the extra bit ---
| |
| 1077 | 1104 |
| 1078 // The rest of the bits are interpreted depending on the value | 1105 // The rest of the bits are interpreted depending on the value |
| 1079 // of the Type field, so they can share the storage. | 1106 // of the Type field, so they can share the storage. |
| 1080 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; | 1107 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; |
| 1081 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; | 1108 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; |
| 1082 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; | 1109 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; |
| 1083 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> | 1110 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> |
| 1084 IdentifierTypeField; | 1111 IdentifierTypeField; |
| 1085 | 1112 |
| 1086 uint32_t code_; | 1113 uint32_t code_; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1170 | 1197 |
| 1171 | 1198 |
| 1172 typedef PreParserList<PreParserStatement> PreParserStatementList; | 1199 typedef PreParserList<PreParserStatement> PreParserStatementList; |
| 1173 | 1200 |
| 1174 | 1201 |
| 1175 class PreParserFactory { | 1202 class PreParserFactory { |
| 1176 public: | 1203 public: |
| 1177 explicit PreParserFactory(void* unused_value_factory) {} | 1204 explicit PreParserFactory(void* unused_value_factory) {} |
| 1178 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 1205 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
| 1179 int pos) { | 1206 int pos) { |
| 1180 return PreParserExpression::Default(); | 1207 return PreParserExpression::StringLiteral(); |
| 1181 } | 1208 } |
| 1182 PreParserExpression NewNumberLiteral(double number, | 1209 PreParserExpression NewNumberLiteral(double number, |
| 1183 int pos) { | 1210 int pos) { |
| 1184 return PreParserExpression::Default(); | 1211 return PreParserExpression::NumberLiteral(); |
| 1185 } | 1212 } |
| 1186 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 1213 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
| 1187 PreParserIdentifier js_flags, | 1214 PreParserIdentifier js_flags, |
| 1188 int literal_index, | 1215 int literal_index, |
| 1189 bool is_strong, | 1216 bool is_strong, |
| 1190 int pos) { | 1217 int pos) { |
| 1191 return PreParserExpression::Default(); | 1218 return PreParserExpression::Default(); |
| 1192 } | 1219 } |
| 1193 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 1220 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
| 1194 int literal_index, | 1221 int literal_index, |
| 1195 bool is_strong, | 1222 bool is_strong, |
| 1196 int pos) { | 1223 int pos) { |
| 1197 return PreParserExpression::Default(); | 1224 return PreParserExpression::ArrayLiteral(); |
| 1198 } | 1225 } |
| 1199 PreParserExpression NewArrayLiteral(PreParserExpressionList values, | 1226 PreParserExpression NewArrayLiteral(PreParserExpressionList values, |
| 1200 int first_spread_index, int literal_index, | 1227 int first_spread_index, int literal_index, |
| 1201 bool is_strong, int pos) { | 1228 bool is_strong, int pos) { |
| 1202 return PreParserExpression::Default(); | 1229 return PreParserExpression::ArrayLiteral(); |
| 1203 } | 1230 } |
| 1204 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 1231 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
| 1205 PreParserExpression value, | 1232 PreParserExpression value, |
| 1206 ObjectLiteralProperty::Kind kind, | 1233 ObjectLiteralProperty::Kind kind, |
| 1207 bool is_static, | 1234 bool is_static, |
| 1208 bool is_computed_name) { | 1235 bool is_computed_name) { |
| 1209 return PreParserExpression::Default(); | 1236 return PreParserExpression::Default(); |
| 1210 } | 1237 } |
| 1211 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 1238 PreParserExpression NewObjectLiteralProperty(PreParserExpression key, |
| 1212 PreParserExpression value, | 1239 PreParserExpression value, |
| 1213 bool is_static, | 1240 bool is_static, |
| 1214 bool is_computed_name) { | 1241 bool is_computed_name) { |
| 1215 return PreParserExpression::Default(); | 1242 return PreParserExpression::Default(); |
| 1216 } | 1243 } |
| 1217 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 1244 PreParserExpression NewObjectLiteral(PreParserExpressionList properties, |
| 1218 int literal_index, | 1245 int literal_index, |
| 1219 int boilerplate_properties, | 1246 int boilerplate_properties, |
| 1220 bool has_function, | 1247 bool has_function, |
| 1221 bool is_strong, | 1248 bool is_strong, |
| 1222 int pos) { | 1249 int pos) { |
| 1223 return PreParserExpression::Default(); | 1250 return PreParserExpression::ObjectLiteral(); |
| 1224 } | 1251 } |
| 1225 PreParserExpression NewVariableProxy(void* variable) { | 1252 PreParserExpression NewVariableProxy(void* variable) { |
| 1226 return PreParserExpression::Default(); | 1253 return PreParserExpression::Default(); |
| 1227 } | 1254 } |
| 1228 PreParserExpression NewProperty(PreParserExpression obj, | 1255 PreParserExpression NewProperty(PreParserExpression obj, |
| 1229 PreParserExpression key, | 1256 PreParserExpression key, |
| 1230 int pos) { | 1257 int pos) { |
| 1231 if (obj.IsThis()) { | 1258 if (obj.IsThis()) { |
| 1232 return PreParserExpression::ThisProperty(); | 1259 return PreParserExpression::ThisProperty(); |
| 1233 } | 1260 } |
| (...skipping 2812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4046 *ok = false; | 4073 *ok = false; |
| 4047 return; | 4074 return; |
| 4048 } | 4075 } |
| 4049 has_seen_constructor_ = true; | 4076 has_seen_constructor_ = true; |
| 4050 return; | 4077 return; |
| 4051 } | 4078 } |
| 4052 } | 4079 } |
| 4053 } } // v8::internal | 4080 } } // v8::internal |
| 4054 | 4081 |
| 4055 #endif // V8_PREPARSER_H | 4082 #endif // V8_PREPARSER_H |
| OLD | NEW |