| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/code_descriptors.h" | 8 #include "vm/code_descriptors.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 owner()->try_index(), | 422 owner()->try_index(), |
| 423 interpol_func, | 423 interpol_func, |
| 424 interpol_arg->names(), | 424 interpol_arg->names(), |
| 425 values); | 425 values); |
| 426 ReturnComputation(call); | 426 ReturnComputation(call); |
| 427 } | 427 } |
| 428 | 428 |
| 429 | 429 |
| 430 void EffectGraphVisitor::BuildInstanceOf(ComparisonNode* node) { | 430 void EffectGraphVisitor::BuildInstanceOf(ComparisonNode* node) { |
| 431 ASSERT(Token::IsInstanceofOperator(node->kind())); | 431 ASSERT(Token::IsInstanceofOperator(node->kind())); |
| 432 EffectGraphVisitor for_left_value(owner(), temp_index()); |
| 433 node->left()->Visit(&for_left_value); |
| 434 Append(for_left_value); |
| 435 } |
| 436 |
| 437 |
| 438 void ValueGraphVisitor::BuildInstanceOf(ComparisonNode* node) { |
| 439 ASSERT(Token::IsInstanceofOperator(node->kind())); |
| 440 const Bool& bool_true = Bool::ZoneHandle(Bool::True()); |
| 441 const Bool& bool_false = Bool::ZoneHandle(Bool::False()); |
| 442 const AbstractType& type = node->right()->AsTypeNode()->type(); |
| 443 ASSERT(type.IsFinalized() && !type.IsMalformed()); |
| 444 const bool negate_result = (node->kind() == Token::kISNOT); |
| 445 // All objects are instances of type T if Object type is a subtype of type T. |
| 446 const Type& object_type = |
| 447 Type::Handle(Isolate::Current()->object_store()->object_type()); |
| 448 Error& malformed_error = Error::Handle(); |
| 449 if (type.IsInstantiated() && |
| 450 object_type.IsSubtypeOf(type, &malformed_error)) { |
| 451 // Must evaluate left side. |
| 452 EffectGraphVisitor for_left_value(owner(), temp_index()); |
| 453 node->left()->Visit(&for_left_value); |
| 454 Append(for_left_value); |
| 455 ReturnValue(new ConstantVal(negate_result ? bool_false : bool_true)); |
| 456 return; |
| 457 } |
| 458 |
| 459 // Eliminate the test if it can be performed successfully at compile time. |
| 460 if ((node->left() != NULL) && |
| 461 node->left()->IsLiteralNode() && |
| 462 type.IsInstantiated()) { |
| 463 const Instance& literal_value = node->left()->AsLiteralNode()->literal(); |
| 464 const Class& cls = Class::Handle(literal_value.clazz()); |
| 465 ConstantVal* result = NULL; |
| 466 if (cls.IsNullClass()) { |
| 467 // A null object is only an instance of Object and Dynamic, which has |
| 468 // already been checked above (if the type is instantiated). So we can |
| 469 // return false here if the instance is null (and if the type is |
| 470 // instantiated). |
| 471 result = new ConstantVal(negate_result ? bool_true : bool_false); |
| 472 } else { |
| 473 Error& malformed_error = Error::Handle(); |
| 474 if (literal_value.IsInstanceOf(type, |
| 475 TypeArguments::Handle(), |
| 476 &malformed_error)) { |
| 477 result = new ConstantVal(negate_result ? bool_false : bool_true); |
| 478 } else { |
| 479 ASSERT(malformed_error.IsNull()); |
| 480 result = new ConstantVal(negate_result ? bool_true : bool_false); |
| 481 } |
| 482 } |
| 483 ReturnValue(result); |
| 484 return; |
| 485 } |
| 486 |
| 432 ArgumentGraphVisitor for_left_value(owner(), temp_index()); | 487 ArgumentGraphVisitor for_left_value(owner(), temp_index()); |
| 433 node->left()->Visit(&for_left_value); | 488 node->left()->Visit(&for_left_value); |
| 434 Append(for_left_value); | 489 Append(for_left_value); |
| 435 const AbstractType& type = node->right()->AsTypeNode()->type(); | |
| 436 ASSERT(type.IsFinalized() && !type.IsMalformed()); | |
| 437 Value* type_arguments = NULL; | 490 Value* type_arguments = NULL; |
| 438 if (!type.IsInstantiated()) { | 491 if (!type.IsInstantiated()) { |
| 439 type_arguments = BuildInstantiatorTypeArguments( | 492 type_arguments = BuildInstantiatorTypeArguments( |
| 440 node->token_index(), for_left_value.temp_index()); | 493 node->token_index(), for_left_value.temp_index()); |
| 441 } | 494 } |
| 442 InstanceOfComp* instance_of = new InstanceOfComp( | 495 InstanceOfComp* instance_of = new InstanceOfComp( |
| 443 node->id(), | 496 node->id(), |
| 444 node->token_index(), | 497 node->token_index(), |
| 445 owner()->try_index(), | 498 owner()->try_index(), |
| 446 for_left_value.value(), | 499 for_left_value.value(), |
| (...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2549 char* chars = reinterpret_cast<char*>( | 2602 char* chars = reinterpret_cast<char*>( |
| 2550 Isolate::Current()->current_zone()->Allocate(len)); | 2603 Isolate::Current()->current_zone()->Allocate(len)); |
| 2551 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2604 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2552 const Error& error = Error::Handle( | 2605 const Error& error = Error::Handle( |
| 2553 LanguageError::New(String::Handle(String::New(chars)))); | 2606 LanguageError::New(String::Handle(String::New(chars)))); |
| 2554 Isolate::Current()->long_jump_base()->Jump(1, error); | 2607 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2555 } | 2608 } |
| 2556 | 2609 |
| 2557 | 2610 |
| 2558 } // namespace dart | 2611 } // namespace dart |
| OLD | NEW |