OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "lib/invocation_mirror.h" | 5 #include "lib/invocation_mirror.h" |
6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 Instance::null_instance()); | 1294 Instance::null_instance()); |
1295 } | 1295 } |
1296 | 1296 |
1297 | 1297 |
1298 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { | 1298 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { |
1299 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 1299 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
1300 return param.bound(); | 1300 return param.bound(); |
1301 } | 1301 } |
1302 | 1302 |
1303 | 1303 |
| 1304 static RawInstance* MakeAccessorClosure(const Class& cls, |
| 1305 const String& selector, |
| 1306 RawFunction::Kind kind) { |
| 1307 const Error& error = Error::Handle(cls.EnsureIsFinalized(Isolate::Current())); |
| 1308 ASSERT(error.IsNull()); |
| 1309 |
| 1310 const String& func_name = String::Handle(Symbols::New(selector)); |
| 1311 const Function& function = |
| 1312 Function::Handle(Function::New(func_name, |
| 1313 kind, |
| 1314 true, // Static. |
| 1315 false, // Not const. |
| 1316 false, // Not abstract. |
| 1317 false, // Not external. |
| 1318 false, // Not native. |
| 1319 cls, |
| 1320 Scanner::kNoSourcePos)); |
| 1321 const Type& dynamic_type = Type::Handle(Type::DynamicType()); |
| 1322 function.set_result_type(dynamic_type); |
| 1323 |
| 1324 // 1 - the closure reciever, 2 - the object whose field is to be gotten. |
| 1325 intptr_t num_params = (kind == RawFunction::kGetFieldClosure) ? 2 : 3; |
| 1326 |
| 1327 function.set_num_fixed_parameters(num_params); |
| 1328 function.set_parameter_types( |
| 1329 Array::Handle(Array::New(num_params, Heap::kOld))); |
| 1330 function.set_parameter_names( |
| 1331 Array::Handle(Array::New(num_params, Heap::kOld))); |
| 1332 for (intptr_t i = 0; i < num_params; i++) { |
| 1333 function.SetParameterTypeAt(i, dynamic_type); |
| 1334 function.SetParameterNameAt(i, Symbols::Other()); |
| 1335 } |
| 1336 function.SetNumOptionalParameters(0, true); |
| 1337 |
| 1338 // Lookup or create a new signature class for the closure function in the |
| 1339 // library of the owner class. |
| 1340 const Library& library = Library::Handle(cls.library()); |
| 1341 const String& signature = String::Handle(function.Signature()); |
| 1342 Class& signature_class = Class::ZoneHandle( |
| 1343 library.LookupLocalClass(signature)); |
| 1344 if (signature_class.IsNull()) { |
| 1345 const Script& script = Script::Handle(cls.script()); |
| 1346 signature_class = Class::NewSignatureClass(signature, |
| 1347 function, |
| 1348 script, |
| 1349 function.token_pos()); |
| 1350 library.AddClass(signature_class); |
| 1351 } else { |
| 1352 function.set_signature_class(signature_class); |
| 1353 } |
| 1354 const Type& signature_type = Type::Handle(signature_class.SignatureType()); |
| 1355 if (!signature_type.IsFinalized()) { |
| 1356 ClassFinalizer::FinalizeType( |
| 1357 signature_class, signature_type, ClassFinalizer::kCanonicalize); |
| 1358 } |
| 1359 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 1360 const Context& context = Context::Handle(object_store->empty_context()); |
| 1361 return Closure::New(function, context, Heap::kOld); |
| 1362 } |
| 1363 |
| 1364 |
| 1365 DEFINE_NATIVE_ENTRY(Mirrors_makeGetter, 2) { |
| 1366 GET_NON_NULL_NATIVE_ARGUMENT(String, selector, arguments->NativeArgAt(0)); |
| 1367 GET_NON_NULL_NATIVE_ARGUMENT(Type, scratch_type, arguments->NativeArgAt(1)); |
| 1368 const Class& cls = Class::Handle(scratch_type.type_class()); |
| 1369 return MakeAccessorClosure(cls, selector, RawFunction::kGetFieldClosure); |
| 1370 } |
| 1371 |
| 1372 |
| 1373 DEFINE_NATIVE_ENTRY(Mirrors_makeSetter, 2) { |
| 1374 GET_NON_NULL_NATIVE_ARGUMENT(String, selector, arguments->NativeArgAt(0)); |
| 1375 GET_NON_NULL_NATIVE_ARGUMENT(Type, scratch_type, arguments->NativeArgAt(1)); |
| 1376 const Class& cls = Class::Handle(scratch_type.type_class()); |
| 1377 return MakeAccessorClosure(cls, selector, RawFunction::kSetFieldClosure); |
| 1378 } |
| 1379 |
| 1380 |
1304 DEFINE_NATIVE_ENTRY(TypedefMirror_declaration, 1) { | 1381 DEFINE_NATIVE_ENTRY(TypedefMirror_declaration, 1) { |
1305 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); | 1382 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); |
1306 const Class& cls = Class::Handle(type.type_class()); | 1383 const Class& cls = Class::Handle(type.type_class()); |
1307 // We represent typedefs as non-canonical signature classes. | 1384 // We represent typedefs as non-canonical signature classes. |
1308 ASSERT(cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass()); | 1385 ASSERT(cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass()); |
1309 return CreateTypedefMirror(cls, | 1386 return CreateTypedefMirror(cls, |
1310 AbstractType::Handle(cls.DeclarationType()), | 1387 AbstractType::Handle(cls.DeclarationType()), |
1311 Bool::True(), // is_declaration | 1388 Bool::True(), // is_declaration |
1312 Object::null_instance()); | 1389 Object::null_instance()); |
1313 } | 1390 } |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 | 2139 |
2063 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) { | 2140 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) { |
2064 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 2141 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
2065 const Field& field = Field::Handle(ref.GetFieldReferent()); | 2142 const Field& field = Field::Handle(ref.GetFieldReferent()); |
2066 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); | 2143 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); |
2067 const AbstractType& type = AbstractType::Handle(field.type()); | 2144 const AbstractType& type = AbstractType::Handle(field.type()); |
2068 return InstantiateType(type, instantiator); | 2145 return InstantiateType(type, instantiator); |
2069 } | 2146 } |
2070 | 2147 |
2071 } // namespace dart | 2148 } // namespace dart |
OLD | NEW |