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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "vm/kernel_to_il.h" | 9 #include "vm/kernel_to_il.h" |
10 | 10 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 270 |
271 ParsedFunction* parsed_function = parsed_function_; | 271 ParsedFunction* parsed_function = parsed_function_; |
272 const dart::Function& function = parsed_function->function(); | 272 const dart::Function& function = parsed_function->function(); |
273 | 273 |
274 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used | 274 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used |
275 // e.g. for type translation. | 275 // e.g. for type translation. |
276 const dart::Class& klass = | 276 const dart::Class& klass = |
277 dart::Class::Handle(zone_, parsed_function_->function().Owner()); | 277 dart::Class::Handle(zone_, parsed_function_->function().Owner()); |
278 Function& outermost_function = Function::Handle(Z); | 278 Function& outermost_function = Function::Handle(Z); |
279 TreeNode* outermost_node = NULL; | 279 TreeNode* outermost_node = NULL; |
280 Class* kernel_class = NULL; | 280 Class* kernel_klass = NULL; |
281 DiscoverEnclosingElements(Z, function, &outermost_function, &outermost_node, | 281 DiscoverEnclosingElements(Z, function, &outermost_function, &outermost_node, |
282 &kernel_class); | 282 &kernel_klass); |
283 // Use [klass]/[kernel_class] as active class. Type parameters will get | 283 // Use [klass]/[kernel_klass] as active class. Type parameters will get |
284 // resolved via [kernel_class] unless we are nested inside a static factory | 284 // resolved via [kernel_klass] unless we are nested inside a static factory |
285 // in which case we will use [member]. | 285 // in which case we will use [member]. |
286 ActiveClassScope active_class_scope(&active_class_, kernel_class, &klass); | 286 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); |
287 Member* member = ((outermost_node != NULL) && outermost_node->IsMember()) | 287 Member* member = ((outermost_node != NULL) && outermost_node->IsMember()) |
288 ? Member::Cast(outermost_node) | 288 ? Member::Cast(outermost_node) |
289 : NULL; | 289 : NULL; |
290 ActiveMemberScope active_member(&active_class_, member); | 290 ActiveMemberScope active_member(&active_class_, member); |
291 | 291 |
292 | 292 |
293 LocalScope* enclosing_scope = NULL; | 293 LocalScope* enclosing_scope = NULL; |
294 if (function.IsLocalFunction()) { | 294 if (function.IsLocalFunction()) { |
295 enclosing_scope = LocalScope::RestoreOuterScope( | 295 enclosing_scope = LocalScope::RestoreOuterScope( |
296 ContextScope::Handle(Z, function.context_scope())); | 296 ContextScope::Handle(Z, function.context_scope())); |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 } | 1063 } |
1064 | 1064 |
1065 | 1065 |
1066 dart::String& TranslationHelper::DartSymbol(String* content) const { | 1066 dart::String& TranslationHelper::DartSymbol(String* content) const { |
1067 return dart::String::ZoneHandle( | 1067 return dart::String::ZoneHandle( |
1068 Z, dart::Symbols::FromUTF8(thread_, content->buffer(), content->size())); | 1068 Z, dart::Symbols::FromUTF8(thread_, content->buffer(), content->size())); |
1069 } | 1069 } |
1070 | 1070 |
1071 | 1071 |
1072 const dart::String& TranslationHelper::DartClassName( | 1072 const dart::String& TranslationHelper::DartClassName( |
1073 CanonicalName* kernel_class) { | 1073 CanonicalName* kernel_klass) { |
1074 ASSERT(kernel_class->IsClass()); | 1074 dart::String& name = DartString(kernel_klass->name()); |
1075 dart::String& name = DartString(kernel_class->name()); | 1075 return ManglePrivateName(kernel_klass->parent(), &name); |
1076 return ManglePrivateName(kernel_class->parent(), &name); | |
1077 } | 1076 } |
1078 | 1077 |
1079 | 1078 |
1080 const dart::String& TranslationHelper::DartConstructorName( | 1079 const dart::String& TranslationHelper::DartConstructorName(Constructor* node) { |
1081 CanonicalName* constructor) { | 1080 Class* klass = Class::Cast(node->parent()); |
1082 ASSERT(constructor->IsConstructor()); | 1081 return DartFactoryName(klass, node->name()); |
1083 return DartFactoryName(constructor); | |
1084 } | 1082 } |
1085 | 1083 |
1086 | 1084 |
1087 const dart::String& TranslationHelper::DartProcedureName( | 1085 const dart::String& TranslationHelper::DartProcedureName(Procedure* procedure) { |
1088 CanonicalName* procedure) { | 1086 if (procedure->kind() == Procedure::kSetter) { |
1089 ASSERT(procedure->IsProcedure()); | 1087 return DartSetterName(procedure->name()); |
1090 if (procedure->IsSetter()) { | 1088 } else if (procedure->kind() == Procedure::kGetter) { |
1091 return DartSetterName(procedure); | 1089 return DartGetterName(procedure->name()); |
1092 } else if (procedure->IsGetter()) { | 1090 } else if (procedure->kind() == Procedure::kFactory) { |
1093 return DartGetterName(procedure); | 1091 return DartFactoryName(Class::Cast(procedure->parent()), procedure->name()); |
1094 } else if (procedure->IsFactory()) { | |
1095 return DartFactoryName(procedure); | |
1096 } else { | 1092 } else { |
1097 return DartMethodName(procedure); | 1093 return DartMethodName(procedure->name()); |
1098 } | 1094 } |
1099 } | 1095 } |
1100 | 1096 |
1101 | 1097 |
1102 const dart::String& TranslationHelper::DartSetterName(CanonicalName* setter) { | 1098 const dart::String& TranslationHelper::DartSetterName(Name* kernel_name) { |
1103 return DartSetterName(setter->parent(), setter->name()); | 1099 // The names flowing into [content] are coming from the Kernel file: |
1104 } | |
1105 | |
1106 | |
1107 const dart::String& TranslationHelper::DartSetterName(Name* setter_name) { | |
1108 return DartSetterName(setter_name->library(), setter_name->string()); | |
1109 } | |
1110 | |
1111 | |
1112 const dart::String& TranslationHelper::DartSetterName(CanonicalName* parent, | |
1113 String* setter) { | |
1114 // The names flowing into [setter] are coming from the Kernel file: | |
1115 // * user-defined setters: `fieldname=` | 1100 // * user-defined setters: `fieldname=` |
1116 // * property-set expressions: `fieldname` | 1101 // * property-set expressions: `fieldname` |
1117 // | 1102 // |
1118 // The VM uses `get:fieldname` and `set:fieldname`. | 1103 // The VM uses `get:fieldname` and `set:fieldname`. |
1119 // | 1104 // |
1120 // => In order to be consistent, we remove the `=` always and adopt the VM | 1105 // => In order to be consistent, we remove the `=` always and adopt the VM |
1121 // conventions. | 1106 // conventions. |
1122 ASSERT(setter->size() > 0); | 1107 String* content = kernel_name->string(); |
| 1108 ASSERT(content->size() > 0); |
1123 intptr_t skip = 0; | 1109 intptr_t skip = 0; |
1124 if (setter->buffer()[setter->size() - 1] == '=') { | 1110 if (content->buffer()[content->size() - 1] == '=') { |
1125 skip = 1; | 1111 skip = 1; |
1126 } | 1112 } |
1127 dart::String& name = dart::String::ZoneHandle( | 1113 dart::String& name = dart::String::ZoneHandle( |
1128 Z, dart::String::FromUTF8(setter->buffer(), setter->size() - skip, | 1114 Z, dart::String::FromUTF8(content->buffer(), content->size() - skip, |
1129 allocation_space_)); | 1115 allocation_space_)); |
1130 ManglePrivateName(parent, &name, false); | 1116 ManglePrivateName(kernel_name->library_reference(), &name, false); |
1131 name = dart::Field::SetterSymbol(name); | 1117 name = dart::Field::SetterSymbol(name); |
1132 return name; | 1118 return name; |
1133 } | 1119 } |
1134 | 1120 |
1135 | 1121 |
1136 const dart::String& TranslationHelper::DartGetterName(CanonicalName* getter) { | 1122 const dart::String& TranslationHelper::DartGetterName(Name* kernel_name) { |
1137 return DartGetterName(getter->parent(), getter->name()); | 1123 dart::String& name = DartString(kernel_name->string()); |
1138 } | 1124 ManglePrivateName(kernel_name->library_reference(), &name, false); |
1139 | |
1140 | |
1141 const dart::String& TranslationHelper::DartGetterName(Name* getter_name) { | |
1142 return DartGetterName(getter_name->library(), getter_name->string()); | |
1143 } | |
1144 | |
1145 | |
1146 const dart::String& TranslationHelper::DartGetterName(CanonicalName* parent, | |
1147 String* getter) { | |
1148 dart::String& name = DartString(getter); | |
1149 ManglePrivateName(parent, &name, false); | |
1150 name = dart::Field::GetterSymbol(name); | 1125 name = dart::Field::GetterSymbol(name); |
1151 return name; | 1126 return name; |
1152 } | 1127 } |
1153 | 1128 |
1154 | 1129 |
1155 const dart::String& TranslationHelper::DartFieldName(Name* kernel_name) { | 1130 const dart::String& TranslationHelper::DartFieldName(Name* kernel_name) { |
1156 dart::String& name = DartString(kernel_name->string()); | 1131 dart::String& name = DartString(kernel_name->string()); |
1157 return ManglePrivateName(kernel_name->library(), &name); | 1132 return ManglePrivateName(kernel_name->library_reference(), &name); |
1158 } | 1133 } |
1159 | 1134 |
1160 | 1135 |
1161 const dart::String& TranslationHelper::DartInitializerName(Name* kernel_name) { | 1136 const dart::String& TranslationHelper::DartInitializerName(Name* kernel_name) { |
1162 // The [DartFieldName] will take care of mangling the name. | 1137 // The [DartFieldName] will take care of mangling the name. |
1163 dart::String& name = | 1138 dart::String& name = |
1164 dart::String::Handle(Z, DartFieldName(kernel_name).raw()); | 1139 dart::String::Handle(Z, DartFieldName(kernel_name).raw()); |
1165 name = Symbols::FromConcat(thread_, Symbols::InitPrefix(), name); | 1140 name = Symbols::FromConcat(thread_, Symbols::InitPrefix(), name); |
1166 return name; | 1141 return name; |
1167 } | 1142 } |
1168 | 1143 |
1169 | 1144 |
1170 const dart::String& TranslationHelper::DartMethodName(CanonicalName* method) { | 1145 const dart::String& TranslationHelper::DartMethodName(Name* kernel_name) { |
1171 return DartMethodName(method->parent(), method->name()); | 1146 dart::String& name = DartString(kernel_name->string()); |
| 1147 return ManglePrivateName(kernel_name->library_reference(), &name); |
1172 } | 1148 } |
1173 | 1149 |
1174 | 1150 |
1175 const dart::String& TranslationHelper::DartMethodName(Name* method_name) { | 1151 const dart::String& TranslationHelper::DartFactoryName(Class* klass, |
1176 return DartMethodName(method_name->library(), method_name->string()); | 1152 Name* method_name) { |
1177 } | 1153 // [DartMethodName] will mangle the name. |
1178 | |
1179 | |
1180 const dart::String& TranslationHelper::DartMethodName(CanonicalName* parent, | |
1181 String* method) { | |
1182 dart::String& name = DartString(method); | |
1183 return ManglePrivateName(parent, &name); | |
1184 } | |
1185 | |
1186 | |
1187 const dart::String& TranslationHelper::DartFactoryName(CanonicalName* factory) { | |
1188 ASSERT(factory->IsConstructor() || factory->IsFactory()); | |
1189 GrowableHandlePtrArray<const dart::String> pieces(Z, 3); | 1154 GrowableHandlePtrArray<const dart::String> pieces(Z, 3); |
1190 pieces.Add(DartClassName(factory->EnclosingName())); | 1155 pieces.Add(DartClassName(klass->canonical_name())); |
1191 pieces.Add(Symbols::Dot()); | 1156 pieces.Add(Symbols::Dot()); |
1192 // [DartMethodName] will mangle the name. | 1157 pieces.Add(DartMethodName(method_name)); |
1193 pieces.Add(DartMethodName(factory)); | |
1194 return dart::String::ZoneHandle( | 1158 return dart::String::ZoneHandle( |
1195 Z, dart::Symbols::FromConcatAll(thread_, pieces)); | 1159 Z, dart::Symbols::FromConcatAll(thread_, pieces)); |
1196 } | 1160 } |
1197 | 1161 |
1198 | 1162 |
1199 dart::RawLibrary* TranslationHelper::LookupLibraryByKernelLibrary( | 1163 dart::RawLibrary* TranslationHelper::LookupLibraryByKernelLibrary( |
1200 CanonicalName* kernel_library) { | 1164 CanonicalName* kernel_library) { |
1201 // We only use the name and don't rely on having any particular parent. This | |
1202 // ASSERT is just a sanity check. | |
1203 ASSERT(kernel_library->IsLibrary() || | |
1204 kernel_library->parent()->IsAdministrative()); | |
1205 const dart::String& library_name = DartSymbol(kernel_library->name()); | 1165 const dart::String& library_name = DartSymbol(kernel_library->name()); |
1206 ASSERT(!library_name.IsNull()); | 1166 ASSERT(!library_name.IsNull()); |
1207 dart::RawLibrary* library = | 1167 dart::RawLibrary* library = |
1208 dart::Library::LookupLibrary(thread_, library_name); | 1168 dart::Library::LookupLibrary(thread_, library_name); |
1209 ASSERT(library != Object::null()); | 1169 ASSERT(library != Object::null()); |
1210 return library; | 1170 return library; |
1211 } | 1171 } |
1212 | 1172 |
1213 | 1173 |
1214 dart::RawClass* TranslationHelper::LookupClassByKernelClass( | 1174 dart::RawClass* TranslationHelper::LookupClassByKernelClass( |
1215 CanonicalName* kernel_class) { | 1175 CanonicalName* kernel_klass) { |
1216 ASSERT(kernel_class->IsClass()); | |
1217 dart::RawClass* klass = NULL; | 1176 dart::RawClass* klass = NULL; |
1218 const dart::String& class_name = DartClassName(kernel_class); | 1177 |
1219 CanonicalName* kernel_library = kernel_class->parent(); | 1178 const dart::String& class_name = DartClassName(kernel_klass); |
| 1179 CanonicalName* kernel_library = kernel_klass->parent(); |
1220 dart::Library& library = | 1180 dart::Library& library = |
1221 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); | 1181 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); |
1222 klass = library.LookupClassAllowPrivate(class_name); | 1182 klass = library.LookupClassAllowPrivate(class_name); |
1223 | 1183 |
1224 ASSERT(klass != Object::null()); | 1184 ASSERT(klass != Object::null()); |
1225 return klass; | 1185 return klass; |
1226 } | 1186 } |
1227 | 1187 |
1228 | 1188 |
1229 dart::RawField* TranslationHelper::LookupFieldByKernelField( | 1189 dart::RawField* TranslationHelper::LookupFieldByKernelField( |
1230 CanonicalName* kernel_field) { | 1190 Field* kernel_field) { |
1231 ASSERT(kernel_field->IsField()); | 1191 TreeNode* node = kernel_field->parent(); |
1232 CanonicalName* enclosing = kernel_field->EnclosingName(); | |
1233 | 1192 |
1234 dart::Class& klass = dart::Class::Handle(Z); | 1193 dart::Class& klass = dart::Class::Handle(Z); |
1235 if (enclosing->IsLibrary()) { | 1194 if (node->IsClass()) { |
1236 dart::Library& library = | 1195 klass = LookupClassByKernelClass(Class::Cast(node)->canonical_name()); |
1237 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(enclosing)); | 1196 } else { |
| 1197 ASSERT(node->IsLibrary()); |
| 1198 dart::Library& library = dart::Library::Handle( |
| 1199 Z, LookupLibraryByKernelLibrary(Library::Cast(node)->canonical_name())); |
1238 klass = library.toplevel_class(); | 1200 klass = library.toplevel_class(); |
1239 } else { | |
1240 ASSERT(enclosing->IsClass()); | |
1241 klass = LookupClassByKernelClass(enclosing); | |
1242 } | 1201 } |
1243 dart::RawField* field = | 1202 dart::RawField* field = |
1244 klass.LookupFieldAllowPrivate(DartSymbol(kernel_field->name())); | 1203 klass.LookupFieldAllowPrivate(DartSymbol(kernel_field->name()->string())); |
1245 ASSERT(field != Object::null()); | 1204 ASSERT(field != Object::null()); |
1246 return field; | 1205 return field; |
1247 } | 1206 } |
1248 | 1207 |
1249 | 1208 |
1250 dart::RawFunction* TranslationHelper::LookupStaticMethodByKernelProcedure( | 1209 dart::RawFunction* TranslationHelper::LookupStaticMethodByKernelProcedure( |
1251 CanonicalName* procedure) { | 1210 Procedure* procedure) { |
| 1211 ASSERT(procedure->IsStatic()); |
1252 const dart::String& procedure_name = DartProcedureName(procedure); | 1212 const dart::String& procedure_name = DartProcedureName(procedure); |
1253 | 1213 |
1254 // The parent is either a library or a class (in which case the procedure is a | 1214 // The parent is either a library or a class (in which case the procedure is a |
1255 // static method). | 1215 // static method). |
1256 CanonicalName* enclosing = procedure->EnclosingName(); | 1216 TreeNode* parent = procedure->parent(); |
1257 if (enclosing->IsLibrary()) { | 1217 if (parent->IsClass()) { |
1258 dart::Library& library = | 1218 dart::Class& klass = dart::Class::Handle( |
1259 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(enclosing)); | 1219 Z, LookupClassByKernelClass(Class::Cast(parent)->canonical_name())); |
1260 dart::RawFunction* function = | |
1261 library.LookupFunctionAllowPrivate(procedure_name); | |
1262 ASSERT(function != Object::null()); | |
1263 return function; | |
1264 } else { | |
1265 ASSERT(enclosing->IsClass()); | |
1266 dart::Class& klass = | |
1267 dart::Class::Handle(Z, LookupClassByKernelClass(enclosing)); | |
1268 dart::RawFunction* raw_function = | 1220 dart::RawFunction* raw_function = |
1269 klass.LookupFunctionAllowPrivate(procedure_name); | 1221 klass.LookupFunctionAllowPrivate(procedure_name); |
1270 ASSERT(raw_function != Object::null()); | 1222 ASSERT(raw_function != Object::null()); |
1271 | 1223 |
1272 // TODO(27590): We can probably get rid of this after no longer using | 1224 // TODO(27590): We can probably get rid of this after no longer using |
1273 // core libraries from the source. | 1225 // core libraries from the source. |
1274 dart::Function& function = dart::Function::ZoneHandle(Z, raw_function); | 1226 dart::Function& function = dart::Function::ZoneHandle(Z, raw_function); |
1275 if (function.IsRedirectingFactory()) { | 1227 if (function.IsRedirectingFactory()) { |
1276 ClassFinalizer::ResolveRedirectingFactory(klass, function); | 1228 ClassFinalizer::ResolveRedirectingFactory(klass, function); |
1277 function = function.RedirectionTarget(); | 1229 function = function.RedirectionTarget(); |
1278 } | 1230 } |
1279 return function.raw(); | 1231 return function.raw(); |
| 1232 } else { |
| 1233 ASSERT(parent->IsLibrary()); |
| 1234 dart::Library& library = dart::Library::Handle( |
| 1235 Z, |
| 1236 LookupLibraryByKernelLibrary(Library::Cast(parent)->canonical_name())); |
| 1237 dart::RawFunction* function = |
| 1238 library.LookupFunctionAllowPrivate(procedure_name); |
| 1239 ASSERT(function != Object::null()); |
| 1240 return function; |
1280 } | 1241 } |
1281 } | 1242 } |
1282 | 1243 |
1283 | 1244 |
1284 dart::RawFunction* TranslationHelper::LookupConstructorByKernelConstructor( | 1245 dart::RawFunction* TranslationHelper::LookupConstructorByKernelConstructor( |
1285 CanonicalName* constructor) { | 1246 Constructor* constructor) { |
1286 ASSERT(constructor->IsConstructor()); | 1247 Class* kernel_klass = Class::Cast(constructor->parent()); |
1287 dart::Class& klass = dart::Class::Handle( | 1248 dart::Class& klass = dart::Class::Handle( |
1288 Z, LookupClassByKernelClass(constructor->EnclosingName())); | 1249 Z, LookupClassByKernelClass(kernel_klass->canonical_name())); |
1289 return LookupConstructorByKernelConstructor(klass, constructor); | 1250 return LookupConstructorByKernelConstructor(klass, constructor); |
1290 } | 1251 } |
1291 | 1252 |
1292 | 1253 |
1293 dart::RawFunction* TranslationHelper::LookupConstructorByKernelConstructor( | 1254 dart::RawFunction* TranslationHelper::LookupConstructorByKernelConstructor( |
1294 const dart::Class& owner, | 1255 const dart::Class& owner, |
1295 CanonicalName* constructor) { | 1256 Constructor* constructor) { |
1296 ASSERT(constructor->IsConstructor()); | |
1297 dart::RawFunction* function = | 1257 dart::RawFunction* function = |
1298 owner.LookupConstructorAllowPrivate(DartConstructorName(constructor)); | 1258 owner.LookupConstructorAllowPrivate(DartConstructorName(constructor)); |
1299 ASSERT(function != Object::null()); | 1259 ASSERT(function != Object::null()); |
1300 return function; | 1260 return function; |
1301 } | 1261 } |
1302 | 1262 |
1303 | 1263 |
1304 dart::Type& TranslationHelper::GetCanonicalType(const dart::Class& klass) { | 1264 dart::Type& TranslationHelper::GetCanonicalType(const dart::Class& klass) { |
1305 ASSERT(!klass.IsNull()); | 1265 ASSERT(!klass.IsNull()); |
1306 // Note that if cls is _Closure, the returned type will be _Closure, | 1266 // Note that if cls is _Closure, the returned type will be _Closure, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 | 1299 |
1340 va_list args; | 1300 va_list args; |
1341 va_start(args, format); | 1301 va_start(args, format); |
1342 Report::LongJumpV(prev_error, null_script, TokenPosition::kNoSource, format, | 1302 Report::LongJumpV(prev_error, null_script, TokenPosition::kNoSource, format, |
1343 args); | 1303 args); |
1344 va_end(args); | 1304 va_end(args); |
1345 UNREACHABLE(); | 1305 UNREACHABLE(); |
1346 } | 1306 } |
1347 | 1307 |
1348 | 1308 |
1349 dart::String& TranslationHelper::ManglePrivateName(CanonicalName* parent, | 1309 dart::String& TranslationHelper::ManglePrivateName( |
1350 dart::String* name_to_modify, | 1310 CanonicalName* kernel_library, |
1351 bool symbolize) { | 1311 dart::String* name_to_modify, |
| 1312 bool symbolize) { |
1352 if (name_to_modify->Length() >= 1 && name_to_modify->CharAt(0) == '_') { | 1313 if (name_to_modify->Length() >= 1 && name_to_modify->CharAt(0) == '_') { |
1353 const dart::Library& library = | 1314 const dart::Library& library = |
1354 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(parent)); | 1315 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); |
1355 *name_to_modify = library.PrivateName(*name_to_modify); | 1316 *name_to_modify = library.PrivateName(*name_to_modify); |
1356 } else if (symbolize) { | 1317 } else if (symbolize) { |
1357 *name_to_modify = Symbols::New(thread_, *name_to_modify); | 1318 *name_to_modify = Symbols::New(thread_, *name_to_modify); |
1358 } | 1319 } |
1359 return *name_to_modify; | 1320 return *name_to_modify; |
1360 } | 1321 } |
1361 | 1322 |
1362 | 1323 |
1363 const Array& TranslationHelper::ArgumentNames(List<NamedExpression>* named) { | 1324 const Array& TranslationHelper::ArgumentNames(List<NamedExpression>* named) { |
1364 if (named->length() == 0) return Array::ZoneHandle(Z); | 1325 if (named->length() == 0) return Array::ZoneHandle(Z); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 ASSERT(!function.IsNull()); | 1673 ASSERT(!function.IsNull()); |
1713 | 1674 |
1714 // Run the method and canonicalize the result. | 1675 // Run the method and canonicalize the result. |
1715 const Object& result = RunFunction(function, kernel_arguments, &receiver); | 1676 const Object& result = RunFunction(function, kernel_arguments, &receiver); |
1716 result_ ^= result.raw(); | 1677 result_ ^= result.raw(); |
1717 result_ = H.Canonicalize(result_); | 1678 result_ = H.Canonicalize(result_); |
1718 } | 1679 } |
1719 | 1680 |
1720 | 1681 |
1721 void ConstantEvaluator::VisitStaticGet(StaticGet* node) { | 1682 void ConstantEvaluator::VisitStaticGet(StaticGet* node) { |
1722 CanonicalName* target = node->target(); | 1683 Member* member = node->target(); |
1723 if (target->IsField()) { | 1684 if (member->IsField()) { |
| 1685 Field* kernel_field = Field::Cast(member); |
1724 const dart::Field& field = | 1686 const dart::Field& field = |
1725 dart::Field::Handle(Z, H.LookupFieldByKernelField(target)); | 1687 dart::Field::Handle(Z, H.LookupFieldByKernelField(kernel_field)); |
1726 if (field.StaticValue() == Object::sentinel().raw() || | 1688 if (field.StaticValue() == Object::sentinel().raw() || |
1727 field.StaticValue() == Object::transition_sentinel().raw()) { | 1689 field.StaticValue() == Object::transition_sentinel().raw()) { |
1728 field.EvaluateInitializer(); | 1690 field.EvaluateInitializer(); |
1729 result_ = field.StaticValue(); | 1691 result_ = field.StaticValue(); |
1730 result_ = H.Canonicalize(result_); | 1692 result_ = H.Canonicalize(result_); |
1731 field.SetStaticValue(result_, true); | 1693 field.SetStaticValue(result_, true); |
1732 } else { | 1694 } else { |
1733 result_ = field.StaticValue(); | 1695 result_ = field.StaticValue(); |
1734 } | 1696 } |
1735 } else if (target->IsProcedure()) { | 1697 } else if (member->IsProcedure()) { |
1736 const Function& function = | 1698 Procedure* procedure = Procedure::Cast(member); |
1737 Function::ZoneHandle(Z, H.LookupStaticMethodByKernelProcedure(target)); | 1699 const Function& target = Function::ZoneHandle( |
| 1700 Z, H.LookupStaticMethodByKernelProcedure(procedure)); |
1738 | 1701 |
1739 if (target->IsMethod()) { | 1702 if (procedure->kind() == Procedure::kMethod) { |
| 1703 ASSERT(procedure->IsStatic()); |
1740 Function& closure_function = | 1704 Function& closure_function = |
1741 Function::ZoneHandle(Z, function.ImplicitClosureFunction()); | 1705 Function::ZoneHandle(Z, target.ImplicitClosureFunction()); |
1742 closure_function.set_kernel_function(function.kernel_function()); | 1706 closure_function.set_kernel_function(target.kernel_function()); |
1743 result_ = closure_function.ImplicitStaticClosure(); | 1707 result_ = closure_function.ImplicitStaticClosure(); |
1744 result_ = H.Canonicalize(result_); | 1708 result_ = H.Canonicalize(result_); |
1745 } else if (target->IsGetter()) { | 1709 } else if (procedure->kind() == Procedure::kGetter) { |
1746 UNIMPLEMENTED(); | 1710 UNIMPLEMENTED(); |
1747 } else { | 1711 } else { |
1748 UNIMPLEMENTED(); | 1712 UNIMPLEMENTED(); |
1749 } | 1713 } |
1750 } | 1714 } |
1751 } | 1715 } |
1752 | 1716 |
1753 | 1717 |
1754 void ConstantEvaluator::VisitVariableGet(VariableGet* node) { | 1718 void ConstantEvaluator::VisitVariableGet(VariableGet* node) { |
1755 // When we see a [VariableGet] the corresponding [VariableDeclaration] must've | 1719 // When we see a [VariableGet] the corresponding [VariableDeclaration] must've |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 } | 1807 } |
1844 } | 1808 } |
1845 | 1809 |
1846 | 1810 |
1847 void ConstantEvaluator::VisitNot(Not* node) { | 1811 void ConstantEvaluator::VisitNot(Not* node) { |
1848 result_ ^= Bool::Get(!EvaluateBooleanExpression(node->expression())).raw(); | 1812 result_ ^= Bool::Get(!EvaluateBooleanExpression(node->expression())).raw(); |
1849 } | 1813 } |
1850 | 1814 |
1851 | 1815 |
1852 void ConstantEvaluator::VisitPropertyGet(PropertyGet* node) { | 1816 void ConstantEvaluator::VisitPropertyGet(PropertyGet* node) { |
1853 const intptr_t kLengthLen = sizeof("length") - 1; | 1817 const intptr_t kLengthLen = strlen("length"); |
1854 | 1818 |
1855 String* string = node->name()->string(); | 1819 String* string = node->name()->string(); |
1856 if ((string->size() == kLengthLen) && | 1820 if ((string->size() == kLengthLen) && |
1857 (memcmp(string->buffer(), "length", kLengthLen) == 0)) { | 1821 (memcmp(string->buffer(), "length", kLengthLen) == 0)) { |
1858 node->receiver()->AcceptExpressionVisitor(this); | 1822 node->receiver()->AcceptExpressionVisitor(this); |
1859 if (result_.IsString()) { | 1823 if (result_.IsString()) { |
1860 const dart::String& str = | 1824 const dart::String& str = |
1861 dart::String::Handle(Z, dart::String::RawCast(result_.raw())); | 1825 dart::String::Handle(Z, dart::String::RawCast(result_.raw())); |
1862 result_ = Integer::New(str.Length()); | 1826 result_ = Integer::New(str.Length()); |
1863 } else { | 1827 } else { |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2868 | 2832 |
2869 instructions += StaticCall(TokenPosition::kNoSource, throw_function, 6); | 2833 instructions += StaticCall(TokenPosition::kNoSource, throw_function, 6); |
2870 // Leave "result" on the stack since callers expect it to be there (even | 2834 // Leave "result" on the stack since callers expect it to be there (even |
2871 // though the function will result in an exception). | 2835 // though the function will result in an exception). |
2872 | 2836 |
2873 return instructions; | 2837 return instructions; |
2874 } | 2838 } |
2875 | 2839 |
2876 | 2840 |
2877 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember( | 2841 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember( |
2878 CanonicalName* target, | 2842 Member* target, |
2879 const dart::String& method_name) { | 2843 const dart::String& method_name) { |
2880 CanonicalName* kernel_class = target->EnclosingName(); | 2844 Class* kernel_klass = Class::Cast(target->parent()); |
2881 dart::Class& klass = | 2845 dart::Class& klass = dart::Class::Handle( |
2882 dart::Class::Handle(Z, H.LookupClassByKernelClass(kernel_class)); | 2846 Z, H.LookupClassByKernelClass(kernel_klass->canonical_name())); |
2883 | 2847 |
2884 dart::RawFunction* function = klass.LookupFunctionAllowPrivate(method_name); | 2848 dart::RawFunction* function = klass.LookupFunctionAllowPrivate(method_name); |
2885 ASSERT(function != Object::null()); | 2849 ASSERT(function != Object::null()); |
2886 return function; | 2850 return function; |
2887 } | 2851 } |
2888 | 2852 |
2889 | 2853 |
2890 LocalVariable* FlowGraphBuilder::MakeTemporary() { | 2854 LocalVariable* FlowGraphBuilder::MakeTemporary() { |
2891 char name[64]; | 2855 char name[64]; |
2892 intptr_t index = stack_->definition()->temp_index(); | 2856 intptr_t index = stack_->definition()->temp_index(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3031 FlowGraph* FlowGraphBuilder::BuildGraph() { | 2995 FlowGraph* FlowGraphBuilder::BuildGraph() { |
3032 const dart::Function& function = parsed_function_->function(); | 2996 const dart::Function& function = parsed_function_->function(); |
3033 | 2997 |
3034 if (function.IsConstructorClosureFunction()) return NULL; | 2998 if (function.IsConstructorClosureFunction()) return NULL; |
3035 | 2999 |
3036 dart::Class& klass = | 3000 dart::Class& klass = |
3037 dart::Class::Handle(zone_, parsed_function_->function().Owner()); | 3001 dart::Class::Handle(zone_, parsed_function_->function().Owner()); |
3038 | 3002 |
3039 Function& outermost_function = Function::Handle(Z); | 3003 Function& outermost_function = Function::Handle(Z); |
3040 TreeNode* outermost_node = NULL; | 3004 TreeNode* outermost_node = NULL; |
3041 Class* kernel_class = NULL; | 3005 Class* kernel_klass = NULL; |
3042 DiscoverEnclosingElements(Z, function, &outermost_function, &outermost_node, | 3006 DiscoverEnclosingElements(Z, function, &outermost_function, &outermost_node, |
3043 &kernel_class); | 3007 &kernel_klass); |
3044 | 3008 |
3045 // Mark that we are using [klass]/[kernell_klass] as active class. Resolving | 3009 // Mark that we are using [klass]/[kernell_klass] as active class. Resolving |
3046 // of type parameters will get resolved via [kernell_klass] unless we are | 3010 // of type parameters will get resolved via [kernell_klass] unless we are |
3047 // nested inside a static factory in which case we will use [member]. | 3011 // nested inside a static factory in which case we will use [member]. |
3048 ActiveClassScope active_class_scope(&active_class_, kernel_class, &klass); | 3012 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); |
3049 Member* member = ((outermost_node != NULL) && outermost_node->IsMember()) | 3013 Member* member = ((outermost_node != NULL) && outermost_node->IsMember()) |
3050 ? Member::Cast(outermost_node) | 3014 ? Member::Cast(outermost_node) |
3051 : NULL; | 3015 : NULL; |
3052 ActiveMemberScope active_member(&active_class_, member); | 3016 ActiveMemberScope active_member(&active_class_, member); |
3053 | 3017 |
3054 // The IR builder will create its own local variables and scopes, and it | 3018 // The IR builder will create its own local variables and scopes, and it |
3055 // will not need an AST. The code generator will assume that there is a | 3019 // will not need an AST. The code generator will assume that there is a |
3056 // local variable stack slot allocated for the current context and (I | 3020 // local variable stack slot allocated for the current context and (I |
3057 // think) that the runtime will expect it to be at a fixed offset which | 3021 // think) that the runtime will expect it to be at a fixed offset which |
3058 // requires allocating an unused expression temporary variable. | 3022 // requires allocating an unused expression temporary variable. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3155 body += StoreLocal(TokenPosition::kNoSource, parameter); | 3119 body += StoreLocal(TokenPosition::kNoSource, parameter); |
3156 body += Drop(); | 3120 body += Drop(); |
3157 } | 3121 } |
3158 } | 3122 } |
3159 body += Drop(); // The context. | 3123 body += Drop(); // The context. |
3160 } | 3124 } |
3161 if (constructor != NULL) { | 3125 if (constructor != NULL) { |
3162 // TODO(27590): Currently the [VariableDeclaration]s from the | 3126 // TODO(27590): Currently the [VariableDeclaration]s from the |
3163 // initializers will be visible inside the entire body of the constructor. | 3127 // initializers will be visible inside the entire body of the constructor. |
3164 // We should make a separate scope for them. | 3128 // We should make a separate scope for them. |
3165 Class* kernel_class = Class::Cast(constructor->parent()); | 3129 Class* kernel_klass = Class::Cast(constructor->parent()); |
3166 body += TranslateInitializers(kernel_class, &constructor->initializers()); | 3130 body += TranslateInitializers(kernel_klass, &constructor->initializers()); |
3167 } | 3131 } |
3168 | 3132 |
3169 // The specification defines the result of `a == b` to be: | 3133 // The specification defines the result of `a == b` to be: |
3170 // | 3134 // |
3171 // a) if either side is `null` then the result is `identical(a, b)`. | 3135 // a) if either side is `null` then the result is `identical(a, b)`. |
3172 // b) else the result is `a.operator==(b)` | 3136 // b) else the result is `a.operator==(b)` |
3173 // | 3137 // |
3174 // For user-defined implementations of `operator==` we need therefore | 3138 // For user-defined implementations of `operator==` we need therefore |
3175 // implement the handling of a). | 3139 // implement the handling of a). |
3176 // | 3140 // |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3556 } | 3520 } |
3557 | 3521 |
3558 | 3522 |
3559 FlowGraph* FlowGraphBuilder::BuildGraphOfFieldAccessor( | 3523 FlowGraph* FlowGraphBuilder::BuildGraphOfFieldAccessor( |
3560 Field* kernel_field, | 3524 Field* kernel_field, |
3561 LocalVariable* setter_value) { | 3525 LocalVariable* setter_value) { |
3562 const dart::Function& function = parsed_function_->function(); | 3526 const dart::Function& function = parsed_function_->function(); |
3563 | 3527 |
3564 bool is_setter = function.IsImplicitSetterFunction(); | 3528 bool is_setter = function.IsImplicitSetterFunction(); |
3565 bool is_method = !function.IsStaticFunction(); | 3529 bool is_method = !function.IsStaticFunction(); |
3566 dart::Field& field = dart::Field::ZoneHandle( | 3530 dart::Field& field = |
3567 Z, H.LookupFieldByKernelField(kernel_field->canonical_name())); | 3531 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(kernel_field)); |
3568 | 3532 |
3569 TargetEntryInstr* normal_entry = BuildTargetEntry(); | 3533 TargetEntryInstr* normal_entry = BuildTargetEntry(); |
3570 graph_entry_ = new (Z) | 3534 graph_entry_ = new (Z) |
3571 GraphEntryInstr(*parsed_function_, normal_entry, Compiler::kNoOSRDeoptId); | 3535 GraphEntryInstr(*parsed_function_, normal_entry, Compiler::kNoOSRDeoptId); |
3572 | 3536 |
3573 Fragment body(normal_entry); | 3537 Fragment body(normal_entry); |
3574 if (is_setter) { | 3538 if (is_setter) { |
3575 if (is_method) { | 3539 if (is_method) { |
3576 body += LoadLocal(scopes_->this_variable); | 3540 body += LoadLocal(scopes_->this_variable); |
3577 body += LoadLocal(setter_value); | 3541 body += LoadLocal(setter_value); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4103 return new (Z) JoinEntryInstr(AllocateBlockId(), try_index); | 4067 return new (Z) JoinEntryInstr(AllocateBlockId(), try_index); |
4104 } | 4068 } |
4105 | 4069 |
4106 | 4070 |
4107 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry() { | 4071 JoinEntryInstr* FlowGraphBuilder::BuildJoinEntry() { |
4108 return new (Z) JoinEntryInstr(AllocateBlockId(), CurrentTryIndex()); | 4072 return new (Z) JoinEntryInstr(AllocateBlockId(), CurrentTryIndex()); |
4109 } | 4073 } |
4110 | 4074 |
4111 | 4075 |
4112 Fragment FlowGraphBuilder::TranslateInitializers( | 4076 Fragment FlowGraphBuilder::TranslateInitializers( |
4113 Class* kernel_class, | 4077 Class* kernel_klass, |
4114 List<Initializer>* initializers) { | 4078 List<Initializer>* initializers) { |
4115 Fragment instructions; | 4079 Fragment instructions; |
4116 | 4080 |
4117 // These come from: | 4081 // These come from: |
4118 // class A { | 4082 // class A { |
4119 // var x = (expr); | 4083 // var x = (expr); |
4120 // } | 4084 // } |
4121 for (intptr_t i = 0; i < kernel_class->fields().length(); i++) { | 4085 for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) { |
4122 Field* kernel_field = kernel_class->fields()[i]; | 4086 Field* kernel_field = kernel_klass->fields()[i]; |
4123 Expression* init = kernel_field->initializer(); | 4087 Expression* init = kernel_field->initializer(); |
4124 if (!kernel_field->IsStatic() && init != NULL) { | 4088 if (!kernel_field->IsStatic() && init != NULL) { |
4125 dart::Field& field = dart::Field::ZoneHandle( | 4089 dart::Field& field = |
4126 Z, H.LookupFieldByKernelField(kernel_field->canonical_name())); | 4090 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(kernel_field)); |
4127 | 4091 |
4128 EnterScope(kernel_field); | 4092 EnterScope(kernel_field); |
4129 instructions += LoadLocal(scopes_->this_variable); | 4093 instructions += LoadLocal(scopes_->this_variable); |
4130 instructions += TranslateExpression(init); | 4094 instructions += TranslateExpression(init); |
4131 instructions += StoreInstanceFieldGuarded(field, true); | 4095 instructions += StoreInstanceFieldGuarded(field, true); |
4132 ExitScope(kernel_field); | 4096 ExitScope(kernel_field); |
4133 } | 4097 } |
4134 } | 4098 } |
4135 | 4099 |
4136 // These to come from: | 4100 // These to come from: |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4511 | 4475 |
4512 | 4476 |
4513 void DartTypeTranslator::VisitInterfaceType(InterfaceType* node) { | 4477 void DartTypeTranslator::VisitInterfaceType(InterfaceType* node) { |
4514 // NOTE: That an interface type like `T<A, B>` is considered to be | 4478 // NOTE: That an interface type like `T<A, B>` is considered to be |
4515 // malformed iff `T` is malformed. | 4479 // malformed iff `T` is malformed. |
4516 // => We therefore ignore errors in `A` or `B`. | 4480 // => We therefore ignore errors in `A` or `B`. |
4517 const TypeArguments& type_arguments = TranslateTypeArguments( | 4481 const TypeArguments& type_arguments = TranslateTypeArguments( |
4518 node->type_arguments().raw_array(), node->type_arguments().length()); | 4482 node->type_arguments().raw_array(), node->type_arguments().length()); |
4519 | 4483 |
4520 | 4484 |
4521 dart::Object& klass = | 4485 dart::Object& klass = dart::Object::Handle( |
4522 dart::Object::Handle(Z, H.LookupClassByKernelClass(node->klass())); | 4486 Z, H.LookupClassByKernelClass(node->class_reference())); |
4523 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); | 4487 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); |
4524 if (finalize_) { | 4488 if (finalize_) { |
4525 ASSERT(active_class_->klass != NULL); | 4489 ASSERT(active_class_->klass != NULL); |
4526 result_ = ClassFinalizer::FinalizeType(*active_class_->klass, result_); | 4490 result_ = ClassFinalizer::FinalizeType(*active_class_->klass, result_); |
4527 } | 4491 } |
4528 } | 4492 } |
4529 | 4493 |
4530 | 4494 |
4531 void DartTypeTranslator::VisitDynamicType(DynamicType* node) { | 4495 void DartTypeTranslator::VisitDynamicType(DynamicType* node) { |
4532 result_ = Object::dynamic_type().raw(); | 4496 result_ = Object::dynamic_type().raw(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4635 instructions = DebugStepCheck(node->position()) + instructions; | 4599 instructions = DebugStepCheck(node->position()) + instructions; |
4636 } | 4600 } |
4637 instructions += CheckVariableTypeInCheckedMode(node->variable()); | 4601 instructions += CheckVariableTypeInCheckedMode(node->variable()); |
4638 instructions += | 4602 instructions += |
4639 StoreLocal(node->position(), LookupVariable(node->variable())); | 4603 StoreLocal(node->position(), LookupVariable(node->variable())); |
4640 fragment_ = instructions; | 4604 fragment_ = instructions; |
4641 } | 4605 } |
4642 | 4606 |
4643 | 4607 |
4644 void FlowGraphBuilder::VisitStaticGet(StaticGet* node) { | 4608 void FlowGraphBuilder::VisitStaticGet(StaticGet* node) { |
4645 CanonicalName* target = node->target(); | 4609 Member* target = node->target(); |
4646 if (target->IsField()) { | 4610 if (target->IsField()) { |
| 4611 Field* kernel_field = Field::Cast(target); |
4647 const dart::Field& field = | 4612 const dart::Field& field = |
4648 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(target)); | 4613 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(kernel_field)); |
4649 if (field.is_const()) { | 4614 if (field.is_const()) { |
4650 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node)); | 4615 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node)); |
4651 } else { | 4616 } else { |
4652 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); | 4617 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); |
4653 const dart::String& getter_name = H.DartGetterName(target); | 4618 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); |
4654 const Function& getter = | 4619 const Function& getter = |
4655 Function::ZoneHandle(Z, owner.LookupStaticFunction(getter_name)); | 4620 Function::ZoneHandle(Z, owner.LookupStaticFunction(getter_name)); |
4656 if (getter.IsNull() || !field.has_initializer()) { | 4621 if (getter.IsNull() || !field.has_initializer()) { |
4657 Fragment instructions = Constant(field); | 4622 Fragment instructions = Constant(field); |
4658 fragment_ = instructions + LoadStaticField(); | 4623 fragment_ = instructions + LoadStaticField(); |
4659 } else { | 4624 } else { |
4660 fragment_ = StaticCall(node->position(), getter, 0); | 4625 fragment_ = StaticCall(node->position(), getter, 0); |
4661 } | 4626 } |
4662 } | 4627 } |
4663 } else { | 4628 } else { |
4664 const Function& function = | 4629 Procedure* procedure = Procedure::Cast(target); |
4665 Function::ZoneHandle(Z, H.LookupStaticMethodByKernelProcedure(target)); | 4630 const Function& target = Function::ZoneHandle( |
| 4631 Z, H.LookupStaticMethodByKernelProcedure(procedure)); |
4666 | 4632 |
4667 if (target->IsGetter()) { | 4633 if (procedure->kind() == Procedure::kGetter) { |
4668 fragment_ = StaticCall(node->position(), function, 0); | 4634 fragment_ = StaticCall(node->position(), target, 0); |
4669 } else if (target->IsMethod()) { | 4635 } else if (procedure->kind() == Procedure::kMethod) { |
| 4636 ASSERT(procedure->IsStatic()); |
4670 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node)); | 4637 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node)); |
4671 } else { | 4638 } else { |
4672 UNIMPLEMENTED(); | 4639 UNIMPLEMENTED(); |
4673 } | 4640 } |
4674 } | 4641 } |
4675 } | 4642 } |
4676 | 4643 |
4677 | 4644 |
4678 void FlowGraphBuilder::VisitStaticSet(StaticSet* node) { | 4645 void FlowGraphBuilder::VisitStaticSet(StaticSet* node) { |
4679 CanonicalName* target = node->target(); | 4646 Member* target = node->target(); |
4680 if (target->IsField()) { | 4647 if (target->IsField()) { |
| 4648 Field* kernel_field = Field::Cast(target); |
4681 const dart::Field& field = | 4649 const dart::Field& field = |
4682 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(target)); | 4650 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(kernel_field)); |
4683 const AbstractType& dst_type = AbstractType::ZoneHandle(Z, field.type()); | 4651 const AbstractType& dst_type = AbstractType::ZoneHandle(Z, field.type()); |
4684 Fragment instructions = TranslateExpression(node->expression()); | 4652 Fragment instructions = TranslateExpression(node->expression()); |
4685 if (NeedsDebugStepCheck(stack_, node->position())) { | 4653 if (NeedsDebugStepCheck(stack_, node->position())) { |
4686 instructions = DebugStepCheck(node->position()) + instructions; | 4654 instructions = DebugStepCheck(node->position()) + instructions; |
4687 } | 4655 } |
4688 instructions += CheckAssignableInCheckedMode( | 4656 instructions += CheckAssignableInCheckedMode( |
4689 dst_type, dart::String::ZoneHandle(Z, field.name())); | 4657 dst_type, dart::String::ZoneHandle(Z, field.name())); |
4690 LocalVariable* variable = MakeTemporary(); | 4658 LocalVariable* variable = MakeTemporary(); |
4691 instructions += LoadLocal(variable); | 4659 instructions += LoadLocal(variable); |
4692 fragment_ = instructions + StoreStaticField(node->position(), field); | 4660 fragment_ = instructions + StoreStaticField(node->position(), field); |
4693 } else { | 4661 } else { |
4694 ASSERT(target->IsProcedure()); | 4662 ASSERT(target->IsProcedure()); |
4695 | 4663 |
4696 // Evaluate the expression on the right hand side. | 4664 // Evaluate the expression on the right hand side. |
4697 Fragment instructions = TranslateExpression(node->expression()); | 4665 Fragment instructions = TranslateExpression(node->expression()); |
4698 LocalVariable* variable = MakeTemporary(); | 4666 LocalVariable* variable = MakeTemporary(); |
4699 | 4667 |
4700 // Prepare argument. | 4668 // Prepare argument. |
4701 instructions += LoadLocal(variable); | 4669 instructions += LoadLocal(variable); |
4702 instructions += PushArgument(); | 4670 instructions += PushArgument(); |
4703 | 4671 |
4704 // Invoke the setter function. | 4672 // Invoke the setter function. |
4705 const Function& function = | 4673 Procedure* procedure = Procedure::Cast(target); |
4706 Function::ZoneHandle(Z, H.LookupStaticMethodByKernelProcedure(target)); | 4674 const Function& target = Function::ZoneHandle( |
4707 instructions += StaticCall(node->position(), function, 1); | 4675 Z, H.LookupStaticMethodByKernelProcedure(procedure)); |
| 4676 instructions += StaticCall(node->position(), target, 1); |
4708 | 4677 |
4709 // Drop the unused result & leave the stored value on the stack. | 4678 // Drop the unused result & leave the stored value on the stack. |
4710 fragment_ = instructions + Drop(); | 4679 fragment_ = instructions + Drop(); |
4711 } | 4680 } |
4712 } | 4681 } |
4713 | 4682 |
4714 | 4683 |
4715 void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) { | 4684 void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) { |
4716 Fragment instructions = TranslateExpression(node->receiver()); | 4685 Fragment instructions = TranslateExpression(node->receiver()); |
4717 instructions += PushArgument(); | 4686 instructions += PushArgument(); |
(...skipping 13 matching lines...) Expand all Loading... |
4731 instructions += PushArgument(); | 4700 instructions += PushArgument(); |
4732 | 4701 |
4733 const dart::String& setter_name = H.DartSetterName(node->name()); | 4702 const dart::String& setter_name = H.DartSetterName(node->name()); |
4734 instructions += InstanceCall(node->position(), setter_name, Token::kSET, 2); | 4703 instructions += InstanceCall(node->position(), setter_name, Token::kSET, 2); |
4735 fragment_ = instructions + Drop(); | 4704 fragment_ = instructions + Drop(); |
4736 } | 4705 } |
4737 | 4706 |
4738 | 4707 |
4739 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { | 4708 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { |
4740 Function& target = Function::ZoneHandle(Z); | 4709 Function& target = Function::ZoneHandle(Z); |
4741 CanonicalName* kernel_name = node->target(); | 4710 if (node->target()->IsProcedure()) { |
4742 if (kernel_name->IsProcedure()) { | 4711 Procedure* kernel_procedure = Procedure::Cast(node->target()); |
4743 if (kernel_name->IsGetter()) { | 4712 Name* kernel_name = kernel_procedure->name(); |
4744 target = LookupMethodByMember(kernel_name, H.DartGetterName(kernel_name)); | 4713 if (kernel_procedure->kind() == Procedure::kGetter) { |
| 4714 target = |
| 4715 LookupMethodByMember(kernel_procedure, H.DartGetterName(kernel_name)); |
4745 } else { | 4716 } else { |
4746 target = LookupMethodByMember(kernel_name, H.DartMethodName(kernel_name)); | 4717 target = |
| 4718 LookupMethodByMember(kernel_procedure, H.DartMethodName(kernel_name)); |
4747 target = target.ImplicitClosureFunction(); | 4719 target = target.ImplicitClosureFunction(); |
4748 ASSERT(!target.IsNull()); | 4720 ASSERT(!target.IsNull()); |
4749 fragment_ = BuildImplicitClosureCreation(target); | 4721 fragment_ = BuildImplicitClosureCreation(target); |
4750 return; | 4722 return; |
4751 } | 4723 } |
4752 } else { | 4724 } else { |
4753 ASSERT(kernel_name->IsField()); | 4725 ASSERT(node->target()->IsField()); |
4754 const dart::String& getter_name = H.DartGetterName(kernel_name); | 4726 const dart::String& getter_name = H.DartGetterName(node->target()->name()); |
4755 target = LookupMethodByMember(kernel_name, getter_name); | 4727 target = LookupMethodByMember(node->target(), getter_name); |
4756 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction()); | 4728 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction()); |
4757 } | 4729 } |
4758 | 4730 |
4759 Fragment instructions = TranslateExpression(node->receiver()); | 4731 Fragment instructions = TranslateExpression(node->receiver()); |
4760 instructions += PushArgument(); | 4732 instructions += PushArgument(); |
4761 fragment_ = instructions + StaticCall(node->position(), target, 1); | 4733 fragment_ = instructions + StaticCall(node->position(), target, 1); |
4762 } | 4734 } |
4763 | 4735 |
4764 | 4736 |
4765 void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) { | 4737 void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) { |
4766 const dart::String& method_name = H.DartSetterName(node->target()); | 4738 const dart::String& method_name = H.DartSetterName(node->target()->name()); |
4767 const Function& target = Function::ZoneHandle( | 4739 const Function& target = Function::ZoneHandle( |
4768 Z, LookupMethodByMember(node->target(), method_name)); | 4740 Z, LookupMethodByMember(node->target(), method_name)); |
4769 ASSERT(target.IsSetterFunction() || target.IsImplicitSetterFunction()); | 4741 ASSERT(target.IsSetterFunction() || target.IsImplicitSetterFunction()); |
4770 | 4742 |
4771 Fragment instructions(NullConstant()); | 4743 Fragment instructions(NullConstant()); |
4772 LocalVariable* value = MakeTemporary(); | 4744 LocalVariable* value = MakeTemporary(); |
4773 instructions += TranslateExpression(node->receiver()); | 4745 instructions += TranslateExpression(node->receiver()); |
4774 instructions += PushArgument(); | 4746 instructions += PushArgument(); |
4775 instructions += TranslateExpression(node->value()); | 4747 instructions += TranslateExpression(node->value()); |
4776 instructions += StoreLocal(TokenPosition::kNoSource, value); | 4748 instructions += StoreLocal(TokenPosition::kNoSource, value); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4948 } | 4920 } |
4949 | 4921 |
4950 | 4922 |
4951 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { | 4923 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { |
4952 if (node->is_const()) { | 4924 if (node->is_const()) { |
4953 fragment_ = | 4925 fragment_ = |
4954 Constant(constant_evaluator_.EvaluateConstructorInvocation(node)); | 4926 Constant(constant_evaluator_.EvaluateConstructorInvocation(node)); |
4955 return; | 4927 return; |
4956 } | 4928 } |
4957 | 4929 |
| 4930 Class* kernel_class = Class::Cast(node->target()->parent()); |
| 4931 |
4958 dart::Class& klass = dart::Class::ZoneHandle( | 4932 dart::Class& klass = dart::Class::ZoneHandle( |
4959 Z, H.LookupClassByKernelClass(node->target()->EnclosingName())); | 4933 Z, H.LookupClassByKernelClass(kernel_class->canonical_name())); |
4960 | 4934 |
4961 Fragment instructions; | 4935 Fragment instructions; |
4962 | 4936 |
4963 // Check for malbounded-ness of type. | 4937 // Check for malbounded-ness of type. |
4964 if (I->type_checks()) { | 4938 if (I->type_checks()) { |
4965 List<DartType>& kernel_type_arguments = node->arguments()->types(); | 4939 List<DartType>& kernel_type_arguments = node->arguments()->types(); |
4966 const TypeArguments& type_arguments = T.TranslateInstantiatedTypeArguments( | 4940 const TypeArguments& type_arguments = T.TranslateInstantiatedTypeArguments( |
4967 klass, kernel_type_arguments.raw_array(), | 4941 klass, kernel_type_arguments.raw_array(), |
4968 kernel_type_arguments.length()); | 4942 kernel_type_arguments.length()); |
4969 | 4943 |
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6489 thread->clear_sticky_error(); | 6463 thread->clear_sticky_error(); |
6490 return error.raw(); | 6464 return error.raw(); |
6491 } | 6465 } |
6492 } | 6466 } |
6493 | 6467 |
6494 | 6468 |
6495 } // namespace kernel | 6469 } // namespace kernel |
6496 } // namespace dart | 6470 } // namespace dart |
6497 | 6471 |
6498 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6472 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |