| 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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 | 1006 |
| 1007 RawClass* Class::NewInterface(const String& name, const Script& script) { | 1007 RawClass* Class::NewInterface(const String& name, const Script& script) { |
| 1008 Class& result = Class::Handle(New<Instance>(name, script)); | 1008 Class& result = Class::Handle(New<Instance>(name, script)); |
| 1009 result.set_is_interface(); | 1009 result.set_is_interface(); |
| 1010 return result.raw(); | 1010 return result.raw(); |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 | 1013 |
| 1014 RawClass* Class::NewSignatureClass(const String& name, | 1014 RawClass* Class::NewSignatureClass(const String& name, |
| 1015 const Function& signature_function, | 1015 const Function& signature_function, |
| 1016 const Script& script, | 1016 const Script& script) { |
| 1017 intptr_t token_index) { | |
| 1018 ASSERT(!signature_function.IsNull()); | 1017 ASSERT(!signature_function.IsNull()); |
| 1019 Type& super_type = Type::Handle(Type::ObjectType()); | 1018 Type& super_type = Type::Handle(Type::ObjectType()); |
| 1020 const Class& owner_class = Class::Handle(signature_function.owner()); | 1019 const Class& owner_class = Class::Handle(signature_function.owner()); |
| 1021 ASSERT(!owner_class.IsNull()); | 1020 ASSERT(!owner_class.IsNull()); |
| 1022 Array& type_parameters = Array::Handle(); | 1021 Array& type_parameters = Array::Handle(); |
| 1023 TypeArray& type_parameter_extends = TypeArray::Handle(); | 1022 TypeArray& type_parameter_extends = TypeArray::Handle(); |
| 1024 if (!signature_function.is_static()) { | 1023 if (!signature_function.is_static()) { |
| 1025 if ((owner_class.NumTypeParameters() > 0) && | 1024 if ((owner_class.NumTypeParameters() > 0) && |
| 1026 !signature_function.HasInstantiatedSignature()) { | 1025 !signature_function.HasInstantiatedSignature()) { |
| 1027 // Share the function owner super class as the super class of the | 1026 // Share the function owner super class as the super class of the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1039 result.set_signature_function(signature_function); | 1038 result.set_signature_function(signature_function); |
| 1040 result.set_type_parameters(type_parameters); | 1039 result.set_type_parameters(type_parameters); |
| 1041 result.set_type_parameter_extends(type_parameter_extends); | 1040 result.set_type_parameter_extends(type_parameter_extends); |
| 1042 result.SetFields(Array::Handle(Array::Empty())); | 1041 result.SetFields(Array::Handle(Array::Empty())); |
| 1043 result.SetFunctions(Array::Handle(Array::Empty())); | 1042 result.SetFunctions(Array::Handle(Array::Empty())); |
| 1044 // Implements interface Function. | 1043 // Implements interface Function. |
| 1045 const Type& function_interface = Type::Handle(Type::FunctionInterface()); | 1044 const Type& function_interface = Type::Handle(Type::FunctionInterface()); |
| 1046 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); | 1045 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); |
| 1047 interfaces.SetAt(0, function_interface); | 1046 interfaces.SetAt(0, function_interface); |
| 1048 result.set_interfaces(interfaces); | 1047 result.set_interfaces(interfaces); |
| 1048 // Unless the signature function already has a signature class, create a |
| 1049 // canonical signature class by having the signature function pointing back to |
| 1050 // the signature class. |
| 1051 if (signature_function.signature_class() == Object::null()) { |
| 1052 signature_function.set_signature_class(result); |
| 1053 } |
| 1049 return result.raw(); | 1054 return result.raw(); |
| 1050 } | 1055 } |
| 1051 | 1056 |
| 1052 | 1057 |
| 1053 RawClass* Class::GetClass(ObjectKind kind) { | 1058 RawClass* Class::GetClass(ObjectKind kind) { |
| 1054 ObjectStore* object_store = Isolate::Current()->object_store(); | 1059 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 1055 switch (kind) { | 1060 switch (kind) { |
| 1056 case kUnhandledException: | 1061 case kUnhandledException: |
| 1057 ASSERT(object_store->unhandled_exception_class() != Class::null()); | 1062 ASSERT(object_store->unhandled_exception_class() != Class::null()); |
| 1058 return object_store->unhandled_exception_class(); | 1063 return object_store->unhandled_exception_class(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 ASSERT(raw_ptr()->allocation_stub_ == Code::null()); | 1197 ASSERT(raw_ptr()->allocation_stub_ == Code::null()); |
| 1193 StorePointer(&raw_ptr()->allocation_stub_, value.raw()); | 1198 StorePointer(&raw_ptr()->allocation_stub_, value.raw()); |
| 1194 } | 1199 } |
| 1195 | 1200 |
| 1196 | 1201 |
| 1197 bool Class::IsObjectClass() const { | 1202 bool Class::IsObjectClass() const { |
| 1198 return raw() == Type::Handle(Type::ObjectType()).type_class(); | 1203 return raw() == Type::Handle(Type::ObjectType()).type_class(); |
| 1199 } | 1204 } |
| 1200 | 1205 |
| 1201 | 1206 |
| 1207 bool Class::IsCanonicalSignatureClass() const { |
| 1208 const Function& function = Function::Handle(signature_function()); |
| 1209 return (!function.IsNull() && (function.signature_class() == raw())); |
| 1210 } |
| 1211 |
| 1212 |
| 1202 // TODO(regis): We can probably merge this function with IsSubtypeOf, but since | 1213 // TODO(regis): We can probably merge this function with IsSubtypeOf, but since |
| 1203 // the spec is not definitive, we still follow it somewhat closely, to make it | 1214 // the spec is not definitive, we still follow it somewhat closely, to make it |
| 1204 // easier to implement spec changes. | 1215 // easier to implement spec changes. |
| 1205 bool Class::IsMoreSpecificThan( | 1216 bool Class::IsMoreSpecificThan( |
| 1206 const TypeArguments& type_arguments, | 1217 const TypeArguments& type_arguments, |
| 1207 const Class& other, | 1218 const Class& other, |
| 1208 const TypeArguments& other_type_arguments) const { | 1219 const TypeArguments& other_type_arguments) const { |
| 1209 // Check for VarType. | 1220 // Check for VarType. |
| 1210 // The VarType on the lefthand side is replaced by the bottom type, which is | 1221 // The VarType on the lefthand side is replaced by the bottom type, which is |
| 1211 // more specific than any type. | 1222 // more specific than any type. |
| (...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2937 Heap::kOld))); | 2948 Heap::kOld))); |
| 2938 Type& param_type = Type::Handle(); | 2949 Type& param_type = Type::Handle(); |
| 2939 String& param_name = String::Handle(); | 2950 String& param_name = String::Handle(); |
| 2940 for (int i = 0; i < num_params; i++) { | 2951 for (int i = 0; i < num_params; i++) { |
| 2941 param_type = ParameterTypeAt(i + has_receiver); | 2952 param_type = ParameterTypeAt(i + has_receiver); |
| 2942 closure_function.SetParameterTypeAt(i, param_type); | 2953 closure_function.SetParameterTypeAt(i, param_type); |
| 2943 param_name = ParameterNameAt(i + has_receiver); | 2954 param_name = ParameterNameAt(i + has_receiver); |
| 2944 closure_function.SetParameterNameAt(i, param_name); | 2955 closure_function.SetParameterNameAt(i, param_name); |
| 2945 } | 2956 } |
| 2946 | 2957 |
| 2947 // Lookup or create a new function type for the closure function in the | 2958 // Lookup or create a new signature class for the closure function in the |
| 2948 // library of the owner class. | 2959 // library of the owner class. |
| 2949 const Class& owner_class = Class::Handle(owner()); | 2960 const Class& owner_class = Class::Handle(owner()); |
| 2950 ASSERT(!owner_class.IsNull() && (owner() == closure_function.owner())); | 2961 ASSERT(!owner_class.IsNull() && (owner() == closure_function.owner())); |
| 2951 const Library& library = Library::Handle(owner_class.library()); | 2962 const Library& library = Library::Handle(owner_class.library()); |
| 2952 ASSERT(!library.IsNull()); | 2963 ASSERT(!library.IsNull()); |
| 2953 const String& signature = String::Handle(closure_function.Signature()); | 2964 const String& signature = String::Handle(closure_function.Signature()); |
| 2954 Class& signature_class = Class::ZoneHandle(library.LookupClass(signature)); | 2965 Class& signature_class = Class::ZoneHandle( |
| 2966 library.LookupLocalClass(signature)); |
| 2955 if (signature_class.IsNull()) { | 2967 if (signature_class.IsNull()) { |
| 2956 const Script& script = Script::Handle(owner_class.script()); | 2968 const Script& script = Script::Handle(owner_class.script()); |
| 2957 signature_class = Class::NewSignatureClass(signature, | 2969 signature_class = Class::NewSignatureClass(signature, |
| 2958 closure_function, | 2970 closure_function, |
| 2959 script, | 2971 script); |
| 2960 token_index()); | |
| 2961 library.AddClass(signature_class); | 2972 library.AddClass(signature_class); |
| 2973 } else { |
| 2974 closure_function.set_signature_class(signature_class); |
| 2962 } | 2975 } |
| 2963 ASSERT(!Function::Handle(signature_class.signature_function()).IsNull()); | 2976 ASSERT(closure_function.signature_class() == signature_class.raw()); |
| 2964 ASSERT(Class::Handle(closure_function.signature_class()).IsNull()); | |
| 2965 closure_function.set_signature_class(signature_class); | |
| 2966 set_implicit_closure_function(closure_function); | 2977 set_implicit_closure_function(closure_function); |
| 2967 ASSERT(closure_function.IsImplicitClosureFunction()); | 2978 ASSERT(closure_function.IsImplicitClosureFunction()); |
| 2968 return closure_function.raw(); | 2979 return closure_function.raw(); |
| 2969 } | 2980 } |
| 2970 | 2981 |
| 2971 | 2982 |
| 2972 template<typename T> | 2983 template<typename T> |
| 2973 static RawArray* NewArray(const GrowableArray<T*>& objs) { | 2984 static RawArray* NewArray(const GrowableArray<T*>& objs) { |
| 2974 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); | 2985 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); |
| 2975 for (int i = 0; i < objs.length(); i++) { | 2986 for (int i = 0; i < objs.length(); i++) { |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3540 StorePointer(&raw_ptr()->dictionary_, new_dict.raw()); | 3551 StorePointer(&raw_ptr()->dictionary_, new_dict.raw()); |
| 3541 } | 3552 } |
| 3542 | 3553 |
| 3543 | 3554 |
| 3544 void Library::AddObject(const Object& obj, const String& name) const { | 3555 void Library::AddObject(const Object& obj, const String& name) const { |
| 3545 ASSERT(obj.IsClass() || | 3556 ASSERT(obj.IsClass() || |
| 3546 obj.IsFunction() || | 3557 obj.IsFunction() || |
| 3547 obj.IsField() || | 3558 obj.IsField() || |
| 3548 obj.IsLibraryPrefix()); | 3559 obj.IsLibraryPrefix()); |
| 3549 ASSERT((LookupObject(name) == Object::null()) || | 3560 ASSERT((LookupObject(name) == Object::null()) || |
| 3550 (obj.IsLibraryPrefix() && | 3561 ((obj.IsLibraryPrefix() || |
| 3562 (obj.IsClass() && |
| 3563 Class::CheckedHandle(obj.raw()).IsCanonicalSignatureClass())) && |
| 3551 (LookupLocalObject(name) == Object::null()))); | 3564 (LookupLocalObject(name) == Object::null()))); |
| 3552 const Array& dict = Array::Handle(dictionary()); | 3565 const Array& dict = Array::Handle(dictionary()); |
| 3553 intptr_t dict_size = dict.Length() - 1; | 3566 intptr_t dict_size = dict.Length() - 1; |
| 3554 intptr_t index = name.Hash() % dict_size; | 3567 intptr_t index = name.Hash() % dict_size; |
| 3555 | 3568 |
| 3556 Object& entry = Object::Handle(); | 3569 Object& entry = Object::Handle(); |
| 3557 entry = dict.At(index); | 3570 entry = dict.At(index); |
| 3558 // An empty spot will be found because we keep the hash set at most 75% full. | 3571 // An empty spot will be found because we keep the hash set at most 75% full. |
| 3559 while (!entry.IsNull()) { | 3572 while (!entry.IsNull()) { |
| 3560 index = (index + 1) % dict_size; | 3573 index = (index + 1) % dict_size; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3715 Object& obj = Object::Handle(); | 3728 Object& obj = Object::Handle(); |
| 3716 Class& cls = Class::Handle(); | 3729 Class& cls = Class::Handle(); |
| 3717 Function& func = Function::Handle(); | 3730 Function& func = Function::Handle(); |
| 3718 Field& field = Field::Handle(); | 3731 Field& field = Field::Handle(); |
| 3719 String& entry_name = String::Handle(); | 3732 String& entry_name = String::Handle(); |
| 3720 while (it.HasNext()) { | 3733 while (it.HasNext()) { |
| 3721 obj = it.GetNext(); | 3734 obj = it.GetNext(); |
| 3722 ASSERT(!obj.IsNull()); | 3735 ASSERT(!obj.IsNull()); |
| 3723 if (obj.IsClass()) { | 3736 if (obj.IsClass()) { |
| 3724 cls ^= obj.raw(); | 3737 cls ^= obj.raw(); |
| 3725 if (cls.IsSignatureClass()) { | 3738 if (cls.IsCanonicalSignatureClass()) { |
| 3726 continue; | 3739 continue; |
| 3727 } | 3740 } |
| 3728 entry_name = cls.Name(); | 3741 entry_name = cls.Name(); |
| 3729 } else if (obj.IsFunction()) { | 3742 } else if (obj.IsFunction()) { |
| 3730 func ^= obj.raw(); | 3743 func ^= obj.raw(); |
| 3731 entry_name = func.name(); | 3744 entry_name = func.name(); |
| 3732 } else if (obj.IsField()) { | 3745 } else if (obj.IsField()) { |
| 3733 field ^= obj.raw(); | 3746 field ^= obj.raw(); |
| 3734 entry_name = field.name(); | 3747 entry_name = field.name(); |
| 3735 } else { | 3748 } else { |
| (...skipping 3057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6793 const String& str = String::Handle(pattern()); | 6806 const String& str = String::Handle(pattern()); |
| 6794 const char* format = "JSRegExp: pattern=%s flags=%s"; | 6807 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 6795 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 6808 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 6796 char* chars = reinterpret_cast<char*>( | 6809 char* chars = reinterpret_cast<char*>( |
| 6797 Isolate::Current()->current_zone()->Allocate(len + 1)); | 6810 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 6798 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 6811 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 6799 return chars; | 6812 return chars; |
| 6800 } | 6813 } |
| 6801 | 6814 |
| 6802 } // namespace dart | 6815 } // namespace dart |
| OLD | NEW |