OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/code_generator.h" | 5 #include "vm/code_generator.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 ASSERT(instantiator.IsNull() || instantiator.IsInstantiated()); | 197 ASSERT(instantiator.IsNull() || instantiator.IsInstantiated()); |
198 Error& bound_error = Error::Handle(); | 198 Error& bound_error = Error::Handle(); |
199 type = | 199 type = |
200 type.InstantiateFrom(instantiator, &bound_error, NULL, NULL, Heap::kOld); | 200 type.InstantiateFrom(instantiator, &bound_error, NULL, NULL, Heap::kOld); |
201 if (!bound_error.IsNull()) { | 201 if (!bound_error.IsNull()) { |
202 // Throw a dynamic type error. | 202 // Throw a dynamic type error. |
203 const TokenPosition location = GetCallerLocation(); | 203 const TokenPosition location = GetCallerLocation(); |
204 String& bound_error_message = String::Handle( | 204 String& bound_error_message = String::Handle( |
205 String::New(bound_error.ToErrorCString())); | 205 String::New(bound_error.ToErrorCString())); |
206 Exceptions::CreateAndThrowTypeError( | 206 Exceptions::CreateAndThrowTypeError( |
207 location, Symbols::Empty(), Symbols::Empty(), | 207 location, AbstractType::Handle(), AbstractType::Handle(), |
srdjan
2016/03/09 22:38:22
Add zone parameters
regis
2016/03/09 23:15:40
Done.
| |
208 Symbols::Empty(), bound_error_message); | 208 Symbols::Empty(), bound_error_message); |
209 UNREACHABLE(); | 209 UNREACHABLE(); |
210 } | 210 } |
211 if (type.IsTypeRef()) { | 211 if (type.IsTypeRef()) { |
212 type = TypeRef::Cast(type).type(); | 212 type = TypeRef::Cast(type).type(); |
213 ASSERT(!type.IsTypeRef()); | 213 ASSERT(!type.IsTypeRef()); |
214 ASSERT(type.IsCanonical()); | 214 ASSERT(type.IsCanonical()); |
215 } | 215 } |
216 ASSERT(!type.IsNull() && type.IsInstantiated()); | 216 ASSERT(!type.IsNull() && type.IsInstantiated()); |
217 arguments.SetReturn(type); | 217 arguments.SetReturn(type); |
(...skipping 18 matching lines...) Expand all Loading... | |
236 Error& bound_error = Error::Handle(); | 236 Error& bound_error = Error::Handle(); |
237 type_arguments = | 237 type_arguments = |
238 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, | 238 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, |
239 &bound_error); | 239 &bound_error); |
240 if (!bound_error.IsNull()) { | 240 if (!bound_error.IsNull()) { |
241 // Throw a dynamic type error. | 241 // Throw a dynamic type error. |
242 const TokenPosition location = GetCallerLocation(); | 242 const TokenPosition location = GetCallerLocation(); |
243 String& bound_error_message = String::Handle( | 243 String& bound_error_message = String::Handle( |
244 String::New(bound_error.ToErrorCString())); | 244 String::New(bound_error.ToErrorCString())); |
245 Exceptions::CreateAndThrowTypeError( | 245 Exceptions::CreateAndThrowTypeError( |
246 location, Symbols::Empty(), Symbols::Empty(), | 246 location, AbstractType::Handle(), AbstractType::Handle(), |
srdjan
2016/03/09 22:38:23
ditto
regis
2016/03/09 23:15:40
Done.
| |
247 Symbols::Empty(), bound_error_message); | 247 Symbols::Empty(), bound_error_message); |
248 UNREACHABLE(); | 248 UNREACHABLE(); |
249 } | 249 } |
250 } else { | 250 } else { |
251 type_arguments = | 251 type_arguments = |
252 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL); | 252 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL); |
253 } | 253 } |
254 ASSERT(type_arguments.IsNull() || type_arguments.IsInstantiated()); | 254 ASSERT(type_arguments.IsNull() || type_arguments.IsInstantiated()); |
255 arguments.SetReturn(type_arguments); | 255 arguments.SetReturn(type_arguments); |
256 } | 256 } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 if (FLAG_trace_type_checks) { | 467 if (FLAG_trace_type_checks) { |
468 PrintTypeCheck("InstanceOf", | 468 PrintTypeCheck("InstanceOf", |
469 instance, type, instantiator_type_arguments, result); | 469 instance, type, instantiator_type_arguments, result); |
470 } | 470 } |
471 if (!result.value() && !bound_error.IsNull()) { | 471 if (!result.value() && !bound_error.IsNull()) { |
472 // Throw a dynamic type error only if the instanceof test fails. | 472 // Throw a dynamic type error only if the instanceof test fails. |
473 const TokenPosition location = GetCallerLocation(); | 473 const TokenPosition location = GetCallerLocation(); |
474 String& bound_error_message = String::Handle( | 474 String& bound_error_message = String::Handle( |
475 String::New(bound_error.ToErrorCString())); | 475 String::New(bound_error.ToErrorCString())); |
476 Exceptions::CreateAndThrowTypeError( | 476 Exceptions::CreateAndThrowTypeError( |
477 location, Symbols::Empty(), Symbols::Empty(), | 477 location, AbstractType::Handle(), AbstractType::Handle(), |
478 Symbols::Empty(), bound_error_message); | 478 Symbols::Empty(), bound_error_message); |
479 UNREACHABLE(); | 479 UNREACHABLE(); |
480 } | 480 } |
481 UpdateTypeTestCache( | 481 UpdateTypeTestCache( |
482 instance, type, instantiator_type_arguments, result, cache); | 482 instance, type, instantiator_type_arguments, result, cache); |
483 arguments.SetReturn(result); | 483 arguments.SetReturn(result); |
484 } | 484 } |
485 | 485 |
486 | 486 |
487 // Check that the type of the given instance is a subtype of the given type and | 487 // Check that the type of the given instance is a subtype of the given type and |
(...skipping 23 matching lines...) Expand all Loading... | |
511 | 511 |
512 if (FLAG_trace_type_checks) { | 512 if (FLAG_trace_type_checks) { |
513 PrintTypeCheck("TypeCheck", | 513 PrintTypeCheck("TypeCheck", |
514 src_instance, dst_type, instantiator_type_arguments, | 514 src_instance, dst_type, instantiator_type_arguments, |
515 Bool::Get(is_instance_of)); | 515 Bool::Get(is_instance_of)); |
516 } | 516 } |
517 if (!is_instance_of) { | 517 if (!is_instance_of) { |
518 // Throw a dynamic type error. | 518 // Throw a dynamic type error. |
519 const TokenPosition location = GetCallerLocation(); | 519 const TokenPosition location = GetCallerLocation(); |
520 const AbstractType& src_type = AbstractType::Handle(src_instance.GetType()); | 520 const AbstractType& src_type = AbstractType::Handle(src_instance.GetType()); |
521 String& src_type_name = String::Handle(src_type.UserVisibleName()); | |
522 if (!dst_type.IsInstantiated()) { | 521 if (!dst_type.IsInstantiated()) { |
523 // Instantiate dst_type before reporting the error. | 522 // Instantiate dst_type before reporting the error. |
524 dst_type = dst_type.InstantiateFrom(instantiator_type_arguments, NULL, | 523 dst_type = dst_type.InstantiateFrom(instantiator_type_arguments, NULL, |
525 NULL, NULL, Heap::kNew); | 524 NULL, NULL, Heap::kNew); |
526 // Note that instantiated dst_type may be malbounded. | 525 // Note that instantiated dst_type may be malbounded. |
527 } | 526 } |
528 String& dst_type_name = String::Handle(dst_type.UserVisibleName()); | |
529 String& bound_error_message = String::Handle(); | 527 String& bound_error_message = String::Handle(); |
530 if (!bound_error.IsNull()) { | 528 if (!bound_error.IsNull()) { |
531 ASSERT(isolate->type_checks()); | 529 ASSERT(isolate->type_checks()); |
532 bound_error_message = String::New(bound_error.ToErrorCString()); | 530 bound_error_message = String::New(bound_error.ToErrorCString()); |
533 } | 531 } |
534 if (src_type_name.Equals(dst_type_name)) { | 532 Exceptions::CreateAndThrowTypeError(location, src_type, dst_type, |
535 src_type_name = src_type.UserVisibleNameWithURI(); | |
536 dst_type_name = dst_type.UserVisibleNameWithURI(); | |
537 } | |
538 Exceptions::CreateAndThrowTypeError(location, src_type_name, dst_type_name, | |
539 dst_name, bound_error_message); | 533 dst_name, bound_error_message); |
540 UNREACHABLE(); | 534 UNREACHABLE(); |
541 } | 535 } |
542 UpdateTypeTestCache( | 536 UpdateTypeTestCache( |
543 src_instance, dst_type, instantiator_type_arguments, Bool::True(), cache); | 537 src_instance, dst_type, instantiator_type_arguments, Bool::True(), cache); |
544 arguments.SetReturn(src_instance); | 538 arguments.SetReturn(src_instance); |
545 } | 539 } |
546 | 540 |
547 | 541 |
548 // Report that the type of the given object is not bool in conditional context. | 542 // Report that the type of the given object is not bool in conditional context. |
(...skipping 15 matching lines...) Expand all Loading... | |
564 args.SetAt(2, Smi::Handle(Smi::New(0))); | 558 args.SetAt(2, Smi::Handle(Smi::New(0))); |
565 args.SetAt(3, Smi::Handle(Smi::New(0))); | 559 args.SetAt(3, Smi::Handle(Smi::New(0))); |
566 | 560 |
567 Exceptions::ThrowByType(Exceptions::kAssertion, args); | 561 Exceptions::ThrowByType(Exceptions::kAssertion, args); |
568 UNREACHABLE(); | 562 UNREACHABLE(); |
569 } | 563 } |
570 | 564 |
571 ASSERT(!src_instance.IsBool()); | 565 ASSERT(!src_instance.IsBool()); |
572 const Type& bool_interface = Type::Handle(Type::BoolType()); | 566 const Type& bool_interface = Type::Handle(Type::BoolType()); |
573 const AbstractType& src_type = AbstractType::Handle(src_instance.GetType()); | 567 const AbstractType& src_type = AbstractType::Handle(src_instance.GetType()); |
574 const String& src_type_name = String::Handle(src_type.UserVisibleName()); | |
575 const String& bool_type_name = | |
576 String::Handle(bool_interface.UserVisibleName()); | |
577 const String& no_bound_error = String::Handle(); | 568 const String& no_bound_error = String::Handle(); |
578 Exceptions::CreateAndThrowTypeError(location, src_type_name, bool_type_name, | 569 Exceptions::CreateAndThrowTypeError(location, src_type, bool_interface, |
579 Symbols::BooleanExpression(), | 570 Symbols::BooleanExpression(), |
580 no_bound_error); | 571 no_bound_error); |
581 UNREACHABLE(); | 572 UNREACHABLE(); |
582 } | 573 } |
583 | 574 |
584 | 575 |
585 // Report that the type of the type check is malformed or malbounded. | 576 // Report that the type of the type check is malformed or malbounded. |
586 // Arg0: src value. | 577 // Arg0: src value. |
587 // Arg1: name of destination being assigned to. | 578 // Arg1: name of destination being assigned to. |
588 // Arg2: type of destination being assigned to. | 579 // Arg2: type of destination being assigned to. |
589 // Return value: none, throws an exception. | 580 // Return value: none, throws an exception. |
590 DEFINE_RUNTIME_ENTRY(BadTypeError, 3) { | 581 DEFINE_RUNTIME_ENTRY(BadTypeError, 3) { |
591 const TokenPosition location = GetCallerLocation(); | 582 const TokenPosition location = GetCallerLocation(); |
592 const Instance& src_value = Instance::CheckedHandle(arguments.ArgAt(0)); | 583 const Instance& src_value = Instance::CheckedHandle(arguments.ArgAt(0)); |
593 const String& dst_name = String::CheckedHandle(arguments.ArgAt(1)); | 584 const String& dst_name = String::CheckedHandle(arguments.ArgAt(1)); |
594 const AbstractType& dst_type = | 585 const AbstractType& dst_type = |
595 AbstractType::CheckedHandle(arguments.ArgAt(2)); | 586 AbstractType::CheckedHandle(arguments.ArgAt(2)); |
596 const AbstractType& src_type = AbstractType::Handle(src_value.GetType()); | 587 const AbstractType& src_type = AbstractType::Handle(src_value.GetType()); |
597 const String& src_type_name = String::Handle(src_type.UserVisibleName()); | |
598 | |
599 String& dst_type_name = String::Handle(); | |
600 LanguageError& error = LanguageError::Handle(dst_type.error()); | |
601 ASSERT(!error.IsNull()); | |
602 if (error.kind() == Report::kMalformedType) { | |
603 dst_type_name = Symbols::Malformed().raw(); | |
604 } else { | |
605 ASSERT(error.kind() == Report::kMalboundedType); | |
606 dst_type_name = Symbols::Malbounded().raw(); | |
607 } | |
608 const String& error_message = String::ZoneHandle( | |
609 Symbols::New(error.ToErrorCString())); | |
610 Exceptions::CreateAndThrowTypeError( | 588 Exceptions::CreateAndThrowTypeError( |
611 location, src_type_name, dst_type_name, dst_name, error_message); | 589 location, src_type, dst_type, dst_name, String::Handle()); |
srdjan
2016/03/09 22:38:23
ditto
regis
2016/03/09 23:15:40
Done.
| |
612 UNREACHABLE(); | 590 UNREACHABLE(); |
613 } | 591 } |
614 | 592 |
615 | 593 |
616 DEFINE_RUNTIME_ENTRY(Throw, 1) { | 594 DEFINE_RUNTIME_ENTRY(Throw, 1) { |
617 const Instance& exception = | 595 const Instance& exception = |
618 Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 596 Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
619 Exceptions::Throw(thread, exception); | 597 Exceptions::Throw(thread, exception); |
620 } | 598 } |
621 | 599 |
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1892 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1870 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
1893 const TypedData& new_data = | 1871 const TypedData& new_data = |
1894 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1872 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
1895 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1873 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
1896 typed_data_cell.SetAt(0, new_data); | 1874 typed_data_cell.SetAt(0, new_data); |
1897 arguments.SetReturn(new_data); | 1875 arguments.SetReturn(new_data); |
1898 } | 1876 } |
1899 | 1877 |
1900 | 1878 |
1901 } // namespace dart | 1879 } // namespace dart |
OLD | NEW |