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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 reinterpret_cast<RawClass*>(RAW_NULL); | 80 reinterpret_cast<RawClass*>(RAW_NULL); |
81 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 81 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
82 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 82 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
83 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 83 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
84 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 84 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
85 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 85 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
86 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 86 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
87 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 87 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
88 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 88 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
89 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 89 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
90 RawClass* Object::namespace_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | |
90 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 91 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
91 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 92 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
92 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 93 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
93 RawClass* Object::stackmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 94 RawClass* Object::stackmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
94 RawClass* Object::var_descriptors_class_ = | 95 RawClass* Object::var_descriptors_class_ = |
95 reinterpret_cast<RawClass*>(RAW_NULL); | 96 reinterpret_cast<RawClass*>(RAW_NULL); |
96 RawClass* Object::exception_handlers_class_ = | 97 RawClass* Object::exception_handlers_class_ = |
97 reinterpret_cast<RawClass*>(RAW_NULL); | 98 reinterpret_cast<RawClass*>(RAW_NULL); |
98 RawClass* Object::deopt_info_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 99 RawClass* Object::deopt_info_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
99 RawClass* Object::context_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 100 RawClass* Object::context_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 | 348 |
348 cls = Class::New<Script>(); | 349 cls = Class::New<Script>(); |
349 script_class_ = cls.raw(); | 350 script_class_ = cls.raw(); |
350 | 351 |
351 cls = Class::New<Library>(); | 352 cls = Class::New<Library>(); |
352 library_class_ = cls.raw(); | 353 library_class_ = cls.raw(); |
353 | 354 |
354 cls = Class::New<LibraryPrefix>(); | 355 cls = Class::New<LibraryPrefix>(); |
355 library_prefix_class_ = cls.raw(); | 356 library_prefix_class_ = cls.raw(); |
356 | 357 |
358 cls = Class::New<Namespace>(); | |
359 namespace_class_ = cls.raw(); | |
360 | |
357 cls = Class::New<Code>(); | 361 cls = Class::New<Code>(); |
358 code_class_ = cls.raw(); | 362 code_class_ = cls.raw(); |
359 | 363 |
360 cls = Class::New<Instructions>(); | 364 cls = Class::New<Instructions>(); |
361 instructions_class_ = cls.raw(); | 365 instructions_class_ = cls.raw(); |
362 | 366 |
363 cls = Class::New<PcDescriptors>(); | 367 cls = Class::New<PcDescriptors>(); |
364 pc_descriptors_class_ = cls.raw(); | 368 pc_descriptors_class_ = cls.raw(); |
365 | 369 |
366 cls = Class::New<Stackmap>(); | 370 cls = Class::New<Stackmap>(); |
(...skipping 5897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6264 Field& field = Field::Handle(LookupLocalField(name)); | 6268 Field& field = Field::Handle(LookupLocalField(name)); |
6265 if (!field.IsNull()) { | 6269 if (!field.IsNull()) { |
6266 return field.raw(); | 6270 return field.raw(); |
6267 } | 6271 } |
6268 | 6272 |
6269 // Do not look up private names in imported libraries. | 6273 // Do not look up private names in imported libraries. |
6270 if (ShouldBePrivate(name)) { | 6274 if (ShouldBePrivate(name)) { |
6271 return Field::null(); | 6275 return Field::null(); |
6272 } | 6276 } |
6273 | 6277 |
6274 // Now check if name is found in the top level scope of any imported | 6278 // Now check if name is found in any imported libs. |
6275 // libs. | |
6276 const Array& imports = Array::Handle(this->imports()); | 6279 const Array& imports = Array::Handle(this->imports()); |
6277 Library& import_lib = Library::Handle(); | 6280 Namespace& import = Namespace::Handle(); |
6281 Object& obj = Object::Handle(); | |
6278 for (intptr_t j = 0; j < this->num_imports(); j++) { | 6282 for (intptr_t j = 0; j < this->num_imports(); j++) { |
6279 import_lib ^= imports.At(j); | 6283 import ^= imports.At(j); |
6280 | 6284 obj = import.Lookup(name); |
6281 | 6285 if (!obj.IsNull() && obj.IsField()) { |
6282 field = import_lib.LookupLocalField(name); | 6286 field ^= obj.raw(); |
6283 if (!field.IsNull()) { | |
6284 return field.raw(); | 6287 return field.raw(); |
6285 } | 6288 } |
6286 } | 6289 } |
6287 return Field::null(); | 6290 return Field::null(); |
6288 } | 6291 } |
6289 | 6292 |
6290 | 6293 |
6291 RawField* Library::LookupLocalField(const String& name) const { | 6294 RawField* Library::LookupLocalField(const String& name) const { |
6292 Isolate* isolate = Isolate::Current(); | 6295 Isolate* isolate = Isolate::Current(); |
6293 Field& field = Field::Handle(isolate, Field::null()); | 6296 Field& field = Field::Handle(isolate, Field::null()); |
(...skipping 21 matching lines...) Expand all Loading... | |
6315 if (!function.IsNull()) { | 6318 if (!function.IsNull()) { |
6316 return function.raw(); | 6319 return function.raw(); |
6317 } | 6320 } |
6318 | 6321 |
6319 // Do not look up private names in imported libraries. | 6322 // Do not look up private names in imported libraries. |
6320 if (ShouldBePrivate(name)) { | 6323 if (ShouldBePrivate(name)) { |
6321 return Function::null(); | 6324 return Function::null(); |
6322 } | 6325 } |
6323 | 6326 |
6324 // Now check if name is found in the top level scope of any imported | 6327 // Now check if name is found in the top level scope of any imported |
6325 // libs. | 6328 // libs. |
siva
2012/09/24 18:28:51
The comment in LookupFieldAllowPrivate has been mo
hausner
2012/09/24 20:25:43
Done.
| |
6326 const Array& imports = Array::Handle(this->imports()); | 6329 const Array& imports = Array::Handle(this->imports()); |
6327 Library& import_lib = Library::Handle(); | 6330 Namespace& import = Namespace::Handle(); |
6331 Object& obj = Object::Handle(); | |
6328 for (intptr_t j = 0; j < this->num_imports(); j++) { | 6332 for (intptr_t j = 0; j < this->num_imports(); j++) { |
6329 import_lib ^= imports.At(j); | 6333 import ^= imports.At(j); |
6330 | 6334 obj = import.Lookup(name); |
6331 | 6335 if (!obj.IsNull() && obj.IsFunction()) { |
6332 function = import_lib.LookupLocalFunction(name); | 6336 function ^= obj.raw(); |
6333 if (!function.IsNull()) { | |
6334 return function.raw(); | 6337 return function.raw(); |
6335 } | 6338 } |
6336 } | 6339 } |
6337 return Function::null(); | 6340 return Function::null(); |
6338 } | 6341 } |
6339 | 6342 |
6340 | 6343 |
6341 RawFunction* Library::LookupLocalFunction(const String& name) const { | 6344 RawFunction* Library::LookupLocalFunction(const String& name) const { |
6342 Isolate* isolate = Isolate::Current(); | 6345 Isolate* isolate = Isolate::Current(); |
6343 Object& obj = Object::Handle(isolate, Object::null()); | 6346 Object& obj = Object::Handle(isolate, Object::null()); |
(...skipping 10 matching lines...) Expand all Loading... | |
6354 return Function::null(); | 6357 return Function::null(); |
6355 } | 6358 } |
6356 | 6359 |
6357 | 6360 |
6358 RawObject* Library::LookupObject(const String& name) const { | 6361 RawObject* Library::LookupObject(const String& name) const { |
6359 // First check if name is found in the local scope of the library. | 6362 // First check if name is found in the local scope of the library. |
6360 Object& obj = Object::Handle(LookupLocalObject(name)); | 6363 Object& obj = Object::Handle(LookupLocalObject(name)); |
6361 if (!obj.IsNull()) { | 6364 if (!obj.IsNull()) { |
6362 return obj.raw(); | 6365 return obj.raw(); |
6363 } | 6366 } |
6364 // Now check if name is found in the top level scope of any imported libs. | 6367 // Now check if name is found in the top level scope of any imported libs. |
siva
2012/09/24 18:28:51
ditto comment regarding comment.
hausner
2012/09/24 20:25:43
Done.
| |
6365 const Array& imports = Array::Handle(this->imports()); | 6368 const Array& imports = Array::Handle(this->imports()); |
6366 Library& import_lib = Library::Handle(); | 6369 Namespace& import = Namespace::Handle(); |
6367 for (intptr_t j = 0; j < this->num_imports(); j++) { | 6370 for (intptr_t j = 0; j < this->num_imports(); j++) { |
6368 import_lib ^= imports.At(j); | 6371 import ^= imports.At(j); |
6369 obj = import_lib.LookupLocalObject(name); | 6372 obj = import.Lookup(name); |
6370 if (!obj.IsNull()) { | 6373 if (!obj.IsNull()) { |
6371 return obj.raw(); | 6374 return obj.raw(); |
6372 } | 6375 } |
6373 } | 6376 } |
6374 return Object::null(); | 6377 return Object::null(); |
6375 } | 6378 } |
6376 | 6379 |
6377 | 6380 |
6378 RawClass* Library::LookupClass(const String& name) const { | 6381 RawClass* Library::LookupClass(const String& name) const { |
6379 Object& obj = Object::Handle(LookupObject(name)); | 6382 Object& obj = Object::Handle(LookupObject(name)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6436 anon_array.SetAt(num_anonymous, cls); | 6439 anon_array.SetAt(num_anonymous, cls); |
6437 num_anonymous++; | 6440 num_anonymous++; |
6438 raw_ptr()->num_anonymous_ = num_anonymous; | 6441 raw_ptr()->num_anonymous_ = num_anonymous; |
6439 } | 6442 } |
6440 | 6443 |
6441 | 6444 |
6442 RawLibrary* Library::LookupImport(const String& url) const { | 6445 RawLibrary* Library::LookupImport(const String& url) const { |
6443 Isolate* isolate = Isolate::Current(); | 6446 Isolate* isolate = Isolate::Current(); |
6444 const Array& imports = Array::Handle(isolate, this->imports()); | 6447 const Array& imports = Array::Handle(isolate, this->imports()); |
6445 intptr_t num_imports = this->num_imports(); | 6448 intptr_t num_imports = this->num_imports(); |
6449 Namespace& import = Namespace::Handle(isolate, Namespace::null()); | |
6446 Library& lib = Library::Handle(isolate, Library::null()); | 6450 Library& lib = Library::Handle(isolate, Library::null()); |
6447 String& import_url = String::Handle(isolate, String::null()); | 6451 String& import_url = String::Handle(isolate, String::null()); |
6448 for (int i = 0; i < num_imports; i++) { | 6452 for (int i = 0; i < num_imports; i++) { |
6449 lib ^= imports.At(i); | 6453 import ^= imports.At(i); |
6454 lib = import.library(); | |
6450 import_url = lib.url(); | 6455 import_url = lib.url(); |
6451 if (url.Equals(import_url)) { | 6456 if (url.Equals(import_url)) { |
6452 return lib.raw(); | 6457 return lib.raw(); |
6453 } | 6458 } |
6454 } | 6459 } |
6455 return Library::null(); | 6460 return Library::null(); |
6456 } | 6461 } |
6457 | 6462 |
6458 | 6463 |
6459 RawLibrary* Library::ImportAt(intptr_t index) const { | 6464 RawLibrary* Library::ImportLibraryAt(intptr_t index) const { |
6460 if ((index < 0) || index >= num_imports()) { | 6465 Namespace& import = Namespace::Handle(ImportAt(index)); |
6466 if (import.IsNull()) { | |
6461 return Library::null(); | 6467 return Library::null(); |
6462 } | 6468 } |
6463 const Array& import_list = Array::Handle(imports()); | 6469 return import.library(); |
6464 Library& lib = Library::Handle(); | |
6465 lib ^= import_list.At(index); | |
6466 return lib.raw(); | |
6467 } | 6470 } |
6468 | 6471 |
6469 | 6472 |
6470 RawLibraryPrefix* Library::ImportPrefixAt(intptr_t index) const { | 6473 RawNamespace* Library::ImportAt(intptr_t index) const { |
6471 const Library& imported = Library::Handle(ImportAt(index)); | 6474 if ((index < 0) || index >= num_imports()) { |
6472 if (imported.IsNull()) { | 6475 return Namespace::null(); |
6473 return LibraryPrefix::null(); | |
6474 } | 6476 } |
6475 DictionaryIterator it(*this); | 6477 const Array& import_list = Array::Handle(imports()); |
6476 Object& obj = Object::Handle(); | 6478 Namespace& import = Namespace::Handle(); |
6477 while (it.HasNext()) { | 6479 import ^= import_list.At(index); |
6478 obj = it.GetNext(); | 6480 return import.raw(); |
6479 if (obj.IsLibraryPrefix()) { | |
6480 const LibraryPrefix& lib_prefix = LibraryPrefix::Cast(obj); | |
6481 if (lib_prefix.ContainsLibrary(imported)) { | |
6482 return lib_prefix.raw(); | |
6483 } | |
6484 } | |
6485 } | |
6486 return LibraryPrefix::null(); | |
6487 } | 6481 } |
6488 | 6482 |
6489 | 6483 |
6490 bool Library::ImportsCorelib() const { | 6484 bool Library::ImportsCorelib() const { |
6491 Isolate* isolate = Isolate::Current(); | 6485 Isolate* isolate = Isolate::Current(); |
6492 Library& imported = Library::Handle(isolate); | 6486 Library& imported = Library::Handle(isolate); |
6493 intptr_t count = num_imports(); | 6487 intptr_t count = num_imports(); |
6494 for (int i = 0; i < count; i++) { | 6488 for (int i = 0; i < count; i++) { |
6495 imported = ImportAt(i); | 6489 imported = ImportLibraryAt(i); |
6496 if (imported.IsCoreLibrary()) { | 6490 if (imported.IsCoreLibrary()) { |
6497 return true; | 6491 return true; |
6498 } | 6492 } |
6499 } | 6493 } |
6500 LibraryPrefix& prefix = LibraryPrefix::Handle(isolate); | 6494 LibraryPrefix& prefix = LibraryPrefix::Handle(isolate); |
6501 LibraryPrefixIterator it(*this); | 6495 LibraryPrefixIterator it(*this); |
6502 while (it.HasNext()) { | 6496 while (it.HasNext()) { |
6503 prefix = it.GetNext(); | 6497 prefix = it.GetNext(); |
6504 count = prefix.num_libs(); | 6498 count = prefix.num_imports(); |
6505 for (int i = 0; i < count; i++) { | 6499 for (int i = 0; i < count; i++) { |
6506 imported = prefix.GetLibrary(i); | 6500 imported = prefix.GetLibrary(i); |
6507 if (imported.IsCoreLibrary()) { | 6501 if (imported.IsCoreLibrary()) { |
6508 return true; | 6502 return true; |
6509 } | 6503 } |
6510 } | 6504 } |
6511 } | 6505 } |
6512 return false; | 6506 return false; |
6513 } | 6507 } |
6514 | 6508 |
6515 | 6509 |
6516 void Library::AddImport(const Library& library) const { | 6510 void Library::AddImport(const Namespace& ns) const { |
6517 Array& imports = Array::Handle(this->imports()); | 6511 Array& imports = Array::Handle(this->imports()); |
6518 intptr_t capacity = imports.Length(); | 6512 intptr_t capacity = imports.Length(); |
6519 if (num_imports() == capacity) { | 6513 if (num_imports() == capacity) { |
6520 capacity = capacity + kImportsCapacityIncrement; | 6514 capacity = capacity + kImportsCapacityIncrement; |
6521 imports = Array::Grow(imports, capacity); | 6515 imports = Array::Grow(imports, capacity); |
6522 StorePointer(&raw_ptr()->imports_, imports.raw()); | 6516 StorePointer(&raw_ptr()->imports_, imports.raw()); |
6523 } | 6517 } |
6524 intptr_t index = num_imports(); | 6518 intptr_t index = num_imports(); |
6525 imports.SetAt(index, library); | 6519 imports.SetAt(index, ns); |
6526 set_num_imports(index + 1); | 6520 set_num_imports(index + 1); |
6527 } | 6521 } |
6528 | 6522 |
6529 | 6523 |
6524 void Library::AddImportAll(const Library& lib) const { | |
6525 const Namespace& ns = Namespace::Handle( | |
6526 Namespace::New(lib, Array::Handle(), Array::Handle())); | |
6527 AddImport(ns); | |
siva
2012/09/24 18:28:51
I would prefer if we did not have his convenience
hausner
2012/09/24 20:25:43
Done. (Although I think the convenience function w
| |
6528 } | |
6529 | |
6530 | |
6530 void Library::InitClassDictionary() const { | 6531 void Library::InitClassDictionary() const { |
6531 // The last element of the dictionary specifies the number of in use slots. | 6532 // The last element of the dictionary specifies the number of in use slots. |
6532 // TODO(iposva): Find reasonable initial size. | 6533 // TODO(iposva): Find reasonable initial size. |
6533 const int kInitialElementCount = 16; | 6534 const int kInitialElementCount = 16; |
6534 | 6535 |
6535 const Array& dictionary = | 6536 const Array& dictionary = |
6536 Array::Handle(Array::New(kInitialElementCount + 1, Heap::kOld)); | 6537 Array::Handle(Array::New(kInitialElementCount + 1, Heap::kOld)); |
6537 dictionary.SetAt(kInitialElementCount, Smi::Handle(Smi::New(0))); | 6538 dictionary.SetAt(kInitialElementCount, Smi::Handle(Smi::New(0))); |
6538 StorePointer(&raw_ptr()->dictionary_, dictionary.raw()); | 6539 StorePointer(&raw_ptr()->dictionary_, dictionary.raw()); |
6539 } | 6540 } |
(...skipping 30 matching lines...) Expand all Loading... | |
6570 result.set_native_entry_resolver(NULL); | 6571 result.set_native_entry_resolver(NULL); |
6571 result.raw_ptr()->corelib_imported_ = true; | 6572 result.raw_ptr()->corelib_imported_ = true; |
6572 result.set_debuggable(false); | 6573 result.set_debuggable(false); |
6573 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; | 6574 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; |
6574 result.raw_ptr()->index_ = -1; | 6575 result.raw_ptr()->index_ = -1; |
6575 result.InitClassDictionary(); | 6576 result.InitClassDictionary(); |
6576 result.InitImportList(); | 6577 result.InitImportList(); |
6577 if (import_core_lib) { | 6578 if (import_core_lib) { |
6578 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 6579 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
6579 ASSERT(!core_lib.IsNull()); | 6580 ASSERT(!core_lib.IsNull()); |
6580 result.AddImport(core_lib); | 6581 result.AddImportAll(core_lib); |
6581 } | 6582 } |
6582 return result.raw(); | 6583 return result.raw(); |
6583 } | 6584 } |
6584 | 6585 |
6585 | 6586 |
6586 RawLibrary* Library::New(const String& url) { | 6587 RawLibrary* Library::New(const String& url) { |
6587 return NewLibraryHelper(url, false); | 6588 return NewLibraryHelper(url, false); |
6588 } | 6589 } |
6589 | 6590 |
6590 | 6591 |
6591 void Library::InitCoreLibrary(Isolate* isolate) { | 6592 void Library::InitCoreLibrary(Isolate* isolate) { |
6592 const String& core_lib_url = String::Handle(Symbols::New("dart:core")); | 6593 const String& core_lib_url = String::Handle(Symbols::New("dart:core")); |
6593 const Library& core_lib = | 6594 const Library& core_lib = |
6594 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); | 6595 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); |
6595 core_lib.Register(); | 6596 core_lib.Register(); |
6596 isolate->object_store()->set_core_library(core_lib); | 6597 isolate->object_store()->set_core_library(core_lib); |
6597 const String& core_impl_lib_url = | 6598 const String& core_impl_lib_url = |
6598 String::Handle(Symbols::New("dart:coreimpl")); | 6599 String::Handle(Symbols::New("dart:coreimpl")); |
6599 const Library& core_impl_lib = | 6600 const Library& core_impl_lib = |
6600 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); | 6601 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); |
6601 isolate->object_store()->set_core_impl_library(core_impl_lib); | 6602 isolate->object_store()->set_core_impl_library(core_impl_lib); |
6602 core_impl_lib.Register(); | 6603 core_impl_lib.Register(); |
6603 core_lib.AddImport(core_impl_lib); | 6604 core_lib.AddImportAll(core_impl_lib); |
6604 core_impl_lib.AddImport(core_lib); | 6605 core_impl_lib.AddImportAll(core_lib); |
6605 Library::InitMathLibrary(isolate); | 6606 Library::InitMathLibrary(isolate); |
6606 const Library& math_lib = Library::Handle(Library::MathLibrary()); | 6607 const Library& math_lib = Library::Handle(Library::MathLibrary()); |
6607 core_lib.AddImport(math_lib); | 6608 core_lib.AddImportAll(math_lib); |
6608 core_impl_lib.AddImport(math_lib); | 6609 core_impl_lib.AddImportAll(math_lib); |
6609 isolate->object_store()->set_root_library(Library::Handle()); | 6610 isolate->object_store()->set_root_library(Library::Handle()); |
6610 | 6611 |
6611 // Hook up predefined classes without setting their library pointers. These | 6612 // Hook up predefined classes without setting their library pointers. These |
6612 // classes are coming from the VM isolate, and are shared between multiple | 6613 // classes are coming from the VM isolate, and are shared between multiple |
6613 // isolates so setting their library pointers would be wrong. | 6614 // isolates so setting their library pointers would be wrong. |
6614 const Class& cls = Class::Handle(Object::dynamic_class()); | 6615 const Class& cls = Class::Handle(Object::dynamic_class()); |
6615 core_lib.AddObject(cls, String::Handle(cls.Name())); | 6616 core_lib.AddObject(cls, String::Handle(cls.Name())); |
6616 } | 6617 } |
6617 | 6618 |
6618 | 6619 |
6619 void Library::InitMathLibrary(Isolate* isolate) { | 6620 void Library::InitMathLibrary(Isolate* isolate) { |
6620 const String& url = String::Handle(Symbols::New("dart:math")); | 6621 const String& url = String::Handle(Symbols::New("dart:math")); |
6621 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | 6622 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); |
6622 lib.Register(); | 6623 lib.Register(); |
6623 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); | 6624 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
6624 lib.AddImport(core_impl_lib); | 6625 lib.AddImportAll(core_impl_lib); |
6625 isolate->object_store()->set_math_library(lib); | 6626 isolate->object_store()->set_math_library(lib); |
6626 } | 6627 } |
6627 | 6628 |
6628 | 6629 |
6629 void Library::InitIsolateLibrary(Isolate* isolate) { | 6630 void Library::InitIsolateLibrary(Isolate* isolate) { |
6630 const String& url = String::Handle(Symbols::New("dart:isolate")); | 6631 const String& url = String::Handle(Symbols::New("dart:isolate")); |
6631 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | 6632 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); |
6632 lib.Register(); | 6633 lib.Register(); |
6633 isolate->object_store()->set_isolate_library(lib); | 6634 isolate->object_store()->set_isolate_library(lib); |
6634 } | 6635 } |
6635 | 6636 |
6636 | 6637 |
6637 void Library::InitMirrorsLibrary(Isolate* isolate) { | 6638 void Library::InitMirrorsLibrary(Isolate* isolate) { |
6638 const String& url = String::Handle(Symbols::New("dart:mirrors")); | 6639 const String& url = String::Handle(Symbols::New("dart:mirrors")); |
6639 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | 6640 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); |
6640 lib.Register(); | 6641 lib.Register(); |
6641 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 6642 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); |
6642 lib.AddImport(isolate_lib); | 6643 lib.AddImportAll(isolate_lib); |
6643 const Library& wrappers_lib = | 6644 const Library& wrappers_lib = |
6644 Library::Handle(Library::NativeWrappersLibrary()); | 6645 Library::Handle(Library::NativeWrappersLibrary()); |
6645 lib.AddImport(wrappers_lib); | 6646 lib.AddImportAll(wrappers_lib); |
6646 isolate->object_store()->set_mirrors_library(lib); | 6647 isolate->object_store()->set_mirrors_library(lib); |
6647 } | 6648 } |
6648 | 6649 |
6649 | 6650 |
6650 void Library::InitScalarlistLibrary(Isolate* isolate) { | 6651 void Library::InitScalarlistLibrary(Isolate* isolate) { |
6651 const String& url = String::Handle(Symbols::New("dart:scalarlist")); | 6652 const String& url = String::Handle(Symbols::New("dart:scalarlist")); |
6652 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | 6653 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); |
6653 lib.Register(); | 6654 lib.Register(); |
6654 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); | 6655 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
6655 lib.AddImport(core_impl_lib); | 6656 lib.AddImportAll(core_impl_lib); |
6656 isolate->object_store()->set_scalarlist_library(lib); | 6657 isolate->object_store()->set_scalarlist_library(lib); |
6657 } | 6658 } |
6658 | 6659 |
6659 | 6660 |
6660 void Library::InitNativeWrappersLibrary(Isolate* isolate) { | 6661 void Library::InitNativeWrappersLibrary(Isolate* isolate) { |
6661 static const int kNumNativeWrappersClasses = 4; | 6662 static const int kNumNativeWrappersClasses = 4; |
6662 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); | 6663 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); |
6663 const String& native_flds_lib_url = String::Handle( | 6664 const String& native_flds_lib_url = String::Handle( |
6664 Symbols::New("dart:nativewrappers")); | 6665 Symbols::New("dart:nativewrappers")); |
6665 const Library& native_flds_lib = Library::Handle( | 6666 const Library& native_flds_lib = Library::Handle( |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6799 const char* kFormat = "Library:'%s'"; | 6800 const char* kFormat = "Library:'%s'"; |
6800 const String& name = String::Handle(url()); | 6801 const String& name = String::Handle(url()); |
6801 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; | 6802 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; |
6802 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 6803 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
6803 OS::SNPrint(chars, len, kFormat, name.ToCString()); | 6804 OS::SNPrint(chars, len, kFormat, name.ToCString()); |
6804 return chars; | 6805 return chars; |
6805 } | 6806 } |
6806 | 6807 |
6807 | 6808 |
6808 RawLibrary* LibraryPrefix::GetLibrary(int index) const { | 6809 RawLibrary* LibraryPrefix::GetLibrary(int index) const { |
6809 Library& lib = Library::Handle(); | 6810 if ((index >= 0) || (index < num_imports())) { |
6810 if ((index >= 0) || (index < num_libs())) { | 6811 const Array& imports = Array::Handle(this->imports()); |
6811 Array& libs = Array::Handle(libraries()); | 6812 const Namespace& import = Namespace::CheckedHandle(imports.At(index)); |
6812 lib ^= libs.At(index); | 6813 return import.library(); |
6813 } | 6814 } |
6814 return lib.raw(); | 6815 return Library::null(); |
6815 } | 6816 } |
6816 | 6817 |
6817 | 6818 |
6818 bool LibraryPrefix::ContainsLibrary(const Library& library) const { | 6819 bool LibraryPrefix::ContainsLibrary(const Library& library) const { |
6819 intptr_t num_current_libs = num_libs(); | 6820 intptr_t num_current_imports = num_imports(); |
6820 if (num_current_libs > 0) { | 6821 if (num_current_imports > 0) { |
6821 Library& lib = Library::Handle(); | 6822 Library& lib = Library::Handle(); |
6822 const String& url = String::Handle(library.url()); | 6823 const String& url = String::Handle(library.url()); |
6823 String& lib_url = String::Handle(); | 6824 String& lib_url = String::Handle(); |
6824 for (intptr_t i = 0; i < num_current_libs; i++) { | 6825 for (intptr_t i = 0; i < num_current_imports; i++) { |
6825 lib = GetLibrary(i); | 6826 lib = GetLibrary(i); |
6826 ASSERT(!lib.IsNull()); | 6827 ASSERT(!lib.IsNull()); |
6827 lib_url = lib.url(); | 6828 lib_url = lib.url(); |
6828 if (url.Equals(lib_url)) { | 6829 if (url.Equals(lib_url)) { |
6829 return true; | 6830 return true; |
6830 } | 6831 } |
6831 } | 6832 } |
6832 } | 6833 } |
6833 return false; | 6834 return false; |
6834 } | 6835 } |
6835 | 6836 |
6836 void LibraryPrefix::AddLibrary(const Library& library) const { | |
6837 intptr_t num_current_libs = num_libs(); | |
6838 | 6837 |
6839 // First check if the library is already in the list of libraries imported. | 6838 void LibraryPrefix::AddImport(const Namespace& import) const { |
6840 if (ContainsLibrary(library)) { | 6839 intptr_t num_current_imports = num_imports(); |
siva
2012/09/24 18:28:51
This seems to imply that a library can be imported
hausner
2012/09/24 20:25:43
The spec does not say what happens if the combinat
| |
6841 return; // Library already imported with same prefix. | |
6842 } | |
6843 | 6840 |
6844 // The library needs to be added to the list. | 6841 // The library needs to be added to the list. |
6845 Array& libs = Array::Handle(libraries()); | 6842 Array& imports = Array::Handle(this->imports()); |
6846 const intptr_t length = (libs.IsNull()) ? 0 : libs.Length(); | 6843 const intptr_t length = (imports.IsNull()) ? 0 : imports.Length(); |
6847 // Grow the list if it is full. | 6844 // Grow the list if it is full. |
6848 if (num_current_libs >= length) { | 6845 if (num_current_imports >= length) { |
6849 const intptr_t new_length = length + kIncrementSize; | 6846 const intptr_t new_length = length + kIncrementSize; |
6850 libs = Array::Grow(libs, new_length, Heap::kOld); | 6847 imports = Array::Grow(imports, new_length, Heap::kOld); |
6851 set_libraries(libs); | 6848 set_imports(imports); |
6852 } | 6849 } |
6853 libs.SetAt(num_current_libs, library); | 6850 imports.SetAt(num_current_imports, import); |
6854 set_num_libs(num_current_libs + 1); | 6851 set_num_imports(num_current_imports + 1); |
6855 } | 6852 } |
6856 | 6853 |
6857 | 6854 |
6858 RawClass* LibraryPrefix::LookupLocalClass(const String& class_name) const { | 6855 RawClass* LibraryPrefix::LookupLocalClass(const String& class_name) const { |
6859 Array& libs = Array::Handle(libraries()); | 6856 Array& imports = Array::Handle(this->imports()); |
6860 Class& resolved_class = Class::Handle(); | 6857 Object& obj = Object::Handle(); |
6861 Library& lib = Library::Handle(); | 6858 Namespace& import = Namespace::Handle(); |
6862 for (intptr_t i = 0; i < num_libs(); i++) { | 6859 for (intptr_t i = 0; i < num_imports(); i++) { |
6863 lib ^= libs.At(i); | 6860 import ^= imports.At(i); |
6864 ASSERT(!lib.IsNull()); | 6861 obj = import.Lookup(class_name); |
6865 resolved_class = lib.LookupLocalClass(class_name); | 6862 if (!obj.IsNull() && obj.IsClass()) { |
6866 if (!resolved_class.IsNull()) { | 6863 // TODO(hausner): |
6867 return resolved_class.raw(); | 6864 return Class::Cast(obj).raw(); |
6868 } | 6865 } |
6869 } | 6866 } |
6870 return Class::null(); | 6867 return Class::null(); |
6871 } | 6868 } |
6872 | 6869 |
6873 | 6870 |
6874 RawLibraryPrefix* LibraryPrefix::New() { | 6871 RawLibraryPrefix* LibraryPrefix::New() { |
6875 ASSERT(Object::library_prefix_class() != Class::null()); | 6872 ASSERT(Object::library_prefix_class() != Class::null()); |
6876 RawObject* raw = Object::Allocate(LibraryPrefix::kClassId, | 6873 RawObject* raw = Object::Allocate(LibraryPrefix::kClassId, |
6877 LibraryPrefix::InstanceSize(), | 6874 LibraryPrefix::InstanceSize(), |
6878 Heap::kOld); | 6875 Heap::kOld); |
6879 return reinterpret_cast<RawLibraryPrefix*>(raw); | 6876 return reinterpret_cast<RawLibraryPrefix*>(raw); |
6880 } | 6877 } |
6881 | 6878 |
6882 | 6879 |
6883 RawLibraryPrefix* LibraryPrefix::New(const String& name, const Library& lib) { | 6880 RawLibraryPrefix* LibraryPrefix::New(const String& name, |
6881 const Namespace& import) { | |
6884 const LibraryPrefix& result = LibraryPrefix::Handle(LibraryPrefix::New()); | 6882 const LibraryPrefix& result = LibraryPrefix::Handle(LibraryPrefix::New()); |
6885 result.set_name(name); | 6883 result.set_name(name); |
6886 result.set_num_libs(0); | 6884 result.set_num_imports(0); |
6887 result.AddLibrary(lib); | 6885 result.set_imports(Array::Handle(Array::New(kInitialSize))); |
6886 result.AddImport(import); | |
6888 return result.raw(); | 6887 return result.raw(); |
6889 } | 6888 } |
6890 | 6889 |
6891 | 6890 |
6891 void LibraryPrefix::set_name(const String& value) const { | |
6892 ASSERT(value.IsSymbol()); | |
6893 StorePointer(&raw_ptr()->name_, value.raw()); | |
6894 } | |
6895 | |
6896 | |
6897 void LibraryPrefix::set_imports(const Array& value) const { | |
6898 StorePointer(&raw_ptr()->imports_, value.raw()); | |
6899 } | |
6900 | |
6901 | |
6902 void LibraryPrefix::set_num_imports(intptr_t value) const { | |
6903 raw_ptr()->num_imports_ = value; | |
6904 } | |
6905 | |
6906 | |
6892 const char* LibraryPrefix::ToCString() const { | 6907 const char* LibraryPrefix::ToCString() const { |
6893 const char* kFormat = "LibraryPrefix:'%s'"; | 6908 const char* kFormat = "LibraryPrefix:'%s'"; |
6894 const String& prefix = String::Handle(name()); | 6909 const String& prefix = String::Handle(name()); |
6895 intptr_t len = OS::SNPrint(NULL, 0, kFormat, prefix.ToCString()) + 1; | 6910 intptr_t len = OS::SNPrint(NULL, 0, kFormat, prefix.ToCString()) + 1; |
6896 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 6911 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
6897 OS::SNPrint(chars, len, kFormat, prefix.ToCString()); | 6912 OS::SNPrint(chars, len, kFormat, prefix.ToCString()); |
6898 return chars; | 6913 return chars; |
6899 } | 6914 } |
6900 | 6915 |
6901 | 6916 |
6902 void LibraryPrefix::set_name(const String& value) const { | 6917 const char* Namespace::ToCString() const { |
6903 ASSERT(value.IsSymbol()); | 6918 const char* kFormat = "Namespace for library '%s'"; |
6904 StorePointer(&raw_ptr()->name_, value.raw()); | 6919 const Library& lib = Library::Handle(library()); |
6920 intptr_t len = OS::SNPrint(NULL, 0, kFormat, lib.ToCString()) + 1; | |
6921 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | |
6922 OS::SNPrint(chars, len, kFormat, lib.ToCString()); | |
6923 return chars; | |
6905 } | 6924 } |
6906 | 6925 |
6907 | 6926 |
6908 void LibraryPrefix::set_libraries(const Array& value) const { | 6927 bool Namespace::HidesName(const String& name) const { |
6909 StorePointer(&raw_ptr()->libraries_, value.raw()); | 6928 // Check whether the name is in the list of explicitly hidden names. |
6929 if (hide_names() != Array::null()) { | |
6930 const Array& names = Array::Handle(hide_names()); | |
6931 String& hidden = String::Handle(); | |
6932 intptr_t num_names = names.Length(); | |
6933 for (intptr_t i = 0; i < num_names; i++) { | |
6934 hidden ^= names.At(i); | |
6935 if (name.Equals(hidden)) { | |
6936 return true; | |
6937 } | |
6938 } | |
6939 } | |
6940 // The name is not explicitly hidden. Now check whether it is in the | |
6941 // list of explicitly visible names, if there is one. | |
6942 if (show_names() != Array::null()) { | |
6943 const Array& names = Array::Handle(show_names()); | |
6944 String& shown = String::Handle(); | |
6945 intptr_t num_names = names.Length(); | |
6946 for (intptr_t i = 0; i < num_names; i++) { | |
6947 shown ^= names.At(i); | |
6948 if (name.Equals(shown)) { | |
6949 return false; | |
6950 } | |
6951 } | |
6952 // There is a list of visible names. The name we're looking for is not | |
6953 // contained in the list, so it is hidden. | |
6954 return true; | |
6955 } | |
6956 // The name is not filtered out. | |
6957 return false; | |
6910 } | 6958 } |
6911 | 6959 |
6912 | 6960 |
6913 void LibraryPrefix::set_num_libs(intptr_t value) const { | 6961 RawObject* Namespace::Lookup(const String& name) const { |
6914 raw_ptr()->num_libs_ = value; | 6962 intptr_t i = 0; |
6963 const Library& lib = Library::Handle(library()); | |
6964 const Object& obj = Object::Handle(lib.LookupEntry(name, &i)); | |
6965 if (obj.IsNull() || HidesName(name)) { | |
6966 return Object::null(); | |
6967 } | |
6968 return obj.raw(); | |
6969 } | |
6970 | |
6971 | |
6972 RawNamespace* Namespace::New() { | |
6973 ASSERT(Object::namespace_class() != Class::null()); | |
6974 RawObject* raw = Object::Allocate(Namespace::kClassId, | |
6975 Namespace::InstanceSize(), | |
6976 Heap::kOld); | |
6977 return reinterpret_cast<RawNamespace*>(raw); | |
6978 } | |
6979 | |
6980 | |
6981 RawNamespace* Namespace::New(const Library& library, | |
6982 const Array& show_names, | |
6983 const Array& hide_names) { | |
6984 ASSERT(show_names.IsNull() || (show_names.Length() > 0)); | |
6985 ASSERT(hide_names.IsNull() || (hide_names.Length() > 0)); | |
6986 const Namespace& result = Namespace::Handle(Namespace::New()); | |
6987 result.StorePointer(&result.raw_ptr()->library_, library.raw()); | |
6988 result.StorePointer(&result.raw_ptr()->show_names_, show_names.raw()); | |
6989 result.StorePointer(&result.raw_ptr()->hide_names_, hide_names.raw()); | |
6990 return result.raw(); | |
6915 } | 6991 } |
6916 | 6992 |
6917 | 6993 |
6918 RawError* Library::CompileAll() { | 6994 RawError* Library::CompileAll() { |
6919 Error& error = Error::Handle(); | 6995 Error& error = Error::Handle(); |
6920 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 6996 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
6921 Isolate::Current()->object_store()->libraries()); | 6997 Isolate::Current()->object_store()->libraries()); |
6922 Library& lib = Library::Handle(); | 6998 Library& lib = Library::Handle(); |
6923 Class& cls = Class::Handle(); | 6999 Class& cls = Class::Handle(); |
6924 for (int i = 0; i < libs.Length(); i++) { | 7000 for (int i = 0; i < libs.Length(); i++) { |
(...skipping 4909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11834 } | 11910 } |
11835 return result.raw(); | 11911 return result.raw(); |
11836 } | 11912 } |
11837 | 11913 |
11838 | 11914 |
11839 const char* WeakProperty::ToCString() const { | 11915 const char* WeakProperty::ToCString() const { |
11840 return "_WeakProperty"; | 11916 return "_WeakProperty"; |
11841 } | 11917 } |
11842 | 11918 |
11843 } // namespace dart | 11919 } // namespace dart |
OLD | NEW |