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