| OLD | NEW |
| 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/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
| 6 | 6 |
| 7 #include "vm/code_generator.h" | 7 #include "vm/code_generator.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (!target.IsNull()) { | 298 if (!target.IsNull()) { |
| 299 // Already resolved. | 299 // Already resolved. |
| 300 return; | 300 return; |
| 301 } | 301 } |
| 302 | 302 |
| 303 // Target is not resolved yet. | 303 // Target is not resolved yet. |
| 304 if (FLAG_trace_class_finalization) { | 304 if (FLAG_trace_class_finalization) { |
| 305 OS::Print("Resolving redirecting factory: %s\n", | 305 OS::Print("Resolving redirecting factory: %s\n", |
| 306 String::Handle(factory.name()).ToCString()); | 306 String::Handle(factory.name()).ToCString()); |
| 307 } | 307 } |
| 308 ResolveType(cls, type); | |
| 309 type ^= FinalizeType(cls, type, kCanonicalize); | 308 type ^= FinalizeType(cls, type, kCanonicalize); |
| 310 factory.SetRedirectionType(type); | 309 factory.SetRedirectionType(type); |
| 311 if (type.IsMalformedOrMalbounded()) { | 310 if (type.IsMalformedOrMalbounded()) { |
| 312 ASSERT(factory.RedirectionTarget() == Function::null()); | 311 ASSERT(factory.RedirectionTarget() == Function::null()); |
| 313 return; | 312 return; |
| 314 } | 313 } |
| 315 ASSERT(!type.IsTypeParameter()); // Resolved in parser. | 314 ASSERT(!type.IsTypeParameter()); // Resolved in parser. |
| 316 if (type.IsDynamicType()) { | 315 if (type.IsDynamicType()) { |
| 317 // Replace the type with a malformed type and compile a throw when called. | 316 // Replace the type with a malformed type and compile a throw when called. |
| 318 type = NewFinalizedMalformedType( | 317 type = NewFinalizedMalformedType( |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 "cannot resolve class '%s' from '%s'", | 453 "cannot resolve class '%s' from '%s'", |
| 455 String::Handle(unresolved_class.Name()).ToCString(), | 454 String::Handle(unresolved_class.Name()).ToCString(), |
| 456 String::Handle(cls.Name()).ToCString()); | 455 String::Handle(cls.Name()).ToCString()); |
| 457 return; | 456 return; |
| 458 } | 457 } |
| 459 parameterized_type.set_type_class(type_class); | 458 parameterized_type.set_type_class(type_class); |
| 460 } | 459 } |
| 461 | 460 |
| 462 | 461 |
| 463 void ClassFinalizer::ResolveType(const Class& cls, const AbstractType& type) { | 462 void ClassFinalizer::ResolveType(const Class& cls, const AbstractType& type) { |
| 464 // TODO(regis): Add a kResolved bit in type_state_ for efficiency. | 463 if (type.IsResolved()) { |
| 465 if (type.IsFinalized() || type.IsResolved()) { | |
| 466 return; | 464 return; |
| 467 } | 465 } |
| 466 ASSERT(type.IsType()); |
| 468 if (FLAG_trace_type_finalization) { | 467 if (FLAG_trace_type_finalization) { |
| 469 OS::Print("Resolve type '%s'\n", String::Handle(type.Name()).ToCString()); | 468 OS::Print("Resolve type '%s'\n", String::Handle(type.Name()).ToCString()); |
| 470 } | 469 } |
| 471 | |
| 472 ResolveTypeClass(cls, type); | 470 ResolveTypeClass(cls, type); |
| 473 | 471 if (type.IsMalformed()) { |
| 472 ASSERT(type.IsResolved()); |
| 473 return; |
| 474 } |
| 475 // Mark type as resolved before resolving its type arguments in order to avoid |
| 476 // repeating resolution of recursive types. |
| 477 Type::Cast(type).set_is_resolved(); |
| 474 // Resolve type arguments, if any. | 478 // Resolve type arguments, if any. |
| 475 const TypeArguments& arguments = TypeArguments::Handle(type.arguments()); | 479 const TypeArguments& arguments = TypeArguments::Handle(type.arguments()); |
| 476 if (!arguments.IsNull()) { | 480 if (!arguments.IsNull()) { |
| 477 const intptr_t num_arguments = arguments.Length(); | 481 const intptr_t num_arguments = arguments.Length(); |
| 478 AbstractType& type_argument = AbstractType::Handle(); | 482 AbstractType& type_argument = AbstractType::Handle(); |
| 479 for (intptr_t i = 0; i < num_arguments; i++) { | 483 for (intptr_t i = 0; i < num_arguments; i++) { |
| 480 type_argument = arguments.TypeAt(i); | 484 type_argument = arguments.TypeAt(i); |
| 481 ResolveType(cls, type_argument); | 485 ResolveType(cls, type_argument); |
| 482 } | 486 } |
| 483 } | 487 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 | 765 |
| 762 if (type.IsBeingFinalized()) { | 766 if (type.IsBeingFinalized()) { |
| 763 if (FLAG_trace_type_finalization) { | 767 if (FLAG_trace_type_finalization) { |
| 764 OS::Print("Creating TypeRef '%s' for class '%s'\n", | 768 OS::Print("Creating TypeRef '%s' for class '%s'\n", |
| 765 String::Handle(type.Name()).ToCString(), | 769 String::Handle(type.Name()).ToCString(), |
| 766 cls.ToCString()); | 770 cls.ToCString()); |
| 767 } | 771 } |
| 768 return TypeRef::New(type); | 772 return TypeRef::New(type); |
| 769 } | 773 } |
| 770 | 774 |
| 771 ASSERT(type.IsResolved()); | 775 ResolveType(cls, type); |
| 772 if (FLAG_trace_type_finalization) { | 776 if (FLAG_trace_type_finalization) { |
| 773 OS::Print("Finalizing type '%s' for class '%s'\n", | 777 OS::Print("Finalizing type '%s' for class '%s'\n", |
| 774 String::Handle(type.Name()).ToCString(), | 778 String::Handle(type.Name()).ToCString(), |
| 775 cls.ToCString()); | 779 cls.ToCString()); |
| 776 } | 780 } |
| 777 | 781 |
| 778 if (type.IsTypeParameter()) { | 782 if (type.IsTypeParameter()) { |
| 779 const TypeParameter& type_parameter = TypeParameter::Cast(type); | 783 const TypeParameter& type_parameter = TypeParameter::Cast(type); |
| 780 const Class& parameterized_class = | 784 const Class& parameterized_class = |
| 781 Class::Handle(type_parameter.parameterized_class()); | 785 Class::Handle(type_parameter.parameterized_class()); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 } | 987 } |
| 984 } | 988 } |
| 985 | 989 |
| 986 | 990 |
| 987 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, | 991 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, |
| 988 const Function& function) { | 992 const Function& function) { |
| 989 // Resolve result type. | 993 // Resolve result type. |
| 990 AbstractType& type = AbstractType::Handle(function.result_type()); | 994 AbstractType& type = AbstractType::Handle(function.result_type()); |
| 991 // It is not a compile time error if this name does not resolve to a class or | 995 // It is not a compile time error if this name does not resolve to a class or |
| 992 // interface. | 996 // interface. |
| 993 ResolveType(cls, type); | |
| 994 type = FinalizeType(cls, type, kCanonicalize); | 997 type = FinalizeType(cls, type, kCanonicalize); |
| 995 // The result type may be malformed or malbounded. | 998 // The result type may be malformed or malbounded. |
| 996 function.set_result_type(type); | 999 function.set_result_type(type); |
| 997 // Resolve formal parameter types. | 1000 // Resolve formal parameter types. |
| 998 const intptr_t num_parameters = function.NumParameters(); | 1001 const intptr_t num_parameters = function.NumParameters(); |
| 999 for (intptr_t i = 0; i < num_parameters; i++) { | 1002 for (intptr_t i = 0; i < num_parameters; i++) { |
| 1000 type = function.ParameterTypeAt(i); | 1003 type = function.ParameterTypeAt(i); |
| 1001 ResolveType(cls, type); | |
| 1002 type = FinalizeType(cls, type, kCanonicalize); | 1004 type = FinalizeType(cls, type, kCanonicalize); |
| 1003 // The parameter type may be malformed or malbounded. | 1005 // The parameter type may be malformed or malbounded. |
| 1004 function.SetParameterTypeAt(i, type); | 1006 function.SetParameterTypeAt(i, type); |
| 1005 } | 1007 } |
| 1006 } | 1008 } |
| 1007 | 1009 |
| 1008 | 1010 |
| 1009 // Check if an instance field, getter, or method of same name exists | 1011 // Check if an instance field, getter, or method of same name exists |
| 1010 // in any super class. | 1012 // in any super class. |
| 1011 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, | 1013 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 Field& field = Field::Handle(); | 1122 Field& field = Field::Handle(); |
| 1121 AbstractType& type = AbstractType::Handle(); | 1123 AbstractType& type = AbstractType::Handle(); |
| 1122 String& name = String::Handle(); | 1124 String& name = String::Handle(); |
| 1123 String& getter_name = String::Handle(); | 1125 String& getter_name = String::Handle(); |
| 1124 String& setter_name = String::Handle(); | 1126 String& setter_name = String::Handle(); |
| 1125 Class& super_class = Class::Handle(); | 1127 Class& super_class = Class::Handle(); |
| 1126 const intptr_t num_fields = array.Length(); | 1128 const intptr_t num_fields = array.Length(); |
| 1127 for (intptr_t i = 0; i < num_fields; i++) { | 1129 for (intptr_t i = 0; i < num_fields; i++) { |
| 1128 field ^= array.At(i); | 1130 field ^= array.At(i); |
| 1129 type = field.type(); | 1131 type = field.type(); |
| 1130 ResolveType(cls, type); | |
| 1131 type = FinalizeType(cls, type, kCanonicalize); | 1132 type = FinalizeType(cls, type, kCanonicalize); |
| 1132 field.set_type(type); | 1133 field.set_type(type); |
| 1133 name = field.name(); | 1134 name = field.name(); |
| 1134 if (field.is_static()) { | 1135 if (field.is_static()) { |
| 1135 getter_name = Field::GetterSymbol(name); | 1136 getter_name = Field::GetterSymbol(name); |
| 1136 super_class = FindSuperOwnerOfInstanceMember(cls, name, getter_name); | 1137 super_class = FindSuperOwnerOfInstanceMember(cls, name, getter_name); |
| 1137 if (!super_class.IsNull()) { | 1138 if (!super_class.IsNull()) { |
| 1138 const String& class_name = String::Handle(cls.Name()); | 1139 const String& class_name = String::Handle(cls.Name()); |
| 1139 const String& super_class_name = String::Handle(super_class.Name()); | 1140 const String& super_class_name = String::Handle(super_class.Name()); |
| 1140 const Script& script = Script::Handle(cls.script()); | 1141 const Script& script = Script::Handle(cls.script()); |
| (...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2927 expected_name ^= String::New("_offset"); | 2928 expected_name ^= String::New("_offset"); |
| 2928 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2929 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 2929 field ^= fields_array.At(2); | 2930 field ^= fields_array.At(2); |
| 2930 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2931 ASSERT(field.Offset() == TypedDataView::length_offset()); |
| 2931 name ^= field.name(); | 2932 name ^= field.name(); |
| 2932 ASSERT(name.Equals("length")); | 2933 ASSERT(name.Equals("length")); |
| 2933 #endif | 2934 #endif |
| 2934 } | 2935 } |
| 2935 | 2936 |
| 2936 } // namespace dart | 2937 } // namespace dart |
| OLD | NEW |