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

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

Issue 11125005: Support for type dynamic in VM (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 // allocated, because the classes reside in the VM isolate. 875 // allocated, because the classes reside in the VM isolate.
876 // The corresponding types are stored in the object store. 876 // The corresponding types are stored in the object store.
877 cls = null_class(); 877 cls = null_class();
878 type = Type::NewNonParameterizedType(cls); 878 type = Type::NewNonParameterizedType(cls);
879 object_store->set_null_type(type); 879 object_store->set_null_type(type);
880 880
881 cls = void_class(); 881 cls = void_class();
882 type = Type::NewNonParameterizedType(cls); 882 type = Type::NewNonParameterizedType(cls);
883 object_store->set_void_type(type); 883 object_store->set_void_type(type);
884 884
885 // The class 'Dynamic' is registered in the class dictionary because its name 885 // The class 'dynamic' is registered in the class dictionary because its name
886 // is a built-in identifier, rather than a reserved keyword. Its name is not 886 // is a built-in identifier, rather than a reserved keyword. Its name is not
887 // heap allocated, because the class resides in the VM isolate. 887 // heap allocated, because the class resides in the VM isolate.
888 // The corresponding type, the "unknown type", is stored in the object store. 888 // The corresponding type, the "unknown type", is stored in the object store.
889 cls = dynamic_class(); 889 cls = dynamic_class();
890 type = Type::NewNonParameterizedType(cls); 890 type = Type::NewNonParameterizedType(cls);
891 object_store->set_dynamic_type(type); 891 object_store->set_dynamic_type(type);
892 892
893 // Allocate pre-initialized values. 893 // Allocate pre-initialized values.
894 Bool& bool_value = Bool::Handle(); 894 Bool& bool_value = Bool::Handle();
895 bool_value = Bool::New(true); 895 bool_value = Bool::New(true);
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 // This class and class 'other' do not need to be finalized, however, they must 2003 // This class and class 'other' do not need to be finalized, however, they must
2004 // be resolved as well as their interfaces. 2004 // be resolved as well as their interfaces.
2005 bool Class::TypeTest( 2005 bool Class::TypeTest(
2006 TypeTestKind test_kind, 2006 TypeTestKind test_kind,
2007 const AbstractTypeArguments& type_arguments, 2007 const AbstractTypeArguments& type_arguments,
2008 const Class& other, 2008 const Class& other,
2009 const AbstractTypeArguments& other_type_arguments, 2009 const AbstractTypeArguments& other_type_arguments,
2010 Error* malformed_error) const { 2010 Error* malformed_error) const {
2011 ASSERT(!IsVoidClass()); 2011 ASSERT(!IsVoidClass());
2012 // Check for DynamicType. 2012 // Check for DynamicType.
2013 // Each occurrence of DynamicType in type T is interpreted as the Dynamic 2013 // Each occurrence of DynamicType in type T is interpreted as the dynamic
2014 // type, a supertype of all types. 2014 // type, a supertype of all types.
2015 if (other.IsDynamicClass()) { 2015 if (other.IsDynamicClass()) {
2016 return true; 2016 return true;
2017 } 2017 }
2018 // In the case of a subtype test, each occurrence of DynamicType in type S is 2018 // In the case of a subtype test, each occurrence of DynamicType in type S is
2019 // interpreted as the bottom type, a subtype of all types. 2019 // interpreted as the bottom type, a subtype of all types.
2020 // However, DynamicType is not more specific than any type. 2020 // However, DynamicType is not more specific than any type.
2021 if (IsDynamicClass()) { 2021 if (IsDynamicClass()) {
2022 return test_kind == kIsSubtypeOf; 2022 return test_kind == kIsSubtypeOf;
2023 } 2023 }
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2581 bool AbstractTypeArguments::IsDynamicTypes(bool raw_instantiated, 2581 bool AbstractTypeArguments::IsDynamicTypes(bool raw_instantiated,
2582 intptr_t len) const { 2582 intptr_t len) const {
2583 ASSERT(Length() >= len); 2583 ASSERT(Length() >= len);
2584 AbstractType& type = AbstractType::Handle(); 2584 AbstractType& type = AbstractType::Handle();
2585 Class& type_class = Class::Handle(); 2585 Class& type_class = Class::Handle();
2586 for (intptr_t i = 0; i < len; i++) { 2586 for (intptr_t i = 0; i < len; i++) {
2587 type = TypeAt(i); 2587 type = TypeAt(i);
2588 ASSERT(!type.IsNull()); 2588 ASSERT(!type.IsNull());
2589 if (!type.HasResolvedTypeClass()) { 2589 if (!type.HasResolvedTypeClass()) {
2590 if (raw_instantiated && type.IsTypeParameter()) { 2590 if (raw_instantiated && type.IsTypeParameter()) {
2591 // An uninstantiated type parameter is equivalent to Dynamic. 2591 // An uninstantiated type parameter is equivalent to dynamic.
2592 continue; 2592 continue;
2593 } 2593 }
2594 ASSERT((!raw_instantiated && type.IsTypeParameter()) || 2594 ASSERT((!raw_instantiated && type.IsTypeParameter()) ||
2595 type.IsMalformed()); 2595 type.IsMalformed());
2596 return false; 2596 return false;
2597 } 2597 }
2598 type_class = type.type_class(); 2598 type_class = type.type_class();
2599 if (!type_class.IsDynamicClass()) { 2599 if (!type_class.IsDynamicClass()) {
2600 return false; 2600 return false;
2601 } 2601 }
(...skipping 5436 matching lines...) Expand 10 before | Expand all | Expand 10 after
8038 // are not the Object::null() instance. 8038 // are not the Object::null() instance.
8039 ASSERT((raw() == Object::transition_sentinel()) || 8039 ASSERT((raw() == Object::transition_sentinel()) ||
8040 (raw() == Object::sentinel())); 8040 (raw() == Object::sentinel()));
8041 ASSERT(!FLAG_eliminate_type_checks); 8041 ASSERT(!FLAG_eliminate_type_checks);
8042 return true; // We are doing an instance of test as part of a type check. 8042 return true; // We are doing an instance of test as part of a type check.
8043 } 8043 }
8044 // The null instance can be returned from a void function. 8044 // The null instance can be returned from a void function.
8045 if (other.IsVoidType()) { 8045 if (other.IsVoidType()) {
8046 return true; 8046 return true;
8047 } 8047 }
8048 // Otherwise, null is only an instance of Object and of Dynamic. 8048 // Otherwise, null is only an instance of Object and of dynamic.
8049 // It is not necessary to fully instantiate the other type for this test. 8049 // It is not necessary to fully instantiate the other type for this test.
8050 Class& other_class = Class::Handle(); 8050 Class& other_class = Class::Handle();
8051 if (other.IsTypeParameter()) { 8051 if (other.IsTypeParameter()) {
8052 if (other_instantiator.IsNull()) { 8052 if (other_instantiator.IsNull()) {
8053 return true; // Other type is uninstantiated, i.e. Dynamic. 8053 return true; // Other type is uninstantiated, i.e. dynamic.
8054 } 8054 }
8055 const TypeParameter& other_type_param = TypeParameter::Cast(other); 8055 const TypeParameter& other_type_param = TypeParameter::Cast(other);
8056 const AbstractType& instantiated_other = AbstractType::Handle( 8056 const AbstractType& instantiated_other = AbstractType::Handle(
8057 other_instantiator.TypeAt(other_type_param.index())); 8057 other_instantiator.TypeAt(other_type_param.index()));
8058 ASSERT(instantiated_other.IsInstantiated()); 8058 ASSERT(instantiated_other.IsInstantiated());
8059 other_class = instantiated_other.type_class(); 8059 other_class = instantiated_other.type_class();
8060 } else { 8060 } else {
8061 other_class = other.type_class(); 8061 other_class = other.type_class();
8062 } 8062 }
8063 return other_class.IsObjectClass() || other_class.IsDynamicClass(); 8063 return other_class.IsObjectClass() || other_class.IsDynamicClass();
(...skipping 20 matching lines...) Expand all
8084 (cls.IsSignatureClass() && 8084 (cls.IsSignatureClass() &&
8085 (type_arguments.Length() > num_type_arguments))); 8085 (type_arguments.Length() > num_type_arguments)));
8086 } 8086 }
8087 Class& other_class = Class::Handle(); 8087 Class& other_class = Class::Handle();
8088 AbstractTypeArguments& other_type_arguments = AbstractTypeArguments::Handle(); 8088 AbstractTypeArguments& other_type_arguments = AbstractTypeArguments::Handle();
8089 // In case 'other' is not instantiated, we could simply call 8089 // In case 'other' is not instantiated, we could simply call
8090 // other.InstantiateFrom(other_instantiator), however, we can save the 8090 // other.InstantiateFrom(other_instantiator), however, we can save the
8091 // allocation of a new AbstractType by inlining the code. 8091 // allocation of a new AbstractType by inlining the code.
8092 if (other.IsTypeParameter()) { 8092 if (other.IsTypeParameter()) {
8093 if (other_instantiator.IsNull()) { 8093 if (other_instantiator.IsNull()) {
8094 // An uninstantiated type parameter is equivalent to Dynamic. 8094 // An uninstantiated type parameter is equivalent to dynamic.
8095 return true; 8095 return true;
8096 } 8096 }
8097 const TypeParameter& other_type_param = TypeParameter::Cast(other); 8097 const TypeParameter& other_type_param = TypeParameter::Cast(other);
8098 AbstractType& instantiated_other = AbstractType::Handle( 8098 AbstractType& instantiated_other = AbstractType::Handle(
8099 other_instantiator.TypeAt(other_type_param.index())); 8099 other_instantiator.TypeAt(other_type_param.index()));
8100 if (instantiated_other.IsDynamicType() || 8100 if (instantiated_other.IsDynamicType() ||
8101 instantiated_other.IsTypeParameter()) { 8101 instantiated_other.IsTypeParameter()) {
8102 return true; 8102 return true;
8103 } 8103 }
8104 other_class = instantiated_other.type_class(); 8104 other_class = instantiated_other.type_class();
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
8314 if (name_visibility == kInternalName) { 8314 if (name_visibility == kInternalName) {
8315 class_name = cls.Name(); 8315 class_name = cls.Name();
8316 } else { 8316 } else {
8317 ASSERT(name_visibility == kUserVisibleName); 8317 ASSERT(name_visibility == kUserVisibleName);
8318 // Map internal types to their corresponding public interfaces. 8318 // Map internal types to their corresponding public interfaces.
8319 class_name = cls.UserVisibleName(); 8319 class_name = cls.UserVisibleName();
8320 } 8320 }
8321 if (num_type_params > num_args) { 8321 if (num_type_params > num_args) {
8322 first_type_param_index = 0; 8322 first_type_param_index = 0;
8323 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { 8323 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
8324 // Most probably a malformed type. Do not fill up with "Dynamic", 8324 // Most probably a malformed type. Do not fill up with "dynamic",
8325 // but use actual vector. 8325 // but use actual vector.
8326 num_type_params = num_args; 8326 num_type_params = num_args;
8327 } else { 8327 } else {
8328 ASSERT(num_args == 0); // Type is raw. 8328 ASSERT(num_args == 0); // Type is raw.
8329 // No need to fill up with "Dynamic". 8329 // No need to fill up with "dynamic".
8330 num_type_params = 0; 8330 num_type_params = 0;
8331 } 8331 }
8332 } else { 8332 } else {
8333 first_type_param_index = num_args - num_type_params; 8333 first_type_param_index = num_args - num_type_params;
8334 } 8334 }
8335 if (cls.IsSignatureClass()) { 8335 if (cls.IsSignatureClass()) {
8336 // We may be reporting an error about a malformed function type. In that 8336 // We may be reporting an error about a malformed function type. In that
8337 // case, avoid instantiating the signature, since it may lead to cycles. 8337 // case, avoid instantiating the signature, since it may lead to cycles.
8338 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { 8338 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
8339 return class_name.raw(); 8339 return class_name.raw();
(...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after
12201 } 12201 }
12202 return result.raw(); 12202 return result.raw();
12203 } 12203 }
12204 12204
12205 12205
12206 const char* WeakProperty::ToCString() const { 12206 const char* WeakProperty::ToCString() const {
12207 return "_WeakProperty"; 12207 return "_WeakProperty";
12208 } 12208 }
12209 12209
12210 } // namespace dart 12210 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698