Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 // Finish the initialization by compiling the bootstrap scripts containing the | 593 // Finish the initialization by compiling the bootstrap scripts containing the |
| 594 // base interfaces and the implementation of the internal classes. | 594 // base interfaces and the implementation of the internal classes. |
| 595 Bootstrap::Compile(core_lib, script); | 595 Bootstrap::Compile(core_lib, script); |
| 596 Bootstrap::Compile(core_impl_lib, impl_script); | 596 Bootstrap::Compile(core_impl_lib, impl_script); |
| 597 | 597 |
| 598 Bootstrap::SetupNativeResolver(); | 598 Bootstrap::SetupNativeResolver(); |
| 599 | 599 |
| 600 // Remove the Object superclass cycle by setting the super type to null (not | 600 // Remove the Object superclass cycle by setting the super type to null (not |
| 601 // to the type of null). | 601 // to the type of null). |
| 602 cls = object_store->object_class(); | 602 cls = object_store->object_class(); |
| 603 cls.set_super_type(AbstractType::Handle()); | 603 cls.set_super_type(Type::Handle()); |
| 604 | 604 |
| 605 ClassFinalizer::VerifyBootstrapClasses(); | 605 ClassFinalizer::VerifyBootstrapClasses(); |
| 606 } | 606 } |
| 607 | 607 |
| 608 | 608 |
| 609 void Object::InitFromSnapshot(Isolate* isolate) { | 609 void Object::InitFromSnapshot(Isolate* isolate) { |
| 610 TIMERSCOPE(time_bootstrap); | 610 TIMERSCOPE(time_bootstrap); |
| 611 ObjectStore* object_store = isolate->object_store(); | 611 ObjectStore* object_store = isolate->object_store(); |
| 612 | 612 |
| 613 Class& cls = Class::Handle(); | 613 Class& cls = Class::Handle(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 RawString* Class::Name() const { | 717 RawString* Class::Name() const { |
| 718 if (raw_ptr()->name_ != String::null()) { | 718 if (raw_ptr()->name_ != String::null()) { |
| 719 return raw_ptr()->name_; | 719 return raw_ptr()->name_; |
| 720 } | 720 } |
| 721 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work. | 721 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work. |
| 722 intptr_t index = GetSingletonClassIndex(raw()); | 722 intptr_t index = GetSingletonClassIndex(raw()); |
| 723 return String::NewSymbol(GetSingletonClassName(index)); | 723 return String::NewSymbol(GetSingletonClassName(index)); |
| 724 } | 724 } |
| 725 | 725 |
| 726 | 726 |
| 727 RawAbstractType* Class::SignatureType() const { | 727 RawType* Class::SignatureType() const { |
| 728 // Return the first canonical signature type if already computed. | 728 // Return the first canonical signature type if already computed. |
| 729 const Array& signature_types = Array::Handle(canonical_types()); | 729 const Array& signature_types = Array::Handle(canonical_types()); |
| 730 if (signature_types.Length() > 0) { | 730 if (signature_types.Length() > 0) { |
| 731 AbstractType& signature_type = AbstractType::Handle(); | 731 Type& signature_type = Type::Handle(); |
| 732 signature_type ^= signature_types.At(0); | 732 signature_type ^= signature_types.At(0); |
| 733 if (!signature_type.IsNull()) { | 733 if (!signature_type.IsNull()) { |
| 734 return signature_type.raw(); | 734 return signature_type.raw(); |
| 735 } | 735 } |
| 736 } | 736 } |
| 737 ASSERT(IsSignatureClass()); | 737 ASSERT(IsSignatureClass()); |
| 738 TypeArguments& signature_type_arguments = TypeArguments::Handle(); | 738 TypeArguments& signature_type_arguments = TypeArguments::Handle(); |
| 739 const intptr_t num_type_params = NumTypeParameters(); | 739 const intptr_t num_type_params = NumTypeParameters(); |
| 740 // A signature class extends class Instance and is parameterized in the same | 740 // A signature class extends class Instance and is parameterized in the same |
| 741 // way as the owner class of its non-static signature function. | 741 // way as the owner class of its non-static signature function. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 // More efficient than calling NumTypeArguments(). | 894 // More efficient than calling NumTypeArguments(). |
| 895 return type_arguments_instance_field_offset() != kNoTypeArguments; | 895 return type_arguments_instance_field_offset() != kNoTypeArguments; |
| 896 } else { | 896 } else { |
| 897 // No need to check NumTypeArguments() if class has type parameters. | 897 // No need to check NumTypeArguments() if class has type parameters. |
| 898 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0); | 898 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0); |
| 899 } | 899 } |
| 900 } | 900 } |
| 901 | 901 |
| 902 | 902 |
| 903 RawClass* Class::SuperClass() const { | 903 RawClass* Class::SuperClass() const { |
| 904 const AbstractType& sup_type = AbstractType::Handle(super_type()); | 904 const Type& sup_type = Type::Handle(super_type()); |
| 905 if (sup_type.IsNull()) { | 905 if (sup_type.IsNull()) { |
| 906 return Class::null(); | 906 return Class::null(); |
| 907 } | 907 } |
| 908 return sup_type.type_class(); | 908 return sup_type.type_class(); |
| 909 } | 909 } |
| 910 | 910 |
| 911 | 911 |
| 912 void Class::set_super_type(const AbstractType& value) const { | 912 void Class::set_super_type(const Type& value) const { |
| 913 StorePointer(&raw_ptr()->super_type_, value.raw()); | 913 StorePointer(&raw_ptr()->super_type_, value.raw()); |
| 914 } | 914 } |
| 915 | 915 |
| 916 | 916 |
| 917 bool Class::HasFactoryClass() const { | 917 bool Class::HasFactoryClass() const { |
| 918 const Object& factory_class = Object::Handle(raw_ptr()->factory_class_); | 918 const Object& factory_class = Object::Handle(raw_ptr()->factory_class_); |
| 919 return !factory_class.IsNull(); | 919 return !factory_class.IsNull(); |
| 920 } | 920 } |
| 921 | 921 |
| 922 | 922 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 // Unless the signature function already has a signature class, create a | 1116 // Unless the signature function already has a signature class, create a |
| 1117 // canonical signature class by having the signature function point back to | 1117 // canonical signature class by having the signature function point back to |
| 1118 // the signature class. | 1118 // the signature class. |
| 1119 if (signature_function.signature_class() == Object::null()) { | 1119 if (signature_function.signature_class() == Object::null()) { |
| 1120 signature_function.set_signature_class(result); | 1120 signature_function.set_signature_class(result); |
| 1121 } | 1121 } |
| 1122 result.set_is_finalized(); | 1122 result.set_is_finalized(); |
| 1123 // Instances of a signature class can only be closures. | 1123 // Instances of a signature class can only be closures. |
| 1124 ASSERT(result.instance_size() == Closure::InstanceSize()); | 1124 ASSERT(result.instance_size() == Closure::InstanceSize()); |
| 1125 // Cache the signature type as the first canonicalized type in result. | 1125 // Cache the signature type as the first canonicalized type in result. |
| 1126 const AbstractType& signature_type = | 1126 const Type& signature_type = Type::Handle(result.SignatureType()); |
| 1127 AbstractType::Handle(result.SignatureType()); | |
| 1128 ASSERT(!signature_type.IsFinalized()); | 1127 ASSERT(!signature_type.IsFinalized()); |
| 1129 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); | 1128 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); |
| 1130 new_canonical_types.SetAt(0, signature_type); | 1129 new_canonical_types.SetAt(0, signature_type); |
| 1131 result.set_canonical_types(new_canonical_types); | 1130 result.set_canonical_types(new_canonical_types); |
| 1132 return result.raw(); | 1131 return result.raw(); |
| 1133 } | 1132 } |
| 1134 | 1133 |
| 1135 | 1134 |
| 1136 RawClass* Class::GetClass(ObjectKind kind) { | 1135 RawClass* Class::GetClass(ObjectKind kind) { |
| 1137 ObjectStore* object_store = Isolate::Current()->object_store(); | 1136 ObjectStore* object_store = Isolate::Current()->object_store(); |
| (...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2114 Type& other_parameterized_type = Type::Handle(); | 2113 Type& other_parameterized_type = Type::Handle(); |
| 2115 other_parameterized_type ^= other.raw(); | 2114 other_parameterized_type ^= other.raw(); |
| 2116 if (type_class() != other_parameterized_type.type_class()) { | 2115 if (type_class() != other_parameterized_type.type_class()) { |
| 2117 return false; | 2116 return false; |
| 2118 } | 2117 } |
| 2119 return TypeArguments::AreEqual(TypeArguments::Handle(arguments()), | 2118 return TypeArguments::AreEqual(TypeArguments::Handle(arguments()), |
| 2120 TypeArguments::Handle(other.arguments())); | 2119 TypeArguments::Handle(other.arguments())); |
| 2121 } | 2120 } |
| 2122 | 2121 |
| 2123 | 2122 |
| 2124 RawAbstractType* Type::Canonicalize() const { | 2123 RawAbstractType* Type::Canonicalize() const { |
|
regis
2011/12/01 19:20:43
I think this should be RawType*
srdjan
2011/12/01 20:04:09
This is a virtual, implemented also in TypeParamet
| |
| 2125 ASSERT(IsFinalized()); | 2124 ASSERT(IsFinalized()); |
| 2126 const Class& cls = Class::Handle(type_class()); | 2125 const Class& cls = Class::Handle(type_class()); |
| 2127 Array& canonical_types = Array::Handle(cls.canonical_types()); | 2126 Array& canonical_types = Array::Handle(cls.canonical_types()); |
| 2128 if (canonical_types.IsNull()) { | 2127 if (canonical_types.IsNull()) { |
| 2129 // Types defined in the VM isolate are canonicalized via the object store. | 2128 // Types defined in the VM isolate are canonicalized via the object store. |
| 2130 // TODO(regis): Should we add null_class_, void_class_, dynamic_class_ to | 2129 // TODO(regis): Should we add null_class_, void_class_, dynamic_class_ to |
| 2131 // the object store, remove all types from the object store, and replace | 2130 // the object store, remove all types from the object store, and replace |
| 2132 // the test above by an assert? | 2131 // the test above by an assert? |
| 2133 return this->raw(); | 2132 return this->raw(); |
| 2134 } | 2133 } |
| 2135 const intptr_t canonical_types_len = canonical_types.Length(); | 2134 const intptr_t canonical_types_len = canonical_types.Length(); |
| 2136 // Linear search to see whether this type is already present in the | 2135 // Linear search to see whether this type is already present in the |
| 2137 // list of canonicalized types. | 2136 // list of canonicalized types. |
| 2138 AbstractType& type = AbstractType::Handle(); | 2137 Type& type = Type::Handle(); |
| 2139 intptr_t index = 0; | 2138 intptr_t index = 0; |
| 2140 while (index < canonical_types_len) { | 2139 while (index < canonical_types_len) { |
| 2141 type ^= canonical_types.At(index); | 2140 type ^= canonical_types.At(index); |
| 2142 if (type.IsNull()) { | 2141 if (type.IsNull()) { |
| 2143 break; | 2142 break; |
| 2144 } | 2143 } |
| 2145 if (!type.IsFinalized()) { | 2144 if (!type.IsFinalized()) { |
| 2146 ASSERT((index == 0) && cls.IsSignatureClass()); | 2145 ASSERT((index == 0) && cls.IsSignatureClass()); |
| 2147 index++; | 2146 index++; |
| 2148 continue; | 2147 continue; |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3217 library.LookupLocalClass(signature)); | 3216 library.LookupLocalClass(signature)); |
| 3218 if (signature_class.IsNull()) { | 3217 if (signature_class.IsNull()) { |
| 3219 const Script& script = Script::Handle(owner_class.script()); | 3218 const Script& script = Script::Handle(owner_class.script()); |
| 3220 signature_class = Class::NewSignatureClass(signature, | 3219 signature_class = Class::NewSignatureClass(signature, |
| 3221 closure_function, | 3220 closure_function, |
| 3222 script); | 3221 script); |
| 3223 library.AddClass(signature_class); | 3222 library.AddClass(signature_class); |
| 3224 } else { | 3223 } else { |
| 3225 closure_function.set_signature_class(signature_class); | 3224 closure_function.set_signature_class(signature_class); |
| 3226 } | 3225 } |
| 3227 const AbstractType& signature_type = | 3226 const Type& signature_type = Type::Handle(signature_class.SignatureType()); |
| 3228 AbstractType::Handle(signature_class.SignatureType()); | |
| 3229 if (!signature_type.IsFinalized()) { | 3227 if (!signature_type.IsFinalized()) { |
| 3230 String& errmsg = String::Handle(); | 3228 String& errmsg = String::Handle(); |
| 3231 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); | 3229 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); |
| 3232 ASSERT(errmsg.IsNull()); | 3230 ASSERT(errmsg.IsNull()); |
| 3233 } | 3231 } |
| 3234 ASSERT(closure_function.signature_class() == signature_class.raw()); | 3232 ASSERT(closure_function.signature_class() == signature_class.raw()); |
| 3235 set_implicit_closure_function(closure_function); | 3233 set_implicit_closure_function(closure_function); |
| 3236 ASSERT(closure_function.IsImplicitClosureFunction()); | 3234 ASSERT(closure_function.IsImplicitClosureFunction()); |
| 3237 return closure_function.raw(); | 3235 return closure_function.raw(); |
| 3238 } | 3236 } |
| (...skipping 4033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7272 const String& str = String::Handle(pattern()); | 7270 const String& str = String::Handle(pattern()); |
| 7273 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7271 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7274 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7272 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7275 char* chars = reinterpret_cast<char*>( | 7273 char* chars = reinterpret_cast<char*>( |
| 7276 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7274 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7277 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7275 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7278 return chars; | 7276 return chars; |
| 7279 } | 7277 } |
| 7280 | 7278 |
| 7281 } // namespace dart | 7279 } // namespace dart |
| OLD | NEW |