| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "vm/kernel_to_il.h" | 8 #include "vm/kernel_to_il.h" |
| 9 | 9 |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } else if ((*outermost_node)->IsConstructor()) { | 51 } else if ((*outermost_node)->IsConstructor()) { |
| 52 parent = Constructor::Cast(*outermost_node)->parent(); | 52 parent = Constructor::Cast(*outermost_node)->parent(); |
| 53 } else if ((*outermost_node)->IsField()) { | 53 } else if ((*outermost_node)->IsField()) { |
| 54 parent = Field::Cast(*outermost_node)->parent(); | 54 parent = Field::Cast(*outermost_node)->parent(); |
| 55 } | 55 } |
| 56 if (parent != NULL && parent->IsClass()) *klass = Class::Cast(parent); | 56 if (parent != NULL && parent->IsClass()) *klass = Class::Cast(parent); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 ScopeBuilder::ScopeBuilder(ParsedFunction* parsed_function, TreeNode* node) |
| 62 : result_(NULL), |
| 63 parsed_function_(parsed_function), |
| 64 node_(node), |
| 65 translation_helper_(Thread::Current()), |
| 66 zone_(translation_helper_.zone()), |
| 67 type_translator_(&translation_helper_, &active_class_, /*finalize=*/true), |
| 68 current_function_scope_(NULL), |
| 69 scope_(NULL), |
| 70 depth_(0), |
| 71 name_index_(0), |
| 72 needs_expr_temp_(false) { |
| 73 Script& script = Script::Handle(Z, parsed_function->function().script()); |
| 74 H.SetStringData(TypedData::Handle(Z, script.kernel_strings())); |
| 75 } |
| 76 |
| 77 |
| 61 void ScopeBuilder::EnterScope(TreeNode* node, TokenPosition start_position) { | 78 void ScopeBuilder::EnterScope(TreeNode* node, TokenPosition start_position) { |
| 62 scope_ = new (Z) LocalScope(scope_, depth_.function_, depth_.loop_); | 79 scope_ = new (Z) LocalScope(scope_, depth_.function_, depth_.loop_); |
| 63 scope_->set_begin_token_pos(start_position); | 80 scope_->set_begin_token_pos(start_position); |
| 64 ASSERT(node->kernel_offset() >= 0); | 81 ASSERT(node->kernel_offset() >= 0); |
| 65 result_->scopes.Insert(node->kernel_offset(), scope_); | 82 result_->scopes.Insert(node->kernel_offset(), scope_); |
| 66 } | 83 } |
| 67 | 84 |
| 68 | 85 |
| 69 void ScopeBuilder::ExitScope(TokenPosition end_position) { | 86 void ScopeBuilder::ExitScope(TokenPosition end_position) { |
| 70 scope_->set_end_token_pos(end_position); | 87 scope_->set_end_token_pos(end_position); |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 } | 1031 } |
| 1015 | 1032 |
| 1016 | 1033 |
| 1017 Fragment operator<<(const Fragment& fragment, Instruction* next) { | 1034 Fragment operator<<(const Fragment& fragment, Instruction* next) { |
| 1018 Fragment result = fragment; | 1035 Fragment result = fragment; |
| 1019 result <<= next; | 1036 result <<= next; |
| 1020 return result; | 1037 return result; |
| 1021 } | 1038 } |
| 1022 | 1039 |
| 1023 | 1040 |
| 1041 TranslationHelper::TranslationHelper(dart::Thread* thread) |
| 1042 : thread_(thread), |
| 1043 zone_(thread->zone()), |
| 1044 isolate_(thread->isolate()), |
| 1045 allocation_space_(thread->IsMutatorThread() ? Heap::kNew : Heap::kOld), |
| 1046 string_data_(TypedData::Handle(zone_)) {} |
| 1047 |
| 1048 |
| 1049 void TranslationHelper::SetStringData(const TypedData& string_data) { |
| 1050 ASSERT(string_data_.IsNull()); |
| 1051 string_data_ = string_data.raw(); |
| 1052 } |
| 1053 |
| 1054 |
| 1055 uint8_t TranslationHelper::CharacterAt(String* string, intptr_t index) { |
| 1056 ASSERT(index < string->size()); |
| 1057 return string_data_.GetUint8(string->offset() + index); |
| 1058 } |
| 1059 |
| 1060 |
| 1061 bool TranslationHelper::StringEquals(String* string, const char* other) { |
| 1062 NoSafepointScope no_safepoint; |
| 1063 intptr_t length = strlen(other); |
| 1064 return (length == string->size()) && |
| 1065 memcmp(string_data_.DataAddr(string->offset()), other, length) == 0; |
| 1066 } |
| 1067 |
| 1068 |
| 1069 bool TranslationHelper::IsAdministrative(CanonicalName* name) { |
| 1070 // Administrative names start with '@'. |
| 1071 return (name->name()->size() > 0) && (CharacterAt(name->name(), 0) == '@'); |
| 1072 } |
| 1073 |
| 1074 |
| 1075 bool TranslationHelper::IsPrivate(CanonicalName* name) { |
| 1076 // Private names start with '_'. |
| 1077 return (name->name()->size() > 0) && (CharacterAt(name->name(), 0) == '_'); |
| 1078 } |
| 1079 |
| 1080 |
| 1081 bool TranslationHelper::IsRoot(CanonicalName* name) { |
| 1082 // The root is the only canonical name with no parent. |
| 1083 return name->parent() == NULL; |
| 1084 } |
| 1085 |
| 1086 |
| 1087 bool TranslationHelper::IsLibrary(CanonicalName* name) { |
| 1088 // Libraries are the only canonical names with the root as their parent. |
| 1089 return !IsRoot(name) && IsRoot(name->parent()); |
| 1090 } |
| 1091 |
| 1092 |
| 1093 bool TranslationHelper::IsClass(CanonicalName* name) { |
| 1094 // Classes have the library as their parent and are not an administrative |
| 1095 // name starting with @. |
| 1096 return !IsAdministrative(name) && !IsRoot(name) && IsLibrary(name->parent()); |
| 1097 } |
| 1098 |
| 1099 |
| 1100 bool TranslationHelper::IsMember(CanonicalName* name) { |
| 1101 return IsConstructor(name) || IsField(name) || IsProcedure(name); |
| 1102 } |
| 1103 |
| 1104 |
| 1105 bool TranslationHelper::IsField(CanonicalName* name) { |
| 1106 // Fields with private names have the import URI of the library where they are |
| 1107 // visible as the parent and the string "@fields" as the parent's parent. |
| 1108 // Fields with non-private names have the string "@fields' as the parent. |
| 1109 if (IsRoot(name)) { |
| 1110 return false; |
| 1111 } |
| 1112 CanonicalName* kind = name->parent(); |
| 1113 if (IsPrivate(name)) { |
| 1114 kind = kind->parent(); |
| 1115 } |
| 1116 return StringEquals(kind->name(), "@fields"); |
| 1117 } |
| 1118 |
| 1119 |
| 1120 bool TranslationHelper::IsConstructor(CanonicalName* name) { |
| 1121 // Constructors with private names have the import URI of the library where |
| 1122 // they are visible as the parent and the string "@constructors" as the |
| 1123 // parent's parent. Constructors with non-private names have the string |
| 1124 // "@constructors" as the parent. |
| 1125 if (IsRoot(name)) { |
| 1126 return false; |
| 1127 } |
| 1128 CanonicalName* kind = name->parent(); |
| 1129 if (IsPrivate(name)) { |
| 1130 kind = kind->parent(); |
| 1131 } |
| 1132 return StringEquals(kind->name(), "@constructors"); |
| 1133 } |
| 1134 |
| 1135 |
| 1136 bool TranslationHelper::IsProcedure(CanonicalName* name) { |
| 1137 return IsMethod(name) || IsGetter(name) || IsSetter(name) || IsFactory(name); |
| 1138 } |
| 1139 |
| 1140 |
| 1141 bool TranslationHelper::IsMethod(CanonicalName* name) { |
| 1142 // Methods with private names have the import URI of the library where they |
| 1143 // are visible as the parent and the string "@methods" as the parent's parent. |
| 1144 // Methods with non-private names have the string "@methods" as the parent. |
| 1145 if (IsRoot(name)) { |
| 1146 return false; |
| 1147 } |
| 1148 CanonicalName* kind = name->parent(); |
| 1149 if (IsPrivate(name)) { |
| 1150 kind = kind->parent(); |
| 1151 } |
| 1152 return StringEquals(kind->name(), "@methods"); |
| 1153 } |
| 1154 |
| 1155 |
| 1156 bool TranslationHelper::IsGetter(CanonicalName* name) { |
| 1157 // Getters with private names have the import URI of the library where they |
| 1158 // are visible as the parent and the string "@getters" as the parent's parent. |
| 1159 // Getters with non-private names have the string "@getters" as the parent. |
| 1160 if (IsRoot(name)) { |
| 1161 return false; |
| 1162 } |
| 1163 CanonicalName* kind = name->parent(); |
| 1164 if (IsPrivate(name)) { |
| 1165 kind = kind->parent(); |
| 1166 } |
| 1167 return StringEquals(kind->name(), "@getters"); |
| 1168 } |
| 1169 |
| 1170 |
| 1171 bool TranslationHelper::IsSetter(CanonicalName* name) { |
| 1172 // Setters with private names have the import URI of the library where they |
| 1173 // are visible as the parent and the string "@setters" as the parent's parent. |
| 1174 // Setters with non-private names have the string "@setters" as the parent. |
| 1175 if (IsRoot(name)) { |
| 1176 return false; |
| 1177 } |
| 1178 CanonicalName* kind = name->parent(); |
| 1179 if (IsPrivate(name)) { |
| 1180 kind = kind->parent(); |
| 1181 } |
| 1182 return StringEquals(kind->name(), "@setters"); |
| 1183 } |
| 1184 |
| 1185 |
| 1186 bool TranslationHelper::IsFactory(CanonicalName* name) { |
| 1187 // Factories with private names have the import URI of the library where they |
| 1188 // are visible as the parent and the string "@factories" as the parent's |
| 1189 // parent. Factories with non-private names have the string "@factories" as |
| 1190 // the parent. |
| 1191 if (IsRoot(name)) { |
| 1192 return false; |
| 1193 } |
| 1194 CanonicalName* kind = name->parent(); |
| 1195 if (IsPrivate(name)) { |
| 1196 kind = kind->parent(); |
| 1197 } |
| 1198 return StringEquals(kind->name(), "@factories"); |
| 1199 } |
| 1200 |
| 1201 |
| 1202 CanonicalName* TranslationHelper::EnclosingName(CanonicalName* name) { |
| 1203 ASSERT(IsField(name) || IsConstructor(name) || IsProcedure(name)); |
| 1204 CanonicalName* enclosing = name->parent()->parent(); |
| 1205 if (IsPrivate(name)) { |
| 1206 enclosing = enclosing->parent(); |
| 1207 } |
| 1208 ASSERT(IsLibrary(enclosing) || IsClass(enclosing)); |
| 1209 return enclosing; |
| 1210 } |
| 1211 |
| 1212 |
| 1024 RawInstance* TranslationHelper::Canonicalize(const Instance& instance) { | 1213 RawInstance* TranslationHelper::Canonicalize(const Instance& instance) { |
| 1025 if (instance.IsNull()) return instance.raw(); | 1214 if (instance.IsNull()) return instance.raw(); |
| 1026 | 1215 |
| 1027 const char* error_str = NULL; | 1216 const char* error_str = NULL; |
| 1028 RawInstance* result = instance.CheckAndCanonicalize(thread(), &error_str); | 1217 RawInstance* result = instance.CheckAndCanonicalize(thread(), &error_str); |
| 1029 if (result == Object::null()) { | 1218 if (result == Object::null()) { |
| 1030 ReportError("Invalid const object %s", error_str); | 1219 ReportError("Invalid const object %s", error_str); |
| 1031 } | 1220 } |
| 1032 return result; | 1221 return result; |
| 1033 } | 1222 } |
| 1034 | 1223 |
| 1035 | 1224 |
| 1036 const dart::String& TranslationHelper::DartString(const char* content, | 1225 const dart::String& TranslationHelper::DartString(const char* content, |
| 1037 Heap::Space space) { | 1226 Heap::Space space) { |
| 1038 return dart::String::ZoneHandle(Z, dart::String::New(content, space)); | 1227 return dart::String::ZoneHandle(Z, dart::String::New(content, space)); |
| 1039 } | 1228 } |
| 1040 | 1229 |
| 1041 | 1230 |
| 1042 dart::String& TranslationHelper::DartString(String* content, | 1231 dart::String& TranslationHelper::DartString(String* content, |
| 1043 Heap::Space space) { | 1232 Heap::Space space) { |
| 1233 intptr_t length = content->size(); |
| 1234 uint8_t* buffer = Z->Alloc<uint8_t>(length); |
| 1235 { |
| 1236 NoSafepointScope no_safepoint; |
| 1237 memmove(buffer, string_data_.DataAddr(content->offset()), length); |
| 1238 } |
| 1044 return dart::String::ZoneHandle( | 1239 return dart::String::ZoneHandle( |
| 1045 Z, dart::String::FromUTF8(content->buffer(), content->size(), space)); | 1240 Z, dart::String::FromUTF8(buffer, length, space)); |
| 1046 } | 1241 } |
| 1047 | 1242 |
| 1048 | 1243 |
| 1049 dart::String& TranslationHelper::DartString(const uint8_t* utf8_array, | 1244 dart::String& TranslationHelper::DartString(const uint8_t* utf8_array, |
| 1050 intptr_t len, | 1245 intptr_t len, |
| 1051 Heap::Space space) { | 1246 Heap::Space space) { |
| 1052 return dart::String::ZoneHandle( | 1247 return dart::String::ZoneHandle( |
| 1053 Z, dart::String::FromUTF8(utf8_array, len, space)); | 1248 Z, dart::String::FromUTF8(utf8_array, len, space)); |
| 1054 } | 1249 } |
| 1055 | 1250 |
| 1056 | 1251 |
| 1057 const dart::String& TranslationHelper::DartSymbol(const char* content) const { | 1252 const dart::String& TranslationHelper::DartSymbol(const char* content) const { |
| 1058 return dart::String::ZoneHandle(Z, Symbols::New(thread_, content)); | 1253 return dart::String::ZoneHandle(Z, Symbols::New(thread_, content)); |
| 1059 } | 1254 } |
| 1060 | 1255 |
| 1061 | 1256 |
| 1062 dart::String& TranslationHelper::DartSymbol(String* content) const { | 1257 dart::String& TranslationHelper::DartSymbol(String* content) const { |
| 1258 intptr_t length = content->size(); |
| 1259 uint8_t* buffer = Z->Alloc<uint8_t>(length); |
| 1260 { |
| 1261 NoSafepointScope no_safepoint; |
| 1262 memmove(buffer, string_data_.DataAddr(content->offset()), length); |
| 1263 } |
| 1063 return dart::String::ZoneHandle( | 1264 return dart::String::ZoneHandle( |
| 1064 Z, dart::Symbols::FromUTF8(thread_, content->buffer(), content->size())); | 1265 Z, dart::Symbols::FromUTF8(thread_, buffer, length)); |
| 1065 } | 1266 } |
| 1066 | 1267 |
| 1067 dart::String& TranslationHelper::DartSymbol(const uint8_t* utf8_array, | 1268 dart::String& TranslationHelper::DartSymbol(const uint8_t* utf8_array, |
| 1068 intptr_t len) const { | 1269 intptr_t len) const { |
| 1069 return dart::String::ZoneHandle( | 1270 return dart::String::ZoneHandle( |
| 1070 Z, dart::Symbols::FromUTF8(thread_, utf8_array, len)); | 1271 Z, dart::Symbols::FromUTF8(thread_, utf8_array, len)); |
| 1071 } | 1272 } |
| 1072 | 1273 |
| 1073 const dart::String& TranslationHelper::DartClassName( | 1274 const dart::String& TranslationHelper::DartClassName( |
| 1074 CanonicalName* kernel_class) { | 1275 CanonicalName* kernel_class) { |
| 1075 ASSERT(kernel_class->IsClass()); | 1276 ASSERT(IsClass(kernel_class)); |
| 1076 dart::String& name = DartString(kernel_class->name()); | 1277 dart::String& name = DartString(kernel_class->name()); |
| 1077 return ManglePrivateName(kernel_class->parent(), &name); | 1278 return ManglePrivateName(kernel_class->parent(), &name); |
| 1078 } | 1279 } |
| 1079 | 1280 |
| 1080 | 1281 |
| 1081 const dart::String& TranslationHelper::DartConstructorName( | 1282 const dart::String& TranslationHelper::DartConstructorName( |
| 1082 CanonicalName* constructor) { | 1283 CanonicalName* constructor) { |
| 1083 ASSERT(constructor->IsConstructor()); | 1284 ASSERT(IsConstructor(constructor)); |
| 1084 return DartFactoryName(constructor); | 1285 return DartFactoryName(constructor); |
| 1085 } | 1286 } |
| 1086 | 1287 |
| 1087 | 1288 |
| 1088 const dart::String& TranslationHelper::DartProcedureName( | 1289 const dart::String& TranslationHelper::DartProcedureName( |
| 1089 CanonicalName* procedure) { | 1290 CanonicalName* procedure) { |
| 1090 ASSERT(procedure->IsProcedure()); | 1291 ASSERT(IsProcedure(procedure)); |
| 1091 if (procedure->IsSetter()) { | 1292 if (IsSetter(procedure)) { |
| 1092 return DartSetterName(procedure); | 1293 return DartSetterName(procedure); |
| 1093 } else if (procedure->IsGetter()) { | 1294 } else if (IsGetter(procedure)) { |
| 1094 return DartGetterName(procedure); | 1295 return DartGetterName(procedure); |
| 1095 } else if (procedure->IsFactory()) { | 1296 } else if (IsFactory(procedure)) { |
| 1096 return DartFactoryName(procedure); | 1297 return DartFactoryName(procedure); |
| 1097 } else { | 1298 } else { |
| 1098 return DartMethodName(procedure); | 1299 return DartMethodName(procedure); |
| 1099 } | 1300 } |
| 1100 } | 1301 } |
| 1101 | 1302 |
| 1102 | 1303 |
| 1103 const dart::String& TranslationHelper::DartSetterName(CanonicalName* setter) { | 1304 const dart::String& TranslationHelper::DartSetterName(CanonicalName* setter) { |
| 1104 return DartSetterName(setter->parent(), setter->name()); | 1305 return DartSetterName(setter->parent(), setter->name()); |
| 1105 } | 1306 } |
| 1106 | 1307 |
| 1107 | 1308 |
| 1108 const dart::String& TranslationHelper::DartSetterName(Name* setter_name) { | 1309 const dart::String& TranslationHelper::DartSetterName(Name* setter_name) { |
| 1109 return DartSetterName(setter_name->library(), setter_name->string()); | 1310 return DartSetterName(setter_name->library(), setter_name->string()); |
| 1110 } | 1311 } |
| 1111 | 1312 |
| 1112 | 1313 |
| 1113 const dart::String& TranslationHelper::DartSetterName(CanonicalName* parent, | 1314 const dart::String& TranslationHelper::DartSetterName(CanonicalName* parent, |
| 1114 String* setter) { | 1315 String* setter) { |
| 1115 // The names flowing into [setter] are coming from the Kernel file: | 1316 // The names flowing into [setter] are coming from the Kernel file: |
| 1116 // * user-defined setters: `fieldname=` | 1317 // * user-defined setters: `fieldname=` |
| 1117 // * property-set expressions: `fieldname` | 1318 // * property-set expressions: `fieldname` |
| 1118 // | 1319 // |
| 1119 // The VM uses `get:fieldname` and `set:fieldname`. | 1320 // The VM uses `get:fieldname` and `set:fieldname`. |
| 1120 // | 1321 // |
| 1121 // => In order to be consistent, we remove the `=` always and adopt the VM | 1322 // => In order to be consistent, we remove the `=` always and adopt the VM |
| 1122 // conventions. | 1323 // conventions. |
| 1123 ASSERT(setter->size() > 0); | 1324 ASSERT(setter->size() > 0); |
| 1124 intptr_t skip = 0; | 1325 intptr_t skip = 0; |
| 1125 if (setter->buffer()[setter->size() - 1] == '=') { | 1326 if (CharacterAt(setter, setter->size() - 1) == '=') { |
| 1126 skip = 1; | 1327 skip = 1; |
| 1127 } | 1328 } |
| 1329 intptr_t length = setter->size() - skip; |
| 1330 uint8_t* buffer = Z->Alloc<uint8_t>(length); |
| 1331 { |
| 1332 NoSafepointScope no_safepoint; |
| 1333 memmove(buffer, string_data_.DataAddr(setter->offset()), length); |
| 1334 } |
| 1128 dart::String& name = dart::String::ZoneHandle( | 1335 dart::String& name = dart::String::ZoneHandle( |
| 1129 Z, dart::String::FromUTF8(setter->buffer(), setter->size() - skip, | 1336 Z, dart::String::FromUTF8(buffer, length, allocation_space_)); |
| 1130 allocation_space_)); | |
| 1131 ManglePrivateName(parent, &name, false); | 1337 ManglePrivateName(parent, &name, false); |
| 1132 name = dart::Field::SetterSymbol(name); | 1338 name = dart::Field::SetterSymbol(name); |
| 1133 return name; | 1339 return name; |
| 1134 } | 1340 } |
| 1135 | 1341 |
| 1136 | 1342 |
| 1137 const dart::String& TranslationHelper::DartGetterName(CanonicalName* getter) { | 1343 const dart::String& TranslationHelper::DartGetterName(CanonicalName* getter) { |
| 1138 return DartGetterName(getter->parent(), getter->name()); | 1344 return DartGetterName(getter->parent(), getter->name()); |
| 1139 } | 1345 } |
| 1140 | 1346 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 | 1385 |
| 1180 | 1386 |
| 1181 const dart::String& TranslationHelper::DartMethodName(CanonicalName* parent, | 1387 const dart::String& TranslationHelper::DartMethodName(CanonicalName* parent, |
| 1182 String* method) { | 1388 String* method) { |
| 1183 dart::String& name = DartString(method); | 1389 dart::String& name = DartString(method); |
| 1184 return ManglePrivateName(parent, &name); | 1390 return ManglePrivateName(parent, &name); |
| 1185 } | 1391 } |
| 1186 | 1392 |
| 1187 | 1393 |
| 1188 const dart::String& TranslationHelper::DartFactoryName(CanonicalName* factory) { | 1394 const dart::String& TranslationHelper::DartFactoryName(CanonicalName* factory) { |
| 1189 ASSERT(factory->IsConstructor() || factory->IsFactory()); | 1395 ASSERT(IsConstructor(factory) || IsFactory(factory)); |
| 1190 GrowableHandlePtrArray<const dart::String> pieces(Z, 3); | 1396 GrowableHandlePtrArray<const dart::String> pieces(Z, 3); |
| 1191 pieces.Add(DartClassName(factory->EnclosingName())); | 1397 pieces.Add(DartClassName(EnclosingName(factory))); |
| 1192 pieces.Add(Symbols::Dot()); | 1398 pieces.Add(Symbols::Dot()); |
| 1193 // [DartMethodName] will mangle the name. | 1399 // [DartMethodName] will mangle the name. |
| 1194 pieces.Add(DartMethodName(factory)); | 1400 pieces.Add(DartMethodName(factory)); |
| 1195 return dart::String::ZoneHandle( | 1401 return dart::String::ZoneHandle( |
| 1196 Z, dart::Symbols::FromConcatAll(thread_, pieces)); | 1402 Z, dart::Symbols::FromConcatAll(thread_, pieces)); |
| 1197 } | 1403 } |
| 1198 | 1404 |
| 1199 | 1405 |
| 1200 dart::RawLibrary* TranslationHelper::LookupLibraryByKernelLibrary( | 1406 dart::RawLibrary* TranslationHelper::LookupLibraryByKernelLibrary( |
| 1201 CanonicalName* kernel_library) { | 1407 CanonicalName* kernel_library) { |
| 1202 // We only use the name and don't rely on having any particular parent. This | 1408 // We only use the string and don't rely on having any particular parent. |
| 1203 // ASSERT is just a sanity check. | 1409 // This ASSERT is just a sanity check. |
| 1204 ASSERT(kernel_library->IsLibrary() || | 1410 ASSERT(IsLibrary(kernel_library) || |
| 1205 kernel_library->parent()->IsAdministrative()); | 1411 IsAdministrative(kernel_library->parent())); |
| 1206 const dart::String& library_name = DartSymbol(kernel_library->name()); | 1412 const dart::String& library_name = DartSymbol(kernel_library->name()); |
| 1207 ASSERT(!library_name.IsNull()); | 1413 ASSERT(!library_name.IsNull()); |
| 1208 dart::RawLibrary* library = | 1414 dart::RawLibrary* library = |
| 1209 dart::Library::LookupLibrary(thread_, library_name); | 1415 dart::Library::LookupLibrary(thread_, library_name); |
| 1210 ASSERT(library != Object::null()); | 1416 ASSERT(library != Object::null()); |
| 1211 return library; | 1417 return library; |
| 1212 } | 1418 } |
| 1213 | 1419 |
| 1214 | 1420 |
| 1215 dart::RawClass* TranslationHelper::LookupClassByKernelClass( | 1421 dart::RawClass* TranslationHelper::LookupClassByKernelClass( |
| 1216 CanonicalName* kernel_class) { | 1422 CanonicalName* kernel_class) { |
| 1217 ASSERT(kernel_class->IsClass()); | 1423 ASSERT(IsClass(kernel_class)); |
| 1218 dart::RawClass* klass = NULL; | 1424 dart::RawClass* klass = NULL; |
| 1219 const dart::String& class_name = DartClassName(kernel_class); | 1425 const dart::String& class_name = DartClassName(kernel_class); |
| 1220 CanonicalName* kernel_library = kernel_class->parent(); | 1426 CanonicalName* kernel_library = kernel_class->parent(); |
| 1221 dart::Library& library = | 1427 dart::Library& library = |
| 1222 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); | 1428 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); |
| 1223 klass = library.LookupClassAllowPrivate(class_name); | 1429 klass = library.LookupClassAllowPrivate(class_name); |
| 1224 | 1430 |
| 1225 ASSERT(klass != Object::null()); | 1431 ASSERT(klass != Object::null()); |
| 1226 return klass; | 1432 return klass; |
| 1227 } | 1433 } |
| 1228 | 1434 |
| 1229 | 1435 |
| 1230 dart::RawField* TranslationHelper::LookupFieldByKernelField( | 1436 dart::RawField* TranslationHelper::LookupFieldByKernelField( |
| 1231 CanonicalName* kernel_field) { | 1437 CanonicalName* kernel_field) { |
| 1232 ASSERT(kernel_field->IsField()); | 1438 ASSERT(IsField(kernel_field)); |
| 1233 CanonicalName* enclosing = kernel_field->EnclosingName(); | 1439 CanonicalName* enclosing = EnclosingName(kernel_field); |
| 1234 | 1440 |
| 1235 dart::Class& klass = dart::Class::Handle(Z); | 1441 dart::Class& klass = dart::Class::Handle(Z); |
| 1236 if (enclosing->IsLibrary()) { | 1442 if (IsLibrary(enclosing)) { |
| 1237 dart::Library& library = | 1443 dart::Library& library = |
| 1238 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(enclosing)); | 1444 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(enclosing)); |
| 1239 klass = library.toplevel_class(); | 1445 klass = library.toplevel_class(); |
| 1240 } else { | 1446 } else { |
| 1241 ASSERT(enclosing->IsClass()); | 1447 ASSERT(IsClass(enclosing)); |
| 1242 klass = LookupClassByKernelClass(enclosing); | 1448 klass = LookupClassByKernelClass(enclosing); |
| 1243 } | 1449 } |
| 1244 dart::RawField* field = | 1450 dart::RawField* field = |
| 1245 klass.LookupFieldAllowPrivate(DartSymbol(kernel_field->name())); | 1451 klass.LookupFieldAllowPrivate(DartSymbol(kernel_field->name())); |
| 1246 ASSERT(field != Object::null()); | 1452 ASSERT(field != Object::null()); |
| 1247 return field; | 1453 return field; |
| 1248 } | 1454 } |
| 1249 | 1455 |
| 1250 | 1456 |
| 1251 dart::RawFunction* TranslationHelper::LookupStaticMethodByKernelProcedure( | 1457 dart::RawFunction* TranslationHelper::LookupStaticMethodByKernelProcedure( |
| 1252 CanonicalName* procedure) { | 1458 CanonicalName* procedure) { |
| 1253 const dart::String& procedure_name = DartProcedureName(procedure); | 1459 const dart::String& procedure_name = DartProcedureName(procedure); |
| 1254 | 1460 |
| 1255 // The parent is either a library or a class (in which case the procedure is a | 1461 // The parent is either a library or a class (in which case the procedure is a |
| 1256 // static method). | 1462 // static method). |
| 1257 CanonicalName* enclosing = procedure->EnclosingName(); | 1463 CanonicalName* enclosing = EnclosingName(procedure); |
| 1258 if (enclosing->IsLibrary()) { | 1464 if (IsLibrary(enclosing)) { |
| 1259 dart::Library& library = | 1465 dart::Library& library = |
| 1260 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(enclosing)); | 1466 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(enclosing)); |
| 1261 dart::RawFunction* function = | 1467 dart::RawFunction* function = |
| 1262 library.LookupFunctionAllowPrivate(procedure_name); | 1468 library.LookupFunctionAllowPrivate(procedure_name); |
| 1263 ASSERT(function != Object::null()); | 1469 ASSERT(function != Object::null()); |
| 1264 return function; | 1470 return function; |
| 1265 } else { | 1471 } else { |
| 1266 ASSERT(enclosing->IsClass()); | 1472 ASSERT(IsClass(enclosing)); |
| 1267 dart::Class& klass = | 1473 dart::Class& klass = |
| 1268 dart::Class::Handle(Z, LookupClassByKernelClass(enclosing)); | 1474 dart::Class::Handle(Z, LookupClassByKernelClass(enclosing)); |
| 1269 dart::RawFunction* raw_function = | 1475 dart::RawFunction* raw_function = |
| 1270 klass.LookupFunctionAllowPrivate(procedure_name); | 1476 klass.LookupFunctionAllowPrivate(procedure_name); |
| 1271 ASSERT(raw_function != Object::null()); | 1477 ASSERT(raw_function != Object::null()); |
| 1272 | 1478 |
| 1273 // TODO(27590): We can probably get rid of this after no longer using | 1479 // TODO(27590): We can probably get rid of this after no longer using |
| 1274 // core libraries from the source. | 1480 // core libraries from the source. |
| 1275 dart::Function& function = dart::Function::ZoneHandle(Z, raw_function); | 1481 dart::Function& function = dart::Function::ZoneHandle(Z, raw_function); |
| 1276 if (function.IsRedirectingFactory()) { | 1482 if (function.IsRedirectingFactory()) { |
| 1277 ClassFinalizer::ResolveRedirectingFactory(klass, function); | 1483 ClassFinalizer::ResolveRedirectingFactory(klass, function); |
| 1278 function = function.RedirectionTarget(); | 1484 function = function.RedirectionTarget(); |
| 1279 } | 1485 } |
| 1280 return function.raw(); | 1486 return function.raw(); |
| 1281 } | 1487 } |
| 1282 } | 1488 } |
| 1283 | 1489 |
| 1284 | 1490 |
| 1285 dart::RawFunction* TranslationHelper::LookupConstructorByKernelConstructor( | 1491 dart::RawFunction* TranslationHelper::LookupConstructorByKernelConstructor( |
| 1286 CanonicalName* constructor) { | 1492 CanonicalName* constructor) { |
| 1287 ASSERT(constructor->IsConstructor()); | 1493 ASSERT(IsConstructor(constructor)); |
| 1288 dart::Class& klass = dart::Class::Handle( | 1494 dart::Class& klass = dart::Class::Handle( |
| 1289 Z, LookupClassByKernelClass(constructor->EnclosingName())); | 1495 Z, LookupClassByKernelClass(EnclosingName(constructor))); |
| 1290 return LookupConstructorByKernelConstructor(klass, constructor); | 1496 return LookupConstructorByKernelConstructor(klass, constructor); |
| 1291 } | 1497 } |
| 1292 | 1498 |
| 1293 | 1499 |
| 1294 dart::RawFunction* TranslationHelper::LookupConstructorByKernelConstructor( | 1500 dart::RawFunction* TranslationHelper::LookupConstructorByKernelConstructor( |
| 1295 const dart::Class& owner, | 1501 const dart::Class& owner, |
| 1296 CanonicalName* constructor) { | 1502 CanonicalName* constructor) { |
| 1297 ASSERT(constructor->IsConstructor()); | 1503 ASSERT(IsConstructor(constructor)); |
| 1298 dart::RawFunction* function = | 1504 dart::RawFunction* function = |
| 1299 owner.LookupConstructorAllowPrivate(DartConstructorName(constructor)); | 1505 owner.LookupConstructorAllowPrivate(DartConstructorName(constructor)); |
| 1300 ASSERT(function != Object::null()); | 1506 ASSERT(function != Object::null()); |
| 1301 return function; | 1507 return function; |
| 1302 } | 1508 } |
| 1303 | 1509 |
| 1304 | 1510 |
| 1305 dart::Type& TranslationHelper::GetCanonicalType(const dart::Class& klass) { | 1511 dart::Type& TranslationHelper::GetCanonicalType(const dart::Class& klass) { |
| 1306 ASSERT(!klass.IsNull()); | 1512 ASSERT(!klass.IsNull()); |
| 1307 // Note that if cls is _Closure, the returned type will be _Closure, | 1513 // Note that if cls is _Closure, the returned type will be _Closure, |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 | 1920 |
| 1715 // Run the method and canonicalize the result. | 1921 // Run the method and canonicalize the result. |
| 1716 const Object& result = RunFunction(function, kernel_arguments, &receiver); | 1922 const Object& result = RunFunction(function, kernel_arguments, &receiver); |
| 1717 result_ ^= result.raw(); | 1923 result_ ^= result.raw(); |
| 1718 result_ = H.Canonicalize(result_); | 1924 result_ = H.Canonicalize(result_); |
| 1719 } | 1925 } |
| 1720 | 1926 |
| 1721 | 1927 |
| 1722 void ConstantEvaluator::VisitStaticGet(StaticGet* node) { | 1928 void ConstantEvaluator::VisitStaticGet(StaticGet* node) { |
| 1723 CanonicalName* target = node->target(); | 1929 CanonicalName* target = node->target(); |
| 1724 if (target->IsField()) { | 1930 if (H.IsField(target)) { |
| 1725 const dart::Field& field = | 1931 const dart::Field& field = |
| 1726 dart::Field::Handle(Z, H.LookupFieldByKernelField(target)); | 1932 dart::Field::Handle(Z, H.LookupFieldByKernelField(target)); |
| 1727 if (field.StaticValue() == Object::sentinel().raw() || | 1933 if (field.StaticValue() == Object::sentinel().raw() || |
| 1728 field.StaticValue() == Object::transition_sentinel().raw()) { | 1934 field.StaticValue() == Object::transition_sentinel().raw()) { |
| 1729 field.EvaluateInitializer(); | 1935 field.EvaluateInitializer(); |
| 1730 result_ = field.StaticValue(); | 1936 result_ = field.StaticValue(); |
| 1731 result_ = H.Canonicalize(result_); | 1937 result_ = H.Canonicalize(result_); |
| 1732 field.SetStaticValue(result_, true); | 1938 field.SetStaticValue(result_, true); |
| 1733 } else { | 1939 } else { |
| 1734 result_ = field.StaticValue(); | 1940 result_ = field.StaticValue(); |
| 1735 } | 1941 } |
| 1736 } else if (target->IsProcedure()) { | 1942 } else if (H.IsProcedure(target)) { |
| 1737 const Function& function = | 1943 const Function& function = |
| 1738 Function::ZoneHandle(Z, H.LookupStaticMethodByKernelProcedure(target)); | 1944 Function::ZoneHandle(Z, H.LookupStaticMethodByKernelProcedure(target)); |
| 1739 | 1945 |
| 1740 if (target->IsMethod()) { | 1946 if (H.IsMethod(target)) { |
| 1741 Function& closure_function = | 1947 Function& closure_function = |
| 1742 Function::ZoneHandle(Z, function.ImplicitClosureFunction()); | 1948 Function::ZoneHandle(Z, function.ImplicitClosureFunction()); |
| 1743 closure_function.set_kernel_function(function.kernel_function()); | 1949 closure_function.set_kernel_function(function.kernel_function()); |
| 1744 result_ = closure_function.ImplicitStaticClosure(); | 1950 result_ = closure_function.ImplicitStaticClosure(); |
| 1745 result_ = H.Canonicalize(result_); | 1951 result_ = H.Canonicalize(result_); |
| 1746 } else if (target->IsGetter()) { | 1952 } else if (H.IsGetter(target)) { |
| 1747 UNIMPLEMENTED(); | 1953 UNIMPLEMENTED(); |
| 1748 } else { | 1954 } else { |
| 1749 UNIMPLEMENTED(); | 1955 UNIMPLEMENTED(); |
| 1750 } | 1956 } |
| 1751 } | 1957 } |
| 1752 } | 1958 } |
| 1753 | 1959 |
| 1754 | 1960 |
| 1755 void ConstantEvaluator::VisitVariableGet(VariableGet* node) { | 1961 void ConstantEvaluator::VisitVariableGet(VariableGet* node) { |
| 1756 // When we see a [VariableGet] the corresponding [VariableDeclaration] must've | 1962 // When we see a [VariableGet] the corresponding [VariableDeclaration] must've |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 | 2053 |
| 1848 void ConstantEvaluator::VisitNot(Not* node) { | 2054 void ConstantEvaluator::VisitNot(Not* node) { |
| 1849 result_ ^= Bool::Get(!EvaluateBooleanExpression(node->expression())).raw(); | 2055 result_ ^= Bool::Get(!EvaluateBooleanExpression(node->expression())).raw(); |
| 1850 } | 2056 } |
| 1851 | 2057 |
| 1852 | 2058 |
| 1853 void ConstantEvaluator::VisitPropertyGet(PropertyGet* node) { | 2059 void ConstantEvaluator::VisitPropertyGet(PropertyGet* node) { |
| 1854 const intptr_t kLengthLen = sizeof("length") - 1; | 2060 const intptr_t kLengthLen = sizeof("length") - 1; |
| 1855 | 2061 |
| 1856 String* string = node->name()->string(); | 2062 String* string = node->name()->string(); |
| 1857 if ((string->size() == kLengthLen) && | 2063 if ((string->size() == kLengthLen) && H.StringEquals(string, "length")) { |
| 1858 (memcmp(string->buffer(), "length", kLengthLen) == 0)) { | |
| 1859 node->receiver()->AcceptExpressionVisitor(this); | 2064 node->receiver()->AcceptExpressionVisitor(this); |
| 1860 if (result_.IsString()) { | 2065 if (result_.IsString()) { |
| 1861 const dart::String& str = | 2066 const dart::String& str = |
| 1862 dart::String::Handle(Z, dart::String::RawCast(result_.raw())); | 2067 dart::String::Handle(Z, dart::String::RawCast(result_.raw())); |
| 1863 result_ = Integer::New(str.Length()); | 2068 result_ = Integer::New(str.Length()); |
| 1864 } else { | 2069 } else { |
| 1865 H.ReportError( | 2070 H.ReportError( |
| 1866 "Constant expressions can only call " | 2071 "Constant expressions can only call " |
| 1867 "'length' on string constants."); | 2072 "'length' on string constants."); |
| 1868 } | 2073 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 breakable_block_(NULL), | 2178 breakable_block_(NULL), |
| 1974 switch_block_(NULL), | 2179 switch_block_(NULL), |
| 1975 try_finally_block_(NULL), | 2180 try_finally_block_(NULL), |
| 1976 try_catch_block_(NULL), | 2181 try_catch_block_(NULL), |
| 1977 next_used_try_index_(0), | 2182 next_used_try_index_(0), |
| 1978 catch_block_(NULL), | 2183 catch_block_(NULL), |
| 1979 type_translator_(&translation_helper_, | 2184 type_translator_(&translation_helper_, |
| 1980 &active_class_, | 2185 &active_class_, |
| 1981 /* finalize= */ true), | 2186 /* finalize= */ true), |
| 1982 constant_evaluator_(this, zone_, &translation_helper_, &type_translator_), | 2187 constant_evaluator_(this, zone_, &translation_helper_, &type_translator_), |
| 1983 streaming_flow_graph_builder_(NULL) {} | 2188 streaming_flow_graph_builder_(NULL) { |
| 2189 Script& script = Script::Handle(Z, parsed_function->function().script()); |
| 2190 H.SetStringData(TypedData::Handle(Z, script.kernel_strings())); |
| 2191 } |
| 1984 | 2192 |
| 1985 | 2193 |
| 1986 FlowGraphBuilder::~FlowGraphBuilder() { | 2194 FlowGraphBuilder::~FlowGraphBuilder() { |
| 1987 if (streaming_flow_graph_builder_ != NULL) { | 2195 if (streaming_flow_graph_builder_ != NULL) { |
| 1988 delete streaming_flow_graph_builder_; | 2196 delete streaming_flow_graph_builder_; |
| 1989 } | 2197 } |
| 1990 } | 2198 } |
| 1991 | 2199 |
| 1992 | 2200 |
| 1993 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( | 2201 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2892 // Leave "result" on the stack since callers expect it to be there (even | 3100 // Leave "result" on the stack since callers expect it to be there (even |
| 2893 // though the function will result in an exception). | 3101 // though the function will result in an exception). |
| 2894 | 3102 |
| 2895 return instructions; | 3103 return instructions; |
| 2896 } | 3104 } |
| 2897 | 3105 |
| 2898 | 3106 |
| 2899 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember( | 3107 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember( |
| 2900 CanonicalName* target, | 3108 CanonicalName* target, |
| 2901 const dart::String& method_name) { | 3109 const dart::String& method_name) { |
| 2902 CanonicalName* kernel_class = target->EnclosingName(); | 3110 CanonicalName* kernel_class = H.EnclosingName(target); |
| 2903 dart::Class& klass = | 3111 dart::Class& klass = |
| 2904 dart::Class::Handle(Z, H.LookupClassByKernelClass(kernel_class)); | 3112 dart::Class::Handle(Z, H.LookupClassByKernelClass(kernel_class)); |
| 2905 | 3113 |
| 2906 dart::RawFunction* function = klass.LookupFunctionAllowPrivate(method_name); | 3114 dart::RawFunction* function = klass.LookupFunctionAllowPrivate(method_name); |
| 2907 ASSERT(function != Object::null()); | 3115 ASSERT(function != Object::null()); |
| 2908 return function; | 3116 return function; |
| 2909 } | 3117 } |
| 2910 | 3118 |
| 2911 | 3119 |
| 2912 LocalVariable* FlowGraphBuilder::MakeTemporary() { | 3120 LocalVariable* FlowGraphBuilder::MakeTemporary() { |
| (...skipping 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4716 } | 4924 } |
| 4717 | 4925 |
| 4718 | 4926 |
| 4719 void FlowGraphBuilder::VisitStaticGet(StaticGet* node) { | 4927 void FlowGraphBuilder::VisitStaticGet(StaticGet* node) { |
| 4720 fragment_ = streaming_flow_graph_builder_->BuildAt(node->kernel_offset()); | 4928 fragment_ = streaming_flow_graph_builder_->BuildAt(node->kernel_offset()); |
| 4721 } | 4929 } |
| 4722 | 4930 |
| 4723 | 4931 |
| 4724 void FlowGraphBuilder::VisitStaticSet(StaticSet* node) { | 4932 void FlowGraphBuilder::VisitStaticSet(StaticSet* node) { |
| 4725 CanonicalName* target = node->target(); | 4933 CanonicalName* target = node->target(); |
| 4726 if (target->IsField()) { | 4934 if (H.IsField(target)) { |
| 4727 const dart::Field& field = | 4935 const dart::Field& field = |
| 4728 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(target)); | 4936 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(target)); |
| 4729 const AbstractType& dst_type = AbstractType::ZoneHandle(Z, field.type()); | 4937 const AbstractType& dst_type = AbstractType::ZoneHandle(Z, field.type()); |
| 4730 Fragment instructions = TranslateExpression(node->expression()); | 4938 Fragment instructions = TranslateExpression(node->expression()); |
| 4731 if (NeedsDebugStepCheck(stack_, node->position())) { | 4939 if (NeedsDebugStepCheck(stack_, node->position())) { |
| 4732 instructions = DebugStepCheck(node->position()) + instructions; | 4940 instructions = DebugStepCheck(node->position()) + instructions; |
| 4733 } | 4941 } |
| 4734 instructions += CheckAssignableInCheckedMode( | 4942 instructions += CheckAssignableInCheckedMode( |
| 4735 dst_type, dart::String::ZoneHandle(Z, field.name())); | 4943 dst_type, dart::String::ZoneHandle(Z, field.name())); |
| 4736 LocalVariable* variable = MakeTemporary(); | 4944 LocalVariable* variable = MakeTemporary(); |
| 4737 instructions += LoadLocal(variable); | 4945 instructions += LoadLocal(variable); |
| 4738 fragment_ = instructions + StoreStaticField(node->position(), field); | 4946 fragment_ = instructions + StoreStaticField(node->position(), field); |
| 4739 } else { | 4947 } else { |
| 4740 ASSERT(target->IsProcedure()); | 4948 ASSERT(H.IsProcedure(target)); |
| 4741 | 4949 |
| 4742 // Evaluate the expression on the right hand side. | 4950 // Evaluate the expression on the right hand side. |
| 4743 Fragment instructions = TranslateExpression(node->expression()); | 4951 Fragment instructions = TranslateExpression(node->expression()); |
| 4744 LocalVariable* variable = MakeTemporary(); | 4952 LocalVariable* variable = MakeTemporary(); |
| 4745 | 4953 |
| 4746 // Prepare argument. | 4954 // Prepare argument. |
| 4747 instructions += LoadLocal(variable); | 4955 instructions += LoadLocal(variable); |
| 4748 instructions += PushArgument(); | 4956 instructions += PushArgument(); |
| 4749 | 4957 |
| 4750 // Invoke the setter function. | 4958 // Invoke the setter function. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4778 | 4986 |
| 4779 const dart::String& setter_name = H.DartSetterName(node->name()); | 4987 const dart::String& setter_name = H.DartSetterName(node->name()); |
| 4780 instructions += InstanceCall(node->position(), setter_name, Token::kSET, 2); | 4988 instructions += InstanceCall(node->position(), setter_name, Token::kSET, 2); |
| 4781 fragment_ = instructions + Drop(); | 4989 fragment_ = instructions + Drop(); |
| 4782 } | 4990 } |
| 4783 | 4991 |
| 4784 | 4992 |
| 4785 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { | 4993 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { |
| 4786 Function& target = Function::ZoneHandle(Z); | 4994 Function& target = Function::ZoneHandle(Z); |
| 4787 CanonicalName* kernel_name = node->target(); | 4995 CanonicalName* kernel_name = node->target(); |
| 4788 if (kernel_name->IsProcedure()) { | 4996 if (H.IsProcedure(kernel_name)) { |
| 4789 if (kernel_name->IsGetter()) { | 4997 if (H.IsGetter(kernel_name)) { |
| 4790 target = LookupMethodByMember(kernel_name, H.DartGetterName(kernel_name)); | 4998 target = LookupMethodByMember(kernel_name, H.DartGetterName(kernel_name)); |
| 4791 } else { | 4999 } else { |
| 4792 target = LookupMethodByMember(kernel_name, H.DartMethodName(kernel_name)); | 5000 target = LookupMethodByMember(kernel_name, H.DartMethodName(kernel_name)); |
| 4793 target = target.ImplicitClosureFunction(); | 5001 target = target.ImplicitClosureFunction(); |
| 4794 ASSERT(!target.IsNull()); | 5002 ASSERT(!target.IsNull()); |
| 4795 fragment_ = BuildImplicitClosureCreation(target); | 5003 fragment_ = BuildImplicitClosureCreation(target); |
| 4796 return; | 5004 return; |
| 4797 } | 5005 } |
| 4798 } else { | 5006 } else { |
| 4799 ASSERT(kernel_name->IsField()); | 5007 ASSERT(H.IsField(kernel_name)); |
| 4800 const dart::String& getter_name = H.DartGetterName(kernel_name); | 5008 const dart::String& getter_name = H.DartGetterName(kernel_name); |
| 4801 target = LookupMethodByMember(kernel_name, getter_name); | 5009 target = LookupMethodByMember(kernel_name, getter_name); |
| 4802 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction()); | 5010 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction()); |
| 4803 } | 5011 } |
| 4804 | 5012 |
| 4805 Fragment instructions = TranslateExpression(node->receiver()); | 5013 Fragment instructions = TranslateExpression(node->receiver()); |
| 4806 instructions += PushArgument(); | 5014 instructions += PushArgument(); |
| 4807 fragment_ = instructions + StaticCall(node->position(), target, 1); | 5015 fragment_ = instructions + StaticCall(node->position(), target, 1); |
| 4808 } | 5016 } |
| 4809 | 5017 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4995 | 5203 |
| 4996 | 5204 |
| 4997 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { | 5205 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { |
| 4998 if (node->is_const()) { | 5206 if (node->is_const()) { |
| 4999 fragment_ = | 5207 fragment_ = |
| 5000 Constant(constant_evaluator_.EvaluateConstructorInvocation(node)); | 5208 Constant(constant_evaluator_.EvaluateConstructorInvocation(node)); |
| 5001 return; | 5209 return; |
| 5002 } | 5210 } |
| 5003 | 5211 |
| 5004 dart::Class& klass = dart::Class::ZoneHandle( | 5212 dart::Class& klass = dart::Class::ZoneHandle( |
| 5005 Z, H.LookupClassByKernelClass(node->target()->EnclosingName())); | 5213 Z, H.LookupClassByKernelClass(H.EnclosingName(node->target()))); |
| 5006 | 5214 |
| 5007 Fragment instructions; | 5215 Fragment instructions; |
| 5008 | 5216 |
| 5009 // Check for malbounded-ness of type. | 5217 // Check for malbounded-ness of type. |
| 5010 if (I->type_checks()) { | 5218 if (I->type_checks()) { |
| 5011 List<DartType>& kernel_type_arguments = node->arguments()->types(); | 5219 List<DartType>& kernel_type_arguments = node->arguments()->types(); |
| 5012 const TypeArguments& type_arguments = T.TranslateTypeArguments( | 5220 const TypeArguments& type_arguments = T.TranslateTypeArguments( |
| 5013 kernel_type_arguments.raw_array(), kernel_type_arguments.length()); | 5221 kernel_type_arguments.raw_array(), kernel_type_arguments.length()); |
| 5014 | 5222 |
| 5015 AbstractType& type = AbstractType::Handle( | 5223 AbstractType& type = AbstractType::Handle( |
| (...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6439 | 6647 |
| 6440 instructions += LoadLocal(closure); | 6648 instructions += LoadLocal(closure); |
| 6441 instructions += LoadLocal(parsed_function_->current_context_var()); | 6649 instructions += LoadLocal(parsed_function_->current_context_var()); |
| 6442 instructions += | 6650 instructions += |
| 6443 StoreInstanceField(TokenPosition::kNoSource, Closure::context_offset()); | 6651 StoreInstanceField(TokenPosition::kNoSource, Closure::context_offset()); |
| 6444 | 6652 |
| 6445 return instructions; | 6653 return instructions; |
| 6446 } | 6654 } |
| 6447 | 6655 |
| 6448 | 6656 |
| 6449 RawObject* EvaluateMetadata(TreeNode* const kernel_node) { | 6657 RawObject* EvaluateMetadata(const dart::Field& metadata_field) { |
| 6450 LongJumpScope jump; | 6658 LongJumpScope jump; |
| 6451 if (setjmp(*jump.Set()) == 0) { | 6659 if (setjmp(*jump.Set()) == 0) { |
| 6452 Thread* thread = Thread::Current(); | 6660 Thread* thread = Thread::Current(); |
| 6453 Zone* zone_ = thread->zone(); | 6661 Zone* zone_ = thread->zone(); |
| 6454 | 6662 |
| 6663 TreeNode* kernel_node = |
| 6664 reinterpret_cast<TreeNode*>(metadata_field.kernel_field()); |
| 6455 List<Expression>* metadata_expressions = NULL; | 6665 List<Expression>* metadata_expressions = NULL; |
| 6456 if (kernel_node->IsClass()) { | 6666 if (kernel_node->IsClass()) { |
| 6457 metadata_expressions = &Class::Cast(kernel_node)->annotations(); | 6667 metadata_expressions = &Class::Cast(kernel_node)->annotations(); |
| 6458 } else if (kernel_node->IsProcedure()) { | 6668 } else if (kernel_node->IsProcedure()) { |
| 6459 metadata_expressions = &Procedure::Cast(kernel_node)->annotations(); | 6669 metadata_expressions = &Procedure::Cast(kernel_node)->annotations(); |
| 6460 } else if (kernel_node->IsField()) { | 6670 } else if (kernel_node->IsField()) { |
| 6461 metadata_expressions = &Field::Cast(kernel_node)->annotations(); | 6671 metadata_expressions = &Field::Cast(kernel_node)->annotations(); |
| 6462 } else if (kernel_node->IsConstructor()) { | 6672 } else if (kernel_node->IsConstructor()) { |
| 6463 metadata_expressions = &Constructor::Cast(kernel_node)->annotations(); | 6673 metadata_expressions = &Constructor::Cast(kernel_node)->annotations(); |
| 6464 } else { | 6674 } else { |
| 6465 FATAL1("No support for metadata on this type of kernel node %p\n", | 6675 FATAL1("No support for metadata on this type of kernel node %p\n", |
| 6466 kernel_node); | 6676 kernel_node); |
| 6467 } | 6677 } |
| 6468 | 6678 |
| 6469 TranslationHelper translation_helper(thread); | 6679 TranslationHelper helper(thread); |
| 6470 DartTypeTranslator type_translator(&translation_helper, NULL, true); | 6680 Script& script = Script::Handle(Z, metadata_field.Script()); |
| 6681 helper.SetStringData(TypedData::Handle(Z, script.kernel_strings())); |
| 6682 DartTypeTranslator type_translator(&helper, NULL, true); |
| 6471 ConstantEvaluator constant_evaluator(/* flow_graph_builder = */ NULL, Z, | 6683 ConstantEvaluator constant_evaluator(/* flow_graph_builder = */ NULL, Z, |
| 6472 &translation_helper, &type_translator); | 6684 &helper, &type_translator); |
| 6473 | 6685 |
| 6474 const Array& metadata_values = | 6686 const Array& metadata_values = |
| 6475 Array::Handle(Z, Array::New(metadata_expressions->length())); | 6687 Array::Handle(Z, Array::New(metadata_expressions->length())); |
| 6476 | 6688 |
| 6477 for (intptr_t i = 0; i < metadata_expressions->length(); i++) { | 6689 for (intptr_t i = 0; i < metadata_expressions->length(); i++) { |
| 6478 const Instance& value = | 6690 const Instance& value = |
| 6479 constant_evaluator.EvaluateExpression((*metadata_expressions)[i]); | 6691 constant_evaluator.EvaluateExpression((*metadata_expressions)[i]); |
| 6480 metadata_values.SetAt(i, value); | 6692 metadata_values.SetAt(i, value); |
| 6481 } | 6693 } |
| 6482 | 6694 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6556 thread->clear_sticky_error(); | 6768 thread->clear_sticky_error(); |
| 6557 return error.raw(); | 6769 return error.raw(); |
| 6558 } | 6770 } |
| 6559 } | 6771 } |
| 6560 | 6772 |
| 6561 | 6773 |
| 6562 } // namespace kernel | 6774 } // namespace kernel |
| 6563 } // namespace dart | 6775 } // namespace dart |
| 6564 | 6776 |
| 6565 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6777 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |