| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); | 369 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); |
| 370 String& str = String::Handle(); | 370 String& str = String::Handle(); |
| 371 str = lib.name(); | 371 str = lib.name(); |
| 372 args.SetAt(1, str); | 372 args.SetAt(1, str); |
| 373 str = lib.url(); | 373 str = lib.url(); |
| 374 args.SetAt(2, str); | 374 args.SetAt(2, str); |
| 375 return CreateMirror(Symbols::_LocalLibraryMirror(), args); | 375 return CreateMirror(Symbols::_LocalLibraryMirror(), args); |
| 376 } | 376 } |
| 377 | 377 |
| 378 | 378 |
| 379 static RawInstance* CreateCombinatorMirror(const Object& identifiers, | |
| 380 bool is_show) { | |
| 381 const Array& args = Array::Handle(Array::New(2)); | |
| 382 args.SetAt(0, identifiers); | |
| 383 args.SetAt(1, Bool::Get(is_show)); | |
| 384 return CreateMirror(Symbols::_LocalCombinatorMirror(), args); | |
| 385 } | |
| 386 | |
| 387 | |
| 388 static RawInstance* CreateLibraryDependencyMirror(const Instance& importer, | |
| 389 const Namespace& ns, | |
| 390 const String& prefix, | |
| 391 bool is_import) { | |
| 392 const Library& importee = Library::Handle(ns.library()); | |
| 393 const Instance& importee_mirror = | |
| 394 Instance::Handle(CreateLibraryMirror(importee)); | |
| 395 | |
| 396 const Array& show_names = Array::Handle(ns.show_names()); | |
| 397 const Array& hide_names = Array::Handle(ns.hide_names()); | |
| 398 intptr_t n = show_names.IsNull() ? 0 : show_names.Length(); | |
| 399 intptr_t m = hide_names.IsNull() ? 0 : hide_names.Length(); | |
| 400 const Array& combinators = Array::Handle(Array::New(n + m)); | |
| 401 Object& t = Object::Handle(); | |
| 402 intptr_t i = 0; | |
| 403 for (intptr_t j = 0; j < n; j++) { | |
| 404 t = show_names.At(j); | |
| 405 t = CreateCombinatorMirror(t, true); | |
| 406 combinators.SetAt(i++, t); | |
| 407 } | |
| 408 for (intptr_t j = 0; j < m; j++) { | |
| 409 t = hide_names.At(j); | |
| 410 t = CreateCombinatorMirror(t, false); | |
| 411 combinators.SetAt(i++, t); | |
| 412 } | |
| 413 | |
| 414 Object& metadata = Object::Handle(ns.GetMetadata()); | |
| 415 if (metadata.IsError()) { | |
| 416 ThrowInvokeError(Error::Cast(metadata)); | |
| 417 UNREACHABLE(); | |
| 418 } | |
| 419 | |
| 420 const Array& args = Array::Handle(Array::New(6)); | |
| 421 args.SetAt(0, importer); | |
| 422 args.SetAt(1, importee_mirror); | |
| 423 args.SetAt(2, combinators); | |
| 424 args.SetAt(3, prefix); | |
| 425 args.SetAt(4, Bool::Get(is_import)); | |
| 426 args.SetAt(5, metadata); | |
| 427 // is_deferred? | |
| 428 return CreateMirror(Symbols::_LocalLibraryDependencyMirror(), args); | |
| 429 } | |
| 430 | |
| 431 | |
| 432 DEFINE_NATIVE_ENTRY(LibraryMirror_libraryDependencies, 2) { | |
| 433 GET_NON_NULL_NATIVE_ARGUMENT(Instance, lib_mirror, arguments->NativeArgAt(0)); | |
| 434 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | |
| 435 const Library& lib = Library::Handle(ref.GetLibraryReferent()); | |
| 436 | |
| 437 Array& ports = Array::Handle(); | |
| 438 Namespace& ns = Namespace::Handle(); | |
| 439 Instance& dep = Instance::Handle(); | |
| 440 String& prefix = String::Handle(); | |
| 441 GrowableObjectArray& deps = | |
| 442 GrowableObjectArray::Handle(GrowableObjectArray::New()); | |
| 443 | |
| 444 // Unprefixed imports. | |
| 445 ports = lib.imports(); | |
| 446 for (intptr_t i = 0; i < ports.Length(); i++) { | |
| 447 ns ^= ports.At(i); | |
| 448 if (!ns.IsNull()) { | |
| 449 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true); | |
| 450 deps.Add(dep); | |
| 451 } | |
| 452 } | |
| 453 | |
| 454 // Exports. | |
| 455 ports = lib.exports(); | |
| 456 for (intptr_t i = 0; i < ports.Length(); i++) { | |
| 457 ns ^= ports.At(i); | |
| 458 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, false); | |
| 459 deps.Add(dep); | |
| 460 } | |
| 461 | |
| 462 // Prefixed imports. | |
| 463 DictionaryIterator entries(lib); | |
| 464 Object& entry = Object::Handle(); | |
| 465 while (entries.HasNext()) { | |
| 466 entry = entries.GetNext(); | |
| 467 if (entry.IsLibraryPrefix()) { | |
| 468 const LibraryPrefix& lib_prefix = LibraryPrefix::Cast(entry); | |
| 469 prefix = lib_prefix.name(); | |
| 470 ports = lib_prefix.imports(); | |
| 471 for (intptr_t i = 0; i < ports.Length(); i++) { | |
| 472 ns ^= ports.At(i); | |
| 473 if (!ns.IsNull()) { | |
| 474 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true); | |
| 475 deps.Add(dep); | |
| 476 } | |
| 477 } | |
| 478 } | |
| 479 } | |
| 480 | |
| 481 return deps.raw(); | |
| 482 } | |
| 483 | |
| 484 static RawInstance* CreateTypeMirror(const AbstractType& type) { | 379 static RawInstance* CreateTypeMirror(const AbstractType& type) { |
| 485 if (type.IsTypeRef()) { | 380 if (type.IsTypeRef()) { |
| 486 AbstractType& ref_type = AbstractType::Handle(TypeRef::Cast(type).type()); | 381 AbstractType& ref_type = AbstractType::Handle(TypeRef::Cast(type).type()); |
| 487 ASSERT(!ref_type.IsTypeRef()); | 382 ASSERT(!ref_type.IsTypeRef()); |
| 488 ASSERT(ref_type.IsCanonical()); | 383 ASSERT(ref_type.IsCanonical()); |
| 489 return CreateTypeMirror(ref_type); | 384 return CreateTypeMirror(ref_type); |
| 490 } | 385 } |
| 491 ASSERT(type.IsFinalized()); | 386 ASSERT(type.IsFinalized()); |
| 492 ASSERT(!type.IsMalformed()); | 387 ASSERT(!type.IsMalformed()); |
| 493 if (type.HasResolvedTypeClass()) { | 388 if (type.HasResolvedTypeClass()) { |
| (...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2222 } | 2117 } |
| 2223 | 2118 |
| 2224 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { | 2119 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { |
| 2225 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2120 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
| 2226 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2121 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
| 2227 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); | 2122 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); |
| 2228 } | 2123 } |
| 2229 | 2124 |
| 2230 | 2125 |
| 2231 } // namespace dart | 2126 } // namespace dart |
| OLD | NEW |