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

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

Issue 10704216: Fix type checking of void type. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 // Type S is specified by this class parameterized with 'type_arguments', and 1775 // Type S is specified by this class parameterized with 'type_arguments', and
1776 // type T by class 'other' parameterized with 'other_type_arguments'. 1776 // type T by class 'other' parameterized with 'other_type_arguments'.
1777 // This class and class 'other' do not need to be finalized, however, they must 1777 // This class and class 'other' do not need to be finalized, however, they must
1778 // be resolved as well as their interfaces. 1778 // be resolved as well as their interfaces.
1779 bool Class::TypeTest( 1779 bool Class::TypeTest(
1780 TypeTestKind test_kind, 1780 TypeTestKind test_kind,
1781 const AbstractTypeArguments& type_arguments, 1781 const AbstractTypeArguments& type_arguments,
1782 const Class& other, 1782 const Class& other,
1783 const AbstractTypeArguments& other_type_arguments, 1783 const AbstractTypeArguments& other_type_arguments,
1784 Error* malformed_error) const { 1784 Error* malformed_error) const {
1785 ASSERT(!IsVoidClass());
1785 // Check for DynamicType. 1786 // Check for DynamicType.
1786 // Each occurrence of DynamicType in type T is interpreted as the Dynamic 1787 // Each occurrence of DynamicType in type T is interpreted as the Dynamic
1787 // type, a supertype of all types. 1788 // type, a supertype of all types.
1788 if (other.IsDynamicClass()) { 1789 if (other.IsDynamicClass()) {
1789 return true; 1790 return true;
1790 } 1791 }
1791 // In the case of a subtype test, each occurrence of DynamicType in type S is 1792 // In the case of a subtype test, each occurrence of DynamicType in type S is
1792 // interpreted as the bottom type, a subtype of all types. 1793 // interpreted as the bottom type, a subtype of all types.
1793 if (IsDynamicClass()) { 1794 if (IsDynamicClass()) {
1794 return test_kind == kIsSubtypeOf; 1795 return test_kind == kIsSubtypeOf;
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 } 2346 }
2346 2347
2347 2348
2348 RawAbstractType* AbstractType::Canonicalize() const { 2349 RawAbstractType* AbstractType::Canonicalize() const {
2349 // AbstractType is an abstract class. 2350 // AbstractType is an abstract class.
2350 UNREACHABLE(); 2351 UNREACHABLE();
2351 return NULL; 2352 return NULL;
2352 } 2353 }
2353 2354
2354 2355
2356 // TODO(regis): Investigate if we can safely map internal integer types (Smi,
2357 // Mint, and Bigint) to 'int' and internal String types (OneByteString, etc...)
2358 // to 'String' here. It may be too early. Also consider the upcoming type()
2359 // method.
2355 RawString* AbstractType::Name() const { 2360 RawString* AbstractType::Name() const {
2356 // If the type is still being finalized, we may be reporting an error about 2361 // If the type is still being finalized, we may be reporting an error about
2357 // an illformed type, so proceed with caution. 2362 // an illformed type, so proceed with caution.
2358 const AbstractTypeArguments& args = 2363 const AbstractTypeArguments& args =
2359 AbstractTypeArguments::Handle(arguments()); 2364 AbstractTypeArguments::Handle(arguments());
2360 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); 2365 const intptr_t num_args = args.IsNull() ? 0 : args.Length();
2361 String& class_name = String::Handle(); 2366 String& class_name = String::Handle();
2362 intptr_t first_type_param_index; 2367 intptr_t first_type_param_index;
2363 intptr_t num_type_params; // Number of type parameters to print. 2368 intptr_t num_type_params; // Number of type parameters to print.
2364 if (HasResolvedTypeClass()) { 2369 if (HasResolvedTypeClass()) {
(...skipping 5287 matching lines...) Expand 10 before | Expand all | Expand 10 after
7652 ASSERT(field_offset != Class::kNoTypeArguments); 7657 ASSERT(field_offset != Class::kNoTypeArguments);
7653 *FieldAddrAtOffset(field_offset) = value.raw(); 7658 *FieldAddrAtOffset(field_offset) = value.raw();
7654 } 7659 }
7655 7660
7656 7661
7657 bool Instance::IsInstanceOf(const AbstractType& other, 7662 bool Instance::IsInstanceOf(const AbstractType& other,
7658 const AbstractTypeArguments& other_instantiator, 7663 const AbstractTypeArguments& other_instantiator,
7659 Error* malformed_error) const { 7664 Error* malformed_error) const {
7660 ASSERT(other.IsFinalized()); 7665 ASSERT(other.IsFinalized());
7661 ASSERT(!other.IsDynamicType()); 7666 ASSERT(!other.IsDynamicType());
7662 ASSERT(!other.IsVoidType());
7663 ASSERT(!other.IsMalformed()); 7667 ASSERT(!other.IsMalformed());
7664 if (IsNull()) { 7668 if (IsNull()) {
7669 // The null instance can be returned from a void function.
7670 if (other.IsVoidType()) {
7671 return true;
7672 }
7673 // Otherwise, null is only an instance of Object and of Dynamic.
7674 // It is not necessary to fully instantiate the other type for this test.
7665 Class& other_class = Class::Handle(); 7675 Class& other_class = Class::Handle();
7666 if (other.IsTypeParameter()) { 7676 if (other.IsTypeParameter()) {
7667 if (other_instantiator.IsNull()) { 7677 if (other_instantiator.IsNull()) {
7668 return true; // Other type is uninstantiated, i.e. Dynamic. 7678 return true; // Other type is uninstantiated, i.e. Dynamic.
7669 } 7679 }
7670 const TypeParameter& other_type_param = TypeParameter::Cast(other); 7680 const TypeParameter& other_type_param = TypeParameter::Cast(other);
7671 const AbstractType& instantiated_other = AbstractType::Handle( 7681 const AbstractType& instantiated_other = AbstractType::Handle(
7672 other_instantiator.TypeAt(other_type_param.index())); 7682 other_instantiator.TypeAt(other_type_param.index()));
7673 ASSERT(instantiated_other.IsInstantiated()); 7683 ASSERT(instantiated_other.IsInstantiated());
7674 other_class = instantiated_other.type_class(); 7684 other_class = instantiated_other.type_class();
7675 } else { 7685 } else {
7676 other_class = other.type_class(); 7686 other_class = other.type_class();
7677 } 7687 }
7678 return other_class.IsObjectClass() || other_class.IsDynamicClass(); 7688 return other_class.IsObjectClass() || other_class.IsDynamicClass();
7679 } 7689 }
7690 if (other.IsVoidType()) {
7691 return false;
7692 }
7680 const Class& cls = Class::Handle(clazz()); 7693 const Class& cls = Class::Handle(clazz());
7681 // We must not encounter Object::sentinel() or Object::transition_sentinel(), 7694 // We must not encounter Object::sentinel() or Object::transition_sentinel(),
7682 // both instances of class NullClass, but not instance Object::null(). 7695 // both instances of class NullClass, but not instance Object::null().
7683 ASSERT(!cls.IsNullClass()); 7696 ASSERT(!cls.IsNullClass());
7684 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 7697 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
7685 const intptr_t num_type_arguments = cls.NumTypeArguments(); 7698 const intptr_t num_type_arguments = cls.NumTypeArguments();
7686 if (num_type_arguments > 0) { 7699 if (num_type_arguments > 0) {
7687 type_arguments = GetTypeArguments(); 7700 type_arguments = GetTypeArguments();
7688 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) { 7701 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) {
7689 type_arguments = type_arguments.Canonicalize(); 7702 type_arguments = type_arguments.Canonicalize();
(...skipping 3097 matching lines...) Expand 10 before | Expand all | Expand 10 after
10787 const String& str = String::Handle(pattern()); 10800 const String& str = String::Handle(pattern());
10788 const char* format = "JSRegExp: pattern=%s flags=%s"; 10801 const char* format = "JSRegExp: pattern=%s flags=%s";
10789 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10802 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10790 char* chars = reinterpret_cast<char*>( 10803 char* chars = reinterpret_cast<char*>(
10791 Isolate::Current()->current_zone()->Allocate(len + 1)); 10804 Isolate::Current()->current_zone()->Allocate(len + 1));
10792 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10805 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10793 return chars; 10806 return chars;
10794 } 10807 }
10795 10808
10796 } // namespace dart 10809 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698