| 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 6955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6966 } | 6966 } |
| 6967 | 6967 |
| 6968 | 6968 |
| 6969 void RedirectionData::PrintJSONImpl(JSONStream* stream, bool ref) const { | 6969 void RedirectionData::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 6970 Object::PrintJSONImpl(stream, ref); | 6970 Object::PrintJSONImpl(stream, ref); |
| 6971 } | 6971 } |
| 6972 | 6972 |
| 6973 | 6973 |
| 6974 RawString* Field::GetterName(const String& field_name) { | 6974 RawString* Field::GetterName(const String& field_name) { |
| 6975 CompilerStats::make_accessor_name++; | 6975 CompilerStats::make_accessor_name++; |
| 6976 // TODO(koda): Avoid most of these allocations by adding prefix-based lookup | |
| 6977 // to Class::Lookup*. | |
| 6978 return String::Concat(Symbols::GetterPrefix(), field_name); | 6976 return String::Concat(Symbols::GetterPrefix(), field_name); |
| 6979 } | 6977 } |
| 6980 | 6978 |
| 6981 | 6979 |
| 6982 RawString* Field::GetterSymbol(const String& field_name) { | 6980 RawString* Field::GetterSymbol(const String& field_name) { |
| 6983 return Symbols::FromConcat(Symbols::GetterPrefix(), field_name); | 6981 return Symbols::FromConcat(Symbols::GetterPrefix(), field_name); |
| 6984 } | 6982 } |
| 6985 | 6983 |
| 6986 | 6984 |
| 6987 RawString* Field::SetterName(const String& field_name) { | 6985 RawString* Field::SetterName(const String& field_name) { |
| 6988 CompilerStats::make_accessor_name++; | 6986 CompilerStats::make_accessor_name++; |
| 6989 // TODO(koda): Avoid most of these allocations by adding prefix-based lookup | |
| 6990 // to Class::Lookup*. | |
| 6991 return String::Concat(Symbols::SetterPrefix(), field_name); | 6987 return String::Concat(Symbols::SetterPrefix(), field_name); |
| 6992 } | 6988 } |
| 6993 | 6989 |
| 6994 | 6990 |
| 6995 RawString* Field::SetterSymbol(const String& field_name) { | 6991 RawString* Field::SetterSymbol(const String& field_name) { |
| 6996 return Symbols::FromConcat(Symbols::SetterPrefix(), field_name); | 6992 return Symbols::FromConcat(Symbols::SetterPrefix(), field_name); |
| 6997 } | 6993 } |
| 6998 | 6994 |
| 6999 | 6995 |
| 7000 RawString* Field::NameFromGetter(const String& getter_name) { | 6996 RawString* Field::NameFromGetter(const String& getter_name) { |
| (...skipping 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8907 field.token_pos()); | 8903 field.token_pos()); |
| 8908 if (metadata.IsArray()) { | 8904 if (metadata.IsArray()) { |
| 8909 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); | 8905 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); |
| 8910 field.set_value(Array::Cast(metadata)); | 8906 field.set_value(Array::Cast(metadata)); |
| 8911 } | 8907 } |
| 8912 } | 8908 } |
| 8913 return metadata.raw(); | 8909 return metadata.raw(); |
| 8914 } | 8910 } |
| 8915 | 8911 |
| 8916 | 8912 |
| 8913 static bool ShouldBePrivate(const String& name) { |
| 8914 return |
| 8915 (name.Length() >= 1 && |
| 8916 name.CharAt(0) == '_') || |
| 8917 (name.Length() >= 5 && |
| 8918 (name.CharAt(4) == '_' && |
| 8919 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && |
| 8920 name.CharAt(1) == 'e' && |
| 8921 name.CharAt(2) == 't' && |
| 8922 name.CharAt(3) == ':')); |
| 8923 } |
| 8924 |
| 8925 |
| 8917 RawObject* Library::ResolveName(const String& name) const { | 8926 RawObject* Library::ResolveName(const String& name) const { |
| 8918 Object& obj = Object::Handle(); | 8927 Object& obj = Object::Handle(); |
| 8919 if (FLAG_use_lib_cache && LookupResolvedNamesCache(name, &obj)) { | 8928 if (FLAG_use_lib_cache && LookupResolvedNamesCache(name, &obj)) { |
| 8920 return obj.raw(); | 8929 return obj.raw(); |
| 8921 } | 8930 } |
| 8922 obj = LookupLocalObject(name); | 8931 obj = LookupLocalObject(name); |
| 8923 if (!obj.IsNull()) { | 8932 if (!obj.IsNull()) { |
| 8924 // Names that are in this library's dictionary and are unmangled | 8933 // Names that are in this library's dictionary and are unmangled |
| 8925 // are not cached. This reduces the size of the the cache. | 8934 // are not cached. This reduces the size of the the cache. |
| 8926 return obj.raw(); | 8935 return obj.raw(); |
| 8927 } | 8936 } |
| 8928 String& accessor_name = String::Handle(Field::GetterName(name)); | 8937 String& accessor_name = String::Handle(Field::GetterName(name)); |
| 8929 obj = LookupLocalObject(accessor_name); | 8938 obj = LookupLocalObject(accessor_name); |
| 8930 if (obj.IsNull()) { | 8939 if (obj.IsNull()) { |
| 8931 accessor_name = Field::SetterName(name); | 8940 accessor_name = Field::SetterName(name); |
| 8932 obj = LookupLocalObject(accessor_name); | 8941 obj = LookupLocalObject(accessor_name); |
| 8933 if (obj.IsNull()) { | 8942 if (obj.IsNull() && !ShouldBePrivate(name)) { |
| 8934 obj = LookupImportedObject(name); | 8943 obj = LookupImportedObject(name); |
| 8935 } | 8944 } |
| 8936 } | 8945 } |
| 8937 AddToResolvedNamesCache(name, obj); | 8946 AddToResolvedNamesCache(name, obj); |
| 8938 return obj.raw(); | 8947 return obj.raw(); |
| 8939 } | 8948 } |
| 8940 | 8949 |
| 8941 | 8950 |
| 8942 class StringEqualsTraits { | 8951 class StringEqualsTraits { |
| 8943 public: | 8952 public: |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9259 return Function::null(); | 9268 return Function::null(); |
| 9260 } | 9269 } |
| 9261 | 9270 |
| 9262 | 9271 |
| 9263 RawObject* Library::LookupLocalObject(const String& name) const { | 9272 RawObject* Library::LookupLocalObject(const String& name) const { |
| 9264 intptr_t index; | 9273 intptr_t index; |
| 9265 return LookupEntry(name, &index); | 9274 return LookupEntry(name, &index); |
| 9266 } | 9275 } |
| 9267 | 9276 |
| 9268 | 9277 |
| 9269 static bool ShouldBePrivate(const String& name) { | |
| 9270 return | |
| 9271 (name.Length() >= 1 && | |
| 9272 name.CharAt(0) == '_') || | |
| 9273 (name.Length() >= 5 && | |
| 9274 (name.CharAt(4) == '_' && | |
| 9275 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && | |
| 9276 name.CharAt(1) == 'e' && | |
| 9277 name.CharAt(2) == 't' && | |
| 9278 name.CharAt(3) == ':')); | |
| 9279 } | |
| 9280 | |
| 9281 | |
| 9282 RawField* Library::LookupFieldAllowPrivate(const String& name) const { | 9278 RawField* Library::LookupFieldAllowPrivate(const String& name) const { |
| 9283 Object& obj = Object::Handle(LookupObjectAllowPrivate(name)); | 9279 Object& obj = Object::Handle(LookupObjectAllowPrivate(name)); |
| 9284 if (obj.IsField()) { | 9280 if (obj.IsField()) { |
| 9285 return Field::Cast(obj).raw(); | 9281 return Field::Cast(obj).raw(); |
| 9286 } | 9282 } |
| 9287 return Field::null(); | 9283 return Field::null(); |
| 9288 } | 9284 } |
| 9289 | 9285 |
| 9290 | 9286 |
| 9291 RawField* Library::LookupLocalField(const String& name) const { | 9287 RawField* Library::LookupLocalField(const String& name) const { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9345 | 9341 |
| 9346 | 9342 |
| 9347 RawObject* Library::LookupImportedObject(const String& name) const { | 9343 RawObject* Library::LookupImportedObject(const String& name) const { |
| 9348 Object& obj = Object::Handle(); | 9344 Object& obj = Object::Handle(); |
| 9349 Namespace& import = Namespace::Handle(); | 9345 Namespace& import = Namespace::Handle(); |
| 9350 Library& import_lib = Library::Handle(); | 9346 Library& import_lib = Library::Handle(); |
| 9351 String& import_lib_url = String::Handle(); | 9347 String& import_lib_url = String::Handle(); |
| 9352 String& first_import_lib_url = String::Handle(); | 9348 String& first_import_lib_url = String::Handle(); |
| 9353 Object& found_obj = Object::Handle(); | 9349 Object& found_obj = Object::Handle(); |
| 9354 String& found_obj_name = String::Handle(); | 9350 String& found_obj_name = String::Handle(); |
| 9351 // We don't look up getter names explicitly. Setter names are |
| 9352 // looked up explicitly when converting top-level getters to setters. |
| 9353 ASSERT(!Field::IsGetterName(name)); |
| 9354 ASSERT(!ShouldBePrivate(name)); |
| 9355 for (intptr_t i = 0; i < num_imports(); i++) { | 9355 for (intptr_t i = 0; i < num_imports(); i++) { |
| 9356 import ^= ImportAt(i); | 9356 import ^= ImportAt(i); |
| 9357 obj = import.Lookup(name); | 9357 obj = import.Lookup(name); |
| 9358 if (!obj.IsNull()) { | 9358 if (!obj.IsNull()) { |
| 9359 import_lib = import.library(); | 9359 import_lib = import.library(); |
| 9360 import_lib_url = import_lib.url(); | 9360 import_lib_url = import_lib.url(); |
| 9361 if (found_obj.raw() != obj.raw()) { | 9361 if (found_obj.raw() != obj.raw()) { |
| 9362 if (first_import_lib_url.IsNull() || | 9362 if (first_import_lib_url.IsNull() || |
| 9363 first_import_lib_url.StartsWith(Symbols::DartScheme())) { | 9363 first_import_lib_url.StartsWith(Symbols::DartScheme())) { |
| 9364 // This is the first object we found, or the | 9364 // This is the first object we found, or the |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10354 | 10354 |
| 10355 | 10355 |
| 10356 // Look up object with given name in library and filter out hidden | 10356 // Look up object with given name in library and filter out hidden |
| 10357 // names. Also look up getters and setters. | 10357 // names. Also look up getters and setters. |
| 10358 RawObject* Namespace::Lookup(const String& name) const { | 10358 RawObject* Namespace::Lookup(const String& name) const { |
| 10359 Isolate* isolate = Isolate::Current(); | 10359 Isolate* isolate = Isolate::Current(); |
| 10360 const Library& lib = Library::Handle(isolate, library()); | 10360 const Library& lib = Library::Handle(isolate, library()); |
| 10361 intptr_t ignore = 0; | 10361 intptr_t ignore = 0; |
| 10362 | 10362 |
| 10363 // Lookup the name in the library's symbols. | 10363 // Lookup the name in the library's symbols. |
| 10364 const String* filter_name = &name; | |
| 10365 Object& obj = Object::Handle(isolate, lib.LookupEntry(name, &ignore)); | 10364 Object& obj = Object::Handle(isolate, lib.LookupEntry(name, &ignore)); |
| 10366 if (Field::IsGetterName(name)) { | 10365 if (!Field::IsGetterName(name) && |
| 10367 filter_name = &String::Handle(Field::NameFromGetter(name)); | 10366 !Field::IsSetterName(name) && |
| 10368 } else if (Field::IsSetterName(name)) { | 10367 (obj.IsNull() || obj.IsLibraryPrefix())) { |
| 10369 filter_name = &String::Handle(Field::NameFromSetter(name)); | 10368 obj = lib.LookupEntry(String::Handle(Field::GetterName(name)), &ignore); |
| 10370 } else { | 10369 if (obj.IsNull()) { |
| 10371 if (obj.IsNull() || obj.IsLibraryPrefix()) { | 10370 obj = lib.LookupEntry(String::Handle(Field::SetterName(name)), &ignore); |
| 10372 obj = lib.LookupEntry(String::Handle(Field::GetterName(name)), &ignore); | |
| 10373 if (obj.IsNull()) { | |
| 10374 obj = lib.LookupEntry(String::Handle(Field::SetterName(name)), &ignore); | |
| 10375 } | |
| 10376 } | 10371 } |
| 10377 } | 10372 } |
| 10378 | 10373 |
| 10379 // Library prefixes are not exported. | 10374 // Library prefixes are not exported. |
| 10380 if (obj.IsNull() || obj.IsLibraryPrefix()) { | 10375 if (obj.IsNull() || obj.IsLibraryPrefix()) { |
| 10381 // Lookup in the re-exported symbols. | 10376 // Lookup in the re-exported symbols. |
| 10382 obj = lib.LookupReExport(name); | 10377 obj = lib.LookupReExport(name); |
| 10383 } | 10378 } |
| 10384 if (obj.IsNull() || HidesName(*filter_name) || obj.IsLibraryPrefix()) { | 10379 if (obj.IsNull() || HidesName(name) || obj.IsLibraryPrefix()) { |
| 10385 return Object::null(); | 10380 return Object::null(); |
| 10386 } | 10381 } |
| 10387 return obj.raw(); | 10382 return obj.raw(); |
| 10388 } | 10383 } |
| 10389 | 10384 |
| 10390 | 10385 |
| 10391 RawNamespace* Namespace::New() { | 10386 RawNamespace* Namespace::New() { |
| 10392 ASSERT(Object::namespace_class() != Class::null()); | 10387 ASSERT(Object::namespace_class() != Class::null()); |
| 10393 RawObject* raw = Object::Allocate(Namespace::kClassId, | 10388 RawObject* raw = Object::Allocate(Namespace::kClassId, |
| 10394 Namespace::InstanceSize(), | 10389 Namespace::InstanceSize(), |
| (...skipping 10328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20723 return tag_label.ToCString(); | 20718 return tag_label.ToCString(); |
| 20724 } | 20719 } |
| 20725 | 20720 |
| 20726 | 20721 |
| 20727 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20722 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20728 Instance::PrintJSONImpl(stream, ref); | 20723 Instance::PrintJSONImpl(stream, ref); |
| 20729 } | 20724 } |
| 20730 | 20725 |
| 20731 | 20726 |
| 20732 } // namespace dart | 20727 } // namespace dart |
| OLD | NEW |