| 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 "lib/error.h" | 5 #include "lib/error.h" |
| 6 | 6 |
| 7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/runtime_entry.h" | 10 #include "vm/runtime_entry.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 AbstractTypeArguments::CheckedHandle(arguments.At(3)); | 219 AbstractTypeArguments::CheckedHandle(arguments.At(3)); |
| 220 const String& dst_name = String::CheckedHandle(arguments.At(4)); | 220 const String& dst_name = String::CheckedHandle(arguments.At(4)); |
| 221 ASSERT(!dst_type.IsDynamicType()); // No need to check assignment. | 221 ASSERT(!dst_type.IsDynamicType()); // No need to check assignment. |
| 222 ASSERT(!src_instance.IsNull()); // Already checked in inlined code. | 222 ASSERT(!src_instance.IsNull()); // Already checked in inlined code. |
| 223 | 223 |
| 224 const bool is_assignable = | 224 const bool is_assignable = |
| 225 src_instance.IsAssignableTo(dst_type, dst_type_instantiator); | 225 src_instance.IsAssignableTo(dst_type, dst_type_instantiator); |
| 226 | 226 |
| 227 if (FLAG_trace_type_checks) { | 227 if (FLAG_trace_type_checks) { |
| 228 const Type& src_type = Type::Handle(src_instance.GetType()); | 228 const Type& src_type = Type::Handle(src_instance.GetType()); |
| 229 AbstractType& instantiated_dst_type = AbstractType::Handle(dst_type.raw()); | 229 if (dst_type.IsInstantiated()) { |
| 230 if (!dst_type.IsInstantiated()) { | 230 OS::Print("TypeCheck: '%s' %s assignable to '%s' of '%s'.\n", |
| 231 String::Handle(src_type.Name()).ToCString(), |
| 232 is_assignable ? "is" : "is not", |
| 233 String::Handle(dst_type.Name()).ToCString(), |
| 234 dst_name.ToCString()); |
| 235 } else { |
| 231 // Instantiate dst_type before printing. | 236 // Instantiate dst_type before printing. |
| 232 instantiated_dst_type = | 237 const AbstractType& instantiated_dst_type = AbstractType::Handle( |
| 233 dst_type.InstantiateFrom(dst_type_instantiator, 0); | 238 dst_type.InstantiateFrom(dst_type_instantiator)); |
| 239 OS::Print("TypeCheck: '%s' %s assignable to '%s' of '%s' " |
| 240 "instantiated from '%s'.\n", |
| 241 String::Handle(src_type.Name()).ToCString(), |
| 242 is_assignable ? "is" : "is not", |
| 243 String::Handle(instantiated_dst_type.Name()).ToCString(), |
| 244 dst_name.ToCString(), |
| 245 String::Handle(dst_type.Name()).ToCString()); |
| 234 } | 246 } |
| 235 OS::Print("TypeCheck: '%s' %s assignable to '%s'.\n", | |
| 236 String::Handle(src_type.Name()).ToCString(), | |
| 237 is_assignable ? "is" : "is not", | |
| 238 String::Handle(dst_type.Name()).ToCString()); | |
| 239 } | 247 } |
| 240 if (!is_assignable) { | 248 if (!is_assignable) { |
| 241 const Type& src_type = Type::Handle(src_instance.GetType()); | 249 const Type& src_type = Type::Handle(src_instance.GetType()); |
| 242 const String& src_type_name = String::Handle(src_type.Name()); | 250 const String& src_type_name = String::Handle(src_type.Name()); |
| 243 String& dst_type_name = String::Handle(); | 251 String& dst_type_name = String::Handle(); |
| 244 if (!dst_type.IsInstantiated()) { | 252 if (!dst_type.IsInstantiated()) { |
| 245 // Instantiate dst_type before reporting the error. | 253 // Instantiate dst_type before reporting the error. |
| 246 const AbstractType& instantiated_dst_type = AbstractType::Handle( | 254 const AbstractType& instantiated_dst_type = AbstractType::Handle( |
| 247 dst_type.InstantiateFrom(dst_type_instantiator, 0)); | 255 dst_type.InstantiateFrom(dst_type_instantiator)); |
| 248 dst_type_name = instantiated_dst_type.Name(); | 256 dst_type_name = instantiated_dst_type.Name(); |
| 249 } else { | 257 } else { |
| 250 dst_type_name = dst_type.Name(); | 258 dst_type_name = dst_type.Name(); |
| 251 } | 259 } |
| 252 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 260 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 253 UNREACHABLE(); | 261 UNREACHABLE(); |
| 254 } | 262 } |
| 255 arguments.SetReturn(src_instance); | 263 arguments.SetReturn(src_instance); |
| 256 } | 264 } |
| 257 | 265 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 // Allocate and throw a new instance of TypeError. | 314 // Allocate and throw a new instance of TypeError. |
| 307 char buf[256]; | 315 char buf[256]; |
| 308 OS::SNPrint(buf, sizeof(buf), "%s[%d]", | 316 OS::SNPrint(buf, sizeof(buf), "%s[%d]", |
| 309 rest_name.ToCString(), static_cast<int>(i)); | 317 rest_name.ToCString(), static_cast<int>(i)); |
| 310 const String& src_type_name = | 318 const String& src_type_name = |
| 311 String::Handle(Type::Handle(elem.GetType()).Name()); | 319 String::Handle(Type::Handle(elem.GetType()).Name()); |
| 312 String& dst_type_name = String::Handle(); | 320 String& dst_type_name = String::Handle(); |
| 313 if (!element_type.IsInstantiated()) { | 321 if (!element_type.IsInstantiated()) { |
| 314 // Instantiate element_type before reporting the error. | 322 // Instantiate element_type before reporting the error. |
| 315 const AbstractType& instantiated_element_type = AbstractType::Handle( | 323 const AbstractType& instantiated_element_type = AbstractType::Handle( |
| 316 element_type.InstantiateFrom(element_type_instantiator, 0)); | 324 element_type.InstantiateFrom(element_type_instantiator)); |
| 317 dst_type_name = instantiated_element_type.Name(); | 325 dst_type_name = instantiated_element_type.Name(); |
| 318 } else { | 326 } else { |
| 319 dst_type_name = element_type.Name(); | 327 dst_type_name = element_type.Name(); |
| 320 } | 328 } |
| 321 const String& dst_name = String::Handle(String::New(buf)); | 329 const String& dst_name = String::Handle(String::New(buf)); |
| 322 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 330 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 323 UNREACHABLE(); | 331 UNREACHABLE(); |
| 324 } | 332 } |
| 325 } | 333 } |
| 326 } | 334 } |
| 327 | 335 |
| 328 } // namespace dart | 336 } // namespace dart |
| OLD | NEW |