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

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

Issue 23484020: Update handling of ambiguous name references (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 V(CoreLibrary, int, _parse) \ 162 V(CoreLibrary, int, _parse) \
163 V(CoreLibrary, StackTrace, _setupFullStackTrace) \ 163 V(CoreLibrary, StackTrace, _setupFullStackTrace) \
164 V(CoreLibrary, _OneByteString, _setAt) \ 164 V(CoreLibrary, _OneByteString, _setAt) \
165 165
166 166
167 static void MarkFunctionAsInvisible(const Library& lib, 167 static void MarkFunctionAsInvisible(const Library& lib,
168 const char* class_name, 168 const char* class_name,
169 const char* function_name) { 169 const char* function_name) {
170 ASSERT(!lib.IsNull()); 170 ASSERT(!lib.IsNull());
171 const Class& cls = Class::Handle( 171 const Class& cls = Class::Handle(
172 lib.LookupClassAllowPrivate(String::Handle(String::New(class_name)), 172 lib.LookupClassAllowPrivate(String::Handle(String::New(class_name))));
173 NULL)); // No ambiguity error expected.
174 ASSERT(!cls.IsNull()); 173 ASSERT(!cls.IsNull());
175 const Function& function = 174 const Function& function =
176 Function::Handle( 175 Function::Handle(
177 cls.LookupFunctionAllowPrivate( 176 cls.LookupFunctionAllowPrivate(
178 String::Handle(String::New(function_name)))); 177 String::Handle(String::New(function_name))));
179 ASSERT(!function.IsNull()); 178 ASSERT(!function.IsNull());
180 function.set_is_visible(false); 179 function.set_is_visible(false);
181 } 180 }
182 181
183 182
(...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 signature_function.set_signature_class(*this); 2215 signature_function.set_signature_class(*this);
2217 ASSERT(IsCanonicalSignatureClass()); 2216 ASSERT(IsCanonicalSignatureClass());
2218 } 2217 }
2219 set_is_prefinalized(); 2218 set_is_prefinalized();
2220 } 2219 }
2221 2220
2222 2221
2223 RawClass* Class::NewNativeWrapper(const Library& library, 2222 RawClass* Class::NewNativeWrapper(const Library& library,
2224 const String& name, 2223 const String& name,
2225 int field_count) { 2224 int field_count) {
2226 String& ambiguity_error_msg = String::Handle(); 2225 Class& cls = Class::Handle(library.LookupClass(name));
2227 Class& cls = Class::Handle(library.LookupClass(name, &ambiguity_error_msg));
2228 if (cls.IsNull()) { 2226 if (cls.IsNull()) {
2229 if (!ambiguity_error_msg.IsNull()) {
2230 return Class::null();
2231 }
2232 cls = New(name, Script::Handle(), Scanner::kDummyTokenIndex); 2227 cls = New(name, Script::Handle(), Scanner::kDummyTokenIndex);
2233 cls.SetFields(Object::empty_array()); 2228 cls.SetFields(Object::empty_array());
2234 cls.SetFunctions(Object::empty_array()); 2229 cls.SetFunctions(Object::empty_array());
2235 // Set super class to Object. 2230 // Set super class to Object.
2236 cls.set_super_type(Type::Handle(Type::ObjectType())); 2231 cls.set_super_type(Type::Handle(Type::ObjectType()));
2237 // Compute instance size. First word contains a pointer to a properly 2232 // Compute instance size. First word contains a pointer to a properly
2238 // sized typed array once the first native field has been set. 2233 // sized typed array once the first native field has been set.
2239 intptr_t instance_size = sizeof(RawObject) + kWordSize; 2234 intptr_t instance_size = sizeof(RawObject) + kWordSize;
2240 cls.set_instance_size(RoundedAllocationSize(instance_size)); 2235 cls.set_instance_size(RoundedAllocationSize(instance_size));
2241 cls.set_next_field_offset(instance_size); 2236 cls.set_next_field_offset(instance_size);
(...skipping 4486 matching lines...) Expand 10 before | Expand all | Expand 10 after
6728 GrowDictionary(dict, dict_size); 6723 GrowDictionary(dict, dict_size);
6729 } 6724 }
6730 6725
6731 // Invalidate the cache of loaded scripts. 6726 // Invalidate the cache of loaded scripts.
6732 if (loaded_scripts() != Array::null()) { 6727 if (loaded_scripts() != Array::null()) {
6733 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); 6728 StorePointer(&raw_ptr()->loaded_scripts_, Array::null());
6734 } 6729 }
6735 } 6730 }
6736 6731
6737 6732
6738 // Lookup a name in the library's export namespace. 6733 // Lookup a name in the library's re-export namespace. The name is
6739 RawObject* Library::LookupExport(const String& name) const { 6734 // unmangled, i.e. no getter or setter names should be looked up.
6735 RawObject* Library::LookupReExport(const String& name) const {
6740 if (HasExports()) { 6736 if (HasExports()) {
6741 const Array& exports = Array::Handle(this->exports()); 6737 const Array& exports = Array::Handle(this->exports());
6742 // Break potential export cycle while looking up name. 6738 // Break potential export cycle while looking up name.
6743 StorePointer(&raw_ptr()->exports_, Object::empty_array().raw()); 6739 StorePointer(&raw_ptr()->exports_, Object::empty_array().raw());
6744 Namespace& ns = Namespace::Handle(); 6740 Namespace& ns = Namespace::Handle();
6745 Object& obj = Object::Handle(); 6741 Object& obj = Object::Handle();
6746 for (int i = 0; i < exports.Length(); i++) { 6742 for (int i = 0; i < exports.Length(); i++) {
6747 ns ^= exports.At(i); 6743 ns ^= exports.At(i);
6748 obj = ns.Lookup(name); 6744 obj = ns.Lookup(name);
6749 if (!obj.IsNull()) { 6745 if (!obj.IsNull()) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
6907 name.CharAt(0) == '_') || 6903 name.CharAt(0) == '_') ||
6908 (name.Length() >= 5 && 6904 (name.Length() >= 5 &&
6909 (name.CharAt(4) == '_' && 6905 (name.CharAt(4) == '_' &&
6910 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && 6906 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') &&
6911 name.CharAt(1) == 'e' && 6907 name.CharAt(1) == 'e' &&
6912 name.CharAt(2) == 't' && 6908 name.CharAt(2) == 't' &&
6913 name.CharAt(3) == ':')); 6909 name.CharAt(3) == ':'));
6914 } 6910 }
6915 6911
6916 6912
6917 RawField* Library::LookupFieldAllowPrivate(const String& name, 6913 RawField* Library::LookupFieldAllowPrivate(const String& name) const {
6918 String* ambiguity_error_msg) const { 6914 Object& obj = Object::Handle(LookupObjectAllowPrivate(name));
6919 Object& obj = Object::Handle(
6920 LookupObjectAllowPrivate(name, ambiguity_error_msg));
6921 if (obj.IsField()) { 6915 if (obj.IsField()) {
6922 return Field::Cast(obj).raw(); 6916 return Field::Cast(obj).raw();
6923 } 6917 }
6924 return Field::null(); 6918 return Field::null();
6925 } 6919 }
6926 6920
6927 6921
6928 RawField* Library::LookupLocalField(const String& name) const { 6922 RawField* Library::LookupLocalField(const String& name) const {
6929 Object& obj = Object::Handle(LookupLocalObjectAllowPrivate(name)); 6923 Object& obj = Object::Handle(LookupLocalObjectAllowPrivate(name));
6930 if (obj.IsField()) { 6924 if (obj.IsField()) {
6931 return Field::Cast(obj).raw(); 6925 return Field::Cast(obj).raw();
6932 } 6926 }
6933 return Field::null(); 6927 return Field::null();
6934 } 6928 }
6935 6929
6936 6930
6937 RawFunction* Library::LookupFunctionAllowPrivate( 6931 RawFunction* Library::LookupFunctionAllowPrivate(const String& name) const {
6938 const String& name, 6932 Object& obj = Object::Handle(LookupObjectAllowPrivate(name));
6939 String* ambiguity_error_msg) const {
6940 Object& obj = Object::Handle(
6941 LookupObjectAllowPrivate(name, ambiguity_error_msg));
6942 if (obj.IsFunction()) { 6933 if (obj.IsFunction()) {
6943 return Function::Cast(obj).raw(); 6934 return Function::Cast(obj).raw();
6944 } 6935 }
6945 return Function::null(); 6936 return Function::null();
6946 } 6937 }
6947 6938
6948 6939
6949 RawFunction* Library::LookupLocalFunction(const String& name) const { 6940 RawFunction* Library::LookupLocalFunction(const String& name) const {
6950 Object& obj = Object::Handle(LookupLocalObjectAllowPrivate(name)); 6941 Object& obj = Object::Handle(LookupLocalObjectAllowPrivate(name));
6951 if (obj.IsFunction()) { 6942 if (obj.IsFunction()) {
6952 return Function::Cast(obj).raw(); 6943 return Function::Cast(obj).raw();
6953 } 6944 }
6954 return Function::null(); 6945 return Function::null();
6955 } 6946 }
6956 6947
6957 6948
6958 RawObject* Library::LookupLocalObjectAllowPrivate(const String& name) const { 6949 RawObject* Library::LookupLocalObjectAllowPrivate(const String& name) const {
6959 Isolate* isolate = Isolate::Current(); 6950 Isolate* isolate = Isolate::Current();
6960 Object& obj = Object::Handle(isolate, Object::null()); 6951 Object& obj = Object::Handle(isolate, Object::null());
6961 obj = LookupLocalObject(name); 6952 obj = LookupLocalObject(name);
6962 if (obj.IsNull() && ShouldBePrivate(name)) { 6953 if (obj.IsNull() && ShouldBePrivate(name)) {
6963 String& private_name = String::Handle(isolate, PrivateName(name)); 6954 String& private_name = String::Handle(isolate, PrivateName(name));
6964 obj = LookupLocalObject(private_name); 6955 obj = LookupLocalObject(private_name);
6965 } 6956 }
6966 return obj.raw(); 6957 return obj.raw();
6967 } 6958 }
6968 6959
6969 6960
6970 RawObject* Library::LookupObjectAllowPrivate( 6961 RawObject* Library::LookupObjectAllowPrivate(const String& name) const {
6971 const String& name,
6972 String* ambiguity_error_msg) const {
6973 // First check if name is found in the local scope of the library. 6962 // First check if name is found in the local scope of the library.
6974 Object& obj = Object::Handle(LookupLocalObjectAllowPrivate(name)); 6963 Object& obj = Object::Handle(LookupLocalObjectAllowPrivate(name));
6975 if (!obj.IsNull()) { 6964 if (!obj.IsNull()) {
6976 return obj.raw(); 6965 return obj.raw();
6977 } 6966 }
6978 6967
6979 // Do not look up private names in imported libraries. 6968 // Do not look up private names in imported libraries.
6980 if (ShouldBePrivate(name)) { 6969 if (ShouldBePrivate(name)) {
6981 return Object::null(); 6970 return Object::null();
6982 } 6971 }
6983 6972
6984 // Now check if name is found in any imported libs. It is a compile-time error 6973 // Now check if name is found in any imported libs.
6985 // if the name is found in more than one import and actually used. 6974 return LookupImportedObject(name);
6986 return LookupImportedObject(name, ambiguity_error_msg);
6987 } 6975 }
6988 6976
6989 6977
6990 RawObject* Library::LookupObject(const String& name, 6978 RawObject* Library::LookupObject(const String& name) const {
6991 String* ambiguity_error_msg) const {
6992 // First check if name is found in the local scope of the library. 6979 // First check if name is found in the local scope of the library.
6993 Object& obj = Object::Handle(LookupLocalObject(name)); 6980 Object& obj = Object::Handle(LookupLocalObject(name));
6994 if (!obj.IsNull()) { 6981 if (!obj.IsNull()) {
6995 return obj.raw(); 6982 return obj.raw();
6996 } 6983 }
6997 // Now check if name is found in any imported libs. It is a compile-time error 6984 // Now check if name is found in any imported libs.
6998 // if the name is found in more than one import and actually used. 6985 return LookupImportedObject(name);
6999 return LookupImportedObject(name, ambiguity_error_msg);
7000 } 6986 }
7001 6987
7002 6988
7003 RawObject* Library::LookupImportedObject(const String& name, 6989 RawObject* Library::LookupImportedObject(const String& name) const {
7004 String* ambiguity_error_msg) const {
7005 Object& obj = Object::Handle(); 6990 Object& obj = Object::Handle();
7006 Namespace& import = Namespace::Handle(); 6991 Namespace& import = Namespace::Handle();
7007 Library& import_lib = Library::Handle(); 6992 Library& import_lib = Library::Handle();
6993 String& import_lib_url = String::Handle();
7008 String& first_import_lib_url = String::Handle(); 6994 String& first_import_lib_url = String::Handle();
7009 Object& found_obj = Object::Handle(); 6995 Object& found_obj = Object::Handle();
7010 for (intptr_t i = 0; i < num_imports(); i++) { 6996 for (intptr_t i = 0; i < num_imports(); i++) {
7011 import ^= ImportAt(i); 6997 import ^= ImportAt(i);
7012 obj = import.Lookup(name); 6998 obj = import.Lookup(name);
7013 if (!obj.IsNull()) { 6999 if (!obj.IsNull()) {
7014 import_lib = import.library(); 7000 import_lib = import.library();
7015 if (!first_import_lib_url.IsNull()) { 7001 import_lib_url = import_lib.url();
7016 // Found duplicate definition. 7002 if (found_obj.raw() != obj.raw()) {
7017 const intptr_t kMessageBufferSize = 512; 7003 if (first_import_lib_url.IsNull() ||
7018 char message_buffer[kMessageBufferSize]; 7004 first_import_lib_url.StartsWith(Symbols::DartScheme())) {
7019 if (first_import_lib_url.raw() == url()) { 7005 // This is the first object we found, or the
7020 OS::SNPrint(message_buffer, 7006 // previously found object is exported from a Dart
7021 kMessageBufferSize, 7007 // system library. The newly found object hides the one
7022 "ambiguous reference to '%s', " 7008 // from the Dart library.
7023 "as library '%s' is imported multiple times", 7009 first_import_lib_url = import_lib.url();
7024 name.ToCString(), 7010 found_obj = obj.raw();
7025 first_import_lib_url.ToCString()); 7011 } else if (import_lib_url.StartsWith(Symbols::DartScheme())) {
7012 // The newly found object is exported from a Dart system
7013 // library. It is hidden by the previously found object.
7014 // We continue to search.
7026 } else { 7015 } else {
7027 OS::SNPrint(message_buffer, 7016 // We found two different objects with the same name.
7028 kMessageBufferSize, 7017 return Object::null();
7029 "ambiguous reference: "
7030 "'%s' is defined in library '%s' and also in '%s'",
7031 name.ToCString(),
7032 first_import_lib_url.ToCString(),
7033 String::Handle(url()).ToCString());
7034 } 7018 }
7035 // If the caller does not expect an ambiguity error, it may pass NULL as
7036 // ambiguity_error_msg in order to avoid the allocation of a handle.
7037 // It typically does so when looking up an object in the core library,
7038 // which is guaranteed not to contain ambiguities, unless the core lib
7039 // is under development, in which case the assert below may fail.
7040 ASSERT(ambiguity_error_msg != NULL); // No ambiguity error expected.
7041 *ambiguity_error_msg = String::New(message_buffer);
7042 return Object::null();
7043 } 7019 }
7044 first_import_lib_url = url();
7045 found_obj = obj.raw();
7046 } 7020 }
7047 } 7021 }
7048 return found_obj.raw(); 7022 return found_obj.raw();
7049 } 7023 }
7050 7024
7051 7025
7052 RawClass* Library::LookupClass(const String& name, 7026 RawClass* Library::LookupClass(const String& name) const {
7053 String* ambiguity_error_msg) const { 7027 Object& obj = Object::Handle(LookupObject(name));
7054 Object& obj = Object::Handle(LookupObject(name, ambiguity_error_msg));
7055 if (obj.IsClass()) { 7028 if (obj.IsClass()) {
7056 return Class::Cast(obj).raw(); 7029 return Class::Cast(obj).raw();
7057 } 7030 }
7058 return Class::null(); 7031 return Class::null();
7059 } 7032 }
7060 7033
7061 7034
7062 RawClass* Library::LookupLocalClass(const String& name) const { 7035 RawClass* Library::LookupLocalClass(const String& name) const {
7063 Object& obj = Object::Handle(LookupLocalObject(name)); 7036 Object& obj = Object::Handle(LookupLocalObject(name));
7064 if (obj.IsClass()) { 7037 if (obj.IsClass()) {
7065 return Class::Cast(obj).raw(); 7038 return Class::Cast(obj).raw();
7066 } 7039 }
7067 return Class::null(); 7040 return Class::null();
7068 } 7041 }
7069 7042
7070 7043
7071 RawClass* Library::LookupClassAllowPrivate(const String& name, 7044 RawClass* Library::LookupClassAllowPrivate(const String& name) const {
7072 String* ambiguity_error_msg) const {
7073 // See if the class is available in this library or in the top level 7045 // See if the class is available in this library or in the top level
7074 // scope of any imported library. 7046 // scope of any imported library.
7075 Isolate* isolate = Isolate::Current(); 7047 Isolate* isolate = Isolate::Current();
7076 const Class& cls = Class::Handle(isolate, LookupClass(name, 7048 const Class& cls = Class::Handle(isolate, LookupClass(name));
7077 ambiguity_error_msg));
7078 if (!cls.IsNull()) { 7049 if (!cls.IsNull()) {
7079 return cls.raw(); 7050 return cls.raw();
7080 } 7051 }
7081 7052
7082 // Now try to lookup the class using its private name, but only in 7053 // Now try to lookup the class using its private name, but only in
7083 // this library (not in imported libraries). 7054 // this library (not in imported libraries).
7084 if (ShouldBePrivate(name)) { 7055 if (ShouldBePrivate(name)) {
7085 String& private_name = String::Handle(isolate, PrivateName(name)); 7056 String& private_name = String::Handle(isolate, PrivateName(name));
7086 const Object& obj = Object::Handle(LookupLocalObject(private_name)); 7057 const Object& obj = Object::Handle(LookupLocalObject(private_name));
7087 if (obj.IsClass()) { 7058 if (obj.IsClass()) {
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
7549 if (num_current_imports >= length) { 7520 if (num_current_imports >= length) {
7550 const intptr_t new_length = length + kIncrementSize; 7521 const intptr_t new_length = length + kIncrementSize;
7551 imports = Array::Grow(imports, new_length, Heap::kOld); 7522 imports = Array::Grow(imports, new_length, Heap::kOld);
7552 set_imports(imports); 7523 set_imports(imports);
7553 } 7524 }
7554 imports.SetAt(num_current_imports, import); 7525 imports.SetAt(num_current_imports, import);
7555 set_num_imports(num_current_imports + 1); 7526 set_num_imports(num_current_imports + 1);
7556 } 7527 }
7557 7528
7558 7529
7559 RawClass* LibraryPrefix::LookupClass(const String& class_name, 7530 RawObject* LibraryPrefix::LookupObject(const String& name) const {
7560 String* ambiguity_error_msg) const {
7561 Array& imports = Array::Handle(this->imports()); 7531 Array& imports = Array::Handle(this->imports());
7562 Object& obj = Object::Handle(); 7532 Object& obj = Object::Handle();
7563 Namespace& import = Namespace::Handle(); 7533 Namespace& import = Namespace::Handle();
7564 Library& import_lib = Library::Handle(); 7534 Library& import_lib = Library::Handle();
7535 String& import_lib_url = String::Handle();
7565 String& first_import_lib_url = String::Handle(); 7536 String& first_import_lib_url = String::Handle();
7566 Object& found_obj = Object::Handle(); 7537 Object& found_obj = Object::Handle();
7567 for (intptr_t i = 0; i < num_imports(); i++) { 7538 for (intptr_t i = 0; i < num_imports(); i++) {
7568 import ^= imports.At(i); 7539 import ^= imports.At(i);
7569 obj = import.Lookup(class_name); 7540 obj = import.Lookup(name);
7570 if (!obj.IsNull()) { 7541 if (!obj.IsNull()) {
7571 import_lib = import.library(); 7542 import_lib = import.library();
7572 if (!first_import_lib_url.IsNull()) { 7543 import_lib_url = import_lib.url();
7573 // Found duplicate definition. 7544 if (found_obj.raw() != obj.raw()) {
7574 const intptr_t kMessageBufferSize = 512; 7545 if (first_import_lib_url.IsNull() ||
7575 char message_buffer[kMessageBufferSize]; 7546 first_import_lib_url.StartsWith(Symbols::DartScheme())) {
7576 if (first_import_lib_url.raw() == import_lib.url()) { 7547 // This is the first object we found, or the
7577 OS::SNPrint(message_buffer, 7548 // previously found object is exported from a Dart
7578 kMessageBufferSize, 7549 // system library. The newly found object hides the one
7579 "ambiguous reference to '%s', " 7550 // from the Dart library.
7580 "as library '%s' is imported multiple times via " 7551 first_import_lib_url = import_lib.url();
7581 "prefix '%s'", 7552 found_obj = obj.raw();
7582 class_name.ToCString(), 7553 } else if (import_lib_url.StartsWith(Symbols::DartScheme())) {
7583 first_import_lib_url.ToCString(), 7554 // The newly found object is exported from a Dart system
7584 String::Handle(name()).ToCString()); 7555 // library. It is hidden by the previously found object.
7556 // We continue to search.
7585 } else { 7557 } else {
7586 OS::SNPrint(message_buffer, 7558 // We found two different objects with the same name.
7587 kMessageBufferSize, 7559 return Object::null();
7588 "ambiguous reference: "
7589 "'%s' is defined in library '%s' and also in '%s', "
7590 "both imported via prefix '%s'",
7591 class_name.ToCString(),
7592 first_import_lib_url.ToCString(),
7593 String::Handle(import_lib.url()).ToCString(),
7594 String::Handle(name()).ToCString());
7595 } 7560 }
7596 // If the caller does not expect an ambiguity error, it may pass NULL as
7597 // ambiguity_error_msg in order to avoid the allocation of a handle.
7598 // It typically does so when looking up a class in the core library,
7599 // which is guaranteed not to contain ambiguities, unless the core lib
7600 // is under development, in which case the assert below may fail.
7601 ASSERT(ambiguity_error_msg != NULL); // No ambiguity error expected.
7602 *ambiguity_error_msg = String::New(message_buffer);
7603 return Class::null();
7604 } 7561 }
7605 first_import_lib_url = import_lib.url();
7606 found_obj = obj.raw();
7607 } 7562 }
7608 } 7563 }
7609 if (found_obj.IsClass()) { 7564 return found_obj.raw();
7610 return Class::Cast(found_obj).raw(); 7565 }
7566
7567
7568 RawClass* LibraryPrefix::LookupClass(const String& class_name) const {
7569 const Object& obj = Object::Handle(LookupObject(class_name));
7570 if (obj.IsClass()) {
7571 return Class::Cast(obj).raw();
7611 } 7572 }
7612 return Class::null(); 7573 return Class::null();
7613 } 7574 }
7614 7575
7615 7576
7616 RawLibraryPrefix* LibraryPrefix::New() { 7577 RawLibraryPrefix* LibraryPrefix::New() {
7617 ASSERT(Object::library_prefix_class() != Class::null()); 7578 ASSERT(Object::library_prefix_class() != Class::null());
7618 RawObject* raw = Object::Allocate(LibraryPrefix::kClassId, 7579 RawObject* raw = Object::Allocate(LibraryPrefix::kClassId,
7619 LibraryPrefix::InstanceSize(), 7580 LibraryPrefix::InstanceSize(),
7620 Heap::kOld); 7581 Heap::kOld);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
7719 } 7680 }
7720 // There is a list of visible names. The name we're looking for is not 7681 // There is a list of visible names. The name we're looking for is not
7721 // contained in the list, so it is hidden. 7682 // contained in the list, so it is hidden.
7722 return true; 7683 return true;
7723 } 7684 }
7724 // The name is not filtered out. 7685 // The name is not filtered out.
7725 return false; 7686 return false;
7726 } 7687 }
7727 7688
7728 7689
7690 // Look up object with given name in library and filter out hidden
7691 // names. Also look up getters and setters.
7729 RawObject* Namespace::Lookup(const String& name) const { 7692 RawObject* Namespace::Lookup(const String& name) const {
7730 Isolate* isolate = Isolate::Current(); 7693 Isolate* isolate = Isolate::Current();
7731 const Library& lib = Library::Handle(isolate, library()); 7694 const Library& lib = Library::Handle(isolate, library());
7732 intptr_t ignore = 0; 7695 intptr_t ignore = 0;
7696
7733 // Lookup the name in the library's symbols. 7697 // Lookup the name in the library's symbols.
7698 const String* filter_name = &name;
7734 Object& obj = Object::Handle(isolate, lib.LookupEntry(name, &ignore)); 7699 Object& obj = Object::Handle(isolate, lib.LookupEntry(name, &ignore));
7700 if (Field::IsGetterName(name)) {
7701 filter_name = &String::Handle(Field::NameFromGetter(name));
7702 } else if (Field::IsSetterName(name)) {
7703 filter_name = &String::Handle(Field::NameFromGetter(name));
7704 } else {
7705 if (obj.IsNull() || obj.IsLibraryPrefix()) {
7706 obj = lib.LookupEntry(String::Handle(Field::GetterName(name)), &ignore);
7707 if (obj.IsNull()) {
7708 obj = lib.LookupEntry(String::Handle(Field::SetterName(name)), &ignore);
7709 }
7710 }
7711 }
7712
7735 // Library prefixes are not exported. 7713 // Library prefixes are not exported.
7736 if (obj.IsNull() || obj.IsLibraryPrefix()) { 7714 if (obj.IsNull() || obj.IsLibraryPrefix()) {
7737 // Lookup in the re-exported symbols. 7715 // Lookup in the re-exported symbols.
7738 obj = lib.LookupExport(name); 7716 obj = lib.LookupReExport(name);
7739 } 7717 }
7740 if (obj.IsNull() || HidesName(name) || obj.IsLibraryPrefix()) { 7718 if (obj.IsNull() || HidesName(*filter_name) || obj.IsLibraryPrefix()) {
7741 return Object::null(); 7719 return Object::null();
7742 } 7720 }
7743 return obj.raw(); 7721 return obj.raw();
7744 } 7722 }
7745 7723
7746 7724
7747 RawNamespace* Namespace::New() { 7725 RawNamespace* Namespace::New() {
7748 ASSERT(Object::namespace_class() != Class::null()); 7726 ASSERT(Object::namespace_class() != Class::null());
7749 RawObject* raw = Object::Allocate(Namespace::kClassId, 7727 RawObject* raw = Object::Allocate(Namespace::kClassId,
7750 Namespace::InstanceSize(), 7728 Namespace::InstanceSize(),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
7804 const char* class_name, 7782 const char* class_name,
7805 const char* function_name) { 7783 const char* function_name) {
7806 Function& func = Function::Handle(); 7784 Function& func = Function::Handle();
7807 String& class_str = String::Handle(); 7785 String& class_str = String::Handle();
7808 String& func_str = String::Handle(); 7786 String& func_str = String::Handle();
7809 Class& cls = Class::Handle(); 7787 Class& cls = Class::Handle();
7810 for (intptr_t l = 0; l < libs.length(); l++) { 7788 for (intptr_t l = 0; l < libs.length(); l++) {
7811 const Library& lib = *libs[l]; 7789 const Library& lib = *libs[l];
7812 if (strcmp(class_name, "::") == 0) { 7790 if (strcmp(class_name, "::") == 0) {
7813 func_str = Symbols::New(function_name); 7791 func_str = Symbols::New(function_name);
7814 func = lib.LookupFunctionAllowPrivate(func_str, NULL); 7792 func = lib.LookupFunctionAllowPrivate(func_str);
7815 } else { 7793 } else {
7816 class_str = String::New(class_name); 7794 class_str = String::New(class_name);
7817 cls = lib.LookupClassAllowPrivate(class_str, NULL); 7795 cls = lib.LookupClassAllowPrivate(class_str);
7818 if (!cls.IsNull()) { 7796 if (!cls.IsNull()) {
7819 func_str = String::New(function_name); 7797 func_str = String::New(function_name);
7820 if (function_name[0] == '.') { 7798 if (function_name[0] == '.') {
7821 func_str = String::Concat(class_str, func_str); 7799 func_str = String::Concat(class_str, func_str);
7822 } 7800 }
7823 func = cls.LookupFunctionAllowPrivate(func_str); 7801 func = cls.LookupFunctionAllowPrivate(func_str);
7824 } 7802 }
7825 } 7803 }
7826 if (!func.IsNull()) { 7804 if (!func.IsNull()) {
7827 return func.raw(); 7805 return func.raw();
(...skipping 7119 matching lines...) Expand 10 before | Expand all | Expand 10 after
14947 } 14925 }
14948 14926
14949 14927
14950 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14928 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14951 stream->OpenObject(); 14929 stream->OpenObject();
14952 stream->CloseObject(); 14930 stream->CloseObject();
14953 } 14931 }
14954 14932
14955 14933
14956 } // namespace dart 14934 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698