Chromium Code Reviews| 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 2128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2139 func = func.Clone(cls); | 2139 func = func.Clone(cls); |
| 2140 cloned_funcs.Add(func); | 2140 cloned_funcs.Add(func); |
| 2141 } | 2141 } |
| 2142 } | 2142 } |
| 2143 functions = Array::MakeArray(cloned_funcs); | 2143 functions = Array::MakeArray(cloned_funcs); |
| 2144 cls.SetFunctions(functions); | 2144 cls.SetFunctions(functions); |
| 2145 | 2145 |
| 2146 // Now clone the fields from the mixin class. There should be no | 2146 // Now clone the fields from the mixin class. There should be no |
| 2147 // existing fields in the mixin application class. | 2147 // existing fields in the mixin application class. |
| 2148 ASSERT(Array::Handle(cls.fields()).Length() == 0); | 2148 ASSERT(Array::Handle(cls.fields()).Length() == 0); |
| 2149 Array& fields = Array::Handle(isolate, mixin_cls.fields()); | 2149 const Array& fields = Array::Handle(isolate, mixin_cls.fields()); |
| 2150 Field& field = Field::Handle(isolate); | 2150 Field& field = Field::Handle(isolate); |
| 2151 const GrowableObjectArray& cloned_fields = | 2151 const GrowableObjectArray& cloned_fields = |
| 2152 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); | 2152 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); |
| 2153 const intptr_t num_fields = fields.Length(); | 2153 const intptr_t num_fields = fields.Length(); |
| 2154 for (intptr_t i = 0; i < num_fields; i++) { | 2154 for (intptr_t i = 0; i < num_fields; i++) { |
| 2155 field ^= fields.At(i); | 2155 field ^= fields.At(i); |
| 2156 if (!field.is_static()) { | 2156 if (!field.is_static()) { |
| 2157 field = field.Clone(cls); | 2157 field = field.Clone(cls); |
| 2158 cloned_fields.Add(field); | 2158 cloned_fields.Add(field); |
| 2159 } | 2159 } |
| 2160 } | 2160 } |
| 2161 fields = Array::MakeArray(cloned_fields); | 2161 cls.AddFields(cloned_fields); |
| 2162 cls.SetFields(fields); | |
| 2163 | 2162 |
| 2164 if (FLAG_trace_class_finalization) { | 2163 if (FLAG_trace_class_finalization) { |
| 2165 OS::Print("Done applying mixin members of %s to %s\n", | 2164 OS::Print("Done applying mixin members of %s to %s\n", |
| 2166 mixin_cls.ToCString(), | 2165 mixin_cls.ToCString(), |
| 2167 cls.ToCString()); | 2166 cls.ToCString()); |
| 2168 } | 2167 } |
| 2169 } | 2168 } |
| 2170 | 2169 |
| 2171 | 2170 |
| 2172 void ClassFinalizer::FinalizeTypesInClass(const Class& cls) { | 2171 void ClassFinalizer::FinalizeTypesInClass(const Class& cls) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2279 // Add this class to the direct subclasses of the superclass, unless the | 2278 // Add this class to the direct subclasses of the superclass, unless the |
| 2280 // superclass is Object. | 2279 // superclass is Object. |
| 2281 if (!super_type.IsNull() && !super_type.IsObjectType()) { | 2280 if (!super_type.IsNull() && !super_type.IsObjectType()) { |
| 2282 ASSERT(!super_class.IsNull()); | 2281 ASSERT(!super_class.IsNull()); |
| 2283 super_class.AddDirectSubclass(cls); | 2282 super_class.AddDirectSubclass(cls); |
| 2284 } | 2283 } |
| 2285 // A top level class is parsed eagerly so just finalize it. | 2284 // A top level class is parsed eagerly so just finalize it. |
| 2286 if (cls.IsTopLevel()) { | 2285 if (cls.IsTopLevel()) { |
| 2287 FinalizeClass(cls); | 2286 FinalizeClass(cls); |
| 2288 } else { | 2287 } else { |
| 2289 // This class should not contain any fields or functions yet, because it has | 2288 // This class should not contain any fields or functions yet, because it has |
|
Ivan Posva
2014/05/08 05:18:50
Please update the comment. Especially since it app
rmacnak
2014/05/08 18:14:54
Noted the class might contain metadata fields for
| |
| 2290 // not been compiled yet. Since 'ResolveAndFinalizeMemberTypes(cls)' has not | 2289 // not been compiled yet. Since 'ResolveAndFinalizeMemberTypes(cls)' has not |
| 2291 // been called yet, unfinalized member types could choke the snapshotter. | 2290 // been called yet, unfinalized member types could choke the snapshotter. |
| 2292 ASSERT(Array::Handle(cls.fields()).Length() == 0); | |
| 2293 ASSERT(Array::Handle(cls.functions()).Length() == 0); | 2291 ASSERT(Array::Handle(cls.functions()).Length() == 0); |
| 2294 } | 2292 } |
| 2295 } | 2293 } |
| 2296 | 2294 |
| 2297 | 2295 |
| 2298 void ClassFinalizer::FinalizeClass(const Class& cls) { | 2296 void ClassFinalizer::FinalizeClass(const Class& cls) { |
| 2299 HANDLESCOPE(Isolate::Current()); | 2297 HANDLESCOPE(Isolate::Current()); |
| 2300 if (cls.is_finalized()) { | 2298 if (cls.is_finalized()) { |
| 2301 return; | 2299 return; |
| 2302 } | 2300 } |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3072 expected_name ^= String::New("_offset"); | 3070 expected_name ^= String::New("_offset"); |
| 3073 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3071 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 3074 field ^= fields_array.At(2); | 3072 field ^= fields_array.At(2); |
| 3075 ASSERT(field.Offset() == TypedDataView::length_offset()); | 3073 ASSERT(field.Offset() == TypedDataView::length_offset()); |
| 3076 name ^= field.name(); | 3074 name ^= field.name(); |
| 3077 ASSERT(name.Equals("length")); | 3075 ASSERT(name.Equals("length")); |
| 3078 #endif | 3076 #endif |
| 3079 } | 3077 } |
| 3080 | 3078 |
| 3081 } // namespace dart | 3079 } // namespace dart |
| OLD | NEW |