Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: runtime/vm/code_generator.cc

Issue 2109743002: DBC: Implement InstanceOf. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 // Arg1: type. 443 // Arg1: type.
444 // Arg2: type arguments of the instantiator of the type. 444 // Arg2: type arguments of the instantiator of the type.
445 // Arg3: SubtypeTestCache. 445 // Arg3: SubtypeTestCache.
446 // Return value: true or false, or may throw a type error in checked mode. 446 // Return value: true or false, or may throw a type error in checked mode.
447 DEFINE_RUNTIME_ENTRY(Instanceof, 4) { 447 DEFINE_RUNTIME_ENTRY(Instanceof, 4) {
448 const Instance& instance = Instance::CheckedHandle(zone, arguments.ArgAt(0)); 448 const Instance& instance = Instance::CheckedHandle(zone, arguments.ArgAt(0));
449 const AbstractType& type = 449 const AbstractType& type =
450 AbstractType::CheckedHandle(zone, arguments.ArgAt(1)); 450 AbstractType::CheckedHandle(zone, arguments.ArgAt(1));
451 const TypeArguments& instantiator_type_arguments = 451 const TypeArguments& instantiator_type_arguments =
452 TypeArguments::CheckedHandle(zone, arguments.ArgAt(2)); 452 TypeArguments::CheckedHandle(zone, arguments.ArgAt(2));
453 #if !defined(TARGET_ARCH_DBC)
zra 2016/06/28 19:28:04 It looks like you're passing the cache, so even th
rmacnak 2016/06/28 21:21:50 The update code is unhappy if it inserts duplicate
453 const SubtypeTestCache& cache = 454 const SubtypeTestCache& cache =
454 SubtypeTestCache::CheckedHandle(zone, arguments.ArgAt(3)); 455 SubtypeTestCache::CheckedHandle(zone, arguments.ArgAt(3));
456 #endif
455 ASSERT(type.IsFinalized()); 457 ASSERT(type.IsFinalized());
456 ASSERT(!type.IsMalformed()); // Already checked in code generator. 458 ASSERT(!type.IsMalformed()); // Already checked in code generator.
457 ASSERT(!type.IsMalbounded()); // Already checked in code generator. 459 ASSERT(!type.IsMalbounded()); // Already checked in code generator.
458 ASSERT(!type.IsDynamicType()); // No need to check assignment. 460 ASSERT(!type.IsDynamicType()); // No need to check assignment.
459 Error& bound_error = Error::Handle(zone); 461 Error& bound_error = Error::Handle(zone);
460 const Bool& result = 462 const Bool& result =
461 Bool::Get(instance.IsInstanceOf(type, 463 Bool::Get(instance.IsInstanceOf(type,
462 instantiator_type_arguments, 464 instantiator_type_arguments,
463 &bound_error)); 465 &bound_error));
464 if (FLAG_trace_type_checks) { 466 if (FLAG_trace_type_checks) {
465 PrintTypeCheck("InstanceOf", 467 PrintTypeCheck("InstanceOf",
466 instance, type, instantiator_type_arguments, result); 468 instance, type, instantiator_type_arguments, result);
467 } 469 }
468 if (!result.value() && !bound_error.IsNull()) { 470 if (!result.value() && !bound_error.IsNull()) {
469 // Throw a dynamic type error only if the instanceof test fails. 471 // Throw a dynamic type error only if the instanceof test fails.
470 const TokenPosition location = GetCallerLocation(); 472 const TokenPosition location = GetCallerLocation();
471 String& bound_error_message = String::Handle( 473 String& bound_error_message = String::Handle(
472 zone, String::New(bound_error.ToErrorCString())); 474 zone, String::New(bound_error.ToErrorCString()));
473 Exceptions::CreateAndThrowTypeError( 475 Exceptions::CreateAndThrowTypeError(
474 location, AbstractType::Handle(zone), AbstractType::Handle(zone), 476 location, AbstractType::Handle(zone), AbstractType::Handle(zone),
475 Symbols::Empty(), bound_error_message); 477 Symbols::Empty(), bound_error_message);
476 UNREACHABLE(); 478 UNREACHABLE();
477 } 479 }
480 #if !defined(TARGET_ARCH_DBC)
478 UpdateTypeTestCache( 481 UpdateTypeTestCache(
479 instance, type, instantiator_type_arguments, result, cache); 482 instance, type, instantiator_type_arguments, result, cache);
483 #endif
480 arguments.SetReturn(result); 484 arguments.SetReturn(result);
481 } 485 }
482 486
483 487
484 // Check that the type of the given instance is a subtype of the given type and 488 // Check that the type of the given instance is a subtype of the given type and
485 // can therefore be assigned. 489 // can therefore be assigned.
486 // Arg0: instance being assigned. 490 // Arg0: instance being assigned.
487 // Arg1: type being assigned to. 491 // Arg1: type being assigned to.
488 // Arg2: type arguments of the instantiator of the type being assigned to. 492 // Arg2: type arguments of the instantiator of the type being assigned to.
489 // Arg3: name of variable being assigned to. 493 // Arg3: name of variable being assigned to.
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 const intptr_t elm_size = old_data.ElementSizeInBytes(); 1883 const intptr_t elm_size = old_data.ElementSizeInBytes();
1880 const TypedData& new_data = 1884 const TypedData& new_data =
1881 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); 1885 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld));
1882 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); 1886 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size);
1883 typed_data_cell.SetAt(0, new_data); 1887 typed_data_cell.SetAt(0, new_data);
1884 arguments.SetReturn(new_data); 1888 arguments.SetReturn(new_data);
1885 } 1889 }
1886 1890
1887 1891
1888 } // namespace dart 1892 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698