Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Side by Side Diff: runtime/vm/object.cc

Issue 10967052: Support for show/hide combinators (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 SET_CLASS_NAME(type_arguments, TypeArguments); 443 SET_CLASS_NAME(type_arguments, TypeArguments);
440 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments); 444 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments);
441 SET_CLASS_NAME(patch_class, PatchClass); 445 SET_CLASS_NAME(patch_class, PatchClass);
442 SET_CLASS_NAME(function, Function); 446 SET_CLASS_NAME(function, Function);
443 SET_CLASS_NAME(closure_data, ClosureData); 447 SET_CLASS_NAME(closure_data, ClosureData);
444 SET_CLASS_NAME(field, Field); 448 SET_CLASS_NAME(field, Field);
445 SET_CLASS_NAME(literal_token, LiteralToken); 449 SET_CLASS_NAME(literal_token, LiteralToken);
446 SET_CLASS_NAME(token_stream, TokenStream); 450 SET_CLASS_NAME(token_stream, TokenStream);
447 SET_CLASS_NAME(script, Script); 451 SET_CLASS_NAME(script, Script);
448 SET_CLASS_NAME(library, LibraryClass); 452 SET_CLASS_NAME(library, LibraryClass);
449 SET_CLASS_NAME(library_prefix, LibraryPrefix); 453 SET_CLASS_NAME(library_prefix, LibraryPrefix);
siva 2012/09/24 21:20:40 oops forgot this: We are missing SET_CLASS_NAME(na
hausner 2012/09/24 21:41:06 Done.
450 SET_CLASS_NAME(code, Code); 454 SET_CLASS_NAME(code, Code);
451 SET_CLASS_NAME(instructions, Instructions); 455 SET_CLASS_NAME(instructions, Instructions);
452 SET_CLASS_NAME(pc_descriptors, PcDescriptors); 456 SET_CLASS_NAME(pc_descriptors, PcDescriptors);
453 SET_CLASS_NAME(stackmap, Stackmap); 457 SET_CLASS_NAME(stackmap, Stackmap);
454 SET_CLASS_NAME(var_descriptors, LocalVarDescriptors); 458 SET_CLASS_NAME(var_descriptors, LocalVarDescriptors);
455 SET_CLASS_NAME(exception_handlers, ExceptionHandlers); 459 SET_CLASS_NAME(exception_handlers, ExceptionHandlers);
456 SET_CLASS_NAME(deopt_info, DeoptInfo); 460 SET_CLASS_NAME(deopt_info, DeoptInfo);
457 SET_CLASS_NAME(context, Context); 461 SET_CLASS_NAME(context, Context);
458 SET_CLASS_NAME(context_scope, ContextScope); 462 SET_CLASS_NAME(context_scope, ContextScope);
459 SET_CLASS_NAME(icdata, ICData); 463 SET_CLASS_NAME(icdata, ICData);
(...skipping 5804 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 20 matching lines...) Expand all
6314 Function& function = Function::Handle(LookupLocalFunction(name)); 6317 Function& function = Function::Handle(LookupLocalFunction(name));
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 any imported libs.
6325 // libs.
6326 const Array& imports = Array::Handle(this->imports()); 6328 const Array& imports = Array::Handle(this->imports());
6327 Library& import_lib = Library::Handle(); 6329 Namespace& import = Namespace::Handle();
6330 Object& obj = Object::Handle();
6328 for (intptr_t j = 0; j < this->num_imports(); j++) { 6331 for (intptr_t j = 0; j < this->num_imports(); j++) {
6329 import_lib ^= imports.At(j); 6332 import ^= imports.At(j);
6330 6333 obj = import.Lookup(name);
6331 6334 if (!obj.IsNull() && obj.IsFunction()) {
6332 function = import_lib.LookupLocalFunction(name); 6335 function ^= obj.raw();
6333 if (!function.IsNull()) {
6334 return function.raw(); 6336 return function.raw();
6335 } 6337 }
6336 } 6338 }
6337 return Function::null(); 6339 return Function::null();
6338 } 6340 }
6339 6341
6340 6342
6341 RawFunction* Library::LookupLocalFunction(const String& name) const { 6343 RawFunction* Library::LookupLocalFunction(const String& name) const {
6342 Isolate* isolate = Isolate::Current(); 6344 Isolate* isolate = Isolate::Current();
6343 Object& obj = Object::Handle(isolate, Object::null()); 6345 Object& obj = Object::Handle(isolate, Object::null());
(...skipping 10 matching lines...) Expand all
6354 return Function::null(); 6356 return Function::null();
6355 } 6357 }
6356 6358
6357 6359
6358 RawObject* Library::LookupObject(const String& name) const { 6360 RawObject* Library::LookupObject(const String& name) const {
6359 // First check if name is found in the local scope of the library. 6361 // First check if name is found in the local scope of the library.
6360 Object& obj = Object::Handle(LookupLocalObject(name)); 6362 Object& obj = Object::Handle(LookupLocalObject(name));
6361 if (!obj.IsNull()) { 6363 if (!obj.IsNull()) {
6362 return obj.raw(); 6364 return obj.raw();
6363 } 6365 }
6364 // Now check if name is found in the top level scope of any imported libs. 6366 // Now check if name is found in any imported libs.
6365 const Array& imports = Array::Handle(this->imports()); 6367 const Array& imports = Array::Handle(this->imports());
6366 Library& import_lib = Library::Handle(); 6368 Namespace& import = Namespace::Handle();
6367 for (intptr_t j = 0; j < this->num_imports(); j++) { 6369 for (intptr_t j = 0; j < this->num_imports(); j++) {
6368 import_lib ^= imports.At(j); 6370 import ^= imports.At(j);
6369 obj = import_lib.LookupLocalObject(name); 6371 obj = import.Lookup(name);
6370 if (!obj.IsNull()) { 6372 if (!obj.IsNull()) {
6371 return obj.raw(); 6373 return obj.raw();
6372 } 6374 }
6373 } 6375 }
6374 return Object::null(); 6376 return Object::null();
6375 } 6377 }
6376 6378
6377 6379
6378 RawClass* Library::LookupClass(const String& name) const { 6380 RawClass* Library::LookupClass(const String& name) const {
6379 Object& obj = Object::Handle(LookupObject(name)); 6381 Object& obj = Object::Handle(LookupObject(name));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
6436 anon_array.SetAt(num_anonymous, cls); 6438 anon_array.SetAt(num_anonymous, cls);
6437 num_anonymous++; 6439 num_anonymous++;
6438 raw_ptr()->num_anonymous_ = num_anonymous; 6440 raw_ptr()->num_anonymous_ = num_anonymous;
6439 } 6441 }
6440 6442
6441 6443
6442 RawLibrary* Library::LookupImport(const String& url) const { 6444 RawLibrary* Library::LookupImport(const String& url) const {
6443 Isolate* isolate = Isolate::Current(); 6445 Isolate* isolate = Isolate::Current();
6444 const Array& imports = Array::Handle(isolate, this->imports()); 6446 const Array& imports = Array::Handle(isolate, this->imports());
6445 intptr_t num_imports = this->num_imports(); 6447 intptr_t num_imports = this->num_imports();
6448 Namespace& import = Namespace::Handle(isolate, Namespace::null());
6446 Library& lib = Library::Handle(isolate, Library::null()); 6449 Library& lib = Library::Handle(isolate, Library::null());
6447 String& import_url = String::Handle(isolate, String::null()); 6450 String& import_url = String::Handle(isolate, String::null());
6448 for (int i = 0; i < num_imports; i++) { 6451 for (int i = 0; i < num_imports; i++) {
6449 lib ^= imports.At(i); 6452 import ^= imports.At(i);
6453 lib = import.library();
6450 import_url = lib.url(); 6454 import_url = lib.url();
6451 if (url.Equals(import_url)) { 6455 if (url.Equals(import_url)) {
6452 return lib.raw(); 6456 return lib.raw();
6453 } 6457 }
6454 } 6458 }
6455 return Library::null(); 6459 return Library::null();
6456 } 6460 }
6457 6461
6458 6462
6459 RawLibrary* Library::ImportAt(intptr_t index) const { 6463 RawLibrary* Library::ImportLibraryAt(intptr_t index) const {
6460 if ((index < 0) || index >= num_imports()) { 6464 Namespace& import = Namespace::Handle(ImportAt(index));
6465 if (import.IsNull()) {
6461 return Library::null(); 6466 return Library::null();
6462 } 6467 }
6463 const Array& import_list = Array::Handle(imports()); 6468 return import.library();
6464 Library& lib = Library::Handle();
6465 lib ^= import_list.At(index);
6466 return lib.raw();
6467 } 6469 }
6468 6470
6469 6471
6470 RawLibraryPrefix* Library::ImportPrefixAt(intptr_t index) const { 6472 RawNamespace* Library::ImportAt(intptr_t index) const {
6471 const Library& imported = Library::Handle(ImportAt(index)); 6473 if ((index < 0) || index >= num_imports()) {
6472 if (imported.IsNull()) { 6474 return Namespace::null();
6473 return LibraryPrefix::null();
6474 } 6475 }
6475 DictionaryIterator it(*this); 6476 const Array& import_list = Array::Handle(imports());
6476 Object& obj = Object::Handle(); 6477 Namespace& import = Namespace::Handle();
6477 while (it.HasNext()) { 6478 import ^= import_list.At(index);
6478 obj = it.GetNext(); 6479 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 } 6480 }
6488 6481
6489 6482
6490 bool Library::ImportsCorelib() const { 6483 bool Library::ImportsCorelib() const {
6491 Isolate* isolate = Isolate::Current(); 6484 Isolate* isolate = Isolate::Current();
6492 Library& imported = Library::Handle(isolate); 6485 Library& imported = Library::Handle(isolate);
6493 intptr_t count = num_imports(); 6486 intptr_t count = num_imports();
6494 for (int i = 0; i < count; i++) { 6487 for (int i = 0; i < count; i++) {
6495 imported = ImportAt(i); 6488 imported = ImportLibraryAt(i);
6496 if (imported.IsCoreLibrary()) { 6489 if (imported.IsCoreLibrary()) {
6497 return true; 6490 return true;
6498 } 6491 }
6499 } 6492 }
6500 LibraryPrefix& prefix = LibraryPrefix::Handle(isolate); 6493 LibraryPrefix& prefix = LibraryPrefix::Handle(isolate);
6501 LibraryPrefixIterator it(*this); 6494 LibraryPrefixIterator it(*this);
6502 while (it.HasNext()) { 6495 while (it.HasNext()) {
6503 prefix = it.GetNext(); 6496 prefix = it.GetNext();
6504 count = prefix.num_libs(); 6497 count = prefix.num_imports();
6505 for (int i = 0; i < count; i++) { 6498 for (int i = 0; i < count; i++) {
6506 imported = prefix.GetLibrary(i); 6499 imported = prefix.GetLibrary(i);
6507 if (imported.IsCoreLibrary()) { 6500 if (imported.IsCoreLibrary()) {
6508 return true; 6501 return true;
6509 } 6502 }
6510 } 6503 }
6511 } 6504 }
6512 return false; 6505 return false;
6513 } 6506 }
6514 6507
6515 6508
6516 void Library::AddImport(const Library& library) const { 6509 void Library::AddImport(const Namespace& ns) const {
6517 Array& imports = Array::Handle(this->imports()); 6510 Array& imports = Array::Handle(this->imports());
6518 intptr_t capacity = imports.Length(); 6511 intptr_t capacity = imports.Length();
6519 if (num_imports() == capacity) { 6512 if (num_imports() == capacity) {
6520 capacity = capacity + kImportsCapacityIncrement; 6513 capacity = capacity + kImportsCapacityIncrement;
6521 imports = Array::Grow(imports, capacity); 6514 imports = Array::Grow(imports, capacity);
6522 StorePointer(&raw_ptr()->imports_, imports.raw()); 6515 StorePointer(&raw_ptr()->imports_, imports.raw());
6523 } 6516 }
6524 intptr_t index = num_imports(); 6517 intptr_t index = num_imports();
6525 imports.SetAt(index, library); 6518 imports.SetAt(index, ns);
6526 set_num_imports(index + 1); 6519 set_num_imports(index + 1);
6527 } 6520 }
6528 6521
6529 6522
6530 void Library::InitClassDictionary() const { 6523 void Library::InitClassDictionary() const {
6531 // The last element of the dictionary specifies the number of in use slots. 6524 // The last element of the dictionary specifies the number of in use slots.
6532 // TODO(iposva): Find reasonable initial size. 6525 // TODO(iposva): Find reasonable initial size.
6533 const int kInitialElementCount = 16; 6526 const int kInitialElementCount = 16;
6534 6527
6535 const Array& dictionary = 6528 const Array& dictionary =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
6568 result.raw_ptr()->imports_ = Object::empty_array(); 6561 result.raw_ptr()->imports_ = Object::empty_array();
6569 result.raw_ptr()->loaded_scripts_ = Array::null(); 6562 result.raw_ptr()->loaded_scripts_ = Array::null();
6570 result.set_native_entry_resolver(NULL); 6563 result.set_native_entry_resolver(NULL);
6571 result.raw_ptr()->corelib_imported_ = true; 6564 result.raw_ptr()->corelib_imported_ = true;
6572 result.set_debuggable(false); 6565 result.set_debuggable(false);
6573 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; 6566 result.raw_ptr()->load_state_ = RawLibrary::kAllocated;
6574 result.raw_ptr()->index_ = -1; 6567 result.raw_ptr()->index_ = -1;
6575 result.InitClassDictionary(); 6568 result.InitClassDictionary();
6576 result.InitImportList(); 6569 result.InitImportList();
6577 if (import_core_lib) { 6570 if (import_core_lib) {
6578 Library& core_lib = Library::Handle(Library::CoreLibrary()); 6571 const Library& core_lib = Library::Handle(Library::CoreLibrary());
6579 ASSERT(!core_lib.IsNull()); 6572 ASSERT(!core_lib.IsNull());
6580 result.AddImport(core_lib); 6573 const Namespace& ns = Namespace::Handle(
6574 Namespace::New(core_lib, Array::Handle(), Array::Handle()));
6575 result.AddImport(ns);
6581 } 6576 }
6582 return result.raw(); 6577 return result.raw();
6583 } 6578 }
6584 6579
6585 6580
6586 RawLibrary* Library::New(const String& url) { 6581 RawLibrary* Library::New(const String& url) {
6587 return NewLibraryHelper(url, false); 6582 return NewLibraryHelper(url, false);
6588 } 6583 }
6589 6584
6590 6585
6591 void Library::InitCoreLibrary(Isolate* isolate) { 6586 void Library::InitCoreLibrary(Isolate* isolate) {
6592 const String& core_lib_url = String::Handle(Symbols::New("dart:core")); 6587 const String& core_lib_url = String::Handle(Symbols::New("dart:core"));
6593 const Library& core_lib = 6588 const Library& core_lib =
6594 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); 6589 Library::Handle(Library::NewLibraryHelper(core_lib_url, false));
6595 core_lib.Register(); 6590 core_lib.Register();
6591 const Namespace& core_ns = Namespace::Handle(
6592 Namespace::New(core_lib, Array::Handle(), Array::Handle()));
6596 isolate->object_store()->set_core_library(core_lib); 6593 isolate->object_store()->set_core_library(core_lib);
6597 const String& core_impl_lib_url = 6594 const String& core_impl_lib_url =
6598 String::Handle(Symbols::New("dart:coreimpl")); 6595 String::Handle(Symbols::New("dart:coreimpl"));
6599 const Library& core_impl_lib = 6596 const Library& core_impl_lib =
6600 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); 6597 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false));
6601 isolate->object_store()->set_core_impl_library(core_impl_lib); 6598 isolate->object_store()->set_core_impl_library(core_impl_lib);
6602 core_impl_lib.Register(); 6599 core_impl_lib.Register();
6603 core_lib.AddImport(core_impl_lib); 6600 const Namespace& impl_ns = Namespace::Handle(
6604 core_impl_lib.AddImport(core_lib); 6601 Namespace::New(core_impl_lib, Array::Handle(), Array::Handle()));
6602 core_lib.AddImport(impl_ns);
6603 core_impl_lib.AddImport(core_ns);
6605 Library::InitMathLibrary(isolate); 6604 Library::InitMathLibrary(isolate);
6606 const Library& math_lib = Library::Handle(Library::MathLibrary()); 6605 const Library& math_lib = Library::Handle(Library::MathLibrary());
6607 core_lib.AddImport(math_lib); 6606 const Namespace& math_ns = Namespace::Handle(
6608 core_impl_lib.AddImport(math_lib); 6607 Namespace::New(math_lib, Array::Handle(), Array::Handle()));
6608 core_lib.AddImport(math_ns);
6609 core_impl_lib.AddImport(math_ns);
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 const Namespace& impl_ns = Namespace::Handle(
6626 Namespace::New(core_impl_lib, Array::Handle(), Array::Handle()));
6627 lib.AddImport(impl_ns);
6625 isolate->object_store()->set_math_library(lib); 6628 isolate->object_store()->set_math_library(lib);
6626 } 6629 }
6627 6630
6628 6631
6629 void Library::InitIsolateLibrary(Isolate* isolate) { 6632 void Library::InitIsolateLibrary(Isolate* isolate) {
6630 const String& url = String::Handle(Symbols::New("dart:isolate")); 6633 const String& url = String::Handle(Symbols::New("dart:isolate"));
6631 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6634 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6632 lib.Register(); 6635 lib.Register();
6633 isolate->object_store()->set_isolate_library(lib); 6636 isolate->object_store()->set_isolate_library(lib);
6634 } 6637 }
6635 6638
6636 6639
6637 void Library::InitMirrorsLibrary(Isolate* isolate) { 6640 void Library::InitMirrorsLibrary(Isolate* isolate) {
6638 const String& url = String::Handle(Symbols::New("dart:mirrors")); 6641 const String& url = String::Handle(Symbols::New("dart:mirrors"));
6639 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6642 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6640 lib.Register(); 6643 lib.Register();
6641 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); 6644 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
6642 lib.AddImport(isolate_lib); 6645 const Namespace& isolate_ns = Namespace::Handle(
6646 Namespace::New(isolate_lib, Array::Handle(), Array::Handle()));
6647 lib.AddImport(isolate_ns);
6643 const Library& wrappers_lib = 6648 const Library& wrappers_lib =
6644 Library::Handle(Library::NativeWrappersLibrary()); 6649 Library::Handle(Library::NativeWrappersLibrary());
6645 lib.AddImport(wrappers_lib); 6650 const Namespace& wrappers_ns = Namespace::Handle(
6651 Namespace::New(wrappers_lib, Array::Handle(), Array::Handle()));
6652 lib.AddImport(wrappers_ns);
6646 isolate->object_store()->set_mirrors_library(lib); 6653 isolate->object_store()->set_mirrors_library(lib);
6647 } 6654 }
6648 6655
6649 6656
6650 void Library::InitScalarlistLibrary(Isolate* isolate) { 6657 void Library::InitScalarlistLibrary(Isolate* isolate) {
6651 const String& url = String::Handle(Symbols::New("dart:scalarlist")); 6658 const String& url = String::Handle(Symbols::New("dart:scalarlist"));
6652 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6659 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6653 lib.Register(); 6660 lib.Register();
6654 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); 6661 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary());
6655 lib.AddImport(core_impl_lib); 6662 const Namespace& impl_ns = Namespace::Handle(
6663 Namespace::New(core_impl_lib, Array::Handle(), Array::Handle()));
6664 lib.AddImport(impl_ns);
6656 isolate->object_store()->set_scalarlist_library(lib); 6665 isolate->object_store()->set_scalarlist_library(lib);
6657 } 6666 }
6658 6667
6659 6668
6660 void Library::InitNativeWrappersLibrary(Isolate* isolate) { 6669 void Library::InitNativeWrappersLibrary(Isolate* isolate) {
6661 static const int kNumNativeWrappersClasses = 4; 6670 static const int kNumNativeWrappersClasses = 4;
6662 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); 6671 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10);
6663 const String& native_flds_lib_url = String::Handle( 6672 const String& native_flds_lib_url = String::Handle(
6664 Symbols::New("dart:nativewrappers")); 6673 Symbols::New("dart:nativewrappers"));
6665 const Library& native_flds_lib = Library::Handle( 6674 const Library& native_flds_lib = Library::Handle(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
6799 const char* kFormat = "Library:'%s'"; 6808 const char* kFormat = "Library:'%s'";
6800 const String& name = String::Handle(url()); 6809 const String& name = String::Handle(url());
6801 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; 6810 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
6802 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 6811 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
6803 OS::SNPrint(chars, len, kFormat, name.ToCString()); 6812 OS::SNPrint(chars, len, kFormat, name.ToCString());
6804 return chars; 6813 return chars;
6805 } 6814 }
6806 6815
6807 6816
6808 RawLibrary* LibraryPrefix::GetLibrary(int index) const { 6817 RawLibrary* LibraryPrefix::GetLibrary(int index) const {
6809 Library& lib = Library::Handle(); 6818 if ((index >= 0) || (index < num_imports())) {
6810 if ((index >= 0) || (index < num_libs())) { 6819 const Array& imports = Array::Handle(this->imports());
6811 Array& libs = Array::Handle(libraries()); 6820 const Namespace& import = Namespace::CheckedHandle(imports.At(index));
6812 lib ^= libs.At(index); 6821 return import.library();
6813 } 6822 }
6814 return lib.raw(); 6823 return Library::null();
6815 } 6824 }
6816 6825
6817 6826
6818 bool LibraryPrefix::ContainsLibrary(const Library& library) const { 6827 bool LibraryPrefix::ContainsLibrary(const Library& library) const {
6819 intptr_t num_current_libs = num_libs(); 6828 intptr_t num_current_imports = num_imports();
6820 if (num_current_libs > 0) { 6829 if (num_current_imports > 0) {
6821 Library& lib = Library::Handle(); 6830 Library& lib = Library::Handle();
6822 const String& url = String::Handle(library.url()); 6831 const String& url = String::Handle(library.url());
6823 String& lib_url = String::Handle(); 6832 String& lib_url = String::Handle();
6824 for (intptr_t i = 0; i < num_current_libs; i++) { 6833 for (intptr_t i = 0; i < num_current_imports; i++) {
6825 lib = GetLibrary(i); 6834 lib = GetLibrary(i);
6826 ASSERT(!lib.IsNull()); 6835 ASSERT(!lib.IsNull());
6827 lib_url = lib.url(); 6836 lib_url = lib.url();
6828 if (url.Equals(lib_url)) { 6837 if (url.Equals(lib_url)) {
6829 return true; 6838 return true;
6830 } 6839 }
6831 } 6840 }
6832 } 6841 }
6833 return false; 6842 return false;
6834 } 6843 }
6835 6844
6836 void LibraryPrefix::AddLibrary(const Library& library) const {
6837 intptr_t num_current_libs = num_libs();
6838 6845
6839 // First check if the library is already in the list of libraries imported. 6846 void LibraryPrefix::AddImport(const Namespace& import) const {
6840 if (ContainsLibrary(library)) { 6847 intptr_t num_current_imports = num_imports();
6841 return; // Library already imported with same prefix.
6842 }
6843 6848
6844 // The library needs to be added to the list. 6849 // The library needs to be added to the list.
6845 Array& libs = Array::Handle(libraries()); 6850 Array& imports = Array::Handle(this->imports());
6846 const intptr_t length = (libs.IsNull()) ? 0 : libs.Length(); 6851 const intptr_t length = (imports.IsNull()) ? 0 : imports.Length();
6847 // Grow the list if it is full. 6852 // Grow the list if it is full.
6848 if (num_current_libs >= length) { 6853 if (num_current_imports >= length) {
6849 const intptr_t new_length = length + kIncrementSize; 6854 const intptr_t new_length = length + kIncrementSize;
6850 libs = Array::Grow(libs, new_length, Heap::kOld); 6855 imports = Array::Grow(imports, new_length, Heap::kOld);
6851 set_libraries(libs); 6856 set_imports(imports);
6852 } 6857 }
6853 libs.SetAt(num_current_libs, library); 6858 imports.SetAt(num_current_imports, import);
6854 set_num_libs(num_current_libs + 1); 6859 set_num_imports(num_current_imports + 1);
6855 } 6860 }
6856 6861
6857 6862
6858 RawClass* LibraryPrefix::LookupLocalClass(const String& class_name) const { 6863 RawClass* LibraryPrefix::LookupLocalClass(const String& class_name) const {
6859 Array& libs = Array::Handle(libraries()); 6864 Array& imports = Array::Handle(this->imports());
6860 Class& resolved_class = Class::Handle(); 6865 Object& obj = Object::Handle();
6861 Library& lib = Library::Handle(); 6866 Namespace& import = Namespace::Handle();
6862 for (intptr_t i = 0; i < num_libs(); i++) { 6867 for (intptr_t i = 0; i < num_imports(); i++) {
6863 lib ^= libs.At(i); 6868 import ^= imports.At(i);
6864 ASSERT(!lib.IsNull()); 6869 obj = import.Lookup(class_name);
6865 resolved_class = lib.LookupLocalClass(class_name); 6870 if (!obj.IsNull() && obj.IsClass()) {
6866 if (!resolved_class.IsNull()) { 6871 // TODO(hausner):
6867 return resolved_class.raw(); 6872 return Class::Cast(obj).raw();
6868 } 6873 }
6869 } 6874 }
6870 return Class::null(); 6875 return Class::null();
6871 } 6876 }
6872 6877
6873 6878
6874 RawLibraryPrefix* LibraryPrefix::New() { 6879 RawLibraryPrefix* LibraryPrefix::New() {
6875 ASSERT(Object::library_prefix_class() != Class::null()); 6880 ASSERT(Object::library_prefix_class() != Class::null());
6876 RawObject* raw = Object::Allocate(LibraryPrefix::kClassId, 6881 RawObject* raw = Object::Allocate(LibraryPrefix::kClassId,
6877 LibraryPrefix::InstanceSize(), 6882 LibraryPrefix::InstanceSize(),
6878 Heap::kOld); 6883 Heap::kOld);
6879 return reinterpret_cast<RawLibraryPrefix*>(raw); 6884 return reinterpret_cast<RawLibraryPrefix*>(raw);
6880 } 6885 }
6881 6886
6882 6887
6883 RawLibraryPrefix* LibraryPrefix::New(const String& name, const Library& lib) { 6888 RawLibraryPrefix* LibraryPrefix::New(const String& name,
6889 const Namespace& import) {
6884 const LibraryPrefix& result = LibraryPrefix::Handle(LibraryPrefix::New()); 6890 const LibraryPrefix& result = LibraryPrefix::Handle(LibraryPrefix::New());
6885 result.set_name(name); 6891 result.set_name(name);
6886 result.set_num_libs(0); 6892 result.set_num_imports(0);
6887 result.AddLibrary(lib); 6893 result.set_imports(Array::Handle(Array::New(kInitialSize)));
6894 result.AddImport(import);
6888 return result.raw(); 6895 return result.raw();
6889 } 6896 }
6890 6897
6891 6898
6899 void LibraryPrefix::set_name(const String& value) const {
6900 ASSERT(value.IsSymbol());
6901 StorePointer(&raw_ptr()->name_, value.raw());
6902 }
6903
6904
6905 void LibraryPrefix::set_imports(const Array& value) const {
6906 StorePointer(&raw_ptr()->imports_, value.raw());
6907 }
6908
6909
6910 void LibraryPrefix::set_num_imports(intptr_t value) const {
6911 raw_ptr()->num_imports_ = value;
6912 }
6913
6914
6892 const char* LibraryPrefix::ToCString() const { 6915 const char* LibraryPrefix::ToCString() const {
6893 const char* kFormat = "LibraryPrefix:'%s'"; 6916 const char* kFormat = "LibraryPrefix:'%s'";
6894 const String& prefix = String::Handle(name()); 6917 const String& prefix = String::Handle(name());
6895 intptr_t len = OS::SNPrint(NULL, 0, kFormat, prefix.ToCString()) + 1; 6918 intptr_t len = OS::SNPrint(NULL, 0, kFormat, prefix.ToCString()) + 1;
6896 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 6919 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
6897 OS::SNPrint(chars, len, kFormat, prefix.ToCString()); 6920 OS::SNPrint(chars, len, kFormat, prefix.ToCString());
6898 return chars; 6921 return chars;
6899 } 6922 }
6900 6923
6901 6924
6902 void LibraryPrefix::set_name(const String& value) const { 6925 const char* Namespace::ToCString() const {
6903 ASSERT(value.IsSymbol()); 6926 const char* kFormat = "Namespace for library '%s'";
6904 StorePointer(&raw_ptr()->name_, value.raw()); 6927 const Library& lib = Library::Handle(library());
6928 intptr_t len = OS::SNPrint(NULL, 0, kFormat, lib.ToCString()) + 1;
6929 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
6930 OS::SNPrint(chars, len, kFormat, lib.ToCString());
6931 return chars;
6905 } 6932 }
6906 6933
6907 6934
6908 void LibraryPrefix::set_libraries(const Array& value) const { 6935 bool Namespace::HidesName(const String& name) const {
6909 StorePointer(&raw_ptr()->libraries_, value.raw()); 6936 // Check whether the name is in the list of explicitly hidden names.
6937 if (hide_names() != Array::null()) {
6938 const Array& names = Array::Handle(hide_names());
6939 String& hidden = String::Handle();
6940 intptr_t num_names = names.Length();
6941 for (intptr_t i = 0; i < num_names; i++) {
6942 hidden ^= names.At(i);
6943 if (name.Equals(hidden)) {
6944 return true;
6945 }
6946 }
6947 }
6948 // The name is not explicitly hidden. Now check whether it is in the
6949 // list of explicitly visible names, if there is one.
6950 if (show_names() != Array::null()) {
6951 const Array& names = Array::Handle(show_names());
6952 String& shown = String::Handle();
6953 intptr_t num_names = names.Length();
6954 for (intptr_t i = 0; i < num_names; i++) {
6955 shown ^= names.At(i);
6956 if (name.Equals(shown)) {
6957 return false;
6958 }
6959 }
6960 // There is a list of visible names. The name we're looking for is not
6961 // contained in the list, so it is hidden.
6962 return true;
6963 }
6964 // The name is not filtered out.
6965 return false;
6910 } 6966 }
6911 6967
6912 6968
6913 void LibraryPrefix::set_num_libs(intptr_t value) const { 6969 RawObject* Namespace::Lookup(const String& name) const {
6914 raw_ptr()->num_libs_ = value; 6970 intptr_t i = 0;
6971 const Library& lib = Library::Handle(library());
6972 const Object& obj = Object::Handle(lib.LookupEntry(name, &i));
6973 if (obj.IsNull() || HidesName(name)) {
6974 return Object::null();
6975 }
6976 return obj.raw();
6977 }
6978
6979
6980 RawNamespace* Namespace::New() {
6981 ASSERT(Object::namespace_class() != Class::null());
6982 RawObject* raw = Object::Allocate(Namespace::kClassId,
6983 Namespace::InstanceSize(),
6984 Heap::kOld);
6985 return reinterpret_cast<RawNamespace*>(raw);
6986 }
6987
6988
6989 RawNamespace* Namespace::New(const Library& library,
6990 const Array& show_names,
6991 const Array& hide_names) {
6992 ASSERT(show_names.IsNull() || (show_names.Length() > 0));
6993 ASSERT(hide_names.IsNull() || (hide_names.Length() > 0));
6994 const Namespace& result = Namespace::Handle(Namespace::New());
6995 result.StorePointer(&result.raw_ptr()->library_, library.raw());
6996 result.StorePointer(&result.raw_ptr()->show_names_, show_names.raw());
6997 result.StorePointer(&result.raw_ptr()->hide_names_, hide_names.raw());
6998 return result.raw();
6915 } 6999 }
6916 7000
6917 7001
6918 RawError* Library::CompileAll() { 7002 RawError* Library::CompileAll() {
6919 Error& error = Error::Handle(); 7003 Error& error = Error::Handle();
6920 const GrowableObjectArray& libs = GrowableObjectArray::Handle( 7004 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
6921 Isolate::Current()->object_store()->libraries()); 7005 Isolate::Current()->object_store()->libraries());
6922 Library& lib = Library::Handle(); 7006 Library& lib = Library::Handle();
6923 Class& cls = Class::Handle(); 7007 Class& cls = Class::Handle();
6924 for (int i = 0; i < libs.Length(); i++) { 7008 for (int i = 0; i < libs.Length(); i++) {
(...skipping 5008 matching lines...) Expand 10 before | Expand all | Expand 10 after
11933 } 12017 }
11934 return result.raw(); 12018 return result.raw();
11935 } 12019 }
11936 12020
11937 12021
11938 const char* WeakProperty::ToCString() const { 12022 const char* WeakProperty::ToCString() const {
11939 return "_WeakProperty"; 12023 return "_WeakProperty";
11940 } 12024 }
11941 12025
11942 } // namespace dart 12026 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698