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/become.h" | 10 #include "vm/become.h" |
| (...skipping 6827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6838 const Instance& result = Instance::Handle(Closure::New(*this, context)); | 6838 const Instance& result = Instance::Handle(Closure::New(*this, context)); |
| 6839 if (cls.IsGeneric()) { | 6839 if (cls.IsGeneric()) { |
| 6840 const TypeArguments& type_arguments = | 6840 const TypeArguments& type_arguments = |
| 6841 TypeArguments::Handle(receiver.GetTypeArguments()); | 6841 TypeArguments::Handle(receiver.GetTypeArguments()); |
| 6842 result.SetTypeArguments(type_arguments); | 6842 result.SetTypeArguments(type_arguments); |
| 6843 } | 6843 } |
| 6844 return result.raw(); | 6844 return result.raw(); |
| 6845 } | 6845 } |
| 6846 | 6846 |
| 6847 | 6847 |
| 6848 RawSmi* Function::GetClosureHashCode() const { | |
| 6849 ASSERT(IsClosureFunction()); | |
| 6850 const Object& obj = Object::Handle(raw_ptr()->data_); | |
| 6851 ASSERT(!obj.IsNull()); | |
| 6852 if (ClosureData::Cast(obj).hash() != Object::null()) { | |
| 6853 ASSERT(Object::Handle(ClosureData::Cast(obj).hash()).IsSmi()); | |
|
Cutch
2016/12/21 16:49:38
Smi::RawCast already ASSERTS that the object is a
Florian Schneider
2016/12/22 10:11:17
Done.
| |
| 6854 return Smi::RawCast(ClosureData::Cast(obj).hash()); | |
| 6855 } | |
| 6856 // Hash not yet computed. Compute and cache it. | |
| 6857 const Class& cls = Class::Handle(Owner()); | |
| 6858 intptr_t result = String::Handle(name()).Hash(); | |
| 6859 result += String::Handle(Signature()).Hash(); | |
| 6860 result += String::Handle(cls.Name()).Hash(); | |
| 6861 // Finalize hash value like for strings so that it fits into a smi. | |
| 6862 result += result << 3; | |
| 6863 result ^= result >> 11; | |
| 6864 result += result << 15; | |
| 6865 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); | |
| 6866 ClosureData::Cast(obj).set_hash(result); | |
| 6867 return Smi::New(result); | |
| 6868 } | |
| 6869 | |
| 6870 | |
| 6848 RawString* Function::BuildSignature(bool instantiate, | 6871 RawString* Function::BuildSignature(bool instantiate, |
| 6849 NameVisibility name_visibility, | 6872 NameVisibility name_visibility, |
| 6850 const TypeArguments& instantiator) const { | 6873 const TypeArguments& instantiator) const { |
| 6851 Thread* thread = Thread::Current(); | 6874 Thread* thread = Thread::Current(); |
| 6852 Zone* zone = thread->zone(); | 6875 Zone* zone = thread->zone(); |
| 6853 GrowableHandlePtrArray<const String> pieces(zone, 4); | 6876 GrowableHandlePtrArray<const String> pieces(zone, 4); |
| 6854 String& name = String::Handle(zone); | 6877 String& name = String::Handle(zone); |
| 6855 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { | 6878 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { |
| 6856 // Prefix the signature with its scope class and type parameters, if any | 6879 // Prefix the signature with its scope class and type parameters, if any |
| 6857 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the | 6880 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7214 } | 7237 } |
| 7215 | 7238 |
| 7216 | 7239 |
| 7217 void ClosureData::set_implicit_static_closure(const Instance& closure) const { | 7240 void ClosureData::set_implicit_static_closure(const Instance& closure) const { |
| 7218 ASSERT(!closure.IsNull()); | 7241 ASSERT(!closure.IsNull()); |
| 7219 ASSERT(raw_ptr()->closure_ == Instance::null()); | 7242 ASSERT(raw_ptr()->closure_ == Instance::null()); |
| 7220 StorePointer(&raw_ptr()->closure_, closure.raw()); | 7243 StorePointer(&raw_ptr()->closure_, closure.raw()); |
| 7221 } | 7244 } |
| 7222 | 7245 |
| 7223 | 7246 |
| 7247 void ClosureData::set_hash(intptr_t value) const { | |
| 7248 StorePointer(&raw_ptr()->hash_, static_cast<RawObject*>(Smi::New(value))); | |
| 7249 } | |
| 7250 | |
| 7251 | |
| 7224 void ClosureData::set_parent_function(const Function& value) const { | 7252 void ClosureData::set_parent_function(const Function& value) const { |
| 7225 StorePointer(&raw_ptr()->parent_function_, value.raw()); | 7253 StorePointer(&raw_ptr()->parent_function_, value.raw()); |
| 7226 } | 7254 } |
| 7227 | 7255 |
| 7228 | 7256 |
| 7229 void ClosureData::set_signature_type(const Type& value) const { | 7257 void ClosureData::set_signature_type(const Type& value) const { |
| 7230 StorePointer(&raw_ptr()->signature_type_, value.raw()); | 7258 StorePointer(&raw_ptr()->signature_type_, value.raw()); |
| 7231 } | 7259 } |
| 7232 | 7260 |
| 7233 | 7261 |
| (...skipping 15638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22872 return UserTag::null(); | 22900 return UserTag::null(); |
| 22873 } | 22901 } |
| 22874 | 22902 |
| 22875 | 22903 |
| 22876 const char* UserTag::ToCString() const { | 22904 const char* UserTag::ToCString() const { |
| 22877 const String& tag_label = String::Handle(label()); | 22905 const String& tag_label = String::Handle(label()); |
| 22878 return tag_label.ToCString(); | 22906 return tag_label.ToCString(); |
| 22879 } | 22907 } |
| 22880 | 22908 |
| 22881 } // namespace dart | 22909 } // namespace dart |
| OLD | NEW |