| 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/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 8 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| 10 #include "vm/port.h" | 11 #include "vm/port.h" |
| 11 #include "vm/symbols.h" | 12 #include "vm/symbols.h" |
| 12 | 13 |
| 13 namespace dart { | 14 namespace dart { |
| 14 | 15 |
| 15 static RawInstance* CreateMirror(const String& mirror_class_name, | 16 static RawInstance* CreateMirror(const String& mirror_class_name, |
| 16 const Array& constructor_arguments) { | 17 const Array& constructor_arguments) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 type ^= args.TypeAt(i); | 92 type ^= args.TypeAt(i); |
| 92 ASSERT(type.IsTypeParameter()); | 93 ASSERT(type.IsTypeParameter()); |
| 93 name ^= type.name(); | 94 name ^= type.name(); |
| 94 result.SetAt(2 * i, name); | 95 result.SetAt(2 * i, name); |
| 95 result.SetAt(2 * i + 1, type); | 96 result.SetAt(2 * i + 1, type); |
| 96 } | 97 } |
| 97 return result.raw(); | 98 return result.raw(); |
| 98 } | 99 } |
| 99 | 100 |
| 100 | 101 |
| 101 static RawInstance* CreateTypedefMirror(const Class& cls, | 102 static RawInstance* CreateTypedefMirror(const AbstractType& type, |
| 102 const Instance& owner_mirror) { | 103 const Instance& owner_mirror) { |
| 104 const Class& cls = Class::Handle(type.type_class()); |
| 103 const Array& args = Array::Handle(Array::New(3)); | 105 const Array& args = Array::Handle(Array::New(3)); |
| 104 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 106 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(type))); |
| 105 args.SetAt(1, String::Handle(cls.UserVisibleName())); | 107 args.SetAt(1, String::Handle(cls.UserVisibleName())); |
| 106 args.SetAt(2, owner_mirror); | 108 args.SetAt(2, owner_mirror); |
| 107 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args); | 109 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args); |
| 108 } | 110 } |
| 109 | 111 |
| 110 | 112 |
| 111 static RawInstance* CreateFunctionTypeMirror(const Class& cls) { | 113 static RawInstance* CreateFunctionTypeMirror(const AbstractType& type) { |
| 112 const Array& args = Array::Handle(Array::New(1)); | 114 const Array& args = Array::Handle(Array::New(1)); |
| 113 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 115 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(type))); |
| 114 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); | 116 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); |
| 115 } | 117 } |
| 116 | 118 |
| 117 | 119 |
| 118 static RawInstance* CreateMethodMirror(const Function& func, | 120 static RawInstance* CreateMethodMirror(const Function& func, |
| 119 const Instance& owner_mirror) { | 121 const Instance& owner_mirror) { |
| 120 const Array& args = Array::Handle(Array::New(12)); | 122 const Array& args = Array::Handle(Array::New(12)); |
| 121 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 123 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 122 args.SetAt(1, String::Handle(func.UserVisibleName())); | 124 args.SetAt(1, String::Handle(func.UserVisibleName())); |
| 123 args.SetAt(2, owner_mirror); | 125 args.SetAt(2, owner_mirror); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 147 args.SetAt(1, name); | 149 args.SetAt(1, name); |
| 148 args.SetAt(2, owner_mirror); | 150 args.SetAt(2, owner_mirror); |
| 149 args.SetAt(3, Instance::Handle()); // Null for type. | 151 args.SetAt(3, Instance::Handle()); // Null for type. |
| 150 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); | 152 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); |
| 151 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); | 153 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); |
| 152 | 154 |
| 153 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 155 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
| 154 } | 156 } |
| 155 | 157 |
| 156 | 158 |
| 157 static RawInstance* CreateClassMirror(const Class& cls, | 159 static RawInstance* CreateClassMirror(const AbstractType& type, |
| 158 const Instance& owner_mirror) { | 160 const Instance& owner_mirror) { |
| 161 const Class& cls = Class::Handle(type.type_class()); |
| 159 if (cls.IsSignatureClass()) { | 162 if (cls.IsSignatureClass()) { |
| 160 if (cls.IsCanonicalSignatureClass()) { | 163 if (cls.IsCanonicalSignatureClass()) { |
| 161 // We represent function types as canonical signature classes. | 164 // We represent function types as canonical signature classes. |
| 162 return CreateFunctionTypeMirror(cls); | 165 return CreateFunctionTypeMirror(type); |
| 163 } else { | 166 } else { |
| 164 // We represent typedefs as non-canonical signature classes. | 167 // We represent typedefs as non-canonical signature classes. |
| 165 return CreateTypedefMirror(cls, owner_mirror); | 168 return CreateTypedefMirror(type, owner_mirror); |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 | 171 |
| 169 const Array& args = Array::Handle(Array::New(2)); | 172 const Array& args = Array::Handle(Array::New(2)); |
| 170 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 173 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(type))); |
| 171 args.SetAt(1, String::Handle(cls.UserVisibleName())); | 174 args.SetAt(1, String::Handle(cls.UserVisibleName())); |
| 172 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 175 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
| 173 } | 176 } |
| 174 | 177 |
| 178 // Note a "raw type" is not the same as a RawType. |
| 179 static RawAbstractType* RawTypeOfClass(const Class& klass) { |
| 180 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 181 Type& type = |
| 182 Type::Handle(Type::New(klass, type_arguments, Scanner::kDummyTokenIndex)); |
| 183 return ClassFinalizer::FinalizeType(klass, |
| 184 type, |
| 185 ClassFinalizer::kCanonicalize); |
| 186 } |
| 187 |
| 188 static RawInstance* CreateGenericClassMirror(const Class& klass, |
| 189 const Instance& owner_mirror) { |
| 190 return CreateClassMirror(AbstractType::Handle(RawTypeOfClass(klass)), |
| 191 owner_mirror); |
| 192 } |
| 193 |
| 175 | 194 |
| 176 static RawInstance* CreateLibraryMirror(const Library& lib) { | 195 static RawInstance* CreateLibraryMirror(const Library& lib) { |
| 177 const Array& args = Array::Handle(Array::New(3)); | 196 const Array& args = Array::Handle(Array::New(3)); |
| 178 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); | 197 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); |
| 179 String& str = String::Handle(); | 198 String& str = String::Handle(); |
| 180 str = lib.name(); | 199 str = lib.name(); |
| 181 args.SetAt(1, str); | 200 args.SetAt(1, str); |
| 182 str = lib.url(); | 201 str = lib.url(); |
| 183 args.SetAt(2, str); | 202 args.SetAt(2, str); |
| 184 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); | 203 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); |
| 185 } | 204 } |
| 186 | 205 |
| 187 | 206 |
| 188 static RawInstance* CreateTypeMirror(const AbstractType& type) { | 207 static RawInstance* CreateTypeMirror(const AbstractType& type) { |
| 189 ASSERT(!type.IsMalformed()); | 208 ASSERT(!type.IsMalformed()); |
| 190 if (type.HasResolvedTypeClass()) { | 209 if (type.HasResolvedTypeClass()) { |
| 191 const Class& cls = Class::Handle(type.type_class()); | 210 const Class& cls = Class::Handle(type.type_class()); |
| 192 // Handle void and dynamic types. | 211 // Handle void and dynamic types. |
| 193 if (cls.IsVoidClass()) { | 212 if (cls.IsVoidClass()) { |
| 194 Array& args = Array::Handle(Array::New(1)); | 213 Array& args = Array::Handle(Array::New(1)); |
| 195 args.SetAt(0, Symbols::Void()); | 214 args.SetAt(0, Symbols::Void()); |
| 196 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. | 215 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. |
| 197 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); | 216 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); |
| 198 } else if (cls.IsDynamicClass()) { | 217 } else if (cls.IsDynamicClass()) { |
| 199 Array& args = Array::Handle(Array::New(1)); | 218 Array& args = Array::Handle(Array::New(1)); |
| 200 args.SetAt(0, Symbols::Dynamic()); | 219 args.SetAt(0, Symbols::Dynamic()); |
| 201 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. | 220 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. |
| 202 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); | 221 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); |
| 203 } | 222 } |
| 204 return CreateClassMirror(cls, Object::null_instance()); | 223 return CreateClassMirror(type, Object::null_instance()); |
| 205 } else if (type.IsTypeParameter()) { | 224 } else if (type.IsTypeParameter()) { |
| 206 return CreateTypeVariableMirror(TypeParameter::Cast(type), | 225 return CreateTypeVariableMirror(TypeParameter::Cast(type), |
| 207 Object::null_instance()); | 226 Object::null_instance()); |
| 208 } | 227 } |
| 209 UNREACHABLE(); | 228 UNREACHABLE(); |
| 210 return Instance::null(); | 229 return Instance::null(); |
| 211 } | 230 } |
| 212 | 231 |
| 213 | 232 |
| 214 static RawInstance* CreateIsolateMirror() { | 233 static RawInstance* CreateIsolateMirror() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 270 } |
| 252 | 271 |
| 253 | 272 |
| 254 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { | 273 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { |
| 255 return CreateMirrorSystem(); | 274 return CreateMirrorSystem(); |
| 256 } | 275 } |
| 257 | 276 |
| 258 | 277 |
| 259 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { | 278 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { |
| 260 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); | 279 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); |
| 261 const Class& cls = Class::Handle(type.type_class()); | 280 return CreateClassMirror(type, Object::null_instance()); |
| 262 return CreateClassMirror(cls, Object::null_instance()); | |
| 263 } | 281 } |
| 264 | 282 |
| 265 | 283 |
| 266 static void ThrowMirroredCompilationError(const String& message) { | 284 static void ThrowMirroredCompilationError(const String& message) { |
| 267 Array& args = Array::Handle(Array::New(1)); | 285 Array& args = Array::Handle(Array::New(1)); |
| 268 args.SetAt(0, message); | 286 args.SetAt(0, message); |
| 269 | 287 |
| 270 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); | 288 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); |
| 271 UNREACHABLE(); | 289 UNREACHABLE(); |
| 272 } | 290 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 288 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { | 306 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { |
| 289 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); | 307 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); |
| 290 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); | 308 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); |
| 291 return Bool::Get(a.referent() == b.referent()); | 309 return Bool::Get(a.referent() == b.referent()); |
| 292 } | 310 } |
| 293 | 311 |
| 294 | 312 |
| 295 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { | 313 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { |
| 296 const MirrorReference& decl_ref = | 314 const MirrorReference& decl_ref = |
| 297 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 315 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 298 const Object& decl = Object::Handle(decl_ref.referent()); | 316 Object& decl = Object::Handle(decl_ref.referent()); |
| 299 | 317 |
| 300 Class& klass = Class::Handle(); | 318 Class& klass = Class::Handle(); |
| 301 Library& library = Library::Handle(); | 319 Library& library = Library::Handle(); |
| 302 | 320 |
| 303 if (decl.IsClass()) { | 321 if (decl.IsAbstractType() || decl.IsType()) { |
| 304 klass ^= decl.raw(); | 322 klass = AbstractType::Cast(decl).type_class(); |
| 305 library = klass.library(); | 323 library = klass.library(); |
| 324 decl = klass.raw(); |
| 306 } else if (decl.IsFunction()) { | 325 } else if (decl.IsFunction()) { |
| 307 klass = Function::Cast(decl).origin(); | 326 klass = Function::Cast(decl).origin(); |
| 308 library = klass.library(); | 327 library = klass.library(); |
| 309 } else if (decl.IsField()) { | 328 } else if (decl.IsField()) { |
| 310 klass = Field::Cast(decl).origin(); | 329 klass = Field::Cast(decl).origin(); |
| 311 library = klass.library(); | 330 library = klass.library(); |
| 312 } else if (decl.IsLibrary()) { | 331 } else if (decl.IsLibrary()) { |
| 313 library ^= decl.raw(); | 332 library ^= decl.raw(); |
| 314 } else { | 333 } else { |
| 315 return Object::empty_array().raw(); | 334 return Object::empty_array().raw(); |
| 316 } | 335 } |
| 317 | 336 |
| 318 const Object& metadata = Object::Handle(library.GetMetadata(decl)); | 337 const Object& metadata = Object::Handle(library.GetMetadata(decl)); |
| 319 if (metadata.IsError()) { | 338 if (metadata.IsError()) { |
| 320 ThrowInvokeError(Error::Cast(metadata)); | 339 ThrowInvokeError(Error::Cast(metadata)); |
| 321 } | 340 } |
| 322 return metadata.raw(); | 341 return metadata.raw(); |
| 323 } | 342 } |
| 324 | 343 |
| 325 | 344 |
| 326 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { | 345 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { |
| 327 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 346 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 328 const Class& cls = Class::Handle(ref.GetClassReferent()); | 347 const AbstractType& type = |
| 329 const Function& func = Function::Handle(cls.signature_function()); | 348 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 349 const Class& klass = Class::Handle(type.type_class()); |
| 350 const Function& func = Function::Handle(klass.signature_function()); |
| 330 return CreateParameterMirrorList(func); | 351 return CreateParameterMirrorList(func); |
| 331 } | 352 } |
| 332 | 353 |
| 333 | 354 |
| 334 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { | 355 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { |
| 335 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 356 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 336 const Class& cls = Class::Handle(ref.GetClassReferent()); | 357 const AbstractType& type = |
| 337 const Function& func = Function::Handle(cls.signature_function()); | 358 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 359 const Class& klass = Class::Handle(type.type_class()); |
| 360 const Function& func = Function::Handle(klass.signature_function()); |
| 338 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 361 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 339 return CreateTypeMirror(return_type); | 362 return CreateTypeMirror(return_type); |
| 340 } | 363 } |
| 341 | 364 |
| 342 | 365 |
| 343 static bool FieldIsUninitialized(const Field& field) { | 366 static bool FieldIsUninitialized(const Field& field) { |
| 344 ASSERT(!field.IsNull()); | 367 ASSERT(!field.IsNull()); |
| 345 | 368 |
| 346 // Return getter method for uninitialized fields, rather than the | 369 // Return getter method for uninitialized fields, rather than the |
| 347 // field object, since the value in the field object will not be | 370 // field object, since the value in the field object will not be |
| 348 // initialized until the first time the getter is invoked. | 371 // initialized until the first time the getter is invoked. |
| 349 const Instance& value = Instance::Handle(field.value()); | 372 const Instance& value = Instance::Handle(field.value()); |
| 350 ASSERT(value.raw() != Object::transition_sentinel().raw()); | 373 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
| 351 return value.raw() == Object::sentinel().raw(); | 374 return value.raw() == Object::sentinel().raw(); |
| 352 } | 375 } |
| 353 | 376 |
| 354 | 377 |
| 355 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { | 378 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { |
| 356 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 379 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 357 const Class& klass = Class::Handle(ref.GetClassReferent()); | 380 const AbstractType& type = |
| 381 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 382 const Class& klass = Class::Handle(type.type_class()); |
| 358 return klass.UserVisibleName(); | 383 return klass.UserVisibleName(); |
| 359 } | 384 } |
| 360 | 385 |
| 361 | 386 |
| 362 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { | 387 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { |
| 363 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 388 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 364 const Class& klass = Class::Handle(ref.GetClassReferent()); | 389 const AbstractType& type = |
| 390 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 391 const Class& klass = Class::Handle(type.type_class()); |
| 365 const Library& library = Library::Handle(klass.library()); | 392 const Library& library = Library::Handle(klass.library()); |
| 366 // TODO(rmacnak): Revisit when we decide what to do about | 393 // TODO(rmacnak): Revisit when we decide what to do about |
| 367 // reflectClass(dynamic). | 394 // reflectClass(dynamic). |
| 368 if (library.IsNull()) { | 395 if (library.IsNull()) { |
| 369 return Instance::null(); | 396 return Instance::null(); |
| 370 } | 397 } |
| 371 return CreateLibraryMirror(library); | 398 return CreateLibraryMirror(library); |
| 372 } | 399 } |
| 373 | 400 |
| 374 | 401 |
| 375 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) { | 402 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) { |
| 376 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 403 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 377 const Class& klass = Class::Handle(ref.GetClassReferent()); | 404 const AbstractType& type = |
| 405 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 406 const Class& klass = Class::Handle(type.type_class()); |
| 378 return klass.super_type(); | 407 return klass.super_type(); |
| 379 } | 408 } |
| 380 | 409 |
| 381 | 410 |
| 382 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { | 411 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { |
| 383 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 412 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 384 const Class& klass = Class::Handle(ref.GetClassReferent()); | 413 const AbstractType& type = |
| 414 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 415 const Class& klass = Class::Handle(type.type_class()); |
| 385 | 416 |
| 386 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 417 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); |
| 387 if (!error.IsNull()) { | 418 if (!error.IsNull()) { |
| 388 ThrowInvokeError(error); | 419 ThrowInvokeError(error); |
| 389 } | 420 } |
| 390 | 421 |
| 391 return klass.interfaces(); | 422 return klass.interfaces(); |
| 392 } | 423 } |
| 393 | 424 |
| 394 | 425 |
| 395 DEFINE_NATIVE_ENTRY(ClassMirror_members, 2) { | 426 DEFINE_NATIVE_ENTRY(ClassMirror_members, 2) { |
| 396 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | 427 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
| 397 owner_mirror, | 428 owner_mirror, |
| 398 arguments->NativeArgAt(0)); | 429 arguments->NativeArgAt(0)); |
| 399 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 430 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 400 const Class& klass = Class::Handle(ref.GetClassReferent()); | 431 const AbstractType& type = |
| 432 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 433 const Class& klass = Class::Handle(type.type_class()); |
| 401 | 434 |
| 402 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 435 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); |
| 403 if (!error.IsNull()) { | 436 if (!error.IsNull()) { |
| 404 ThrowInvokeError(error); | 437 ThrowInvokeError(error); |
| 405 } | 438 } |
| 406 | 439 |
| 407 const Array& fields = Array::Handle(klass.fields()); | 440 const Array& fields = Array::Handle(klass.fields()); |
| 408 // Some special types like 'dynamic' have a null fields list, but they should | 441 // Some special types like 'dynamic' have a null fields list, but they should |
| 409 // not wind up as the reflectees of ClassMirrors. | 442 // not wind up as the reflectees of ClassMirrors. |
| 410 ASSERT(!fields.IsNull()); | 443 ASSERT(!fields.IsNull()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 440 | 473 |
| 441 return member_mirrors.raw(); | 474 return member_mirrors.raw(); |
| 442 } | 475 } |
| 443 | 476 |
| 444 | 477 |
| 445 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) { | 478 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) { |
| 446 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | 479 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
| 447 owner_mirror, | 480 owner_mirror, |
| 448 arguments->NativeArgAt(0)); | 481 arguments->NativeArgAt(0)); |
| 449 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 482 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 450 const Class& klass = Class::Handle(ref.GetClassReferent()); | 483 const AbstractType& type = |
| 484 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 485 const Class& klass = Class::Handle(type.type_class()); |
| 451 | 486 |
| 452 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 487 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); |
| 453 if (!error.IsNull()) { | 488 if (!error.IsNull()) { |
| 454 ThrowInvokeError(error); | 489 ThrowInvokeError(error); |
| 455 } | 490 } |
| 456 | 491 |
| 457 const Array& functions = Array::Handle(klass.functions()); | 492 const Array& functions = Array::Handle(klass.functions()); |
| 458 // Some special types like 'dynamic' have a null functions list, but they | 493 // Some special types like 'dynamic' have a null functions list, but they |
| 459 // should not wind up as the reflectees of ClassMirrors. | 494 // should not wind up as the reflectees of ClassMirrors. |
| 460 ASSERT(!functions.IsNull()); | 495 ASSERT(!functions.IsNull()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 DictionaryIterator entries(library); | 527 DictionaryIterator entries(library); |
| 493 | 528 |
| 494 while (entries.HasNext()) { | 529 while (entries.HasNext()) { |
| 495 entry = entries.GetNext(); | 530 entry = entries.GetNext(); |
| 496 if (entry.IsClass()) { | 531 if (entry.IsClass()) { |
| 497 const Class& klass = Class::Cast(entry); | 532 const Class& klass = Class::Cast(entry); |
| 498 if (!klass.IsCanonicalSignatureClass()) { | 533 if (!klass.IsCanonicalSignatureClass()) { |
| 499 // The various implementations of public classes don't always have the | 534 // The various implementations of public classes don't always have the |
| 500 // expected superinterfaces or other properties, so we filter them out. | 535 // expected superinterfaces or other properties, so we filter them out. |
| 501 if (!RawObject::IsImplementationClassId(klass.id())) { | 536 if (!RawObject::IsImplementationClassId(klass.id())) { |
| 502 member_mirror = CreateClassMirror(klass, owner_mirror); | 537 member_mirror = CreateGenericClassMirror(klass, owner_mirror); |
| 503 member_mirrors.Add(member_mirror); | 538 member_mirrors.Add(member_mirror); |
| 504 } | 539 } |
| 505 } | 540 } |
| 506 } else if (entry.IsField()) { | 541 } else if (entry.IsField()) { |
| 507 const Field& field = Field::Cast(entry); | 542 const Field& field = Field::Cast(entry); |
| 508 member_mirror = CreateVariableMirror(field, owner_mirror); | 543 member_mirror = CreateVariableMirror(field, owner_mirror); |
| 509 member_mirrors.Add(member_mirror); | 544 member_mirrors.Add(member_mirror); |
| 510 } else if (entry.IsFunction()) { | 545 } else if (entry.IsFunction()) { |
| 511 const Function& func = Function::Cast(entry); | 546 const Function& func = Function::Cast(entry); |
| 512 if (func.kind() == RawFunction::kRegularFunction || | 547 if (func.kind() == RawFunction::kRegularFunction || |
| 513 func.kind() == RawFunction::kGetterFunction || | 548 func.kind() == RawFunction::kGetterFunction || |
| 514 func.kind() == RawFunction::kSetterFunction) { | 549 func.kind() == RawFunction::kSetterFunction) { |
| 515 member_mirror = CreateMethodMirror(func, owner_mirror); | 550 member_mirror = CreateMethodMirror(func, owner_mirror); |
| 516 member_mirrors.Add(member_mirror); | 551 member_mirrors.Add(member_mirror); |
| 517 } | 552 } |
| 518 } | 553 } |
| 519 } | 554 } |
| 520 | 555 |
| 521 return member_mirrors.raw(); | 556 return member_mirrors.raw(); |
| 522 } | 557 } |
| 523 | 558 |
| 524 | 559 |
| 525 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) { | 560 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) { |
| 526 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 561 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 527 const Class& klass = Class::Handle(ref.GetClassReferent()); | 562 const AbstractType& type = |
| 563 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 564 const Class& klass = Class::Handle(type.type_class()); |
| 528 return CreateTypeVariableList(klass); | 565 return CreateTypeVariableList(klass); |
| 529 } | 566 } |
| 530 | 567 |
| 531 | 568 |
| 569 DEFINE_NATIVE_ENTRY(ClassMirror_type_arguments, 1) { |
| 570 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 571 AbstractType& type = AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 572 |
| 573 const AbstractTypeArguments& args = |
| 574 AbstractTypeArguments::Handle(type.arguments()); |
| 575 if (args.IsNull()) { |
| 576 return Object::empty_array().raw(); |
| 577 } |
| 578 |
| 579 const Array& result = Array::Handle(Array::New(args.Length())); |
| 580 Instance& type_mirror = Instance::Handle(); |
| 581 for (intptr_t i = 0; i < args.Length(); i++) { |
| 582 type ^= args.TypeAt(i); |
| 583 type_mirror = CreateTypeMirror(type); |
| 584 result.SetAt(i, type_mirror); |
| 585 } |
| 586 return result.raw(); |
| 587 } |
| 588 |
| 589 |
| 532 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_owner, 1) { | 590 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_owner, 1) { |
| 533 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 591 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 534 return CreateClassMirror(Class::Handle(param.parameterized_class()), | 592 return CreateGenericClassMirror(Class::Handle(param.parameterized_class()), |
| 535 Instance::null_instance()); | 593 Instance::null_instance()); |
| 536 } | 594 } |
| 537 | 595 |
| 538 | 596 |
| 539 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_upper_bound, 1) { | 597 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_upper_bound, 1) { |
| 540 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 598 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 541 return CreateTypeMirror(AbstractType::Handle(param.bound())); | 599 return CreateTypeMirror(AbstractType::Handle(param.bound())); |
| 542 } | 600 } |
| 543 | 601 |
| 544 | 602 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); | 814 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); |
| 757 UNREACHABLE(); | 815 UNREACHABLE(); |
| 758 } | 816 } |
| 759 | 817 |
| 760 | 818 |
| 761 static void ThrowNoSuchMethod(const Class& klass, | 819 static void ThrowNoSuchMethod(const Class& klass, |
| 762 const String& function_name, | 820 const String& function_name, |
| 763 const Function& function, | 821 const Function& function, |
| 764 const InvocationMirror::Call call, | 822 const InvocationMirror::Call call, |
| 765 const InvocationMirror::Type type) { | 823 const InvocationMirror::Type type) { |
| 766 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 824 AbstractType& runtime_type = AbstractType::Handle(RawTypeOfClass(klass)); |
| 767 Type& pre_type = Type::Handle( | |
| 768 Type::New(klass, type_arguments, Scanner::kDummyTokenIndex)); | |
| 769 pre_type.SetIsFinalized(); | |
| 770 AbstractType& runtime_type = AbstractType::Handle(pre_type.Canonicalize()); | |
| 771 | 825 |
| 772 ThrowNoSuchMethod(runtime_type, | 826 ThrowNoSuchMethod(runtime_type, |
| 773 function_name, | 827 function_name, |
| 774 function, | 828 function, |
| 775 call, | 829 call, |
| 776 type); | 830 type); |
| 777 UNREACHABLE(); | 831 UNREACHABLE(); |
| 778 } | 832 } |
| 779 | 833 |
| 780 | 834 |
| 781 static void ThrowNoSuchMethod(const Library& library, | 835 static void ThrowNoSuchMethod(const Library& library, |
| 782 const String& function_name, | 836 const String& function_name, |
| 783 const Function& function, | 837 const Function& function, |
| 784 const InvocationMirror::Call call, | 838 const InvocationMirror::Call call, |
| 785 const InvocationMirror::Type type) { | 839 const InvocationMirror::Type type) { |
| 786 ThrowNoSuchMethod(Instance::null_instance(), | 840 ThrowNoSuchMethod(Instance::null_instance(), |
| 787 function_name, | 841 function_name, |
| 788 function, | 842 function, |
| 789 call, | 843 call, |
| 790 type); | 844 type); |
| 791 UNREACHABLE(); | 845 UNREACHABLE(); |
| 792 } | 846 } |
| 793 | 847 |
| 794 | 848 |
| 795 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 4) { | 849 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 4) { |
| 796 // Argument 0 is the mirror, which is unused by the native. It exists | 850 // Argument 0 is the mirror, which is unused by the native. It exists |
| 797 // because this native is an instance method in order to be polymorphic | 851 // because this native is an instance method in order to be polymorphic |
| 798 // with its cousins. | 852 // with its cousins. |
| 799 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 853 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 800 const Class& klass = Class::Handle(ref.GetClassReferent()); | 854 const AbstractType& type = |
| 855 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 856 const Class& klass = Class::Handle(type.type_class()); |
| 801 GET_NON_NULL_NATIVE_ARGUMENT( | 857 GET_NON_NULL_NATIVE_ARGUMENT( |
| 802 String, function_name, arguments->NativeArgAt(2)); | 858 String, function_name, arguments->NativeArgAt(2)); |
| 803 GET_NON_NULL_NATIVE_ARGUMENT( | 859 GET_NON_NULL_NATIVE_ARGUMENT( |
| 804 Array, positional_args, arguments->NativeArgAt(3)); | 860 Array, positional_args, arguments->NativeArgAt(3)); |
| 805 | 861 |
| 806 intptr_t number_of_arguments = positional_args.Length(); | 862 intptr_t number_of_arguments = positional_args.Length(); |
| 807 | 863 |
| 808 const Function& function = Function::Handle( | 864 const Function& function = Function::Handle( |
| 809 klass.LookupStaticFunctionAllowPrivate(function_name)); | 865 klass.LookupStaticFunctionAllowPrivate(function_name)); |
| 810 | 866 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 828 } | 884 } |
| 829 return result.raw(); | 885 return result.raw(); |
| 830 } | 886 } |
| 831 | 887 |
| 832 | 888 |
| 833 DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { | 889 DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { |
| 834 // Argument 0 is the mirror, which is unused by the native. It exists | 890 // Argument 0 is the mirror, which is unused by the native. It exists |
| 835 // because this native is an instance method in order to be polymorphic | 891 // because this native is an instance method in order to be polymorphic |
| 836 // with its cousins. | 892 // with its cousins. |
| 837 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 893 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 838 const Class& klass = Class::Handle(ref.GetClassReferent()); | 894 const AbstractType& type = |
| 895 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 896 const Class& klass = Class::Handle(type.type_class()); |
| 839 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); | 897 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 840 | 898 |
| 841 // Note static fields do not have implicit getters. | 899 // Note static fields do not have implicit getters. |
| 842 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 900 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
| 843 if (field.IsNull() || FieldIsUninitialized(field)) { | 901 if (field.IsNull() || FieldIsUninitialized(field)) { |
| 844 const String& internal_getter_name = String::Handle( | 902 const String& internal_getter_name = String::Handle( |
| 845 Field::GetterName(getter_name)); | 903 Field::GetterName(getter_name)); |
| 846 const Function& getter = Function::Handle( | 904 const Function& getter = Function::Handle( |
| 847 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); | 905 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); |
| 848 | 906 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 866 } | 924 } |
| 867 return field.value(); | 925 return field.value(); |
| 868 } | 926 } |
| 869 | 927 |
| 870 | 928 |
| 871 DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 4) { | 929 DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 4) { |
| 872 // Argument 0 is the mirror, which is unused by the native. It exists | 930 // Argument 0 is the mirror, which is unused by the native. It exists |
| 873 // because this native is an instance method in order to be polymorphic | 931 // because this native is an instance method in order to be polymorphic |
| 874 // with its cousins. | 932 // with its cousins. |
| 875 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 933 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 876 const Class& klass = Class::Handle(ref.GetClassReferent()); | 934 const AbstractType& type = |
| 935 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 936 const Class& klass = Class::Handle(type.type_class()); |
| 877 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 937 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 878 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 938 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 879 | 939 |
| 880 // Check for real fields and user-defined setters. | 940 // Check for real fields and user-defined setters. |
| 881 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 941 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
| 882 if (field.IsNull()) { | 942 if (field.IsNull()) { |
| 883 const String& internal_setter_name = String::Handle( | 943 const String& internal_setter_name = String::Handle( |
| 884 Field::SetterName(setter_name)); | 944 Field::SetterName(setter_name)); |
| 885 const Function& setter = Function::Handle( | 945 const Function& setter = Function::Handle( |
| 886 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); | 946 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 917 UNREACHABLE(); | 977 UNREACHABLE(); |
| 918 } | 978 } |
| 919 | 979 |
| 920 field.set_value(value); | 980 field.set_value(value); |
| 921 return value.raw(); | 981 return value.raw(); |
| 922 } | 982 } |
| 923 | 983 |
| 924 | 984 |
| 925 DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 3) { | 985 DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 3) { |
| 926 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 986 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 927 const Class& klass = Class::Handle(ref.GetClassReferent()); | 987 const AbstractType& type = |
| 988 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 989 const Class& klass = Class::Handle(type.type_class()); |
| 928 GET_NON_NULL_NATIVE_ARGUMENT( | 990 GET_NON_NULL_NATIVE_ARGUMENT( |
| 929 String, constructor_name, arguments->NativeArgAt(1)); | 991 String, constructor_name, arguments->NativeArgAt(1)); |
| 930 GET_NON_NULL_NATIVE_ARGUMENT( | 992 GET_NON_NULL_NATIVE_ARGUMENT( |
| 931 Array, positional_args, arguments->NativeArgAt(2)); | 993 Array, positional_args, arguments->NativeArgAt(2)); |
| 932 | 994 |
| 933 intptr_t number_of_arguments = positional_args.Length(); | 995 intptr_t number_of_arguments = positional_args.Length(); |
| 934 | 996 |
| 935 // By convention, the static function implementing a named constructor 'C' | 997 // By convention, the static function implementing a named constructor 'C' |
| 936 // for class 'A' is labeled 'A.C', and the static function implementing the | 998 // for class 'A' is labeled 'A.C', and the static function implementing the |
| 937 // unnamed constructor for class 'A' is labeled 'A.'. | 999 // unnamed constructor for class 'A' is labeled 'A.'. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 setter_name.ToCString())); | 1195 setter_name.ToCString())); |
| 1134 ThrowMirroredCompilationError(message); | 1196 ThrowMirroredCompilationError(message); |
| 1135 UNREACHABLE(); | 1197 UNREACHABLE(); |
| 1136 } | 1198 } |
| 1137 | 1199 |
| 1138 field.set_value(value); | 1200 field.set_value(value); |
| 1139 return value.raw(); | 1201 return value.raw(); |
| 1140 } | 1202 } |
| 1141 | 1203 |
| 1142 | 1204 |
| 1205 |
| 1143 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { | 1206 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { |
| 1144 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1207 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1145 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1208 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1146 if (func.IsNonImplicitClosureFunction()) { | 1209 if (func.IsNonImplicitClosureFunction()) { |
| 1147 return CreateMethodMirror(Function::Handle( | 1210 return CreateMethodMirror(Function::Handle( |
| 1148 func.parent_function()), Object::null_instance()); | 1211 func.parent_function()), Object::null_instance()); |
| 1149 } | 1212 } |
| 1150 const Class& owner = Class::Handle(func.Owner()); | 1213 const Class& owner = Class::Handle(func.Owner()); |
| 1151 if (owner.IsTopLevel()) { | 1214 if (owner.IsTopLevel()) { |
| 1152 return CreateLibraryMirror(Library::Handle(owner.library())); | 1215 return CreateLibraryMirror(Library::Handle(owner.library())); |
| 1153 } | 1216 } |
| 1154 return CreateClassMirror(owner, Object::null_instance()); | 1217 return CreateGenericClassMirror(owner, Object::null_instance()); |
| 1155 } | 1218 } |
| 1156 | 1219 |
| 1157 | 1220 |
| 1158 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { | 1221 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { |
| 1159 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1222 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1160 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1223 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1161 return CreateParameterMirrorList(func); | 1224 return CreateParameterMirrorList(func); |
| 1162 } | 1225 } |
| 1163 | 1226 |
| 1164 | 1227 |
| 1165 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1228 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1166 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1229 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1167 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1230 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1168 // We handle constructors in Dart code. | 1231 // We handle constructors in Dart code. |
| 1169 ASSERT(!func.IsConstructor()); | 1232 ASSERT(!func.IsConstructor()); |
| 1170 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 1233 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 1171 return CreateTypeMirror(return_type); | 1234 return CreateTypeMirror(return_type); |
| 1172 } | 1235 } |
| 1173 | 1236 |
| 1174 | 1237 |
| 1175 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { | 1238 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { |
| 1176 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1239 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1177 const Class& cls = Class::Handle(ref.GetClassReferent()); | 1240 const AbstractType& type = |
| 1241 AbstractType::Handle(ref.GetAbstractTypeReferent()); |
| 1242 const Class& cls = Class::Handle(type.type_class()); |
| 1178 const Function& sig_func = Function::Handle(cls.signature_function()); | 1243 const Function& sig_func = Function::Handle(cls.signature_function()); |
| 1179 const Class& sig_cls = Class::Handle(sig_func.signature_class()); | 1244 const Class& sig_cls = Class::Handle(sig_func.signature_class()); |
| 1180 return MirrorReference::New(sig_cls); | 1245 |
| 1246 // Possibly losing information here.... |
| 1247 AbstractType& runtime_type = AbstractType::Handle(RawTypeOfClass(sig_cls)); |
| 1248 |
| 1249 return MirrorReference::New(runtime_type); |
| 1181 } | 1250 } |
| 1182 | 1251 |
| 1183 | 1252 |
| 1184 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { | 1253 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { |
| 1185 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1254 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1186 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); | 1255 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); |
| 1187 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1256 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1188 const AbstractType& param_type = AbstractType::Handle(func.ParameterTypeAt( | 1257 const AbstractType& param_type = AbstractType::Handle(func.ParameterTypeAt( |
| 1189 func.NumImplicitParameters() + pos.Value())); | 1258 func.NumImplicitParameters() + pos.Value())); |
| 1190 return CreateTypeMirror(param_type); | 1259 return CreateTypeMirror(param_type); |
| 1191 } | 1260 } |
| 1192 | 1261 |
| 1193 | 1262 |
| 1194 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1263 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1195 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1264 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1196 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1265 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1197 | 1266 |
| 1198 const AbstractType& type = AbstractType::Handle(field.type()); | 1267 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1199 return CreateTypeMirror(type); | 1268 return CreateTypeMirror(type); |
| 1200 } | 1269 } |
| 1201 | 1270 |
| 1202 } // namespace dart | 1271 } // namespace dart |
| OLD | NEW |