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

Side by Side Diff: runtime/vm/class_finalizer.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/class_finalizer.h ('k') | runtime/vm/dart_api_impl.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/class_finalizer.h" 5 #include "vm/class_finalizer.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/heap.h" 8 #include "vm/heap.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 if (!cls.is_finalized()) { 625 if (!cls.is_finalized()) {
626 FinalizeTypeParameters(cls); 626 FinalizeTypeParameters(cls);
627 } 627 }
628 Type& super_type = Type::Handle(cls.super_type()); 628 Type& super_type = Type::Handle(cls.super_type());
629 if (!super_type.IsNull()) { 629 if (!super_type.IsNull()) {
630 const Class& super_class = Class::Handle(super_type.type_class()); 630 const Class& super_class = Class::Handle(super_type.type_class());
631 AbstractTypeArguments& super_type_args = AbstractTypeArguments::Handle(); 631 AbstractTypeArguments& super_type_args = AbstractTypeArguments::Handle();
632 if (super_type.IsBeingFinalized()) { 632 if (super_type.IsBeingFinalized()) {
633 // This type references itself via its type arguments. This is legal, but 633 // This type references itself via its type arguments. This is legal, but
634 // we must avoid endless recursion. We therefore map the innermost 634 // we must avoid endless recursion. We therefore map the innermost
635 // super type to Dynamic. 635 // super type to dynamic.
636 // Note that a direct self-reference via the super class chain is illegal 636 // Note that a direct self-reference via the super class chain is illegal
637 // and reported as an error earlier. 637 // and reported as an error earlier.
638 // Such legal self-references occur with F-bounded quantification. 638 // Such legal self-references occur with F-bounded quantification.
639 // Example 1: class Derived extends Base<Derived>. 639 // Example 1: class Derived extends Base<Derived>.
640 // The type 'Derived' forms a cycle by pointing to itself via its 640 // The type 'Derived' forms a cycle by pointing to itself via its
641 // flattened type argument vector: Derived[Base[Derived[Base[...]]]] 641 // flattened type argument vector: Derived[Base[Derived[Base[...]]]]
642 // We break the cycle as follows: Derived[Base[Derived[Dynamic]]] 642 // We break the cycle as follows: Derived[Base[Derived[dynamic]]]
643 // Example 2: class Derived extends Base<Middle<Derived>> results in 643 // Example 2: class Derived extends Base<Middle<Derived>> results in
644 // Derived[Base[Middle[Derived[Dynamic]]]] 644 // Derived[Base[Middle[Derived[dynamic]]]]
645 // Example 3: class Derived<T> extends Base<Derived<T>> results in 645 // Example 3: class Derived<T> extends Base<Derived<T>> results in
646 // Derived[Base[Derived[Dynamic]], T]. 646 // Derived[Base[Derived[dynamic]], T].
647 ASSERT(super_type_args.IsNull()); // Same as a vector of Dynamic. 647 ASSERT(super_type_args.IsNull()); // Same as a vector of dynamic.
648 } else { 648 } else {
649 super_type ^= FinalizeType(cls, super_type, finalization); 649 super_type ^= FinalizeType(cls, super_type, finalization);
650 cls.set_super_type(super_type); 650 cls.set_super_type(super_type);
651 super_type_args = super_type.arguments(); 651 super_type_args = super_type.arguments();
652 } 652 }
653 const intptr_t num_super_type_params = super_class.NumTypeParameters(); 653 const intptr_t num_super_type_params = super_class.NumTypeParameters();
654 const intptr_t offset = super_class.NumTypeArguments(); 654 const intptr_t offset = super_class.NumTypeArguments();
655 const intptr_t super_offset = offset - num_super_type_params; 655 const intptr_t super_offset = offset - num_super_type_params;
656 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); 656 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters()));
657 AbstractType& super_type_arg = AbstractType::Handle(Type::DynamicType()); 657 AbstractType& super_type_arg = AbstractType::Handle(Type::DynamicType());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 // Malformed type arguments to a constructor of a generic type are 747 // Malformed type arguments to a constructor of a generic type are
748 // reported as a compile-time error. 748 // reported as a compile-time error.
749 if (finalization >= kCanonicalizeForCreation) { 749 if (finalization >= kCanonicalizeForCreation) {
750 const Script& script = Script::Handle(cls.script()); 750 const Script& script = Script::Handle(cls.script());
751 const String& type_name = 751 const String& type_name =
752 String::Handle(parameterized_type.UserVisibleName()); 752 String::Handle(parameterized_type.UserVisibleName());
753 ReportError(script, parameterized_type.token_pos(), 753 ReportError(script, parameterized_type.token_pos(),
754 "type '%s' has malformed type argument", 754 "type '%s' has malformed type argument",
755 type_name.ToCString()); 755 type_name.ToCString());
756 } 756 }
757 // In production mode, malformed type arguments are mapped to Dynamic. 757 // In production mode, malformed type arguments are mapped to dynamic.
758 // In checked mode, a type with malformed type arguments is malformed. 758 // In checked mode, a type with malformed type arguments is malformed.
759 if (FLAG_enable_type_checks || FLAG_error_on_malformed_type) { 759 if (FLAG_enable_type_checks || FLAG_error_on_malformed_type) {
760 const Error& error = Error::Handle(type_argument.malformed_error()); 760 const Error& error = Error::Handle(type_argument.malformed_error());
761 const String& type_name = 761 const String& type_name =
762 String::Handle(parameterized_type.UserVisibleName()); 762 String::Handle(parameterized_type.UserVisibleName());
763 FinalizeMalformedType(error, cls, parameterized_type, finalization, 763 FinalizeMalformedType(error, cls, parameterized_type, finalization,
764 "type '%s' has malformed type argument", 764 "type '%s' has malformed type argument",
765 type_name.ToCString()); 765 type_name.ToCString());
766 return parameterized_type.raw(); 766 return parameterized_type.raw();
767 } else { 767 } else {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, 918 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls,
919 const Function& function) { 919 const Function& function) {
920 // Resolve result type. 920 // Resolve result type.
921 AbstractType& type = AbstractType::Handle(function.result_type()); 921 AbstractType& type = AbstractType::Handle(function.result_type());
922 // In case of a factory, the parser sets the factory result type to a type 922 // In case of a factory, the parser sets the factory result type to a type
923 // with an unresolved class whose name matches the factory name. 923 // with an unresolved class whose name matches the factory name.
924 // It is not a compile time error if this name does not resolve to a class or 924 // It is not a compile time error if this name does not resolve to a class or
925 // interface. 925 // interface.
926 ResolveType(cls, type, kCanonicalize); 926 ResolveType(cls, type, kCanonicalize);
927 type = FinalizeType(cls, type, kCanonicalize); 927 type = FinalizeType(cls, type, kCanonicalize);
928 // In production mode, a malformed result type is mapped to Dynamic. 928 // In production mode, a malformed result type is mapped to dynamic.
929 if (!FLAG_enable_type_checks && type.IsMalformed()) { 929 if (!FLAG_enable_type_checks && type.IsMalformed()) {
930 type = Type::DynamicType(); 930 type = Type::DynamicType();
931 } 931 }
932 function.set_result_type(type); 932 function.set_result_type(type);
933 // Resolve formal parameter types. 933 // Resolve formal parameter types.
934 const intptr_t num_parameters = function.NumParameters(); 934 const intptr_t num_parameters = function.NumParameters();
935 for (intptr_t i = 0; i < num_parameters; i++) { 935 for (intptr_t i = 0; i < num_parameters; i++) {
936 type = function.ParameterTypeAt(i); 936 type = function.ParameterTypeAt(i);
937 ResolveType(cls, type, kCanonicalize); 937 ResolveType(cls, type, kCanonicalize);
938 type = FinalizeType(cls, type, kCanonicalize); 938 type = FinalizeType(cls, type, kCanonicalize);
939 // In production mode, a malformed parameter type is mapped to Dynamic. 939 // In production mode, a malformed parameter type is mapped to dynamic.
940 if (!FLAG_enable_type_checks && type.IsMalformed()) { 940 if (!FLAG_enable_type_checks && type.IsMalformed()) {
941 type = Type::DynamicType(); 941 type = Type::DynamicType();
942 } 942 }
943 function.SetParameterTypeAt(i, type); 943 function.SetParameterTypeAt(i, type);
944 } 944 }
945 } 945 }
946 946
947 947
948 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, 948 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls,
949 const String& name) { 949 const String& name) {
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 String::Handle(interface.Name()).ToCString()); 1377 String::Handle(interface.Name()).ToCString());
1378 } 1378 }
1379 interface_class = interface.type_class(); 1379 interface_class = interface.type_class();
1380 if (interface_class.IsSignatureClass()) { 1380 if (interface_class.IsSignatureClass()) {
1381 const Script& script = Script::Handle(cls.script()); 1381 const Script& script = Script::Handle(cls.script());
1382 ReportError(script, cls.token_pos(), 1382 ReportError(script, cls.token_pos(),
1383 "'%s' is used where an interface or class name is expected", 1383 "'%s' is used where an interface or class name is expected",
1384 String::Handle(interface_class.Name()).ToCString()); 1384 String::Handle(interface_class.Name()).ToCString());
1385 } 1385 }
1386 // Verify that unless cls belongs to core lib, it cannot extend or implement 1386 // Verify that unless cls belongs to core lib, it cannot extend or implement
1387 // any of bool, num, int, double, String, Function, Dynamic. 1387 // any of bool, num, int, double, String, Function, dynamic.
1388 // The exception is signature classes, which are compiler generated and 1388 // The exception is signature classes, which are compiler generated and
1389 // represent a function type, therefore implementing the Function interface. 1389 // represent a function type, therefore implementing the Function interface.
1390 if (!cls_belongs_to_core_lib) { 1390 if (!cls_belongs_to_core_lib) {
1391 if (interface.IsBoolType() || 1391 if (interface.IsBoolType() ||
1392 interface.IsNumberType() || 1392 interface.IsNumberType() ||
1393 interface.IsIntType() || 1393 interface.IsIntType() ||
1394 interface.IsDoubleType() || 1394 interface.IsDoubleType() ||
1395 interface.IsStringInterface() || 1395 interface.IsStringInterface() ||
1396 (interface.IsFunctionType() && !cls.IsSignatureClass()) || 1396 (interface.IsFunctionType() && !cls.IsSignatureClass()) ||
1397 interface.IsDynamicType()) { 1397 interface.IsDynamicType()) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 void ClassFinalizer::ReportError(const char* format, ...) { 1585 void ClassFinalizer::ReportError(const char* format, ...) {
1586 va_list args; 1586 va_list args;
1587 va_start(args, format); 1587 va_start(args, format);
1588 const Error& error = Error::Handle( 1588 const Error& error = Error::Handle(
1589 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); 1589 Parser::FormatError(Script::Handle(), -1, "Error", format, args));
1590 va_end(args); 1590 va_end(args);
1591 ReportError(error); 1591 ReportError(error);
1592 } 1592 }
1593 1593
1594 } // namespace dart 1594 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698