Chromium Code Reviews| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 6702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6713 literal = String::EscapeSpecialCharacters(literal); | 6713 literal = String::EscapeSpecialCharacters(literal); |
| 6714 literals.Add(literal); | 6714 literals.Add(literal); |
| 6715 } else { | 6715 } else { |
| 6716 literals.Add(literal); | 6716 literals.Add(literal); |
| 6717 } | 6717 } |
| 6718 if ((next != Token::kINTERPOL_VAR) && (next != Token::kINTERPOL_START)) { | 6718 if ((next != Token::kINTERPOL_VAR) && (next != Token::kINTERPOL_START)) { |
| 6719 literals.Add(Symbols::DoubleQuotes()); | 6719 literals.Add(Symbols::DoubleQuotes()); |
| 6720 } | 6720 } |
| 6721 } else if (curr == Token::kINTERPOL_VAR) { | 6721 } else if (curr == Token::kINTERPOL_VAR) { |
| 6722 literals.Add(Symbols::Dollar()); | 6722 literals.Add(Symbols::Dollar()); |
| 6723 if (literal.CharAt(0) == Scanner::kPrivateIdentifierStart) { | 6723 if (literal.CharAt(0) == Library::kPrivateIdentifierStart) { |
| 6724 literal = String::SubString(literal, 0, literal.Length() - private_len); | 6724 literal = String::SubString(literal, 0, literal.Length() - private_len); |
| 6725 } | 6725 } |
| 6726 literals.Add(literal); | 6726 literals.Add(literal); |
| 6727 } else if (curr == Token::kIDENT) { | 6727 } else if (curr == Token::kIDENT) { |
| 6728 if (literal.CharAt(0) == Scanner::kPrivateIdentifierStart) { | 6728 if (literal.CharAt(0) == Library::kPrivateIdentifierStart) { |
| 6729 literal = String::SubString(literal, 0, literal.Length() - private_len); | 6729 literal = String::SubString(literal, 0, literal.Length() - private_len); |
| 6730 } | 6730 } |
| 6731 literals.Add(literal); | 6731 literals.Add(literal); |
| 6732 } else { | 6732 } else { |
| 6733 literals.Add(literal); | 6733 literals.Add(literal); |
| 6734 } | 6734 } |
| 6735 // Determine the separation text based on this current token. | 6735 // Determine the separation text based on this current token. |
| 6736 const String* separator = NULL; | 6736 const String* separator = NULL; |
| 6737 switch (curr) { | 6737 switch (curr) { |
| 6738 case Token::kLBRACE: | 6738 case Token::kLBRACE: |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7841 | 7841 |
| 7842 | 7842 |
| 7843 // Add a name to the resolved name cache. This name resolves to the | 7843 // Add a name to the resolved name cache. This name resolves to the |
| 7844 // given object in this library scope. obj may be null, which means | 7844 // given object in this library scope. obj may be null, which means |
| 7845 // the name does not resolve to anything in this library scope. | 7845 // the name does not resolve to anything in this library scope. |
| 7846 void Library::AddToResolvedNamesCache(const String& name, | 7846 void Library::AddToResolvedNamesCache(const String& name, |
| 7847 const Object& obj) const { | 7847 const Object& obj) const { |
| 7848 if (!FLAG_use_lib_cache) { | 7848 if (!FLAG_use_lib_cache) { |
| 7849 return; | 7849 return; |
| 7850 } | 7850 } |
| 7851 ASSERT(!Field::IsGetterName(name) && !Field::IsSetterName(name)); | |
|
hausner
2014/02/10 21:07:35
Unrelated but on purpose.
| |
| 7851 const Array& cache = Array::Handle(resolved_names()); | 7852 const Array& cache = Array::Handle(resolved_names()); |
| 7852 // let N = cache.Length(); | 7853 // let N = cache.Length(); |
| 7853 // The entry cache[N-1] is used as a counter | 7854 // The entry cache[N-1] is used as a counter |
| 7854 // The array entries [0..N-2] are used as cache entries. | 7855 // The array entries [0..N-2] are used as cache entries. |
| 7855 // cache[i] contains the name of the entry | 7856 // cache[i] contains the name of the entry |
| 7856 // cache[i+(N-1)/2] contains the resolved entity, or NULL if that name | 7857 // cache[i+(N-1)/2] contains the resolved entity, or NULL if that name |
| 7857 // is not present in the library. | 7858 // is not present in the library. |
| 7858 const intptr_t counter_index = cache.Length() - 1; | 7859 const intptr_t counter_index = cache.Length() - 1; |
| 7859 intptr_t cache_size = ResolvedNameCacheSize(cache); | 7860 intptr_t cache_size = ResolvedNameCacheSize(cache); |
| 7860 intptr_t index = name.Hash() % cache_size; | 7861 intptr_t index = name.Hash() % cache_size; |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8428 Heap::kOld); | 8429 Heap::kOld); |
| 8429 return reinterpret_cast<RawLibrary*>(raw); | 8430 return reinterpret_cast<RawLibrary*>(raw); |
| 8430 } | 8431 } |
| 8431 | 8432 |
| 8432 | 8433 |
| 8433 RawLibrary* Library::NewLibraryHelper(const String& url, | 8434 RawLibrary* Library::NewLibraryHelper(const String& url, |
| 8434 bool import_core_lib) { | 8435 bool import_core_lib) { |
| 8435 const Library& result = Library::Handle(Library::New()); | 8436 const Library& result = Library::Handle(Library::New()); |
| 8436 result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw()); | 8437 result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw()); |
| 8437 result.StorePointer(&result.raw_ptr()->url_, url.raw()); | 8438 result.StorePointer(&result.raw_ptr()->url_, url.raw()); |
| 8438 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); | |
| 8439 result.raw_ptr()->resolved_names_ = Object::empty_array().raw(); | 8439 result.raw_ptr()->resolved_names_ = Object::empty_array().raw(); |
| 8440 result.raw_ptr()->dictionary_ = Object::empty_array().raw(); | 8440 result.raw_ptr()->dictionary_ = Object::empty_array().raw(); |
| 8441 result.StorePointer(&result.raw_ptr()->metadata_, | 8441 result.StorePointer(&result.raw_ptr()->metadata_, |
| 8442 GrowableObjectArray::New(4, Heap::kOld)); | 8442 GrowableObjectArray::New(4, Heap::kOld)); |
| 8443 result.raw_ptr()->anonymous_classes_ = Object::empty_array().raw(); | 8443 result.raw_ptr()->anonymous_classes_ = Object::empty_array().raw(); |
| 8444 result.raw_ptr()->num_anonymous_ = 0; | 8444 result.raw_ptr()->num_anonymous_ = 0; |
| 8445 result.raw_ptr()->imports_ = Object::empty_array().raw(); | 8445 result.raw_ptr()->imports_ = Object::empty_array().raw(); |
| 8446 result.raw_ptr()->exports_ = Object::empty_array().raw(); | 8446 result.raw_ptr()->exports_ = Object::empty_array().raw(); |
| 8447 result.raw_ptr()->loaded_scripts_ = Array::null(); | 8447 result.raw_ptr()->loaded_scripts_ = Array::null(); |
| 8448 result.set_native_entry_resolver(NULL); | 8448 result.set_native_entry_resolver(NULL); |
| 8449 result.raw_ptr()->corelib_imported_ = true; | 8449 result.raw_ptr()->corelib_imported_ = true; |
| 8450 result.set_debuggable(false); | 8450 result.set_debuggable(false); |
| 8451 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; | 8451 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; |
| 8452 result.raw_ptr()->index_ = -1; | 8452 result.raw_ptr()->index_ = -1; |
| 8453 const intptr_t kInitialNameCacheSize = 64; | 8453 const intptr_t kInitialNameCacheSize = 64; |
| 8454 result.InitResolvedNamesCache(kInitialNameCacheSize); | 8454 result.InitResolvedNamesCache(kInitialNameCacheSize); |
| 8455 result.InitClassDictionary(); | 8455 result.InitClassDictionary(); |
| 8456 result.InitImportList(); | 8456 result.InitImportList(); |
| 8457 result.AllocatePrivateKey(); | |
| 8457 if (import_core_lib) { | 8458 if (import_core_lib) { |
| 8458 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 8459 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 8459 ASSERT(!core_lib.IsNull()); | 8460 ASSERT(!core_lib.IsNull()); |
| 8460 const Namespace& ns = Namespace::Handle( | 8461 const Namespace& ns = Namespace::Handle( |
| 8461 Namespace::New(core_lib, Object::null_array(), Object::null_array())); | 8462 Namespace::New(core_lib, Object::null_array(), Object::null_array())); |
| 8462 result.AddImport(ns); | 8463 result.AddImport(ns); |
| 8463 } | 8464 } |
| 8464 return result.raw(); | 8465 return result.raw(); |
| 8465 } | 8466 } |
| 8466 | 8467 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8543 return Library::null(); | 8544 return Library::null(); |
| 8544 } | 8545 } |
| 8545 | 8546 |
| 8546 | 8547 |
| 8547 RawError* Library::Patch(const Script& script) const { | 8548 RawError* Library::Patch(const Script& script) const { |
| 8548 ASSERT(script.kind() == RawScript::kPatchTag); | 8549 ASSERT(script.kind() == RawScript::kPatchTag); |
| 8549 return Compiler::Compile(*this, script); | 8550 return Compiler::Compile(*this, script); |
| 8550 } | 8551 } |
| 8551 | 8552 |
| 8552 | 8553 |
| 8554 bool Library::IsPrivate(const String& name) { | |
| 8555 if (ShouldBePrivate(name)) return true; | |
| 8556 // Factory names: List._fromLiteral. | |
| 8557 for (intptr_t i = 1; i < name.Length() - 1; i++) { | |
| 8558 if (name.CharAt(i) == '.') { | |
| 8559 if (name.CharAt(i + 1) == '_') { | |
| 8560 return true; | |
| 8561 } | |
| 8562 } | |
| 8563 } | |
| 8564 return false; | |
| 8565 } | |
| 8566 | |
| 8567 | |
| 8553 bool Library::IsKeyUsed(intptr_t key) { | 8568 bool Library::IsKeyUsed(intptr_t key) { |
| 8554 intptr_t lib_key; | 8569 intptr_t lib_key; |
| 8555 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 8570 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 8556 Isolate::Current()->object_store()->libraries()); | 8571 Isolate::Current()->object_store()->libraries()); |
| 8557 Library& lib = Library::Handle(); | 8572 Library& lib = Library::Handle(); |
| 8558 String& lib_url = String::Handle(); | 8573 String& lib_url = String::Handle(); |
| 8559 for (int i = 0; i < libs.Length(); i++) { | 8574 for (int i = 0; i < libs.Length(); i++) { |
| 8560 lib ^= libs.At(i); | 8575 lib ^= libs.At(i); |
| 8561 lib_url ^= lib.url(); | 8576 lib_url ^= lib.url(); |
| 8562 lib_key = lib_url.Hash(); | 8577 lib_key = lib_url.Hash(); |
| 8563 if (lib_key == key) { | 8578 if (lib_key == key) { |
| 8564 return true; | 8579 return true; |
| 8565 } | 8580 } |
| 8566 } | 8581 } |
| 8567 return false; | 8582 return false; |
| 8568 } | 8583 } |
| 8569 | 8584 |
| 8570 | 8585 |
| 8571 bool Library::IsPrivate(const String& name) { | 8586 void Library::AllocatePrivateKey() const { |
| 8572 if (ShouldBePrivate(name)) return true; | 8587 const String& url = String::Handle(this->url()); |
| 8573 // Factory names: List._fromLiteral. | 8588 intptr_t key_value = url.Hash(); |
| 8574 for (intptr_t i = 1; i < name.Length() - 1; i++) { | 8589 while (Library::IsKeyUsed(key_value)) { |
| 8575 if (name.CharAt(i) == '.') { | 8590 key_value++; |
| 8576 if (name.CharAt(i + 1) == '_') { | |
| 8577 return true; | |
| 8578 } | |
| 8579 } | |
| 8580 } | 8591 } |
| 8581 return false; | 8592 char private_key[32]; |
| 8593 OS::SNPrint(private_key, sizeof(private_key), | |
| 8594 "%c%#" Px "", kPrivateKeySeparator, key_value); | |
| 8595 StorePointer(&raw_ptr()->private_key_, String::New(private_key, Heap::kOld)); | |
| 8582 } | 8596 } |
| 8583 | 8597 |
| 8584 | 8598 |
| 8585 const String& Library::PrivateCoreLibName(const String& member) { | 8599 const String& Library::PrivateCoreLibName(const String& member) { |
| 8586 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 8600 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 8587 const String& private_name = String::ZoneHandle(core_lib.PrivateName(member)); | 8601 const String& private_name = String::ZoneHandle(core_lib.PrivateName(member)); |
| 8588 return private_name; | 8602 return private_name; |
| 8589 } | 8603 } |
| 8590 | 8604 |
| 8591 | 8605 |
| 8592 RawClass* Library::LookupCoreClass(const String& class_name) { | 8606 RawClass* Library::LookupCoreClass(const String& class_name) { |
| 8593 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 8607 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 8594 String& name = String::Handle(class_name.raw()); | 8608 String& name = String::Handle(class_name.raw()); |
| 8595 if (class_name.CharAt(0) == Scanner::kPrivateIdentifierStart) { | 8609 if (class_name.CharAt(0) == kPrivateIdentifierStart) { |
| 8596 // Private identifiers are mangled on a per library basis. | 8610 // Private identifiers are mangled on a per library basis. |
| 8597 name = String::Concat(name, String::Handle(core_lib.private_key())); | 8611 name = String::Concat(name, String::Handle(core_lib.private_key())); |
| 8598 name = Symbols::New(name); | 8612 name = Symbols::New(name); |
| 8599 } | 8613 } |
| 8600 return core_lib.LookupClass(name); | 8614 return core_lib.LookupClass(name); |
| 8601 } | 8615 } |
| 8602 | 8616 |
| 8603 | 8617 |
| 8604 // Cannot handle qualified names properly as it only appends private key to | 8618 // Cannot handle qualified names properly as it only appends private key to |
| 8605 // the end (e.g. _Alfa.foo -> _Alfa.foo@...). | 8619 // the end (e.g. _Alfa.foo -> _Alfa.foo@...). |
| (...skipping 6880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15486 } | 15500 } |
| 15487 if (len < str2_len) { | 15501 if (len < str2_len) { |
| 15488 return false; // No way they can match. | 15502 return false; // No way they can match. |
| 15489 } | 15503 } |
| 15490 intptr_t pos = 0; | 15504 intptr_t pos = 0; |
| 15491 intptr_t str2_pos = 0; | 15505 intptr_t str2_pos = 0; |
| 15492 while (pos < len) { | 15506 while (pos < len) { |
| 15493 int32_t ch = T1::CharAt(str1, pos); | 15507 int32_t ch = T1::CharAt(str1, pos); |
| 15494 pos++; | 15508 pos++; |
| 15495 | 15509 |
| 15496 if (ch == Scanner::kPrivateKeySeparator) { | 15510 if (ch == Library::kPrivateKeySeparator) { |
| 15497 // Consume a private key separator. | 15511 // Consume a private key separator. |
| 15498 while ((pos < len) && (T1::CharAt(str1, pos) != '.')) { | 15512 while ((pos < len) && (T1::CharAt(str1, pos) != '.')) { |
| 15499 pos++; | 15513 pos++; |
| 15500 } | 15514 } |
| 15501 // Resume matching characters. | 15515 // Resume matching characters. |
| 15502 continue; | 15516 continue; |
| 15503 } | 15517 } |
| 15504 if ((str2_pos == str2_len) || (ch != T2::CharAt(str2, str2_pos))) { | 15518 if ((str2_pos == str2_len) || (ch != T2::CharAt(str2, str2_pos))) { |
| 15505 return false; | 15519 return false; |
| 15506 } | 15520 } |
| (...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17336 return "_MirrorReference"; | 17350 return "_MirrorReference"; |
| 17337 } | 17351 } |
| 17338 | 17352 |
| 17339 | 17353 |
| 17340 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17354 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17341 Instance::PrintToJSONStream(stream, ref); | 17355 Instance::PrintToJSONStream(stream, ref); |
| 17342 } | 17356 } |
| 17343 | 17357 |
| 17344 | 17358 |
| 17345 } // namespace dart | 17359 } // namespace dart |
| OLD | NEW |