Chromium Code Reviews| 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/code_generator.h" | 5 #include "vm/code_generator.h" |
| 6 | 6 |
| 7 #include "vm/code_index_table.h" | 7 #include "vm/code_index_table.h" |
| 8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 } | 460 } |
| 461 DartFrameIterator iterator; | 461 DartFrameIterator iterator; |
| 462 DartFrame* caller_frame = iterator.NextFrame(); | 462 DartFrame* caller_frame = iterator.NextFrame(); |
| 463 ASSERT(caller_frame != NULL); | 463 ASSERT(caller_frame != NULL); |
| 464 const Function& function = Function::Handle( | 464 const Function& function = Function::Handle( |
| 465 caller_frame->LookupDartFunction()); | 465 caller_frame->LookupDartFunction()); |
| 466 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString()); | 466 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString()); |
| 467 } | 467 } |
| 468 if (!is_instance_of) { | 468 if (!is_instance_of) { |
| 469 const Type& src_type = Type::Handle(src_instance.GetType()); | 469 const Type& src_type = Type::Handle(src_instance.GetType()); |
| 470 const String& src_type_name = String::Handle(src_type.Name()); | 470 String& src_type_name = String::Handle(); |
| 471 if (src_instance.IsInteger()) { | |
| 472 // Hide implementation detail (Smi, Mint, Bigint). | |
| 473 src_type_name = String::NewSymbol("int"); | |
| 474 } else { | |
| 475 src_type_name = src_type.Name(); | |
| 476 } | |
| 471 String& dst_type_name = String::Handle(); | 477 String& dst_type_name = String::Handle(); |
| 472 if (!dst_type.IsInstantiated()) { | 478 if (!dst_type.IsInstantiated()) { |
| 473 // Instantiate dst_type before reporting the error. | 479 // Instantiate dst_type before reporting the error. |
| 474 const AbstractType& instantiated_dst_type = AbstractType::Handle( | 480 const AbstractType& instantiated_dst_type = AbstractType::Handle( |
| 475 dst_type.InstantiateFrom(dst_type_instantiator)); | 481 dst_type.InstantiateFrom(dst_type_instantiator)); |
| 476 dst_type_name = instantiated_dst_type.Name(); | 482 dst_type_name = instantiated_dst_type.Name(); |
| 477 } else { | 483 } else { |
| 478 dst_type_name = dst_type.Name(); | 484 dst_type_name = dst_type.Name(); |
| 479 } | 485 } |
| 480 String& malformed_error_message = String::Handle(); | 486 String& malformed_error_message = String::Handle(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 496 // Return value: none, throws a TypeError. | 502 // Return value: none, throws a TypeError. |
| 497 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) { | 503 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) { |
| 498 ASSERT(arguments.Count() == | 504 ASSERT(arguments.Count() == |
| 499 kConditionTypeErrorRuntimeEntry.argument_count()); | 505 kConditionTypeErrorRuntimeEntry.argument_count()); |
| 500 // TODO(regis): Get the token index from the PcDesc (via DartFrame). | 506 // TODO(regis): Get the token index from the PcDesc (via DartFrame). |
| 501 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); | 507 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); |
| 502 const Instance& src_instance = Instance::CheckedHandle(arguments.At(1)); | 508 const Instance& src_instance = Instance::CheckedHandle(arguments.At(1)); |
| 503 ASSERT(src_instance.IsNull() || !src_instance.IsBool()); | 509 ASSERT(src_instance.IsNull() || !src_instance.IsBool()); |
| 504 const Type& bool_interface = Type::Handle(Type::BoolInterface()); | 510 const Type& bool_interface = Type::Handle(Type::BoolInterface()); |
| 505 const Type& src_type = Type::Handle(src_instance.GetType()); | 511 const Type& src_type = Type::Handle(src_instance.GetType()); |
| 506 const String& src_type_name = String::Handle(src_type.Name()); | 512 const String& src_type_name = String::Handle(src_type.Name()); |
|
regis
2012/03/15 00:56:39
You should map the name here as well.
srdjan
2012/03/15 01:10:13
Done.
| |
| 507 const String& bool_type_name = String::Handle(bool_interface.Name()); | 513 const String& bool_type_name = String::Handle(bool_interface.Name()); |
| 508 const String& expr = String::Handle(String::NewSymbol("boolean expression")); | 514 const String& expr = String::Handle(String::NewSymbol("boolean expression")); |
| 509 const String& no_malformed_type_error = String::Handle(); | 515 const String& no_malformed_type_error = String::Handle(); |
| 510 Exceptions::CreateAndThrowTypeError(location, src_type_name, bool_type_name, | 516 Exceptions::CreateAndThrowTypeError(location, src_type_name, bool_type_name, |
| 511 expr, no_malformed_type_error); | 517 expr, no_malformed_type_error); |
| 512 UNREACHABLE(); | 518 UNREACHABLE(); |
| 513 } | 519 } |
| 514 | 520 |
| 515 | 521 |
| 516 // Report that the type of the type check is malformed. | 522 // Report that the type of the type check is malformed. |
| 517 // Arg0: index of the token of the failed type check. | 523 // Arg0: index of the token of the failed type check. |
| 518 // Arg1: src value. | 524 // Arg1: src value. |
| 519 // Arg2: name of instance being assigned to. | 525 // Arg2: name of instance being assigned to. |
| 520 // Arg3: malformed type error message. | 526 // Arg3: malformed type error message. |
| 521 // Return value: none, throws an exception. | 527 // Return value: none, throws an exception. |
| 522 DEFINE_RUNTIME_ENTRY(MalformedTypeError, 4) { | 528 DEFINE_RUNTIME_ENTRY(MalformedTypeError, 4) { |
| 523 ASSERT(arguments.Count() == | 529 ASSERT(arguments.Count() == |
| 524 kMalformedTypeErrorRuntimeEntry.argument_count()); | 530 kMalformedTypeErrorRuntimeEntry.argument_count()); |
| 525 // TODO(regis): Get the token index from the PcDesc (via DartFrame). | 531 // TODO(regis): Get the token index from the PcDesc (via DartFrame). |
| 526 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); | 532 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); |
| 527 const Instance& src_value = Instance::CheckedHandle(arguments.At(1)); | 533 const Instance& src_value = Instance::CheckedHandle(arguments.At(1)); |
| 528 const String& dst_name = String::CheckedHandle(arguments.At(2)); | 534 const String& dst_name = String::CheckedHandle(arguments.At(2)); |
| 529 const String& malformed_error = String::CheckedHandle(arguments.At(3)); | 535 const String& malformed_error = String::CheckedHandle(arguments.At(3)); |
| 530 const String& dst_type_name = String::Handle(String::NewSymbol("malformed")); | 536 const String& dst_type_name = String::Handle(String::NewSymbol("malformed")); |
| 531 const String& src_type_name = | 537 const String& src_type_name = |
| 532 String::Handle(Type::Handle(src_value.GetType()).Name()); | 538 String::Handle(Type::Handle(src_value.GetType()).Name()); |
|
regis
2012/03/15 00:56:39
And here.
srdjan
2012/03/15 01:10:13
Done.
| |
| 533 Exceptions::CreateAndThrowTypeError(location, src_type_name, | 539 Exceptions::CreateAndThrowTypeError(location, src_type_name, |
| 534 dst_type_name, dst_name, malformed_error); | 540 dst_type_name, dst_name, malformed_error); |
| 535 UNREACHABLE(); | 541 UNREACHABLE(); |
| 536 } | 542 } |
| 537 | 543 |
| 538 | 544 |
| 539 // TODO(regis): Function rest arguments are not supported anymore, but they may | 545 // TODO(regis): Function rest arguments are not supported anymore, but they may |
| 540 // come back. | 546 // come back. |
| 541 // Check that the type of each element of the given array is assignable to the | 547 // Check that the type of each element of the given array is assignable to the |
| 542 // given type. | 548 // given type. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 569 // Note that a returned malformed_error is ignored if a type check succeeds. | 575 // Note that a returned malformed_error is ignored if a type check succeeds. |
| 570 malformed_error = Error::null(); | 576 malformed_error = Error::null(); |
| 571 if (!elem.IsNull() && !elem.IsInstanceOf(element_type, | 577 if (!elem.IsNull() && !elem.IsInstanceOf(element_type, |
| 572 element_type_instantiator, | 578 element_type_instantiator, |
| 573 &malformed_error)) { | 579 &malformed_error)) { |
| 574 // Allocate and throw a new instance of TypeError. | 580 // Allocate and throw a new instance of TypeError. |
| 575 char buf[256]; | 581 char buf[256]; |
| 576 OS::SNPrint(buf, sizeof(buf), "%s[%d]", | 582 OS::SNPrint(buf, sizeof(buf), "%s[%d]", |
| 577 rest_name.ToCString(), static_cast<int>(i)); | 583 rest_name.ToCString(), static_cast<int>(i)); |
| 578 const String& src_type_name = | 584 const String& src_type_name = |
| 579 String::Handle(Type::Handle(elem.GetType()).Name()); | 585 String::Handle(Type::Handle(elem.GetType()).Name()); |
|
regis
2012/03/15 00:56:39
And here, although this function is not used anymo
srdjan
2012/03/15 01:10:13
Done.
| |
| 580 String& dst_type_name = String::Handle(); | 586 String& dst_type_name = String::Handle(); |
| 581 if (!element_type.IsInstantiated()) { | 587 if (!element_type.IsInstantiated()) { |
| 582 // Instantiate element_type before reporting the error. | 588 // Instantiate element_type before reporting the error. |
| 583 const AbstractType& instantiated_element_type = AbstractType::Handle( | 589 const AbstractType& instantiated_element_type = AbstractType::Handle( |
| 584 element_type.InstantiateFrom(element_type_instantiator)); | 590 element_type.InstantiateFrom(element_type_instantiator)); |
| 585 dst_type_name = instantiated_element_type.Name(); | 591 dst_type_name = instantiated_element_type.Name(); |
| 586 } else { | 592 } else { |
| 587 dst_type_name = element_type.Name(); | 593 dst_type_name = element_type.Name(); |
| 588 } | 594 } |
| 589 const String& dst_name = String::Handle(String::New(buf)); | 595 const String& dst_name = String::Handle(String::New(buf)); |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1439 } | 1445 } |
| 1440 } | 1446 } |
| 1441 } | 1447 } |
| 1442 // The cache is null terminated, therefore the loop above should never | 1448 // The cache is null terminated, therefore the loop above should never |
| 1443 // terminate by itself. | 1449 // terminate by itself. |
| 1444 UNREACHABLE(); | 1450 UNREACHABLE(); |
| 1445 return Code::null(); | 1451 return Code::null(); |
| 1446 } | 1452 } |
| 1447 | 1453 |
| 1448 } // namespace dart | 1454 } // namespace dart |
| OLD | NEW |