Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "lib/invocation_mirror.h" | 5 #include "lib/invocation_mirror.h" |
| 6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { | 836 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { |
| 837 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 837 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 838 ASSERT(!type.IsMalformed()); | 838 ASSERT(!type.IsMalformed()); |
| 839 ASSERT(type.IsFinalized()); | 839 ASSERT(type.IsFinalized()); |
| 840 ASSERT(type.HasResolvedTypeClass()); | 840 ASSERT(type.HasResolvedTypeClass()); |
| 841 const Class& cls = Class::Handle(type.type_class()); | 841 const Class& cls = Class::Handle(type.type_class()); |
| 842 if (cls.IsDynamicClass() || cls.IsVoidClass()) { | 842 if (cls.IsDynamicClass() || cls.IsVoidClass()) { |
| 843 Exceptions::ThrowArgumentError(type); | 843 Exceptions::ThrowArgumentError(type); |
| 844 UNREACHABLE(); | 844 UNREACHABLE(); |
| 845 } | 845 } |
| 846 const AbstractType& stripped_type = AbstractType::Handle(cls.RareType()); | |
| 847 return CreateClassMirror(cls, | 846 return CreateClassMirror(cls, |
| 848 stripped_type, | 847 AbstractType::Handle(cls.DeclarationType()), |
| 849 Bool::True(), // is_declaration | 848 Bool::True(), // is_declaration |
| 850 Object::null_instance()); | 849 Object::null_instance()); |
| 851 } | 850 } |
| 852 | 851 |
| 853 | 852 |
| 854 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { | 853 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { |
| 855 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 854 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 856 return CreateTypeMirror(type); | 855 return CreateTypeMirror(type); |
| 857 } | 856 } |
| 858 | 857 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 994 result ^= result.Canonicalize(); | 993 result ^= result.Canonicalize(); |
| 995 ASSERT(result.IsType()); | 994 ASSERT(result.IsType()); |
| 996 } | 995 } |
| 997 | 996 |
| 998 ASSERT(result.IsFinalized()); | 997 ASSERT(result.IsFinalized()); |
| 999 return result.raw(); | 998 return result.raw(); |
| 1000 } | 999 } |
| 1001 | 1000 |
| 1002 | 1001 |
| 1003 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { | 1002 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { |
| 1004 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1003 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 1005 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1004 ASSERT(!type.IsMalformed()); |
| 1006 | 1005 ASSERT(type.IsFinalized()); |
| 1007 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 1006 const Class& cls = Class::Handle(type.type_class()); |
|
regis
2013/10/16 23:35:01
If someone passes a TypeParameter as the input typ
rmacnak
2013/10/17 00:15:27
Got 'em.
| |
| 1007 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); | |
| 1008 if (!error.IsNull()) { | 1008 if (!error.IsNull()) { |
| 1009 ThrowInvokeError(error); | 1009 ThrowInvokeError(error); |
| 1010 } | 1010 } |
| 1011 | 1011 |
| 1012 return klass.interfaces(); | 1012 return cls.interfaces(); |
| 1013 } | |
| 1014 | |
| 1015 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces_instantiated, 1) { | |
| 1016 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | |
| 1017 ASSERT(!type.IsMalformed()); | |
| 1018 ASSERT(type.IsFinalized()); | |
| 1019 const Class& cls = Class::Handle(type.type_class()); | |
|
regis
2013/10/16 23:35:01
ditto
| |
| 1020 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); | |
| 1021 if (!error.IsNull()) { | |
| 1022 ThrowInvokeError(error); | |
| 1023 } | |
| 1024 | |
| 1025 AbstractTypeArguments& type_args = | |
| 1026 AbstractTypeArguments::Handle(type.arguments()); | |
| 1027 Error& bound_error = Error::Handle(); | |
| 1028 | |
| 1029 Array& interfaces = Array::Handle(cls.interfaces()); | |
| 1030 Array& interfaces_inst = Array::Handle(Array::New(interfaces.Length())); | |
| 1031 AbstractType& interface = AbstractType::Handle(); | |
| 1032 | |
| 1033 for (int i = 0; i < interfaces.Length(); i++) { | |
| 1034 interface ^= interfaces.At(i); | |
| 1035 ASSERT(interface.IsType()); | |
| 1036 if (!interface.IsInstantiated()) { | |
| 1037 bound_error ^= Object::null(); | |
| 1038 interface ^= interface.InstantiateFrom(type_args, &bound_error); | |
| 1039 if (!bound_error.IsNull()) { | |
| 1040 ThrowInvokeError(bound_error); | |
| 1041 UNREACHABLE(); | |
| 1042 } | |
| 1043 interface ^= interface.Canonicalize(); | |
| 1044 ASSERT(interface.IsType()); | |
| 1045 } | |
| 1046 interfaces_inst.SetAt(i, interface); | |
| 1047 } | |
| 1048 | |
| 1049 return interfaces_inst.raw(); | |
| 1013 } | 1050 } |
| 1014 | 1051 |
| 1015 | 1052 |
| 1016 DEFINE_NATIVE_ENTRY(ClassMirror_mixin, 1) { | 1053 DEFINE_NATIVE_ENTRY(ClassMirror_mixin, 1) { |
| 1017 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1054 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 1018 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1055 ASSERT(!type.IsMalformed()); |
| 1019 return klass.mixin(); | 1056 ASSERT(type.IsFinalized()); |
| 1057 const Class& cls = Class::Handle(type.type_class()); | |
|
regis
2013/10/16 23:35:01
ditto
| |
| 1058 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); | |
| 1059 ASSERT(mixin_type.IsNull() || mixin_type.IsFinalized()); | |
| 1060 return mixin_type.raw(); | |
| 1020 } | 1061 } |
| 1021 | 1062 |
| 1022 | 1063 |
| 1064 DEFINE_NATIVE_ENTRY(ClassMirror_mixin_instantiated, 2) { | |
| 1065 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | |
| 1066 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, | |
| 1067 instantiator, | |
| 1068 arguments->NativeArgAt(1)); | |
| 1069 ASSERT(!type.IsMalformed()); | |
| 1070 ASSERT(type.IsFinalized()); | |
| 1071 const Class& cls = Class::Handle(type.type_class()); | |
|
regis
2013/10/16 23:35:01
ditto
| |
| 1072 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); | |
| 1073 if (mixin_type.IsNull()) { | |
| 1074 return mixin_type.raw(); | |
| 1075 } | |
| 1076 ASSERT(mixin_type.IsFinalized()); | |
| 1077 | |
| 1078 ASSERT(!instantiator.IsMalformed()); | |
| 1079 ASSERT(instantiator.IsFinalized()); | |
| 1080 | |
| 1081 AbstractType& result = AbstractType::Handle(mixin_type.raw()); | |
| 1082 | |
| 1083 ASSERT(mixin_type.IsType()); | |
| 1084 if (!mixin_type.IsInstantiated()) { | |
| 1085 AbstractTypeArguments& type_args = | |
| 1086 AbstractTypeArguments::Handle(instantiator.arguments()); | |
| 1087 Error& bound_error = Error::Handle(); | |
| 1088 result ^= mixin_type.InstantiateFrom(type_args, &bound_error); | |
| 1089 if (!bound_error.IsNull()) { | |
| 1090 ThrowInvokeError(bound_error); | |
| 1091 UNREACHABLE(); | |
| 1092 } | |
| 1093 result ^= result.Canonicalize(); | |
| 1094 ASSERT(result.IsType()); | |
| 1095 } | |
| 1096 | |
| 1097 ASSERT(result.IsFinalized()); | |
| 1098 return result.raw(); | |
| 1099 } | |
| 1100 | |
| 1101 | |
| 1023 DEFINE_NATIVE_ENTRY(ClassMirror_members, 2) { | 1102 DEFINE_NATIVE_ENTRY(ClassMirror_members, 2) { |
| 1024 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | 1103 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
| 1025 owner_mirror, | 1104 owner_mirror, |
| 1026 arguments->NativeArgAt(0)); | 1105 arguments->NativeArgAt(0)); |
| 1027 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1106 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1028 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1107 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1029 | 1108 |
| 1030 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 1109 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); |
| 1031 if (!error.IsNull()) { | 1110 if (!error.IsNull()) { |
| 1032 ThrowInvokeError(error); | 1111 ThrowInvokeError(error); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 AbstractType& type = AbstractType::Handle(); | 1193 AbstractType& type = AbstractType::Handle(); |
| 1115 | 1194 |
| 1116 while (entries.HasNext()) { | 1195 while (entries.HasNext()) { |
| 1117 entry = entries.GetNext(); | 1196 entry = entries.GetNext(); |
| 1118 if (entry.IsClass()) { | 1197 if (entry.IsClass()) { |
| 1119 const Class& klass = Class::Cast(entry); | 1198 const Class& klass = Class::Cast(entry); |
| 1120 // We filter out function signature classes and dynamic. | 1199 // We filter out function signature classes and dynamic. |
| 1121 // TODO(12478): Should not need to filter out dynamic. | 1200 // TODO(12478): Should not need to filter out dynamic. |
| 1122 if (!klass.IsCanonicalSignatureClass() && | 1201 if (!klass.IsCanonicalSignatureClass() && |
| 1123 !klass.IsDynamicClass()) { | 1202 !klass.IsDynamicClass()) { |
| 1124 type = klass.RareType(); | 1203 type = klass.DeclarationType(); |
| 1125 member_mirror = CreateClassMirror(klass, | 1204 member_mirror = CreateClassMirror(klass, |
| 1126 type, | 1205 type, |
| 1127 Bool::True(), // is_declaration | 1206 Bool::True(), // is_declaration |
| 1128 owner_mirror); | 1207 owner_mirror); |
| 1129 member_mirrors.Add(member_mirror); | 1208 member_mirrors.Add(member_mirror); |
| 1130 } | 1209 } |
| 1131 } else if (entry.IsField()) { | 1210 } else if (entry.IsField()) { |
| 1132 const Field& field = Field::Cast(entry); | 1211 const Field& field = Field::Cast(entry); |
| 1133 member_mirror = CreateVariableMirror(field, owner_mirror); | 1212 member_mirror = CreateVariableMirror(field, owner_mirror); |
| 1134 member_mirrors.Add(member_mirror); | 1213 member_mirrors.Add(member_mirror); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1189 type_mirror = CreateTypeMirror(arg_type); | 1268 type_mirror = CreateTypeMirror(arg_type); |
| 1190 result.SetAt(i, type_mirror); | 1269 result.SetAt(i, type_mirror); |
| 1191 } | 1270 } |
| 1192 return result.raw(); | 1271 return result.raw(); |
| 1193 } | 1272 } |
| 1194 | 1273 |
| 1195 | 1274 |
| 1196 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { | 1275 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { |
| 1197 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 1276 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 1198 const Class& owner = Class::Handle(param.parameterized_class()); | 1277 const Class& owner = Class::Handle(param.parameterized_class()); |
| 1199 const AbstractType& type = AbstractType::Handle(owner.RareType()); | 1278 const AbstractType& type = AbstractType::Handle(owner.DeclarationType()); |
| 1200 return CreateClassMirror(owner, | 1279 return CreateClassMirror(owner, |
| 1201 type, | 1280 type, |
| 1202 Bool::True(), // is_declaration | 1281 Bool::True(), // is_declaration |
| 1203 Instance::null_instance()); | 1282 Instance::null_instance()); |
| 1204 } | 1283 } |
| 1205 | 1284 |
| 1206 | 1285 |
| 1207 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { | 1286 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { |
| 1208 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 1287 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 1209 return param.bound(); | 1288 return param.bound(); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1563 internal_constructor_name, | 1642 internal_constructor_name, |
| 1564 lookup_constructor, | 1643 lookup_constructor, |
| 1565 InvocationMirror::kConstructor, | 1644 InvocationMirror::kConstructor, |
| 1566 InvocationMirror::kMethod); | 1645 InvocationMirror::kMethod); |
| 1567 UNREACHABLE(); | 1646 UNREACHABLE(); |
| 1568 } | 1647 } |
| 1569 | 1648 |
| 1570 ASSERT(!type.IsNull()); | 1649 ASSERT(!type.IsNull()); |
| 1571 AbstractTypeArguments& type_arguments = | 1650 AbstractTypeArguments& type_arguments = |
| 1572 AbstractTypeArguments::Handle(type.arguments()); | 1651 AbstractTypeArguments::Handle(type.arguments()); |
| 1652 if (!type.IsInstantiated()) { | |
| 1653 // Must have been a declaration type. | |
| 1654 AbstractType& rare_type = AbstractType::Handle(klass.RareType()); | |
| 1655 ASSERT(rare_type.IsInstantiated()); | |
| 1656 type_arguments = rare_type.arguments(); | |
| 1657 } | |
| 1573 | 1658 |
| 1574 Class& redirected_klass = Class::Handle(klass.raw()); | 1659 Class& redirected_klass = Class::Handle(klass.raw()); |
| 1575 Function& redirected_constructor = Function::Handle(lookup_constructor.raw()); | 1660 Function& redirected_constructor = Function::Handle(lookup_constructor.raw()); |
| 1576 if (lookup_constructor.IsRedirectingFactory()) { | 1661 if (lookup_constructor.IsRedirectingFactory()) { |
| 1577 ClassFinalizer::ResolveRedirectingFactory(klass, lookup_constructor); | 1662 ClassFinalizer::ResolveRedirectingFactory(klass, lookup_constructor); |
| 1578 Type& redirect_type = Type::Handle(lookup_constructor.RedirectionType()); | 1663 Type& redirect_type = Type::Handle(lookup_constructor.RedirectionType()); |
| 1579 | 1664 |
| 1580 if (!redirect_type.IsInstantiated()) { | 1665 if (!redirect_type.IsInstantiated()) { |
| 1581 // The type arguments of the redirection type are instantiated from the | 1666 // The type arguments of the redirection type are instantiated from the |
| 1582 // type arguments of the type reflected by the class mirror. | 1667 // type arguments of the type reflected by the class mirror. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1779 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1864 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1780 if (func.IsNonImplicitClosureFunction()) { | 1865 if (func.IsNonImplicitClosureFunction()) { |
| 1781 return CreateMethodMirror(Function::Handle( | 1866 return CreateMethodMirror(Function::Handle( |
| 1782 func.parent_function()), Object::null_instance()); | 1867 func.parent_function()), Object::null_instance()); |
| 1783 } | 1868 } |
| 1784 const Class& owner = Class::Handle(func.Owner()); | 1869 const Class& owner = Class::Handle(func.Owner()); |
| 1785 if (owner.IsTopLevel()) { | 1870 if (owner.IsTopLevel()) { |
| 1786 return CreateLibraryMirror(Library::Handle(owner.library())); | 1871 return CreateLibraryMirror(Library::Handle(owner.library())); |
| 1787 } | 1872 } |
| 1788 | 1873 |
| 1789 AbstractType& type = AbstractType::Handle(owner.RareType()); | 1874 AbstractType& type = AbstractType::Handle(owner.DeclarationType()); |
| 1790 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance()); | 1875 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance()); |
| 1791 } | 1876 } |
| 1792 | 1877 |
| 1793 | 1878 |
| 1794 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 2) { | 1879 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 2) { |
| 1795 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); | 1880 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); |
| 1796 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1881 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1797 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1882 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1798 return CreateParameterMirrorList(func, owner); | 1883 return CreateParameterMirrorList(func, owner); |
| 1799 } | 1884 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1854 } | 1939 } |
| 1855 | 1940 |
| 1856 | 1941 |
| 1857 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1942 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1858 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1943 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1859 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1944 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1860 return field.type(); | 1945 return field.type(); |
| 1861 } | 1946 } |
| 1862 | 1947 |
| 1863 } // namespace dart | 1948 } // namespace dart |
| OLD | NEW |