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 30 matching lines...) Expand all Loading... |
41 #if defined(RAW_NULL) | 41 #if defined(RAW_NULL) |
42 #error RAW_NULL should not be defined. | 42 #error RAW_NULL should not be defined. |
43 #endif | 43 #endif |
44 #define RAW_NULL kHeapObjectTag | 44 #define RAW_NULL kHeapObjectTag |
45 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); | 45 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); |
46 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL); | 46 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL); |
47 RawInstance* Object::transition_sentinel_ = | 47 RawInstance* Object::transition_sentinel_ = |
48 reinterpret_cast<RawInstance*>(RAW_NULL); | 48 reinterpret_cast<RawInstance*>(RAW_NULL); |
49 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 49 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
50 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 50 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
51 RawClass* Object::var_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 51 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
52 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 52 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
53 RawClass* Object::unresolved_class_class_ = | 53 RawClass* Object::unresolved_class_class_ = |
54 reinterpret_cast<RawClass*>(RAW_NULL); | 54 reinterpret_cast<RawClass*>(RAW_NULL); |
55 RawClass* Object::parameterized_type_class_ = | 55 RawClass* Object::parameterized_type_class_ = |
56 reinterpret_cast<RawClass*>(RAW_NULL); | 56 reinterpret_cast<RawClass*>(RAW_NULL); |
57 RawClass* Object::type_parameter_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 57 RawClass* Object::type_parameter_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
58 RawClass* Object::instantiated_type_class_ = | 58 RawClass* Object::instantiated_type_class_ = |
59 reinterpret_cast<RawClass*>(RAW_NULL); | 59 reinterpret_cast<RawClass*>(RAW_NULL); |
60 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 60 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
61 RawClass* Object::type_array_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 61 RawClass* Object::type_array_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
(...skipping 14 matching lines...) Expand all Loading... |
76 RawClass* Object::context_scope_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 76 RawClass* Object::context_scope_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
77 RawClass* Object::api_failure_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 77 RawClass* Object::api_failure_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
78 #undef RAW_NULL | 78 #undef RAW_NULL |
79 | 79 |
80 int Object::GetSingletonClassIndex(const RawClass* raw_class) { | 80 int Object::GetSingletonClassIndex(const RawClass* raw_class) { |
81 ASSERT(raw_class->IsHeapObject()); | 81 ASSERT(raw_class->IsHeapObject()); |
82 if (raw_class == class_class()) { | 82 if (raw_class == class_class()) { |
83 return kClassClass; | 83 return kClassClass; |
84 } else if (raw_class == null_class()) { | 84 } else if (raw_class == null_class()) { |
85 return kNullClass; | 85 return kNullClass; |
86 } else if (raw_class == var_class()) { | 86 } else if (raw_class == dynamic_class()) { |
87 return kVarClass; | 87 return kDynamicClass; |
88 } else if (raw_class == void_class()) { | 88 } else if (raw_class == void_class()) { |
89 return kVoidClass; | 89 return kVoidClass; |
90 } else if (raw_class == unresolved_class_class()) { | 90 } else if (raw_class == unresolved_class_class()) { |
91 return kUnresolvedClassClass; | 91 return kUnresolvedClassClass; |
92 } else if (raw_class == parameterized_type_class()) { | 92 } else if (raw_class == parameterized_type_class()) { |
93 return kParameterizedTypeClass; | 93 return kParameterizedTypeClass; |
94 } else if (raw_class == type_parameter_class()) { | 94 } else if (raw_class == type_parameter_class()) { |
95 return kTypeParameterClass; | 95 return kTypeParameterClass; |
96 } else if (raw_class == instantiated_type_class()) { | 96 } else if (raw_class == instantiated_type_class()) { |
97 return kInstantiatedTypeClass; | 97 return kInstantiatedTypeClass; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 return kApiFailureClass; | 129 return kApiFailureClass; |
130 } | 130 } |
131 return kInvalidIndex; | 131 return kInvalidIndex; |
132 } | 132 } |
133 | 133 |
134 | 134 |
135 RawClass* Object::GetSingletonClass(int index) { | 135 RawClass* Object::GetSingletonClass(int index) { |
136 switch (index) { | 136 switch (index) { |
137 case kClassClass: return class_class(); | 137 case kClassClass: return class_class(); |
138 case kNullClass: return null_class(); | 138 case kNullClass: return null_class(); |
139 case kVarClass: return var_class(); | 139 case kDynamicClass: return dynamic_class(); |
140 case kVoidClass: return void_class(); | 140 case kVoidClass: return void_class(); |
141 case kUnresolvedClassClass: return unresolved_class_class(); | 141 case kUnresolvedClassClass: return unresolved_class_class(); |
142 case kParameterizedTypeClass: return parameterized_type_class(); | 142 case kParameterizedTypeClass: return parameterized_type_class(); |
143 case kTypeParameterClass: return type_parameter_class(); | 143 case kTypeParameterClass: return type_parameter_class(); |
144 case kInstantiatedTypeClass: return instantiated_type_class(); | 144 case kInstantiatedTypeClass: return instantiated_type_class(); |
145 case kTypeArgumentsClass: return type_arguments_class(); | 145 case kTypeArgumentsClass: return type_arguments_class(); |
146 case kTypeArrayClass: return type_array_class(); | 146 case kTypeArrayClass: return type_array_class(); |
147 case kInstantiatedTypeArgumentsClass: | 147 case kInstantiatedTypeArgumentsClass: |
148 return instantiated_type_arguments_class(); | 148 return instantiated_type_arguments_class(); |
149 case kFunctionClass: return function_class(); | 149 case kFunctionClass: return function_class(); |
(...skipping 13 matching lines...) Expand all Loading... |
163 } | 163 } |
164 UNREACHABLE(); | 164 UNREACHABLE(); |
165 return reinterpret_cast<RawClass*>(kHeapObjectTag); // return RAW_NULL. | 165 return reinterpret_cast<RawClass*>(kHeapObjectTag); // return RAW_NULL. |
166 } | 166 } |
167 | 167 |
168 | 168 |
169 const char* Object::GetSingletonClassName(int index) { | 169 const char* Object::GetSingletonClassName(int index) { |
170 switch (index) { | 170 switch (index) { |
171 case kClassClass: return "Class"; | 171 case kClassClass: return "Class"; |
172 case kNullClass: return "Null"; | 172 case kNullClass: return "Null"; |
173 case kVarClass: return "var"; | 173 case kDynamicClass: return "Dynamic"; |
174 case kVoidClass: return "void"; | 174 case kVoidClass: return "void"; |
175 case kUnresolvedClassClass: return "UnresolvedClass"; | 175 case kUnresolvedClassClass: return "UnresolvedClass"; |
176 case kParameterizedTypeClass: return "ParameterizedType"; | 176 case kParameterizedTypeClass: return "ParameterizedType"; |
177 case kTypeParameterClass: return "TypeParameter"; | 177 case kTypeParameterClass: return "TypeParameter"; |
178 case kInstantiatedTypeClass: return "InstantiatedType"; | 178 case kInstantiatedTypeClass: return "InstantiatedType"; |
179 case kTypeArgumentsClass: return "TypeArguments"; | 179 case kTypeArgumentsClass: return "TypeArguments"; |
180 case kTypeArrayClass: return "TypeArray"; | 180 case kTypeArrayClass: return "TypeArray"; |
181 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; | 181 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; |
182 case kFunctionClass: return "Function"; | 182 case kFunctionClass: return "Function"; |
183 case kFieldClass: return "Field"; | 183 case kFieldClass: return "Field"; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 transition_sentinel ^= | 256 transition_sentinel ^= |
257 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); | 257 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); |
258 transition_sentinel_ = transition_sentinel.raw(); | 258 transition_sentinel_ = transition_sentinel.raw(); |
259 } | 259 } |
260 | 260 |
261 // Allocate the remaining VM internal classes. | 261 // Allocate the remaining VM internal classes. |
262 cls = Class::New<UnresolvedClass>(); | 262 cls = Class::New<UnresolvedClass>(); |
263 unresolved_class_class_ = cls.raw(); | 263 unresolved_class_class_ = cls.raw(); |
264 | 264 |
265 cls = Class::New<Instance>(); | 265 cls = Class::New<Instance>(); |
266 var_class_ = cls.raw(); | 266 dynamic_class_ = cls.raw(); |
267 | 267 |
268 cls = Class::New<Instance>(); | 268 cls = Class::New<Instance>(); |
269 void_class_ = cls.raw(); | 269 void_class_ = cls.raw(); |
270 | 270 |
271 cls = Class::New<ParameterizedType>(); | 271 cls = Class::New<ParameterizedType>(); |
272 parameterized_type_class_ = cls.raw(); | 272 parameterized_type_class_ = cls.raw(); |
273 | 273 |
274 cls = Class::New<TypeParameter>(); | 274 cls = Class::New<TypeParameter>(); |
275 type_parameter_class_ = cls.raw(); | 275 type_parameter_class_ = cls.raw(); |
276 | 276 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 core_lib.AddClass(cls); | 550 core_lib.AddClass(cls); |
551 type = Type::NewNonParameterizedType(cls); | 551 type = Type::NewNonParameterizedType(cls); |
552 object_store->set_string_interface(type); | 552 object_store->set_string_interface(type); |
553 | 553 |
554 name = String::NewSymbol("bool"); | 554 name = String::NewSymbol("bool"); |
555 cls = Class::NewInterface(name, script); | 555 cls = Class::NewInterface(name, script); |
556 core_lib.AddClass(cls); | 556 core_lib.AddClass(cls); |
557 type = Type::NewNonParameterizedType(cls); | 557 type = Type::NewNonParameterizedType(cls); |
558 object_store->set_bool_interface(type); | 558 object_store->set_bool_interface(type); |
559 | 559 |
560 // The classes 'null', 'var', and 'void' are not registered in the class | 560 // The classes 'Null', 'Dynamic', and 'void' are not registered in the class |
561 // dictionary and are not named, but corresponding types are stored in the | 561 // dictionary and are not named, but corresponding types are stored in the |
562 // object store. | 562 // object store. |
563 cls = null_class_; | 563 cls = null_class_; |
564 type = Type::NewNonParameterizedType(cls); | 564 type = Type::NewNonParameterizedType(cls); |
565 object_store->set_null_type(type); | 565 object_store->set_null_type(type); |
566 | 566 |
567 cls = var_class_; | 567 cls = dynamic_class_; |
568 type = Type::NewNonParameterizedType(cls); | 568 type = Type::NewNonParameterizedType(cls); |
569 object_store->set_var_type(type); | 569 object_store->set_dynamic_type(type); |
570 | 570 |
571 cls = void_class_; | 571 cls = void_class_; |
572 type = Type::NewNonParameterizedType(cls); | 572 type = Type::NewNonParameterizedType(cls); |
573 object_store->set_void_type(type); | 573 object_store->set_void_type(type); |
574 | 574 |
575 // Finish the initialization by compiling the bootstrap script containing the | 575 // Finish the initialization by compiling the bootstrap script containing the |
576 // implementation of the internal classes. | 576 // implementation of the internal classes. |
577 Bootstrap::Compile(Library::Handle(Library::CoreLibrary()), script); | 577 Bootstrap::Compile(Library::Handle(Library::CoreLibrary()), script); |
578 Bootstrap::Compile(Library::Handle(Library::CoreImplLibrary()), impl_script); | 578 Bootstrap::Compile(Library::Handle(Library::CoreImplLibrary()), impl_script); |
579 | 579 |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 bool Class::IsCanonicalSignatureClass() const { | 1207 bool Class::IsCanonicalSignatureClass() const { |
1208 const Function& function = Function::Handle(signature_function()); | 1208 const Function& function = Function::Handle(signature_function()); |
1209 return (!function.IsNull() && (function.signature_class() == raw())); | 1209 return (!function.IsNull() && (function.signature_class() == raw())); |
1210 } | 1210 } |
1211 | 1211 |
1212 | 1212 |
1213 bool Class::IsMoreSpecificThan( | 1213 bool Class::IsMoreSpecificThan( |
1214 const TypeArguments& type_arguments, | 1214 const TypeArguments& type_arguments, |
1215 const Class& other, | 1215 const Class& other, |
1216 const TypeArguments& other_type_arguments) const { | 1216 const TypeArguments& other_type_arguments) const { |
1217 // Check for VarType. | 1217 // Check for DynamicType. |
1218 // The VarType on the lefthand side is replaced by the bottom type, which is | 1218 // The DynamicType on the lefthand side is replaced by the bottom type, which |
1219 // more specific than any type. | 1219 // is more specific than any type. |
1220 // Any type is more specific than the VarType on the righthand side. | 1220 // Any type is more specific than the DynamicType on the righthand side. |
1221 if (IsVarClass() || other.IsVarClass()) { | 1221 if (IsDynamicClass() || other.IsDynamicClass()) { |
1222 return true; | 1222 return true; |
1223 } | 1223 } |
1224 // Check for reflexivity. | 1224 // Check for reflexivity. |
1225 if (raw() == other.raw()) { | 1225 if (raw() == other.raw()) { |
1226 const intptr_t len = NumTypeArguments(); | 1226 const intptr_t len = NumTypeArguments(); |
1227 if (len == 0) { | 1227 if (len == 0) { |
1228 return true; | 1228 return true; |
1229 } | 1229 } |
1230 // Since we do not truncate the type argument vector of a subclass (see | 1230 // Since we do not truncate the type argument vector of a subclass (see |
1231 // below), we only check a prefix of the proper length. | 1231 // below), we only check a prefix of the proper length. |
1232 // Check for covariance. | 1232 // Check for covariance. |
1233 if (type_arguments.IsNull() || | 1233 if (type_arguments.IsNull() || |
1234 other_type_arguments.IsNull() || | 1234 other_type_arguments.IsNull() || |
1235 type_arguments.IsVarTypes(len) || | 1235 type_arguments.IsDynamicTypes(len) || |
1236 other_type_arguments.IsVarTypes(len)) { | 1236 other_type_arguments.IsDynamicTypes(len)) { |
1237 return true; | 1237 return true; |
1238 } | 1238 } |
1239 return type_arguments.IsMoreSpecificThan(other_type_arguments, len); | 1239 return type_arguments.IsMoreSpecificThan(other_type_arguments, len); |
1240 } | 1240 } |
1241 // Check for two function types. | 1241 // Check for two function types. |
1242 if (IsSignatureClass() && other.IsSignatureClass()) { | 1242 if (IsSignatureClass() && other.IsSignatureClass()) { |
1243 const Function& fun = Function::Handle(signature_function()); | 1243 const Function& fun = Function::Handle(signature_function()); |
1244 const Function& other_fun = Function::Handle(other.signature_function()); | 1244 const Function& other_fun = Function::Handle(other.signature_function()); |
1245 return fun.IsSubtypeOf(type_arguments, | 1245 return fun.IsSubtypeOf(type_arguments, |
1246 other_fun, | 1246 other_fun, |
(...skipping 21 matching lines...) Expand all Loading... |
1268 // interface. | 1268 // interface. |
1269 interface_args = TypeArguments::null(); | 1269 interface_args = TypeArguments::null(); |
1270 } else { | 1270 } else { |
1271 // The type arguments of this type that are referred to by the type | 1271 // The type arguments of this type that are referred to by the type |
1272 // parameters of the interface are at the end of the type vector, | 1272 // parameters of the interface are at the end of the type vector, |
1273 // after the type arguments of the super type of this type. | 1273 // after the type arguments of the super type of this type. |
1274 const intptr_t offset = NumTypeArguments() - NumTypeParameters(); | 1274 const intptr_t offset = NumTypeArguments() - NumTypeParameters(); |
1275 interface_args = interface_args.InstantiateFrom(type_arguments, | 1275 interface_args = interface_args.InstantiateFrom(type_arguments, |
1276 offset); | 1276 offset); |
1277 // TODO(regis): Check the subtyping constraints if any, i.e. if | 1277 // TODO(regis): Check the subtyping constraints if any, i.e. if |
1278 // interface.type_parameter_extends() is not an array of VarType. | 1278 // interface.type_parameter_extends() is not an array of DynamicType. |
1279 // Should we pass the constraints to InstantiateFrom and it would | 1279 // Should we pass the constraints to InstantiateFrom and it would |
1280 // return null on failure? | 1280 // return null on failure? |
1281 } | 1281 } |
1282 } | 1282 } |
1283 if (interface_class.IsMoreSpecificThan(interface_args, | 1283 if (interface_class.IsMoreSpecificThan(interface_args, |
1284 other, | 1284 other, |
1285 other_type_arguments)) { | 1285 other_type_arguments)) { |
1286 return true; | 1286 return true; |
1287 } | 1287 } |
1288 } | 1288 } |
1289 } | 1289 } |
1290 // Check the interface case. | 1290 // Check the interface case. |
1291 if (is_interface()) { | 1291 if (is_interface()) { |
1292 // We already checked the case where 'other' is an interface. Now, 'this', | 1292 // We already checked the case where 'other' is an interface. Now, 'this', |
1293 // an interface, cannot be more specific than a class, except class Object, | 1293 // an interface, cannot be more specific than a class, except class Object, |
1294 // because although Object is not considered an interface by the vm, it is | 1294 // because although Object is not considered an interface by the vm, it is |
1295 // one. In other words, all classes implementing this interface also extend | 1295 // one. In other words, all classes implementing this interface also extend |
1296 // class Object. An interface is also more specific than the VarType. | 1296 // class Object. An interface is also more specific than the DynamicType. |
1297 return (other.IsVarClass() || other.IsObjectClass()); | 1297 return (other.IsDynamicClass() || other.IsObjectClass()); |
1298 } | 1298 } |
1299 const Class& super_class = Class::Handle(SuperClass()); | 1299 const Class& super_class = Class::Handle(SuperClass()); |
1300 if (super_class.IsNull()) { | 1300 if (super_class.IsNull()) { |
1301 return false; | 1301 return false; |
1302 } | 1302 } |
1303 // Instead of truncating the type argument vector to the length of the super | 1303 // Instead of truncating the type argument vector to the length of the super |
1304 // type argument vector, we make sure that the code works with a vector that | 1304 // type argument vector, we make sure that the code works with a vector that |
1305 // is longer than necessary. | 1305 // is longer than necessary. |
1306 return super_class.IsMoreSpecificThan(type_arguments, | 1306 return super_class.IsMoreSpecificThan(type_arguments, |
1307 other, | 1307 other, |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 String& class_name = String::Handle(); | 1653 String& class_name = String::Handle(); |
1654 intptr_t first_type_param_index; | 1654 intptr_t first_type_param_index; |
1655 intptr_t num_type_params; // Number of type parameters to print. | 1655 intptr_t num_type_params; // Number of type parameters to print. |
1656 if (HasResolvedTypeClass()) { | 1656 if (HasResolvedTypeClass()) { |
1657 const Class& cls = Class::Handle(type_class()); | 1657 const Class& cls = Class::Handle(type_class()); |
1658 class_name = cls.Name(); | 1658 class_name = cls.Name(); |
1659 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. | 1659 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. |
1660 if (num_type_params > num_args) { | 1660 if (num_type_params > num_args) { |
1661 first_type_param_index = 0; | 1661 first_type_param_index = 0; |
1662 if (IsBeingFinalized()) { | 1662 if (IsBeingFinalized()) { |
1663 // Most probably an illformed type. Do not fill up with "var". | 1663 // Most probably an illformed type. Do not fill up with "Dynamic". |
1664 num_type_params = num_args; | 1664 num_type_params = num_args; |
1665 } else { | 1665 } else { |
1666 ASSERT(num_args == 0); // Type is raw. | 1666 ASSERT(num_args == 0); // Type is raw. |
1667 // We fill up with "var". | 1667 // We fill up with "Dynamic". |
1668 } | 1668 } |
1669 } else { | 1669 } else { |
1670 first_type_param_index = num_args - num_type_params; | 1670 first_type_param_index = num_args - num_type_params; |
1671 } | 1671 } |
1672 if (cls.IsSignatureClass()) { | 1672 if (cls.IsSignatureClass()) { |
1673 // We may be reporting an error about an illformed function type. In that | 1673 // We may be reporting an error about an illformed function type. In that |
1674 // case, avoid instantiating the signature, since it may lead to cycles. | 1674 // case, avoid instantiating the signature, since it may lead to cycles. |
1675 if (IsBeingFinalized()) { | 1675 if (IsBeingFinalized()) { |
1676 return class_name.raw(); | 1676 return class_name.raw(); |
1677 } | 1677 } |
(...skipping 14 matching lines...) Expand all Loading... |
1692 } else { | 1692 } else { |
1693 const intptr_t num_strings = 2*num_type_params + 2; // "C""<""T"", ""T"">". | 1693 const intptr_t num_strings = 2*num_type_params + 2; // "C""<""T"", ""T"">". |
1694 const Array& strings = Array::Handle(Array::New(num_strings)); | 1694 const Array& strings = Array::Handle(Array::New(num_strings)); |
1695 intptr_t s = 0; | 1695 intptr_t s = 0; |
1696 strings.SetAt(s++, class_name); | 1696 strings.SetAt(s++, class_name); |
1697 strings.SetAt(s++, String::Handle(String::NewSymbol("<"))); | 1697 strings.SetAt(s++, String::Handle(String::NewSymbol("<"))); |
1698 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); | 1698 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); |
1699 Type& type = Type::Handle(); | 1699 Type& type = Type::Handle(); |
1700 for (intptr_t i = 0; i < num_type_params; i++) { | 1700 for (intptr_t i = 0; i < num_type_params; i++) { |
1701 if (first_type_param_index + i >= num_args) { | 1701 if (first_type_param_index + i >= num_args) { |
1702 type = VarType(); | 1702 type = DynamicType(); |
1703 } else { | 1703 } else { |
1704 type = args.TypeAt(first_type_param_index + i); | 1704 type = args.TypeAt(first_type_param_index + i); |
1705 } | 1705 } |
1706 type_name = type.Name(); | 1706 type_name = type.Name(); |
1707 strings.SetAt(s++, type_name); | 1707 strings.SetAt(s++, type_name); |
1708 if (i < num_type_params - 1) { | 1708 if (i < num_type_params - 1) { |
1709 strings.SetAt(s++, kCommaSpace); | 1709 strings.SetAt(s++, kCommaSpace); |
1710 } | 1710 } |
1711 } | 1711 } |
1712 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); | 1712 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 TypeArguments::Handle(other.arguments())); | 1807 TypeArguments::Handle(other.arguments())); |
1808 } | 1808 } |
1809 } | 1809 } |
1810 | 1810 |
1811 | 1811 |
1812 RawType* Type::NullType() { | 1812 RawType* Type::NullType() { |
1813 return Isolate::Current()->object_store()->null_type(); | 1813 return Isolate::Current()->object_store()->null_type(); |
1814 } | 1814 } |
1815 | 1815 |
1816 | 1816 |
1817 RawType* Type::VarType() { | 1817 RawType* Type::DynamicType() { |
1818 return Isolate::Current()->object_store()->var_type(); | 1818 return Isolate::Current()->object_store()->dynamic_type(); |
1819 } | 1819 } |
1820 | 1820 |
1821 | 1821 |
1822 RawType* Type::VoidType() { | 1822 RawType* Type::VoidType() { |
1823 return Isolate::Current()->object_store()->void_type(); | 1823 return Isolate::Current()->object_store()->void_type(); |
1824 } | 1824 } |
1825 | 1825 |
1826 | 1826 |
1827 RawType* Type::ObjectType() { | 1827 RawType* Type::ObjectType() { |
1828 return Isolate::Current()->object_store()->object_type(); | 1828 return Isolate::Current()->object_store()->object_type(); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 void TypeParameter::set_name(const String& value) const { | 2033 void TypeParameter::set_name(const String& value) const { |
2034 ASSERT(value.IsSymbol()); | 2034 ASSERT(value.IsSymbol()); |
2035 StorePointer(&raw_ptr()->name_, value.raw()); | 2035 StorePointer(&raw_ptr()->name_, value.raw()); |
2036 } | 2036 } |
2037 | 2037 |
2038 | 2038 |
2039 RawType* TypeParameter::InstantiateFrom( | 2039 RawType* TypeParameter::InstantiateFrom( |
2040 const TypeArguments& instantiator_type_arguments, | 2040 const TypeArguments& instantiator_type_arguments, |
2041 intptr_t offset) const { | 2041 intptr_t offset) const { |
2042 if (instantiator_type_arguments.IsNull()) { | 2042 if (instantiator_type_arguments.IsNull()) { |
2043 return VarType(); | 2043 return DynamicType(); |
2044 } | 2044 } |
2045 return instantiator_type_arguments.TypeAt(Index() + offset); | 2045 return instantiator_type_arguments.TypeAt(Index() + offset); |
2046 } | 2046 } |
2047 | 2047 |
2048 | 2048 |
2049 RawTypeParameter* TypeParameter::New() { | 2049 RawTypeParameter* TypeParameter::New() { |
2050 const Class& type_parameter_class = | 2050 const Class& type_parameter_class = |
2051 Class::Handle(Object::type_parameter_class()); | 2051 Class::Handle(Object::type_parameter_class()); |
2052 RawObject* raw = Object::Allocate(type_parameter_class, | 2052 RawObject* raw = Object::Allocate(type_parameter_class, |
2053 TypeParameter::InstanceSize(), | 2053 TypeParameter::InstanceSize(), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2161 | 2161 |
2162 RawTypeArguments* TypeArguments::InstantiateFrom( | 2162 RawTypeArguments* TypeArguments::InstantiateFrom( |
2163 const TypeArguments& instantiator_type_arguments, | 2163 const TypeArguments& instantiator_type_arguments, |
2164 intptr_t offset) const { | 2164 intptr_t offset) const { |
2165 // TypeArguments is an abstract class. | 2165 // TypeArguments is an abstract class. |
2166 UNREACHABLE(); | 2166 UNREACHABLE(); |
2167 return TypeArguments::null(); | 2167 return TypeArguments::null(); |
2168 } | 2168 } |
2169 | 2169 |
2170 | 2170 |
2171 bool TypeArguments::IsVarTypes(intptr_t len) const { | 2171 bool TypeArguments::IsDynamicTypes(intptr_t len) const { |
2172 ASSERT(Length() >= len); | 2172 ASSERT(Length() >= len); |
2173 Type& type = Type::Handle(); | 2173 Type& type = Type::Handle(); |
2174 Class& type_class = Class::Handle(); | 2174 Class& type_class = Class::Handle(); |
2175 for (intptr_t i = 0; i < len; i++) { | 2175 for (intptr_t i = 0; i < len; i++) { |
2176 type = TypeAt(i); | 2176 type = TypeAt(i); |
2177 ASSERT(!type.IsNull()); | 2177 ASSERT(!type.IsNull()); |
2178 if (!type.HasResolvedTypeClass()) { | 2178 if (!type.HasResolvedTypeClass()) { |
2179 ASSERT(type.IsTypeParameter()); | 2179 ASSERT(type.IsTypeParameter()); |
2180 return false; | 2180 return false; |
2181 } | 2181 } |
2182 type_class = type.type_class(); | 2182 type_class = type.type_class(); |
2183 if (!type_class.IsVarClass()) { | 2183 if (!type_class.IsDynamicClass()) { |
2184 return false; | 2184 return false; |
2185 } | 2185 } |
2186 } | 2186 } |
2187 return true; | 2187 return true; |
2188 } | 2188 } |
2189 | 2189 |
2190 | 2190 |
2191 bool TypeArguments::IsMoreSpecificThan(const TypeArguments& other, | 2191 bool TypeArguments::IsMoreSpecificThan(const TypeArguments& other, |
2192 intptr_t len) const { | 2192 intptr_t len) const { |
2193 ASSERT(Length() >= len); | 2193 ASSERT(Length() >= len); |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2721 if ((num_fixed_params != other_num_fixed_params) || | 2721 if ((num_fixed_params != other_num_fixed_params) || |
2722 ((test == Type::kIsSubtypeOf) && | 2722 ((test == Type::kIsSubtypeOf) && |
2723 (num_opt_params < other_num_opt_params))) { | 2723 (num_opt_params < other_num_opt_params))) { |
2724 return false; | 2724 return false; |
2725 } | 2725 } |
2726 // Check the result type. | 2726 // Check the result type. |
2727 Type& other_res_type = Type::Handle(other.result_type()); | 2727 Type& other_res_type = Type::Handle(other.result_type()); |
2728 if (!other_res_type.IsInstantiated()) { | 2728 if (!other_res_type.IsInstantiated()) { |
2729 other_res_type = other_res_type.InstantiateFrom(other_type_arguments, 0); | 2729 other_res_type = other_res_type.InstantiateFrom(other_type_arguments, 0); |
2730 } | 2730 } |
2731 if (!other_res_type.IsVarType() && !other_res_type.IsVoidType()) { | 2731 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { |
2732 Type& res_type = Type::Handle(result_type()); | 2732 Type& res_type = Type::Handle(result_type()); |
2733 if (!res_type.IsInstantiated()) { | 2733 if (!res_type.IsInstantiated()) { |
2734 res_type = res_type.InstantiateFrom(type_arguments, 0); | 2734 res_type = res_type.InstantiateFrom(type_arguments, 0); |
2735 } | 2735 } |
2736 if (!res_type.IsVarType() && | 2736 if (!res_type.IsDynamicType() && |
2737 (res_type.IsVoidType() || !res_type.IsAssignableTo(other_res_type))) { | 2737 (res_type.IsVoidType() || !res_type.IsAssignableTo(other_res_type))) { |
2738 return false; | 2738 return false; |
2739 } | 2739 } |
2740 } | 2740 } |
2741 // Check the types of fixed parameters. | 2741 // Check the types of fixed parameters. |
2742 Type& param_type = Type::Handle(); | 2742 Type& param_type = Type::Handle(); |
2743 Type& other_param_type = Type::Handle(); | 2743 Type& other_param_type = Type::Handle(); |
2744 for (intptr_t i = 0; i < num_fixed_params; i++) { | 2744 for (intptr_t i = 0; i < num_fixed_params; i++) { |
2745 param_type = ParameterTypeAt(i); | 2745 param_type = ParameterTypeAt(i); |
2746 if (!param_type.IsInstantiated()) { | 2746 if (!param_type.IsInstantiated()) { |
2747 param_type = param_type.InstantiateFrom(type_arguments, 0); | 2747 param_type = param_type.InstantiateFrom(type_arguments, 0); |
2748 } | 2748 } |
2749 if (param_type.IsVarType()) { | 2749 if (param_type.IsDynamicType()) { |
2750 continue; | 2750 continue; |
2751 } | 2751 } |
2752 other_param_type = other.ParameterTypeAt(i); | 2752 other_param_type = other.ParameterTypeAt(i); |
2753 if (!other_param_type.IsInstantiated()) { | 2753 if (!other_param_type.IsInstantiated()) { |
2754 other_param_type = | 2754 other_param_type = |
2755 other_param_type.InstantiateFrom(other_type_arguments, 0); | 2755 other_param_type.InstantiateFrom(other_type_arguments, 0); |
2756 } | 2756 } |
2757 if (other_param_type.IsVarType()) { | 2757 if (other_param_type.IsDynamicType()) { |
2758 continue; | 2758 continue; |
2759 } | 2759 } |
2760 // Subtyping and assignability rules are identical when applied to parameter | 2760 // Subtyping and assignability rules are identical when applied to parameter |
2761 // types. | 2761 // types. |
2762 ASSERT((test == Type::kIsSubtypeOf) || (test == Type::kIsAssignableTo)); | 2762 ASSERT((test == Type::kIsSubtypeOf) || (test == Type::kIsAssignableTo)); |
2763 if (!param_type.IsSubtypeOf(other_param_type) && | 2763 if (!param_type.IsSubtypeOf(other_param_type) && |
2764 !other_param_type.IsSubtypeOf(param_type)) { | 2764 !other_param_type.IsSubtypeOf(param_type)) { |
2765 return false; | 2765 return false; |
2766 } | 2766 } |
2767 } | 2767 } |
(...skipping 12 matching lines...) Expand all Loading... |
2780 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { | 2780 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { |
2781 other_param_name = other.ParameterNameAt(i); | 2781 other_param_name = other.ParameterNameAt(i); |
2782 found_param_name = false; | 2782 found_param_name = false; |
2783 for (intptr_t j = num_fixed_params; j < num_params; j++) { | 2783 for (intptr_t j = num_fixed_params; j < num_params; j++) { |
2784 if (ParameterNameAt(j) == other_param_name.raw()) { | 2784 if (ParameterNameAt(j) == other_param_name.raw()) { |
2785 found_param_name = true; | 2785 found_param_name = true; |
2786 param_type = ParameterTypeAt(j); | 2786 param_type = ParameterTypeAt(j); |
2787 if (!param_type.IsInstantiated()) { | 2787 if (!param_type.IsInstantiated()) { |
2788 param_type = param_type.InstantiateFrom(type_arguments, 0); | 2788 param_type = param_type.InstantiateFrom(type_arguments, 0); |
2789 } | 2789 } |
2790 if (param_type.IsVarType()) { | 2790 if (param_type.IsDynamicType()) { |
2791 break; | 2791 break; |
2792 } | 2792 } |
2793 other_param_type = other.ParameterTypeAt(i); | 2793 other_param_type = other.ParameterTypeAt(i); |
2794 if (!other_param_type.IsInstantiated()) { | 2794 if (!other_param_type.IsInstantiated()) { |
2795 other_param_type = | 2795 other_param_type = |
2796 other_param_type.InstantiateFrom(other_type_arguments, 0); | 2796 other_param_type.InstantiateFrom(other_type_arguments, 0); |
2797 } | 2797 } |
2798 if (other_param_type.IsVarType()) { | 2798 if (other_param_type.IsDynamicType()) { |
2799 break; | 2799 break; |
2800 } | 2800 } |
2801 if (!param_type.IsSubtypeOf(other_param_type) && | 2801 if (!param_type.IsSubtypeOf(other_param_type) && |
2802 !other_param_type.IsSubtypeOf(param_type)) { | 2802 !other_param_type.IsSubtypeOf(param_type)) { |
2803 is_subtype = false; | 2803 is_subtype = false; |
2804 } | 2804 } |
2805 break; | 2805 break; |
2806 } | 2806 } |
2807 } | 2807 } |
2808 if (!found_param_name) { | 2808 if (!found_param_name) { |
(...skipping 20 matching lines...) Expand all Loading... |
2829 param_name = ParameterNameAt(i); | 2829 param_name = ParameterNameAt(i); |
2830 found_param_name = false; | 2830 found_param_name = false; |
2831 for (intptr_t j = other_num_fixed_params; j < other_num_params; j++) { | 2831 for (intptr_t j = other_num_fixed_params; j < other_num_params; j++) { |
2832 if (other.ParameterNameAt(j) == param_name.raw()) { | 2832 if (other.ParameterNameAt(j) == param_name.raw()) { |
2833 found_param_name = true; | 2833 found_param_name = true; |
2834 other_param_type = other.ParameterTypeAt(j); | 2834 other_param_type = other.ParameterTypeAt(j); |
2835 if (!other_param_type.IsInstantiated()) { | 2835 if (!other_param_type.IsInstantiated()) { |
2836 other_param_type = | 2836 other_param_type = |
2837 other_param_type.InstantiateFrom(other_type_arguments, 0); | 2837 other_param_type.InstantiateFrom(other_type_arguments, 0); |
2838 } | 2838 } |
2839 if (other_param_type.IsVarType()) { | 2839 if (other_param_type.IsDynamicType()) { |
2840 break; | 2840 break; |
2841 } | 2841 } |
2842 param_type = ParameterTypeAt(i); | 2842 param_type = ParameterTypeAt(i); |
2843 if (!param_type.IsInstantiated()) { | 2843 if (!param_type.IsInstantiated()) { |
2844 param_type = param_type.InstantiateFrom(type_arguments, 0); | 2844 param_type = param_type.InstantiateFrom(type_arguments, 0); |
2845 } | 2845 } |
2846 if (param_type.IsVarType()) { | 2846 if (param_type.IsDynamicType()) { |
2847 break; | 2847 break; |
2848 } | 2848 } |
2849 if (!other_param_type.IsSubtypeOf(param_type) && | 2849 if (!other_param_type.IsSubtypeOf(param_type) && |
2850 !param_type.IsSubtypeOf(other_param_type)) { | 2850 !param_type.IsSubtypeOf(other_param_type)) { |
2851 return false; | 2851 return false; |
2852 } | 2852 } |
2853 break; | 2853 break; |
2854 } | 2854 } |
2855 } | 2855 } |
2856 if (!found_param_name) { | 2856 if (!found_param_name) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3021 intptr_t num_type_parameters = type_parameters.Length(); | 3021 intptr_t num_type_parameters = type_parameters.Length(); |
3022 pieces.Add(&kLAngleBracket); | 3022 pieces.Add(&kLAngleBracket); |
3023 const TypeArray& type_parameter_extends = TypeArray::Handle( | 3023 const TypeArray& type_parameter_extends = TypeArray::Handle( |
3024 function_class.type_parameter_extends()); | 3024 function_class.type_parameter_extends()); |
3025 Type& parameter_extends = Type::Handle(); | 3025 Type& parameter_extends = Type::Handle(); |
3026 for (intptr_t i = 0; i < num_type_parameters; i++) { | 3026 for (intptr_t i = 0; i < num_type_parameters; i++) { |
3027 String& type_parameter = String::ZoneHandle(); | 3027 String& type_parameter = String::ZoneHandle(); |
3028 type_parameter ^= type_parameters.At(i); | 3028 type_parameter ^= type_parameters.At(i); |
3029 pieces.Add(&type_parameter); | 3029 pieces.Add(&type_parameter); |
3030 parameter_extends = type_parameter_extends.TypeAt(i); | 3030 parameter_extends = type_parameter_extends.TypeAt(i); |
3031 if (!parameter_extends.IsNull() && !parameter_extends.IsVarType()) { | 3031 if (!parameter_extends.IsNull() && !parameter_extends.IsDynamicType()) { |
3032 pieces.Add(&kSpaceExtendsSpace); | 3032 pieces.Add(&kSpaceExtendsSpace); |
3033 pieces.Add(&String::ZoneHandle(parameter_extends.Name())); | 3033 pieces.Add(&String::ZoneHandle(parameter_extends.Name())); |
3034 } | 3034 } |
3035 if (i < num_type_parameters - 1) { | 3035 if (i < num_type_parameters - 1) { |
3036 pieces.Add(&kCommaSpace); | 3036 pieces.Add(&kCommaSpace); |
3037 } | 3037 } |
3038 } | 3038 } |
3039 pieces.Add(&kRAngleBracket); | 3039 pieces.Add(&kRAngleBracket); |
3040 } | 3040 } |
3041 } | 3041 } |
(...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4707 intptr_t field_offset = cls.type_arguments_instance_field_offset(); | 4707 intptr_t field_offset = cls.type_arguments_instance_field_offset(); |
4708 ASSERT(field_offset != Class::kNoTypeArguments); | 4708 ASSERT(field_offset != Class::kNoTypeArguments); |
4709 *FieldAddrAtOffset(field_offset) = value.raw(); | 4709 *FieldAddrAtOffset(field_offset) = value.raw(); |
4710 } | 4710 } |
4711 | 4711 |
4712 | 4712 |
4713 bool Instance::TestType(TypeTestKind test, | 4713 bool Instance::TestType(TypeTestKind test, |
4714 const Type& other, | 4714 const Type& other, |
4715 const TypeArguments& other_instantiator) const { | 4715 const TypeArguments& other_instantiator) const { |
4716 ASSERT(other.IsFinalized()); | 4716 ASSERT(other.IsFinalized()); |
4717 ASSERT(!other.IsVarType()); | 4717 ASSERT(!other.IsDynamicType()); |
4718 ASSERT(!other.IsVoidType()); | 4718 ASSERT(!other.IsVoidType()); |
4719 if (IsNull()) { | 4719 if (IsNull()) { |
4720 if (test == Type::kIsSubtypeOf) { | 4720 if (test == Type::kIsSubtypeOf) { |
4721 const Type& object_type = | 4721 const Type& object_type = |
4722 Type::Handle(Isolate::Current()->object_store()->object_type()); | 4722 Type::Handle(Isolate::Current()->object_store()->object_type()); |
4723 if (other.IsInstantiated() && object_type.IsSubtypeOf(other)) { | 4723 if (other.IsInstantiated() && object_type.IsSubtypeOf(other)) { |
4724 ASSERT(other_instantiator.IsNull()); | 4724 ASSERT(other_instantiator.IsNull()); |
4725 // null is an instance of the Object class. | 4725 // null is an instance of the Object class. |
4726 return true; | 4726 return true; |
4727 } | 4727 } |
(...skipping 23 matching lines...) Expand all Loading... |
4751 TypeArguments& other_type_arguments = TypeArguments::Handle(); | 4751 TypeArguments& other_type_arguments = TypeArguments::Handle(); |
4752 // In case 'other' is not instantiated, we could simply call | 4752 // In case 'other' is not instantiated, we could simply call |
4753 // other.InstantiateFrom(other_instantiator, 0), however, we can save the | 4753 // other.InstantiateFrom(other_instantiator, 0), however, we can save the |
4754 // allocation of a new Type by inlining the code. | 4754 // allocation of a new Type by inlining the code. |
4755 if (other.IsTypeParameter()) { | 4755 if (other.IsTypeParameter()) { |
4756 Type& instantiated_other = Type::Handle(); | 4756 Type& instantiated_other = Type::Handle(); |
4757 if (!other_instantiator.IsNull()) { | 4757 if (!other_instantiator.IsNull()) { |
4758 instantiated_other = other_instantiator.TypeAt(other.Index()); | 4758 instantiated_other = other_instantiator.TypeAt(other.Index()); |
4759 ASSERT(instantiated_other.IsInstantiated()); | 4759 ASSERT(instantiated_other.IsInstantiated()); |
4760 } else { | 4760 } else { |
4761 instantiated_other = Type::VarType(); | 4761 instantiated_other = Type::DynamicType(); |
4762 } | 4762 } |
4763 other_class = instantiated_other.type_class(); | 4763 other_class = instantiated_other.type_class(); |
4764 other_type_arguments = instantiated_other.arguments(); | 4764 other_type_arguments = instantiated_other.arguments(); |
4765 } else { | 4765 } else { |
4766 other_class = other.type_class(); | 4766 other_class = other.type_class(); |
4767 other_type_arguments = other.arguments(); | 4767 other_type_arguments = other.arguments(); |
4768 if (!other_type_arguments.IsNull() && | 4768 if (!other_type_arguments.IsNull() && |
4769 !other_type_arguments.IsInstantiated()) { | 4769 !other_type_arguments.IsInstantiated()) { |
4770 other_type_arguments = | 4770 other_type_arguments = |
4771 other_type_arguments.InstantiateFrom(other_instantiator, 0); | 4771 other_type_arguments.InstantiateFrom(other_instantiator, 0); |
(...skipping 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6787 const String& str = String::Handle(pattern()); | 6787 const String& str = String::Handle(pattern()); |
6788 const char* format = "JSRegExp: pattern=%s flags=%s"; | 6788 const char* format = "JSRegExp: pattern=%s flags=%s"; |
6789 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 6789 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
6790 char* chars = reinterpret_cast<char*>( | 6790 char* chars = reinterpret_cast<char*>( |
6791 Isolate::Current()->current_zone()->Allocate(len + 1)); | 6791 Isolate::Current()->current_zone()->Allocate(len + 1)); |
6792 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 6792 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
6793 return chars; | 6793 return chars; |
6794 } | 6794 } |
6795 | 6795 |
6796 } // namespace dart | 6796 } // namespace dart |
OLD | NEW |