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

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

Issue 13992002: Prohibit use of dynamic when extending or implementing classes (was crashing). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 | « no previous file | 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) 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/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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 } 62 }
63 } 63 }
64 #endif 64 #endif
65 } 65 }
66 66
67 67
68 void AddSuperType(const AbstractType& type, 68 void AddSuperType(const AbstractType& type,
69 GrowableArray<intptr_t>* finalized_super_classes) { 69 GrowableArray<intptr_t>* finalized_super_classes) {
70 ASSERT(type.HasResolvedTypeClass()); 70 ASSERT(type.HasResolvedTypeClass());
71 ASSERT(!type.IsDynamicType());
71 if (type.IsObjectType()) { 72 if (type.IsObjectType()) {
72 return; 73 return;
73 } 74 }
74 const Class& cls = Class::Handle(type.type_class()); 75 const Class& cls = Class::Handle(type.type_class());
75 ASSERT(cls.is_finalized()); 76 ASSERT(cls.is_finalized());
76 const intptr_t cid = cls.id(); 77 const intptr_t cid = cls.id();
77 for (intptr_t i = 0; i < finalized_super_classes->length(); i++) { 78 for (intptr_t i = 0; i < finalized_super_classes->length(); i++) {
78 if ((*finalized_super_classes)[i] == cid) { 79 if ((*finalized_super_classes)[i] == cid) {
79 // Already added. 80 // Already added.
80 return; 81 return;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 154 }
154 if (FLAG_print_classes) { 155 if (FLAG_print_classes) {
155 for (intptr_t i = 0; i < class_array.Length(); i++) { 156 for (intptr_t i = 0; i < class_array.Length(); i++) {
156 cls ^= class_array.At(i); 157 cls ^= class_array.At(i);
157 PrintClassInformation(cls); 158 PrintClassInformation(cls);
158 } 159 }
159 } 160 }
160 // Clear pending classes array. 161 // Clear pending classes array.
161 class_array = GrowableObjectArray::New(); 162 class_array = GrowableObjectArray::New();
162 object_store->set_pending_classes(class_array); 163 object_store->set_pending_classes(class_array);
164 VerifyImplicitFieldOffsets(); // Verification after an error may fail.
163 } else { 165 } else {
164 retval = false; 166 retval = false;
165 } 167 }
166 isolate->set_long_jump_base(base); 168 isolate->set_long_jump_base(base);
167 if (FLAG_use_cha) { 169 if (FLAG_use_cha) {
168 RemoveOptimizedCode(added_subclasses_to_cids); 170 RemoveOptimizedCode(added_subclasses_to_cids);
169 } 171 }
170 VerifyImplicitFieldOffsets();
171 return retval; 172 return retval;
172 } 173 }
173 174
174 175
175 // Adds all interfaces of cls into 'collected'. Duplicate entries may occur. 176 // Adds all interfaces of cls into 'collected'. Duplicate entries may occur.
176 // No cycles are allowed. 177 // No cycles are allowed.
177 void ClassFinalizer::CollectInterfaces(const Class& cls, 178 void ClassFinalizer::CollectInterfaces(const Class& cls,
178 const GrowableObjectArray& collected) { 179 const GrowableObjectArray& collected) {
179 const Array& interface_array = Array::Handle(cls.interfaces()); 180 const Array& interface_array = Array::Handle(cls.interfaces());
180 AbstractType& interface = AbstractType::Handle(); 181 AbstractType& interface = AbstractType::Handle();
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } else { 891 } else {
891 return parameterized_type.raw(); 892 return parameterized_type.raw();
892 } 893 }
893 } 894 }
894 895
895 896
896 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, 897 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls,
897 const Function& function) { 898 const Function& function) {
898 // Resolve result type. 899 // Resolve result type.
899 AbstractType& type = AbstractType::Handle(function.result_type()); 900 AbstractType& type = AbstractType::Handle(function.result_type());
900 // TODO(regis): Remove this code once the parser checks the factory name and
901 // once the core library is fixed. See issue 6641.
902 // In case of a factory, the parser sets the factory result type to a type
903 // with an unresolved class whose name matches the factory name and no type
904 // arguments. We resolve the class and specify type arguments in case the
905 // class is generic.
906 if (function.IsFactory()) {
907 Type& factory_result_type = Type::Handle();
908 factory_result_type ^= type.raw();
909 ASSERT(factory_result_type.arguments() == TypeArguments::null());
910 const UnresolvedClass& unresolved_factory_class =
911 UnresolvedClass::Handle(factory_result_type.unresolved_class());
912 const Class& factory_class =
913 Class::Handle(ResolveClass(cls, unresolved_factory_class));
914 if (factory_class.IsNull()) {
915 type = NewFinalizedMalformedType(
916 Error::Handle(), // No previous error.
917 cls,
918 unresolved_factory_class.token_pos(),
919 kTryResolve, // No compile-time error.
920 "cannot resolve factory class name '%s' from '%s'",
921 String::Handle(unresolved_factory_class.Name()).ToCString(),
922 String::Handle(cls.Name()).ToCString());
923 } else {
924 type = Type::New(factory_class,
925 TypeArguments::Handle(factory_class.type_parameters()),
926 unresolved_factory_class.token_pos());
927 }
928 }
929 // It is not a compile time error if this name does not resolve to a class or 901 // It is not a compile time error if this name does not resolve to a class or
930 // interface. 902 // interface.
931 ResolveType(cls, type, kCanonicalize); 903 ResolveType(cls, type, kCanonicalize);
932 type = FinalizeType(cls, type, kCanonicalize); 904 type = FinalizeType(cls, type, kCanonicalize);
933 // In production mode, a malformed result type is mapped to dynamic. 905 // In production mode, a malformed result type is mapped to dynamic.
934 if (!FLAG_enable_type_checks && type.IsMalformed()) { 906 if (!FLAG_enable_type_checks && type.IsMalformed()) {
935 type = Type::DynamicType(); 907 type = Type::DynamicType();
936 } 908 }
937 function.set_result_type(type); 909 function.set_result_type(type);
938 // Resolve formal parameter types. 910 // Resolve formal parameter types.
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 expected_name ^= String::New("_offset"); 1994 expected_name ^= String::New("_offset");
2023 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); 1995 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name));
2024 field ^= fields_array.At(2); 1996 field ^= fields_array.At(2);
2025 ASSERT(field.Offset() == TypedDataView::length_offset()); 1997 ASSERT(field.Offset() == TypedDataView::length_offset());
2026 name ^= field.name(); 1998 name ^= field.name();
2027 ASSERT(name.Equals("length")); 1999 ASSERT(name.Equals("length"));
2028 #endif 2000 #endif
2029 } 2001 }
2030 2002
2031 } // namespace dart 2003 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698