| 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 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 const GrowableObjectArray& collected_args) { | 1846 const GrowableObjectArray& collected_args) { |
| 1847 ASSERT(type.HasResolvedTypeClass()); | 1847 ASSERT(type.HasResolvedTypeClass()); |
| 1848 Class& type_class = Class::Handle(type.type_class()); | 1848 Class& type_class = Class::Handle(type.type_class()); |
| 1849 AbstractTypeArguments& type_args = | 1849 AbstractTypeArguments& type_args = |
| 1850 AbstractTypeArguments::Handle(type.arguments()); | 1850 AbstractTypeArguments::Handle(type.arguments()); |
| 1851 const intptr_t num_type_parameters = type_class.NumTypeParameters(); | 1851 const intptr_t num_type_parameters = type_class.NumTypeParameters(); |
| 1852 const intptr_t num_type_arguments = | 1852 const intptr_t num_type_arguments = |
| 1853 type_args.IsNull() ? 0 : type_args.Length(); | 1853 type_args.IsNull() ? 0 : type_args.Length(); |
| 1854 AbstractType& arg = AbstractType::Handle(); | 1854 AbstractType& arg = AbstractType::Handle(); |
| 1855 if (num_type_arguments > 0) { | 1855 if (num_type_arguments > 0) { |
| 1856 if (num_type_arguments != num_type_parameters) { | 1856 if (num_type_arguments == num_type_parameters) { |
| 1857 for (int i = 0; i < num_type_arguments; i++) { |
| 1858 arg = type_args.TypeAt(i); |
| 1859 collected_args.Add(arg); |
| 1860 } |
| 1861 return; |
| 1862 } |
| 1863 if (FLAG_error_on_bad_type) { |
| 1857 const Script& script = Script::Handle(cls.script()); | 1864 const Script& script = Script::Handle(cls.script()); |
| 1858 const String& type_class_name = String::Handle(type_class.Name()); | 1865 const String& type_class_name = String::Handle(type_class.Name()); |
| 1859 // TODO(regis): This should not be a compile time error anymore. | |
| 1860 ReportError(Error::Handle(), // No previous error. | 1866 ReportError(Error::Handle(), // No previous error. |
| 1861 script, type.token_pos(), | 1867 script, type.token_pos(), |
| 1862 "wrong number of type arguments for class '%s'", | 1868 "wrong number of type arguments for class '%s'", |
| 1863 type_class_name.ToCString()); | 1869 type_class_name.ToCString()); |
| 1864 } | 1870 } |
| 1865 for (int i = 0; i < num_type_arguments; i++) { | 1871 // Discard provided type arguments and treat type as raw. |
| 1866 arg = type_args.TypeAt(i); | 1872 } |
| 1867 collected_args.Add(arg); | 1873 // Fill arguments with type dynamic. |
| 1868 } | 1874 for (int i = 0; i < num_type_parameters; i++) { |
| 1869 } else { | 1875 arg = Type::DynamicType(); |
| 1870 // Fill arguments with type dynamic. | 1876 collected_args.Add(arg); |
| 1871 for (int i = 0; i < num_type_parameters; i++) { | |
| 1872 arg = Type::DynamicType(); | |
| 1873 collected_args.Add(arg); | |
| 1874 } | |
| 1875 } | 1877 } |
| 1876 } | 1878 } |
| 1877 | 1879 |
| 1878 | 1880 |
| 1879 RawType* ClassFinalizer::ResolveMixinAppType(const Class& cls, | 1881 RawType* ClassFinalizer::ResolveMixinAppType(const Class& cls, |
| 1880 const MixinAppType& mixin_app) { | 1882 const MixinAppType& mixin_app) { |
| 1881 // Resolve super type and all mixin types. | 1883 // Resolve super type and all mixin types. |
| 1882 const GrowableObjectArray& type_args = | 1884 const GrowableObjectArray& type_args = |
| 1883 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 1885 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 1884 AbstractType& type = AbstractType::Handle(mixin_app.super_type()); | 1886 AbstractType& type = AbstractType::Handle(mixin_app.SuperType()); |
| 1885 ResolveType(cls, type, kCanonicalizeWellFormed); | 1887 ResolveType(cls, type, kCanonicalizeWellFormed); |
| 1886 ASSERT(type.HasResolvedTypeClass()); | 1888 ASSERT(type.HasResolvedTypeClass()); |
| 1887 // TODO(hausner): May need to handle BoundedType here. | 1889 // TODO(hausner): May need to handle BoundedType here. |
| 1888 ASSERT(type.IsType()); | 1890 ASSERT(type.IsType()); |
| 1889 CollectTypeArguments(cls, Type::Cast(type), type_args); | 1891 CollectTypeArguments(cls, Type::Cast(type), type_args); |
| 1890 const Array& mixins = Array::Handle(mixin_app.mixin_types()); | |
| 1891 Class& mixin_app_class = Class::Handle(); | 1892 Class& mixin_app_class = Class::Handle(); |
| 1892 for (int i = 0; i < mixins.Length(); i++) { | 1893 const intptr_t depth = mixin_app.Depth(); |
| 1893 type ^= mixins.At(i); | 1894 for (int i = 0; i < depth; i++) { |
| 1894 ASSERT(type.HasResolvedTypeClass()); // Newly created class in parser. | 1895 mixin_app_class = mixin_app.MixinAppAt(i); |
| 1895 mixin_app_class ^= type.type_class(); | |
| 1896 type = mixin_app_class.mixin(); | 1896 type = mixin_app_class.mixin(); |
| 1897 ASSERT(!type.IsNull()); | 1897 ASSERT(!type.IsNull()); |
| 1898 ResolveType(cls, type, kCanonicalizeWellFormed); | 1898 ResolveType(cls, type, kCanonicalizeWellFormed); |
| 1899 ASSERT(type.HasResolvedTypeClass()); | 1899 ASSERT(type.HasResolvedTypeClass()); |
| 1900 ASSERT(type.IsType()); | 1900 ASSERT(type.IsType()); |
| 1901 CollectTypeArguments(cls, Type::Cast(type), type_args); | 1901 CollectTypeArguments(cls, Type::Cast(type), type_args); |
| 1902 } | 1902 } |
| 1903 const TypeArguments& mixin_app_args = | 1903 const TypeArguments& mixin_app_args = |
| 1904 TypeArguments::Handle(TypeArguments::New(type_args.Length())); | 1904 TypeArguments::Handle(TypeArguments::New(type_args.Length())); |
| 1905 for (int i = 0; i < type_args.Length(); i++) { | 1905 for (int i = 0; i < type_args.Length(); i++) { |
| 1906 type ^= type_args.At(i); | 1906 type ^= type_args.At(i); |
| 1907 mixin_app_args.SetTypeAt(i, type); | 1907 mixin_app_args.SetTypeAt(i, type); |
| 1908 } | 1908 } |
| 1909 if (FLAG_trace_class_finalization) { | 1909 if (FLAG_trace_class_finalization) { |
| 1910 OS::Print("ResolveMixinAppType: mixin appl type args: %s\n", | 1910 OS::Print("ResolveMixinAppType: mixin appl type args: %s\n", |
| 1911 mixin_app_args.ToCString()); | 1911 mixin_app_args.ToCString()); |
| 1912 } | 1912 } |
| 1913 // The last element in the mixins array is the lowest mixin application | 1913 // The mixin application class at depth k is a subclass of mixin application |
| 1914 // type in the mixin chain. Build a new super type with its type class | 1914 // class at depth k - 1. Build a new super type with the class at the highest |
| 1915 // and the collected type arguments from the super type and all | 1915 // depth (the last one processed by the loop above) as the type class and the |
| 1916 // mixin types. This super type replaces the MixinAppType object | 1916 // collected type arguments from the super type and all mixin types. |
| 1917 // in the class that extends the mixin application. | 1917 // This super type replaces the MixinAppType object in the class that extends |
| 1918 type ^= mixins.At(mixins.Length() - 1); | 1918 // the mixin application. |
| 1919 mixin_app_class ^= type.type_class(); | 1919 return Type::New(mixin_app_class, mixin_app_args, mixin_app.token_pos()); |
| 1920 return Type::New(mixin_app_class, | |
| 1921 mixin_app_args, | |
| 1922 mixin_app.token_pos()); | |
| 1923 } | 1920 } |
| 1924 | 1921 |
| 1925 | 1922 |
| 1926 // Recursively walks the graph of explicitly declared super type and | 1923 // Recursively walks the graph of explicitly declared super type and |
| 1927 // interfaces, resolving unresolved super types and interfaces. | 1924 // interfaces, resolving unresolved super types and interfaces. |
| 1928 // Reports an error if there is an interface reference that cannot be | 1925 // Reports an error if there is an interface reference that cannot be |
| 1929 // resolved, or if there is a cycle in the graph. We detect cycles by | 1926 // resolved, or if there is a cycle in the graph. We detect cycles by |
| 1930 // remembering interfaces we've visited in each path through the | 1927 // remembering interfaces we've visited in each path through the |
| 1931 // graph. If we visit an interface a second time on a given path, | 1928 // graph. If we visit an interface a second time on a given path, |
| 1932 // we found a loop. | 1929 // we found a loop. |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 expected_name ^= String::New("_offset"); | 2316 expected_name ^= String::New("_offset"); |
| 2320 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2317 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 2321 field ^= fields_array.At(2); | 2318 field ^= fields_array.At(2); |
| 2322 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2319 ASSERT(field.Offset() == TypedDataView::length_offset()); |
| 2323 name ^= field.name(); | 2320 name ^= field.name(); |
| 2324 ASSERT(name.Equals("length")); | 2321 ASSERT(name.Equals("length")); |
| 2325 #endif | 2322 #endif |
| 2326 } | 2323 } |
| 2327 | 2324 |
| 2328 } // namespace dart | 2325 } // namespace dart |
| OLD | NEW |