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 "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 5364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5375 GrowDictionary(dict, dict_size); | 5375 GrowDictionary(dict, dict_size); |
5376 } | 5376 } |
5377 | 5377 |
5378 // Invalidate the cache of loaded scripts. | 5378 // Invalidate the cache of loaded scripts. |
5379 if (loaded_scripts() != Array::null()) { | 5379 if (loaded_scripts() != Array::null()) { |
5380 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); | 5380 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); |
5381 } | 5381 } |
5382 } | 5382 } |
5383 | 5383 |
5384 | 5384 |
| 5385 // Lookup a name in the library's export namespace. |
| 5386 RawObject* Library::LookupExport(const String& name) const { |
| 5387 if (HasExports()) { |
| 5388 const Array& exports = Array::Handle(this->exports()); |
| 5389 Namespace& ns = Namespace::Handle(); |
| 5390 Object& obj = Object::Handle(); |
| 5391 for (int i = 0; i < exports.Length(); i++) { |
| 5392 ns ^= exports.At(i); |
| 5393 obj = ns.Lookup(name); |
| 5394 if (!obj.IsNull()) { |
| 5395 return obj.raw(); |
| 5396 } |
| 5397 } |
| 5398 } |
| 5399 return Object::null(); |
| 5400 } |
| 5401 |
| 5402 |
5385 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { | 5403 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { |
5386 Isolate* isolate = Isolate::Current(); | 5404 Isolate* isolate = Isolate::Current(); |
5387 const Array& dict = Array::Handle(isolate, dictionary()); | 5405 const Array& dict = Array::Handle(isolate, dictionary()); |
5388 intptr_t dict_size = dict.Length() - 1; | 5406 intptr_t dict_size = dict.Length() - 1; |
5389 *index = name.Hash() % dict_size; | 5407 *index = name.Hash() % dict_size; |
5390 | 5408 |
5391 Object& entry = Object::Handle(isolate); | 5409 Object& entry = Object::Handle(isolate); |
5392 String& entry_name = String::Handle(isolate); | 5410 String& entry_name = String::Handle(isolate); |
5393 entry = dict.At(*index); | 5411 entry = dict.At(*index); |
5394 // Search the entry in the hash set. | 5412 // Search the entry in the hash set. |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5731 intptr_t new_len = (num_anonymous == 0) ? 4 : num_anonymous * 2; | 5749 intptr_t new_len = (num_anonymous == 0) ? 4 : num_anonymous * 2; |
5732 anon_array = Array::Grow(anon_array, new_len); | 5750 anon_array = Array::Grow(anon_array, new_len); |
5733 StorePointer(&raw_ptr()->anonymous_classes_, anon_array.raw()); | 5751 StorePointer(&raw_ptr()->anonymous_classes_, anon_array.raw()); |
5734 } | 5752 } |
5735 anon_array.SetAt(num_anonymous, cls); | 5753 anon_array.SetAt(num_anonymous, cls); |
5736 num_anonymous++; | 5754 num_anonymous++; |
5737 raw_ptr()->num_anonymous_ = num_anonymous; | 5755 raw_ptr()->num_anonymous_ = num_anonymous; |
5738 } | 5756 } |
5739 | 5757 |
5740 | 5758 |
5741 RawLibrary* Library::LookupImport(const String& url) const { | |
5742 Isolate* isolate = Isolate::Current(); | |
5743 const Array& imports = Array::Handle(isolate, this->imports()); | |
5744 intptr_t num_imports = this->num_imports(); | |
5745 Namespace& import = Namespace::Handle(isolate, Namespace::null()); | |
5746 Library& lib = Library::Handle(isolate, Library::null()); | |
5747 String& import_url = String::Handle(isolate, String::null()); | |
5748 for (int i = 0; i < num_imports; i++) { | |
5749 import ^= imports.At(i); | |
5750 lib = import.library(); | |
5751 import_url = lib.url(); | |
5752 if (url.Equals(import_url)) { | |
5753 return lib.raw(); | |
5754 } | |
5755 } | |
5756 return Library::null(); | |
5757 } | |
5758 | |
5759 | |
5760 RawLibrary* Library::ImportLibraryAt(intptr_t index) const { | 5759 RawLibrary* Library::ImportLibraryAt(intptr_t index) const { |
5761 Namespace& import = Namespace::Handle(ImportAt(index)); | 5760 Namespace& import = Namespace::Handle(ImportAt(index)); |
5762 if (import.IsNull()) { | 5761 if (import.IsNull()) { |
5763 return Library::null(); | 5762 return Library::null(); |
5764 } | 5763 } |
5765 return import.library(); | 5764 return import.library(); |
5766 } | 5765 } |
5767 | 5766 |
5768 | 5767 |
5769 RawNamespace* Library::ImportAt(intptr_t index) const { | 5768 RawNamespace* Library::ImportAt(intptr_t index) const { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5810 capacity = capacity + kImportsCapacityIncrement; | 5809 capacity = capacity + kImportsCapacityIncrement; |
5811 imports = Array::Grow(imports, capacity); | 5810 imports = Array::Grow(imports, capacity); |
5812 StorePointer(&raw_ptr()->imports_, imports.raw()); | 5811 StorePointer(&raw_ptr()->imports_, imports.raw()); |
5813 } | 5812 } |
5814 intptr_t index = num_imports(); | 5813 intptr_t index = num_imports(); |
5815 imports.SetAt(index, ns); | 5814 imports.SetAt(index, ns); |
5816 set_num_imports(index + 1); | 5815 set_num_imports(index + 1); |
5817 } | 5816 } |
5818 | 5817 |
5819 | 5818 |
| 5819 // Convenience function to determine whether the export list is |
| 5820 // non-empty. |
| 5821 bool Library::HasExports() const { |
| 5822 return exports() != Object::empty_array(); |
| 5823 } |
| 5824 |
| 5825 |
| 5826 // We add one namespace at a time to the exports array and don't |
| 5827 // pre-allocate any unused capacity. The assumption is that |
| 5828 // re-exports are quite rare. |
| 5829 void Library::AddExport(const Namespace& ns) const { |
| 5830 Array &exports = Array::Handle(this->exports()); |
| 5831 intptr_t num_exports = exports.Length(); |
| 5832 exports = Array::Grow(exports, num_exports + 1); |
| 5833 StorePointer(&raw_ptr()->exports_, exports.raw()); |
| 5834 exports.SetAt(num_exports, ns); |
| 5835 } |
| 5836 |
| 5837 |
5820 void Library::InitClassDictionary() const { | 5838 void Library::InitClassDictionary() const { |
5821 // The last element of the dictionary specifies the number of in use slots. | 5839 // The last element of the dictionary specifies the number of in use slots. |
5822 // TODO(iposva): Find reasonable initial size. | 5840 // TODO(iposva): Find reasonable initial size. |
5823 const int kInitialElementCount = 16; | 5841 const int kInitialElementCount = 16; |
5824 | 5842 |
5825 const Array& dictionary = | 5843 const Array& dictionary = |
5826 Array::Handle(Array::New(kInitialElementCount + 1, Heap::kOld)); | 5844 Array::Handle(Array::New(kInitialElementCount + 1, Heap::kOld)); |
5827 dictionary.SetAt(kInitialElementCount, Smi::Handle(Smi::New(0))); | 5845 dictionary.SetAt(kInitialElementCount, Smi::Handle(Smi::New(0))); |
5828 StorePointer(&raw_ptr()->dictionary_, dictionary.raw()); | 5846 StorePointer(&raw_ptr()->dictionary_, dictionary.raw()); |
5829 } | 5847 } |
(...skipping 19 matching lines...) Expand all Loading... |
5849 RawLibrary* Library::NewLibraryHelper(const String& url, | 5867 RawLibrary* Library::NewLibraryHelper(const String& url, |
5850 bool import_core_lib) { | 5868 bool import_core_lib) { |
5851 const Library& result = Library::Handle(Library::New()); | 5869 const Library& result = Library::Handle(Library::New()); |
5852 result.StorePointer(&result.raw_ptr()->name_, url.raw()); | 5870 result.StorePointer(&result.raw_ptr()->name_, url.raw()); |
5853 result.StorePointer(&result.raw_ptr()->url_, url.raw()); | 5871 result.StorePointer(&result.raw_ptr()->url_, url.raw()); |
5854 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); | 5872 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); |
5855 result.raw_ptr()->dictionary_ = Object::empty_array(); | 5873 result.raw_ptr()->dictionary_ = Object::empty_array(); |
5856 result.raw_ptr()->anonymous_classes_ = Object::empty_array(); | 5874 result.raw_ptr()->anonymous_classes_ = Object::empty_array(); |
5857 result.raw_ptr()->num_anonymous_ = 0; | 5875 result.raw_ptr()->num_anonymous_ = 0; |
5858 result.raw_ptr()->imports_ = Object::empty_array(); | 5876 result.raw_ptr()->imports_ = Object::empty_array(); |
| 5877 result.raw_ptr()->exports_ = Object::empty_array(); |
5859 result.raw_ptr()->loaded_scripts_ = Array::null(); | 5878 result.raw_ptr()->loaded_scripts_ = Array::null(); |
5860 result.set_native_entry_resolver(NULL); | 5879 result.set_native_entry_resolver(NULL); |
5861 result.raw_ptr()->corelib_imported_ = true; | 5880 result.raw_ptr()->corelib_imported_ = true; |
5862 result.set_debuggable(false); | 5881 result.set_debuggable(false); |
5863 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; | 5882 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; |
5864 result.raw_ptr()->index_ = -1; | 5883 result.raw_ptr()->index_ = -1; |
5865 result.InitClassDictionary(); | 5884 result.InitClassDictionary(); |
5866 result.InitImportList(); | 5885 result.InitImportList(); |
5867 if (import_core_lib) { | 5886 if (import_core_lib) { |
5868 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 5887 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6257 // There is a list of visible names. The name we're looking for is not | 6276 // There is a list of visible names. The name we're looking for is not |
6258 // contained in the list, so it is hidden. | 6277 // contained in the list, so it is hidden. |
6259 return true; | 6278 return true; |
6260 } | 6279 } |
6261 // The name is not filtered out. | 6280 // The name is not filtered out. |
6262 return false; | 6281 return false; |
6263 } | 6282 } |
6264 | 6283 |
6265 | 6284 |
6266 RawObject* Namespace::Lookup(const String& name) const { | 6285 RawObject* Namespace::Lookup(const String& name) const { |
6267 intptr_t i = 0; | |
6268 const Library& lib = Library::Handle(library()); | 6286 const Library& lib = Library::Handle(library()); |
6269 const Object& obj = Object::Handle(lib.LookupEntry(name, &i)); | 6287 intptr_t ignore = 0; |
| 6288 // Lookup the name in the libraries symbols. |
| 6289 Object& obj = Object::Handle(lib.LookupEntry(name, &ignore)); |
| 6290 if (obj.IsNull()) { |
| 6291 // Lookup in the re-exported symbols. |
| 6292 obj = lib.LookupExport(name); |
| 6293 } |
6270 if (obj.IsNull() || HidesName(name)) { | 6294 if (obj.IsNull() || HidesName(name)) { |
6271 return Object::null(); | 6295 return Object::null(); |
6272 } | 6296 } |
6273 return obj.raw(); | 6297 return obj.raw(); |
6274 } | 6298 } |
6275 | 6299 |
6276 | 6300 |
6277 RawNamespace* Namespace::New() { | 6301 RawNamespace* Namespace::New() { |
6278 ASSERT(Object::namespace_class() != Class::null()); | 6302 ASSERT(Object::namespace_class() != Class::null()); |
6279 RawObject* raw = Object::Allocate(Namespace::kClassId, | 6303 RawObject* raw = Object::Allocate(Namespace::kClassId, |
(...skipping 5892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12172 } | 12196 } |
12173 return result.raw(); | 12197 return result.raw(); |
12174 } | 12198 } |
12175 | 12199 |
12176 | 12200 |
12177 const char* WeakProperty::ToCString() const { | 12201 const char* WeakProperty::ToCString() const { |
12178 return "_WeakProperty"; | 12202 return "_WeakProperty"; |
12179 } | 12203 } |
12180 | 12204 |
12181 } // namespace dart | 12205 } // namespace dart |
OLD | NEW |