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

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

Issue 10696155: Allocate types in proper heap space. (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
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | runtime/vm/flow_graph_builder.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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // Resolve unresolved supertype (String -> Class). 312 // Resolve unresolved supertype (String -> Class).
313 void ClassFinalizer::ResolveSuperType(const Class& cls) { 313 void ClassFinalizer::ResolveSuperType(const Class& cls) {
314 if (cls.is_finalized()) { 314 if (cls.is_finalized()) {
315 return; 315 return;
316 } 316 }
317 Type& super_type = Type::Handle(cls.super_type()); 317 Type& super_type = Type::Handle(cls.super_type());
318 if (super_type.IsNull()) { 318 if (super_type.IsNull()) {
319 return; 319 return;
320 } 320 }
321 // Resolve failures lead to a longjmp. 321 // Resolve failures lead to a longjmp.
322 ResolveType(cls, super_type, kFinalizeWellFormed); 322 ResolveType(cls, super_type, kCanonicalizeWellFormed);
323 const Class& super_class = Class::Handle(super_type.type_class()); 323 const Class& super_class = Class::Handle(super_type.type_class());
324 if (cls.is_interface() != super_class.is_interface()) { 324 if (cls.is_interface() != super_class.is_interface()) {
325 String& class_name = String::Handle(cls.Name()); 325 String& class_name = String::Handle(cls.Name());
326 String& super_class_name = String::Handle(super_class.Name()); 326 String& super_class_name = String::Handle(super_class.Name());
327 const Script& script = Script::Handle(cls.script()); 327 const Script& script = Script::Handle(cls.script());
328 ReportError(script, cls.token_pos(), 328 ReportError(script, cls.token_pos(),
329 "class '%s' and superclass '%s' are not " 329 "class '%s' and superclass '%s' are not "
330 "both classes or both interfaces", 330 "both classes or both interfaces",
331 class_name.ToCString(), 331 class_name.ToCString(),
332 super_class_name.ToCString()); 332 super_class_name.ToCString());
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 525
526 526
527 void ClassFinalizer::FinalizeTypeParameters(const Class& cls) { 527 void ClassFinalizer::FinalizeTypeParameters(const Class& cls) {
528 const TypeArguments& type_parameters = 528 const TypeArguments& type_parameters =
529 TypeArguments::Handle(cls.type_parameters()); 529 TypeArguments::Handle(cls.type_parameters());
530 if (!type_parameters.IsNull()) { 530 if (!type_parameters.IsNull()) {
531 TypeParameter& type_parameter = TypeParameter::Handle(); 531 TypeParameter& type_parameter = TypeParameter::Handle();
532 const intptr_t num_types = type_parameters.Length(); 532 const intptr_t num_types = type_parameters.Length();
533 for (intptr_t i = 0; i < num_types; i++) { 533 for (intptr_t i = 0; i < num_types; i++) {
534 type_parameter ^= type_parameters.TypeAt(i); 534 type_parameter ^= type_parameters.TypeAt(i);
535 type_parameter ^= FinalizeType(cls, type_parameter, kFinalizeWellFormed); 535 type_parameter ^= FinalizeType(cls,
536 type_parameter,
537 kCanonicalizeWellFormed);
536 type_parameters.SetTypeAt(i, type_parameter); 538 type_parameters.SetTypeAt(i, type_parameter);
537 } 539 }
538 } 540 }
539 } 541 }
540 542
541 543
542 // Finalize the type argument vector 'arguments' of the type defined by the 544 // Finalize the type argument vector 'arguments' of the type defined by the
543 // class 'cls' parameterized with the type arguments 'cls_args'. 545 // class 'cls' parameterized with the type arguments 'cls_args'.
544 // The vector 'cls_args' is already initialized as a subvector at the correct 546 // The vector 'cls_args' is already initialized as a subvector at the correct
545 // position in the passed in 'arguments' vector. 547 // position in the passed in 'arguments' vector.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 const intptr_t offset = super_class.NumTypeArguments(); 594 const intptr_t offset = super_class.NumTypeArguments();
593 const intptr_t super_offset = offset - num_super_type_params; 595 const intptr_t super_offset = offset - num_super_type_params;
594 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters())); 596 ASSERT(offset == (cls.NumTypeArguments() - cls.NumTypeParameters()));
595 AbstractType& super_type_arg = AbstractType::Handle(Type::DynamicType()); 597 AbstractType& super_type_arg = AbstractType::Handle(Type::DynamicType());
596 for (intptr_t i = 0; i < num_super_type_params; i++) { 598 for (intptr_t i = 0; i < num_super_type_params; i++) {
597 if (!super_type_args.IsNull()) { 599 if (!super_type_args.IsNull()) {
598 super_type_arg = super_type_args.TypeAt(super_offset + i); 600 super_type_arg = super_type_args.TypeAt(super_offset + i);
599 if (!super_type_arg.IsInstantiated()) { 601 if (!super_type_arg.IsInstantiated()) {
600 super_type_arg = super_type_arg.InstantiateFrom(arguments); 602 super_type_arg = super_type_arg.InstantiateFrom(arguments);
601 } 603 }
602 super_type_arg = super_type_arg.Canonicalize(); 604 if (finalization >= kCanonicalize) {
605 super_type_arg = super_type_arg.Canonicalize();
606 }
603 } 607 }
604 arguments.SetTypeAt(super_offset + i, super_type_arg); 608 arguments.SetTypeAt(super_offset + i, super_type_arg);
605 } 609 }
606 FinalizeTypeArguments(super_class, arguments, finalization); 610 FinalizeTypeArguments(super_class, arguments, finalization);
607 } 611 }
608 } 612 }
609 613
610 614
611 RawAbstractType* ClassFinalizer::FinalizeType(const Class& cls, 615 RawAbstractType* ClassFinalizer::FinalizeType(const Class& cls,
612 const AbstractType& type, 616 const AbstractType& type,
613 FinalizationKind finalization) { 617 FinalizationKind finalization) {
614 if (type.IsFinalized()) { 618 if (type.IsFinalized()) {
615 return type.raw(); 619 return type.raw();
616 } 620 }
617 ASSERT(type.IsResolved()); 621 ASSERT(type.IsResolved());
618 ASSERT((finalization == kFinalize) || (finalization == kFinalizeWellFormed)); 622 ASSERT(finalization >= kFinalize);
619 623
620 if (FLAG_trace_type_finalization) { 624 if (FLAG_trace_type_finalization) {
621 OS::Print("Finalize type '%s'\n", String::Handle(type.Name()).ToCString()); 625 OS::Print("Finalize type '%s'\n", String::Handle(type.Name()).ToCString());
622 } 626 }
623 627
624 if (type.IsTypeParameter()) { 628 if (type.IsTypeParameter()) {
625 const TypeParameter& type_parameter = TypeParameter::Cast(type); 629 const TypeParameter& type_parameter = TypeParameter::Cast(type);
626 const Class& parameterized_class = 630 const Class& parameterized_class =
627 Class::Handle(type_parameter.parameterized_class()); 631 Class::Handle(type_parameter.parameterized_class());
628 ASSERT(!parameterized_class.IsNull()); 632 ASSERT(!parameterized_class.IsNull());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 ASSERT(!signature_fun.is_static()); 745 ASSERT(!signature_fun.is_static());
742 const Class& sig_fun_owner = Class::Handle(signature_fun.owner()); 746 const Class& sig_fun_owner = Class::Handle(signature_fun.owner());
743 FinalizeTypeArguments(sig_fun_owner, full_arguments, finalization); 747 FinalizeTypeArguments(sig_fun_owner, full_arguments, finalization);
744 } else { 748 } else {
745 FinalizeTypeArguments(type_class, full_arguments, finalization); 749 FinalizeTypeArguments(type_class, full_arguments, finalization);
746 } 750 }
747 if (full_arguments.IsRaw(num_type_arguments)) { 751 if (full_arguments.IsRaw(num_type_arguments)) {
748 // The parameterized_type is raw. Set its argument vector to null, which 752 // The parameterized_type is raw. Set its argument vector to null, which
749 // is more efficient in type tests. 753 // is more efficient in type tests.
750 full_arguments = TypeArguments::null(); 754 full_arguments = TypeArguments::null();
751 } else { 755 } else if (finalization >= kCanonicalize) {
752 // FinalizeTypeArguments can modify 'full_arguments', 756 // FinalizeTypeArguments can modify 'full_arguments',
753 // canonicalize afterwards. 757 // canonicalize afterwards.
754 full_arguments ^= full_arguments.Canonicalize(); 758 full_arguments ^= full_arguments.Canonicalize();
755 } 759 }
756 parameterized_type.set_arguments(full_arguments); 760 parameterized_type.set_arguments(full_arguments);
757 } else { 761 } else {
758 ASSERT(full_arguments.IsNull()); // Use null vector for raw type. 762 ASSERT(full_arguments.IsNull()); // Use null vector for raw type.
759 } 763 }
760 } 764 }
761 765
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 // This type is a function type alias. Its class may need to be finalized 819 // This type is a function type alias. Its class may need to be finalized
816 // and checked for illegal self reference. 820 // and checked for illegal self reference.
817 FinalizeClass(type_class, false); 821 FinalizeClass(type_class, false);
818 // Finalizing the signature function here (as in the canonical case above) 822 // Finalizing the signature function here (as in the canonical case above)
819 // would not mark the canonical signature type as finalized. 823 // would not mark the canonical signature type as finalized.
820 const Type& signature_type = Type::Handle(type_class.SignatureType()); 824 const Type& signature_type = Type::Handle(type_class.SignatureType());
821 FinalizeType(cls, signature_type, finalization); 825 FinalizeType(cls, signature_type, finalization);
822 } 826 }
823 } 827 }
824 828
825 return parameterized_type.Canonicalize(); 829 if (finalization >= kCanonicalize) {
830 return parameterized_type.Canonicalize();
831 } else {
832 return parameterized_type.raw();
833 }
826 } 834 }
827 835
828 836
829 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, 837 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls,
830 const Function& function) { 838 const Function& function) {
831 // Resolve result type. 839 // Resolve result type.
832 AbstractType& type = AbstractType::Handle(function.result_type()); 840 AbstractType& type = AbstractType::Handle(function.result_type());
833 // In case of a factory, the parser sets the factory result type to a type 841 // In case of a factory, the parser sets the factory result type to a type
834 // with an unresolved class whose name matches the factory name. 842 // with an unresolved class whose name matches the factory name.
835 // It is not a compile time error if this name does not resolve to a class or 843 // It is not a compile time error if this name does not resolve to a class or
836 // interface. 844 // interface.
837 ResolveType(cls, type, kFinalize); 845 ResolveType(cls, type, kCanonicalize);
838 type = FinalizeType(cls, type, kFinalize); 846 type = FinalizeType(cls, type, kCanonicalize);
839 // In production mode, a malformed result type is mapped to Dynamic. 847 // In production mode, a malformed result type is mapped to Dynamic.
840 if (!FLAG_enable_type_checks && type.IsMalformed()) { 848 if (!FLAG_enable_type_checks && type.IsMalformed()) {
841 type = Type::DynamicType(); 849 type = Type::DynamicType();
842 } 850 }
843 function.set_result_type(type); 851 function.set_result_type(type);
844 // Resolve formal parameter types. 852 // Resolve formal parameter types.
845 const intptr_t num_parameters = function.NumberOfParameters(); 853 const intptr_t num_parameters = function.NumberOfParameters();
846 for (intptr_t i = 0; i < num_parameters; i++) { 854 for (intptr_t i = 0; i < num_parameters; i++) {
847 type = function.ParameterTypeAt(i); 855 type = function.ParameterTypeAt(i);
848 ResolveType(cls, type, kFinalize); 856 ResolveType(cls, type, kCanonicalize);
849 type = FinalizeType(cls, type, kFinalize); 857 type = FinalizeType(cls, type, kCanonicalize);
850 // In production mode, a malformed parameter type is mapped to Dynamic. 858 // In production mode, a malformed parameter type is mapped to Dynamic.
851 if (!FLAG_enable_type_checks && type.IsMalformed()) { 859 if (!FLAG_enable_type_checks && type.IsMalformed()) {
852 type = Type::DynamicType(); 860 type = Type::DynamicType();
853 } 861 }
854 function.SetParameterTypeAt(i, type); 862 function.SetParameterTypeAt(i, type);
855 } 863 }
856 } 864 }
857 865
858 866
859 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, 867 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 const AbstractTypeArguments& type_params = 911 const AbstractTypeArguments& type_params =
904 AbstractTypeArguments::Handle(cls.type_parameters()); 912 AbstractTypeArguments::Handle(cls.type_parameters());
905 ASSERT((type_params.IsNull() && (num_type_params == 0)) || 913 ASSERT((type_params.IsNull() && (num_type_params == 0)) ||
906 (type_params.Length() == num_type_params)); 914 (type_params.Length() == num_type_params));
907 for (intptr_t i = 0; i < num_type_params; i++) { 915 for (intptr_t i = 0; i < num_type_params; i++) {
908 type_param ^= type_params.TypeAt(i); 916 type_param ^= type_params.TypeAt(i);
909 bound = type_param.bound(); 917 bound = type_param.bound();
910 if (bound.IsFinalized()) { 918 if (bound.IsFinalized()) {
911 continue; 919 continue;
912 } 920 }
913 ResolveType(cls, bound, kFinalize); 921 ResolveType(cls, bound, kCanonicalize);
914 bound = FinalizeType(cls, bound, kFinalize); 922 bound = FinalizeType(cls, bound, kCanonicalize);
915 type_param.set_bound(bound); 923 type_param.set_bound(bound);
916 } 924 }
917 } 925 }
918 926
919 927
920 void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) { 928 void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) {
921 // Note that getters and setters are explicitly listed as such in the list of 929 // Note that getters and setters are explicitly listed as such in the list of
922 // functions of a class, so we do not need to consider fields as implicitly 930 // functions of a class, so we do not need to consider fields as implicitly
923 // generating getters and setters. 931 // generating getters and setters.
924 // The only compile errors we report are therefore: 932 // The only compile errors we report are therefore:
925 // - a getter having the same name as a method (but not a getter) in a super 933 // - a getter having the same name as a method (but not a getter) in a super
926 // class or in a subclass. 934 // class or in a subclass.
927 // - a setter having the same name as a method (but not a setter) in a super 935 // - a setter having the same name as a method (but not a setter) in a super
928 // class or in a subclass. 936 // class or in a subclass.
929 // - a static field, instance field, or static method (but not an instance 937 // - a static field, instance field, or static method (but not an instance
930 // method) having the same name as an instance member in a super class. 938 // method) having the same name as an instance member in a super class.
931 939
932 // Resolve type of fields and check for conflicts in super classes. 940 // Resolve type of fields and check for conflicts in super classes.
933 Array& array = Array::Handle(cls.fields()); 941 Array& array = Array::Handle(cls.fields());
934 Field& field = Field::Handle(); 942 Field& field = Field::Handle();
935 AbstractType& type = AbstractType::Handle(); 943 AbstractType& type = AbstractType::Handle();
936 String& name = String::Handle(); 944 String& name = String::Handle();
937 Class& super_class = Class::Handle(); 945 Class& super_class = Class::Handle();
938 intptr_t num_fields = array.Length(); 946 intptr_t num_fields = array.Length();
939 for (intptr_t i = 0; i < num_fields; i++) { 947 for (intptr_t i = 0; i < num_fields; i++) {
940 field ^= array.At(i); 948 field ^= array.At(i);
941 type = field.type(); 949 type = field.type();
942 ResolveType(cls, type, kFinalize); 950 ResolveType(cls, type, kCanonicalize);
943 type = FinalizeType(cls, type, kFinalize); 951 type = FinalizeType(cls, type, kCanonicalize);
944 field.set_type(type); 952 field.set_type(type);
945 name = field.name(); 953 name = field.name();
946 super_class = FindSuperOwnerOfInstanceMember(cls, name); 954 super_class = FindSuperOwnerOfInstanceMember(cls, name);
947 if (!super_class.IsNull()) { 955 if (!super_class.IsNull()) {
948 const String& class_name = String::Handle(cls.Name()); 956 const String& class_name = String::Handle(cls.Name());
949 const String& super_class_name = String::Handle(super_class.Name()); 957 const String& super_class_name = String::Handle(super_class.Name());
950 const Script& script = Script::Handle(cls.script()); 958 const Script& script = Script::Handle(cls.script());
951 ReportError(script, field.token_pos(), 959 ReportError(script, field.token_pos(),
952 "field '%s' of class '%s' conflicts with instance " 960 "field '%s' of class '%s' conflicts with instance "
953 "member '%s' of super class '%s'", 961 "member '%s' of super class '%s'",
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 // Finalize super class. 1103 // Finalize super class.
1096 const Class& super_class = Class::Handle(cls.SuperClass()); 1104 const Class& super_class = Class::Handle(cls.SuperClass());
1097 if (!super_class.IsNull()) { 1105 if (!super_class.IsNull()) {
1098 FinalizeClass(super_class, generating_snapshot); 1106 FinalizeClass(super_class, generating_snapshot);
1099 } 1107 }
1100 // Finalize type parameters before finalizing the super type. 1108 // Finalize type parameters before finalizing the super type.
1101 FinalizeTypeParameters(cls); 1109 FinalizeTypeParameters(cls);
1102 // Finalize super type. 1110 // Finalize super type.
1103 Type& super_type = Type::Handle(cls.super_type()); 1111 Type& super_type = Type::Handle(cls.super_type());
1104 if (!super_type.IsNull()) { 1112 if (!super_type.IsNull()) {
1105 super_type ^= FinalizeType(cls, super_type, kFinalizeWellFormed); 1113 super_type ^= FinalizeType(cls, super_type, kCanonicalizeWellFormed);
1106 cls.set_super_type(super_type); 1114 cls.set_super_type(super_type);
1107 } 1115 }
1108 // Signature classes are finalized upon creation, except function type 1116 // Signature classes are finalized upon creation, except function type
1109 // aliases. 1117 // aliases.
1110 if (cls.IsSignatureClass()) { 1118 if (cls.IsSignatureClass()) {
1111 ASSERT(!cls.IsCanonicalSignatureClass()); 1119 ASSERT(!cls.IsCanonicalSignatureClass());
1112 // Check for illegal self references. 1120 // Check for illegal self references.
1113 GrowableArray<intptr_t> visited_aliases; 1121 GrowableArray<intptr_t> visited_aliases;
1114 if (!IsAliasCycleFree(cls, &visited_aliases)) { 1122 if (!IsAliasCycleFree(cls, &visited_aliases)) {
1115 const String& name = String::Handle(cls.Name()); 1123 const String& name = String::Handle(cls.Name());
(...skipping 16 matching lines...) Expand all
1132 return; 1140 return;
1133 } 1141 }
1134 } 1142 }
1135 } 1143 }
1136 } 1144 }
1137 // Finalize interface types (but not necessarily interface classes). 1145 // Finalize interface types (but not necessarily interface classes).
1138 Array& interface_types = Array::Handle(cls.interfaces()); 1146 Array& interface_types = Array::Handle(cls.interfaces());
1139 AbstractType& interface_type = AbstractType::Handle(); 1147 AbstractType& interface_type = AbstractType::Handle();
1140 for (intptr_t i = 0; i < interface_types.Length(); i++) { 1148 for (intptr_t i = 0; i < interface_types.Length(); i++) {
1141 interface_type ^= interface_types.At(i); 1149 interface_type ^= interface_types.At(i);
1142 interface_type = FinalizeType(cls, interface_type, kFinalizeWellFormed); 1150 interface_type = FinalizeType(cls, interface_type, kCanonicalizeWellFormed);
1143 interface_types.SetAt(i, interface_type); 1151 interface_types.SetAt(i, interface_type);
1144 } 1152 }
1145 // Mark as finalized before resolving type parameter upper bounds and member 1153 // Mark as finalized before resolving type parameter upper bounds and member
1146 // types in order to break cycles. 1154 // types in order to break cycles.
1147 cls.Finalize(); 1155 cls.Finalize();
1148 ResolveAndFinalizeUpperBounds(cls); 1156 ResolveAndFinalizeUpperBounds(cls);
1149 ResolveAndFinalizeMemberTypes(cls); 1157 ResolveAndFinalizeMemberTypes(cls);
1150 // Run additional checks after all types are finalized. 1158 // Run additional checks after all types are finalized.
1151 if (cls.is_const()) { 1159 if (cls.is_const()) {
1152 CheckForLegalConstClass(cls); 1160 CheckForLegalConstClass(cls);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 // We have already visited alias 'cls'. We found a cycle. 1211 // We have already visited alias 'cls'. We found a cycle.
1204 return false; 1212 return false;
1205 } 1213 }
1206 } 1214 }
1207 1215
1208 // Visit the result type and parameter types of this signature type. 1216 // Visit the result type and parameter types of this signature type.
1209 visited->Add(cls.id()); 1217 visited->Add(cls.id());
1210 const Function& function = Function::Handle(cls.signature_function()); 1218 const Function& function = Function::Handle(cls.signature_function());
1211 // Check class of result type. 1219 // Check class of result type.
1212 AbstractType& type = AbstractType::Handle(function.result_type()); 1220 AbstractType& type = AbstractType::Handle(function.result_type());
1213 ResolveType(cls, type, kFinalize); 1221 ResolveType(cls, type, kCanonicalize);
1214 if (type.IsType() && !type.IsMalformed()) { 1222 if (type.IsType() && !type.IsMalformed()) {
1215 const Class& type_class = Class::Handle(type.type_class()); 1223 const Class& type_class = Class::Handle(type.type_class());
1216 if (!type_class.is_finalized() && 1224 if (!type_class.is_finalized() &&
1217 type_class.IsSignatureClass() && 1225 type_class.IsSignatureClass() &&
1218 !type_class.IsCanonicalSignatureClass()) { 1226 !type_class.IsCanonicalSignatureClass()) {
1219 if (!IsAliasCycleFree(type_class, visited)) { 1227 if (!IsAliasCycleFree(type_class, visited)) {
1220 return false; 1228 return false;
1221 } 1229 }
1222 } 1230 }
1223 } 1231 }
1224 // Check classes of formal parameter types. 1232 // Check classes of formal parameter types.
1225 const intptr_t num_parameters = function.NumberOfParameters(); 1233 const intptr_t num_parameters = function.NumberOfParameters();
1226 for (intptr_t i = 0; i < num_parameters; i++) { 1234 for (intptr_t i = 0; i < num_parameters; i++) {
1227 type = function.ParameterTypeAt(i); 1235 type = function.ParameterTypeAt(i);
1228 ResolveType(cls, type, kFinalize); 1236 ResolveType(cls, type, kCanonicalize);
1229 if (type.IsType() && !type.IsMalformed()) { 1237 if (type.IsType() && !type.IsMalformed()) {
1230 const Class& type_class = Class::Handle(type.type_class()); 1238 const Class& type_class = Class::Handle(type.type_class());
1231 if (!type_class.is_finalized() && 1239 if (!type_class.is_finalized() &&
1232 type_class.IsSignatureClass() && 1240 type_class.IsSignatureClass() &&
1233 !type_class.IsCanonicalSignatureClass()) { 1241 !type_class.IsCanonicalSignatureClass()) {
1234 if (!IsAliasCycleFree(type_class, visited)) { 1242 if (!IsAliasCycleFree(type_class, visited)) {
1235 return false; 1243 return false;
1236 } 1244 }
1237 } 1245 }
1238 } 1246 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 const bool cls_belongs_to_core_lib = 1313 const bool cls_belongs_to_core_lib =
1306 (cls.library() == Library::CoreLibrary()) || 1314 (cls.library() == Library::CoreLibrary()) ||
1307 (cls.library() == Library::CoreImplLibrary()); 1315 (cls.library() == Library::CoreImplLibrary());
1308 1316
1309 // Resolve and check the interfaces of cls. 1317 // Resolve and check the interfaces of cls.
1310 visited->Add(cls_index); 1318 visited->Add(cls_index);
1311 AbstractType& interface = AbstractType::Handle(); 1319 AbstractType& interface = AbstractType::Handle();
1312 Class& interface_class = Class::Handle(); 1320 Class& interface_class = Class::Handle();
1313 for (intptr_t i = 0; i < super_interfaces.Length(); i++) { 1321 for (intptr_t i = 0; i < super_interfaces.Length(); i++) {
1314 interface ^= super_interfaces.At(i); 1322 interface ^= super_interfaces.At(i);
1315 ResolveType(cls, interface, kFinalizeWellFormed); 1323 ResolveType(cls, interface, kCanonicalizeWellFormed);
1316 if (interface.IsTypeParameter()) { 1324 if (interface.IsTypeParameter()) {
1317 const Script& script = Script::Handle(cls.script()); 1325 const Script& script = Script::Handle(cls.script());
1318 ReportError(script, cls.token_pos(), 1326 ReportError(script, cls.token_pos(),
1319 "type parameter '%s' cannot be used as interface", 1327 "type parameter '%s' cannot be used as interface",
1320 String::Handle(interface.Name()).ToCString()); 1328 String::Handle(interface.Name()).ToCString());
1321 } 1329 }
1322 interface_class = interface.type_class(); 1330 interface_class = interface.type_class();
1323 if (interface_class.IsSignatureClass()) { 1331 if (interface_class.IsSignatureClass()) {
1324 const Script& script = Script::Handle(cls.script()); 1332 const Script& script = Script::Handle(cls.script());
1325 ReportError(script, cls.token_pos(), 1333 ReportError(script, cls.token_pos(),
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 void ClassFinalizer::FinalizeMalformedType(const Error& prev_error, 1443 void ClassFinalizer::FinalizeMalformedType(const Error& prev_error,
1436 const Class& cls, 1444 const Class& cls,
1437 const Type& type, 1445 const Type& type,
1438 FinalizationKind finalization, 1446 FinalizationKind finalization,
1439 const char* format, ...) { 1447 const char* format, ...) {
1440 va_list args; 1448 va_list args;
1441 va_start(args, format); 1449 va_start(args, format);
1442 LanguageError& error = LanguageError::Handle(); 1450 LanguageError& error = LanguageError::Handle();
1443 if (FLAG_enable_type_checks || 1451 if (FLAG_enable_type_checks ||
1444 !type.HasResolvedTypeClass() || 1452 !type.HasResolvedTypeClass() ||
1445 (finalization == kFinalizeWellFormed)) { 1453 (finalization == kCanonicalizeWellFormed)) {
1446 const Script& script = Script::Handle(cls.script()); 1454 const Script& script = Script::Handle(cls.script());
1447 if (prev_error.IsNull()) { 1455 if (prev_error.IsNull()) {
1448 error ^= Parser::FormatError( 1456 error ^= Parser::FormatError(
1449 script, type.token_pos(), "Error", format, args); 1457 script, type.token_pos(), "Error", format, args);
1450 } else { 1458 } else {
1451 error ^= Parser::FormatErrorWithAppend( 1459 error ^= Parser::FormatErrorWithAppend(
1452 prev_error, script, type.token_pos(), "Error", format, args); 1460 prev_error, script, type.token_pos(), "Error", format, args);
1453 } 1461 }
1454 if (finalization == kFinalizeWellFormed) { 1462 if (finalization == kCanonicalizeWellFormed) {
1455 ReportError(error); 1463 ReportError(error);
1456 } 1464 }
1457 } 1465 }
1458 if (FLAG_enable_type_checks || !type.HasResolvedTypeClass()) { 1466 if (FLAG_enable_type_checks || !type.HasResolvedTypeClass()) {
1459 // In check mode, always mark the type as malformed. 1467 // In check mode, always mark the type as malformed.
1460 // In production mode, mark the type as malformed only if its type class is 1468 // In production mode, mark the type as malformed only if its type class is
1461 // not resolved. 1469 // not resolved.
1462 type.set_malformed_error(error); 1470 type.set_malformed_error(error);
1463 } else { 1471 } else {
1464 // In production mode, do not mark the type with a resolved type class as 1472 // In production mode, do not mark the type with a resolved type class as
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 void ClassFinalizer::ReportError(const char* format, ...) { 1505 void ClassFinalizer::ReportError(const char* format, ...) {
1498 va_list args; 1506 va_list args;
1499 va_start(args, format); 1507 va_start(args, format);
1500 const Error& error = Error::Handle( 1508 const Error& error = Error::Handle(
1501 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); 1509 Parser::FormatError(Script::Handle(), -1, "Error", format, args));
1502 va_end(args); 1510 va_end(args);
1503 ReportError(error); 1511 ReportError(error);
1504 } 1512 }
1505 1513
1506 } // namespace dart 1514 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | runtime/vm/flow_graph_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698