| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 ASSERT(arguments.Count() == kTypeCheckRuntimeEntry.argument_count()); | 192 ASSERT(arguments.Count() == kTypeCheckRuntimeEntry.argument_count()); |
| 193 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); | 193 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); |
| 194 const Instance& src_instance = Instance::CheckedHandle(arguments.At(1)); | 194 const Instance& src_instance = Instance::CheckedHandle(arguments.At(1)); |
| 195 const Type& dst_type = Type::CheckedHandle(arguments.At(2)); | 195 const Type& dst_type = Type::CheckedHandle(arguments.At(2)); |
| 196 const TypeArguments& dst_type_instantiator = | 196 const TypeArguments& dst_type_instantiator = |
| 197 TypeArguments::CheckedHandle(arguments.At(3)); | 197 TypeArguments::CheckedHandle(arguments.At(3)); |
| 198 const String& dst_name = String::CheckedHandle(arguments.At(4)); | 198 const String& dst_name = String::CheckedHandle(arguments.At(4)); |
| 199 ASSERT(!dst_type.IsDynamicType()); // No need to check assignment. | 199 ASSERT(!dst_type.IsDynamicType()); // No need to check assignment. |
| 200 ASSERT(!src_instance.IsNull()); // Already checked in inlined code. | 200 ASSERT(!src_instance.IsNull()); // Already checked in inlined code. |
| 201 | 201 |
| 202 if (!src_instance.IsAssignableTo(dst_type, dst_type_instantiator)) { | 202 const bool is_assignable = |
| 203 src_instance.IsAssignableTo(dst_type, dst_type_instantiator); |
| 204 |
| 205 if (FLAG_trace_type_checks) { |
| 206 const Type& src_type = Type::Handle(src_instance.GetType()); |
| 207 Type& instantiated_dst_type = Type::Handle(dst_type.raw()); |
| 208 if (!dst_type.IsInstantiated()) { |
| 209 // Instantiate dst_type before printing. |
| 210 instantiated_dst_type = |
| 211 dst_type.InstantiateFrom(dst_type_instantiator, 0); |
| 212 } |
| 213 OS::Print("TypeCheck: '%s' %s assignable to '%s'.\n", |
| 214 String::Handle(src_type.Name()).ToCString(), |
| 215 is_assignable ? "is" : "is not", |
| 216 String::Handle(dst_type.Name()).ToCString()); |
| 217 } |
| 218 if (!is_assignable) { |
| 203 const Type& src_type = Type::Handle(src_instance.GetType()); | 219 const Type& src_type = Type::Handle(src_instance.GetType()); |
| 204 const String& src_type_name = String::Handle(src_type.Name()); | 220 const String& src_type_name = String::Handle(src_type.Name()); |
| 205 String& dst_type_name = String::Handle(); | 221 String& dst_type_name = String::Handle(); |
| 206 if (!dst_type.IsInstantiated()) { | 222 if (!dst_type.IsInstantiated()) { |
| 207 // Instantiate dst_type before reporting the error. | 223 // Instantiate dst_type before reporting the error. |
| 208 const Type& instantiated_dst_type = Type::Handle( | 224 const Type& instantiated_dst_type = Type::Handle( |
| 209 dst_type.InstantiateFrom(dst_type_instantiator, 0)); | 225 dst_type.InstantiateFrom(dst_type_instantiator, 0)); |
| 210 dst_type_name = instantiated_dst_type.Name(); | 226 dst_type_name = instantiated_dst_type.Name(); |
| 211 } else { | 227 } else { |
| 212 dst_type_name = dst_type.Name(); | 228 dst_type_name = dst_type.Name(); |
| 213 } | 229 } |
| 214 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 230 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 215 UNREACHABLE(); | 231 UNREACHABLE(); |
| 216 } | 232 } |
| 217 | |
| 218 if (FLAG_trace_type_checks) { | |
| 219 Class& cls = Class::Handle(src_instance.clazz()); | |
| 220 // TODO(regis): Remove once all classes finalized. | |
| 221 if (cls.is_finalized()) { | |
| 222 OS::Print("TypeCheck '%s' vs '%s'\n", | |
| 223 String::Handle(Type::Handle(src_instance.GetType()).Name()). | |
| 224 ToCString(), | |
| 225 String::Handle(dst_type.Name()).ToCString()); | |
| 226 } | |
| 227 } | |
| 228 arguments.SetReturn(src_instance); | 233 arguments.SetReturn(src_instance); |
| 229 } | 234 } |
| 230 | 235 |
| 231 | 236 |
| 232 // Report that the type of the given object is not bool in conditional context. | 237 // Report that the type of the given object is not bool in conditional context. |
| 233 // Arg0: index of the token of the assignment (source location). | 238 // Arg0: index of the token of the assignment (source location). |
| 234 // Arg1: bad object. | 239 // Arg1: bad object. |
| 235 // Return value: none, throws a TypeError. | 240 // Return value: none, throws a TypeError. |
| 236 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) { | 241 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) { |
| 237 ASSERT(arguments.Count() == | 242 ASSERT(arguments.Count() == |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 dst_type_name = element_type.Name(); | 296 dst_type_name = element_type.Name(); |
| 292 } | 297 } |
| 293 const String& dst_name = String::Handle(String::New(buf)); | 298 const String& dst_name = String::Handle(String::New(buf)); |
| 294 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 299 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 295 UNREACHABLE(); | 300 UNREACHABLE(); |
| 296 } | 301 } |
| 297 } | 302 } |
| 298 } | 303 } |
| 299 | 304 |
| 300 } // namespace dart | 305 } // namespace dart |
| OLD | NEW |