| 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/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 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1694 const String& super_name = String::Handle(super_class.Name()); | 1694 const String& super_name = String::Handle(super_class.Name()); |
| 1695 const Type& dynamic_type = Type::Handle(Type::DynamicType()); | 1695 const Type& dynamic_type = Type::Handle(Type::DynamicType()); |
| 1696 const Array& functions = Array::Handle(super_class.functions()); | 1696 const Array& functions = Array::Handle(super_class.functions()); |
| 1697 const intptr_t num_functions = functions.Length(); | 1697 const intptr_t num_functions = functions.Length(); |
| 1698 Function& func = Function::Handle(); | 1698 Function& func = Function::Handle(); |
| 1699 for (intptr_t i = 0; i < num_functions; i++) { | 1699 for (intptr_t i = 0; i < num_functions; i++) { |
| 1700 func ^= functions.At(i); | 1700 func ^= functions.At(i); |
| 1701 if (func.IsConstructor()) { | 1701 if (func.IsConstructor()) { |
| 1702 // Build constructor name from mixin application class name | 1702 // Build constructor name from mixin application class name |
| 1703 // and name of cloned super class constructor. | 1703 // and name of cloned super class constructor. |
| 1704 String& ctor_name = String::Handle(func.name()); | 1704 const String& ctor_name = String::Handle(func.name()); |
| 1705 ctor_name = String::SubString(ctor_name, super_name.Length()); | 1705 String& clone_name = String::Handle( |
| 1706 String& clone_name = | 1706 String::SubString(ctor_name, super_name.Length())); |
| 1707 String::Handle(String::Concat(mixin_name, ctor_name)); | 1707 clone_name = String::Concat(mixin_name, clone_name); |
| 1708 clone_name = Symbols::New(clone_name); | 1708 clone_name = Symbols::New(clone_name); |
| 1709 | 1709 |
| 1710 if (FLAG_trace_class_finalization) { |
| 1711 OS::Print("Cloning constructor '%s' as '%s'\n", |
| 1712 ctor_name.ToCString(), |
| 1713 clone_name.ToCString()); |
| 1714 } |
| 1710 const Function& clone = Function::Handle( | 1715 const Function& clone = Function::Handle( |
| 1711 Function::New(clone_name, | 1716 Function::New(clone_name, |
| 1712 func.kind(), | 1717 func.kind(), |
| 1713 func.is_static(), | 1718 func.is_static(), |
| 1714 false, // Not const. | 1719 false, // Not const. |
| 1715 false, // Not abstract. | 1720 false, // Not abstract. |
| 1716 false, // Not external. | 1721 false, // Not external. |
| 1717 mixin_app, | 1722 mixin_app, |
| 1718 mixin_app.token_pos())); | 1723 mixin_app.token_pos())); |
| 1719 | 1724 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1960 // the class conflict with inherited methods. | 1965 // the class conflict with inherited methods. |
| 1961 ApplyMixinMembers(cls); | 1966 ApplyMixinMembers(cls); |
| 1962 } | 1967 } |
| 1963 // Ensure super class is finalized. | 1968 // Ensure super class is finalized. |
| 1964 const Class& super = Class::Handle(cls.SuperClass()); | 1969 const Class& super = Class::Handle(cls.SuperClass()); |
| 1965 if (!super.IsNull()) { | 1970 if (!super.IsNull()) { |
| 1966 FinalizeClass(super); | 1971 FinalizeClass(super); |
| 1967 } | 1972 } |
| 1968 // Mark as parsed and finalized. | 1973 // Mark as parsed and finalized. |
| 1969 cls.Finalize(); | 1974 cls.Finalize(); |
| 1970 // Mixin typedef classes may still lack their implicit constructor. | 1975 // Mixin typedef classes may still lack their forwarding constructor. |
| 1971 if (cls.is_mixin_typedef() && | 1976 if (cls.is_mixin_typedef() && |
| 1972 (cls.functions() == Object::empty_array().raw())) { | 1977 (cls.functions() == Object::empty_array().raw())) { |
| 1973 Parser::AddImplicitConstructor(cls); | 1978 const GrowableObjectArray& cloned_funcs = |
| 1979 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 1980 CreateForwardingConstructors(cls, cloned_funcs); |
| 1981 const Array& functions = Array::Handle(Array::MakeArray(cloned_funcs)); |
| 1982 cls.SetFunctions(functions); |
| 1974 } | 1983 } |
| 1975 // Every class should have at least a constructor, unless it is a top level | 1984 // Every class should have at least a constructor, unless it is a top level |
| 1976 // class or a signature class. | 1985 // class or a signature class. |
| 1977 ASSERT(cls.IsTopLevel() || | 1986 ASSERT(cls.IsTopLevel() || |
| 1978 cls.IsSignatureClass() || | 1987 cls.IsSignatureClass() || |
| 1979 (Array::Handle(cls.functions()).Length() > 0)); | 1988 (Array::Handle(cls.functions()).Length() > 0)); |
| 1980 // Resolve and finalize all member types. | 1989 // Resolve and finalize all member types. |
| 1981 ResolveAndFinalizeMemberTypes(cls); | 1990 ResolveAndFinalizeMemberTypes(cls); |
| 1982 // Run additional checks after all types are finalized. | 1991 // Run additional checks after all types are finalized. |
| 1983 if (cls.is_const()) { | 1992 if (cls.is_const()) { |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2587 expected_name ^= String::New("_offset"); | 2596 expected_name ^= String::New("_offset"); |
| 2588 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2597 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 2589 field ^= fields_array.At(2); | 2598 field ^= fields_array.At(2); |
| 2590 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2599 ASSERT(field.Offset() == TypedDataView::length_offset()); |
| 2591 name ^= field.name(); | 2600 name ^= field.name(); |
| 2592 ASSERT(name.Equals("length")); | 2601 ASSERT(name.Equals("length")); |
| 2593 #endif | 2602 #endif |
| 2594 } | 2603 } |
| 2595 | 2604 |
| 2596 } // namespace dart | 2605 } // namespace dart |
| OLD | NEW |