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

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

Issue 10447045: Introduce library ids and info in the wire protocol (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 5244 matching lines...) Expand 10 before | Expand all | Expand 10 after
5255 lib ^= imports.At(i); 5255 lib ^= imports.At(i);
5256 import_url = lib.url(); 5256 import_url = lib.url();
5257 if (url.Equals(import_url)) { 5257 if (url.Equals(import_url)) {
5258 return lib.raw(); 5258 return lib.raw();
5259 } 5259 }
5260 } 5260 }
5261 return Library::null(); 5261 return Library::null();
5262 } 5262 }
5263 5263
5264 5264
5265 RawLibrary* Library::ImportAt(intptr_t index) const {
5266 if ((index < 0) || index >= num_imports()) {
5267 return Library::null();
5268 }
5269 const Array& import_list = Array::Handle(imports());
5270 Library& lib = Library::Handle();
5271 lib ^= import_list.At(index);
5272 return lib.raw();
5273 }
5274
5275
5276 RawLibraryPrefix* Library::ImportPrefixAt(intptr_t index) const {
5277 const Library& imported = Library::Handle(ImportAt(index));
5278 if (imported.IsNull()) {
5279 return LibraryPrefix::null();
5280 }
5281 DictionaryIterator it(*this);
5282 LibraryPrefix& lib_prefix = LibraryPrefix::Handle();
5283 Object& obj = Object::Handle();
5284 while (it.HasNext()) {
5285 obj = it.GetNext();
5286 if (obj.IsLibraryPrefix()) {
5287 lib_prefix ^= obj.raw();
5288 if (lib_prefix.ContainsLibrary(imported)) {
5289 return lib_prefix.raw();
5290 }
5291 }
5292 }
5293 return LibraryPrefix::null();
5294 }
5295
5296
5265 void Library::AddImport(const Library& library) const { 5297 void Library::AddImport(const Library& library) const {
5266 Array& imports = Array::Handle(this->imports()); 5298 Array& imports = Array::Handle(this->imports());
5267 intptr_t capacity = imports.Length(); 5299 intptr_t capacity = imports.Length();
5268 if (num_imports() == capacity) { 5300 if (num_imports() == capacity) {
5269 capacity = capacity + kImportsCapacityIncrement; 5301 capacity = capacity + kImportsCapacityIncrement;
5270 imports = Array::Grow(imports, capacity); 5302 imports = Array::Grow(imports, capacity);
5271 StorePointer(&raw_ptr()->imports_, imports.raw()); 5303 StorePointer(&raw_ptr()->imports_, imports.raw());
5272 } 5304 }
5273 intptr_t index = num_imports(); 5305 intptr_t index = num_imports();
5274 imports.SetAt(index, library); 5306 imports.SetAt(index, library);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
5335 result.raw_ptr()->url_ = url.raw(); 5367 result.raw_ptr()->url_ = url.raw();
5336 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); 5368 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result);
5337 result.raw_ptr()->dictionary_ = Array::Empty(); 5369 result.raw_ptr()->dictionary_ = Array::Empty();
5338 result.raw_ptr()->anonymous_classes_ = Array::Empty(); 5370 result.raw_ptr()->anonymous_classes_ = Array::Empty();
5339 result.raw_ptr()->num_anonymous_ = 0; 5371 result.raw_ptr()->num_anonymous_ = 0;
5340 result.raw_ptr()->imports_ = Array::Empty(); 5372 result.raw_ptr()->imports_ = Array::Empty();
5341 result.raw_ptr()->loaded_scripts_ = Array::null(); 5373 result.raw_ptr()->loaded_scripts_ = Array::null();
5342 result.set_native_entry_resolver(NULL); 5374 result.set_native_entry_resolver(NULL);
5343 result.raw_ptr()->corelib_imported_ = true; 5375 result.raw_ptr()->corelib_imported_ = true;
5344 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; 5376 result.raw_ptr()->load_state_ = RawLibrary::kAllocated;
5377 result.raw_ptr()->index_ = -1;
5345 result.InitClassDictionary(); 5378 result.InitClassDictionary();
5346 result.InitImportList(); 5379 result.InitImportList();
5347 result.InitImportedIntoList(); 5380 result.InitImportedIntoList();
5348 if (import_core_lib) { 5381 if (import_core_lib) {
5349 Library& core_lib = Library::Handle(Library::CoreLibrary()); 5382 Library& core_lib = Library::Handle(Library::CoreLibrary());
5350 ASSERT(!core_lib.IsNull()); 5383 ASSERT(!core_lib.IsNull());
5351 result.AddImport(core_lib); 5384 result.AddImport(core_lib);
5352 } 5385 }
5353 return result.raw(); 5386 return result.raw();
5354 } 5387 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
5510 return Library::null(); 5543 return Library::null();
5511 } 5544 }
5512 5545
5513 5546
5514 void Library::Register() const { 5547 void Library::Register() const {
5515 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); 5548 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null());
5516 ObjectStore* object_store = Isolate::Current()->object_store(); 5549 ObjectStore* object_store = Isolate::Current()->object_store();
5517 GrowableObjectArray& libs = 5550 GrowableObjectArray& libs =
5518 GrowableObjectArray::Handle(object_store->libraries()); 5551 GrowableObjectArray::Handle(object_store->libraries());
5519 ASSERT(!libs.IsNull()); 5552 ASSERT(!libs.IsNull());
5553 set_index(libs.Length());
siva 2012/05/29 18:07:53 This is probably ok for now, but there is a propos
hausner 2012/05/29 19:48:18 As we discussed offline, the code and its assumpti
5520 libs.Add(*this); 5554 libs.Add(*this);
5521 } 5555 }
5522 5556
5523 5557
5524 RawLibrary* Library::CoreLibrary() { 5558 RawLibrary* Library::CoreLibrary() {
5525 return Isolate::Current()->object_store()->core_library(); 5559 return Isolate::Current()->object_store()->core_library();
5526 } 5560 }
5527 5561
5528 5562
5529 RawLibrary* Library::CoreImplLibrary() { 5563 RawLibrary* Library::CoreImplLibrary() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5565 RawLibrary* LibraryPrefix::GetLibrary(int index) const { 5599 RawLibrary* LibraryPrefix::GetLibrary(int index) const {
5566 Library& lib = Library::Handle(); 5600 Library& lib = Library::Handle();
5567 if ((index >= 0) || (index < num_libs())) { 5601 if ((index >= 0) || (index < num_libs())) {
5568 Array& libs = Array::Handle(libraries()); 5602 Array& libs = Array::Handle(libraries());
5569 lib ^= libs.At(index); 5603 lib ^= libs.At(index);
5570 } 5604 }
5571 return lib.raw(); 5605 return lib.raw();
5572 } 5606 }
5573 5607
5574 5608
5575 void LibraryPrefix::AddLibrary(const Library& library) const { 5609 bool LibraryPrefix::ContainsLibrary(const Library& library) const {
5576 Library& lib = Library::Handle();
5577 intptr_t num_current_libs = num_libs(); 5610 intptr_t num_current_libs = num_libs();
5578
5579 // First check if the library is already in the list of libraries imported.
5580 if (num_current_libs > 0) { 5611 if (num_current_libs > 0) {
5612 Library& lib = Library::Handle();
5581 const String& url = String::Handle(library.url()); 5613 const String& url = String::Handle(library.url());
5582 String& lib_url = String::Handle(); 5614 String& lib_url = String::Handle();
5583 for (intptr_t i = 0; i < num_current_libs; i++) { 5615 for (intptr_t i = 0; i < num_current_libs; i++) {
5584 lib = GetLibrary(i); 5616 lib = GetLibrary(i);
5585 ASSERT(!lib.IsNull()); 5617 ASSERT(!lib.IsNull());
5586 lib_url = lib.url(); 5618 lib_url = lib.url();
5587 if (url.Equals(lib_url)) { 5619 if (url.Equals(lib_url)) {
5588 return; // Library already imported with same prefix. 5620 return true;
5589 } 5621 }
5590 } 5622 }
5591 } 5623 }
5624 return false;
5625 }
5626
5627 void LibraryPrefix::AddLibrary(const Library& library) const {
5628 intptr_t num_current_libs = num_libs();
5629
5630 // First check if the library is already in the list of libraries imported.
5631 if (ContainsLibrary(library)) {
5632 return; // Library already imported with same prefix.
5633 }
5592 5634
5593 // The library needs to be added to the list. 5635 // The library needs to be added to the list.
5594 Array& libs = Array::Handle(libraries()); 5636 Array& libs = Array::Handle(libraries());
5595 const intptr_t length = (libs.IsNull()) ? 0 : libs.Length(); 5637 const intptr_t length = (libs.IsNull()) ? 0 : libs.Length();
5596 // Grow the list if it is full. 5638 // Grow the list if it is full.
5597 if (num_current_libs >= length) { 5639 if (num_current_libs >= length) {
5598 const intptr_t new_length = length + kIncrementSize; 5640 const intptr_t new_length = length + kIncrementSize;
5599 libs = Array::Grow(libs, new_length, Heap::kOld); 5641 libs = Array::Grow(libs, new_length, Heap::kOld);
5600 set_libraries(libs); 5642 set_libraries(libs);
5601 } 5643 }
(...skipping 4468 matching lines...) Expand 10 before | Expand all | Expand 10 after
10070 const String& str = String::Handle(pattern()); 10112 const String& str = String::Handle(pattern());
10071 const char* format = "JSRegExp: pattern=%s flags=%s"; 10113 const char* format = "JSRegExp: pattern=%s flags=%s";
10072 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10114 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10073 char* chars = reinterpret_cast<char*>( 10115 char* chars = reinterpret_cast<char*>(
10074 Isolate::Current()->current_zone()->Allocate(len + 1)); 10116 Isolate::Current()->current_zone()->Allocate(len + 1));
10075 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10117 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10076 return chars; 10118 return chars;
10077 } 10119 }
10078 10120
10079 } // namespace dart 10121 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698