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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 62273003: Use the runtime for generic subsitution of variable types, return types, parameter types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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/lib/mirrors_impl.dart » ('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) 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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 // Fall through case: Indicate that we didn't find any function or field using 834 // Fall through case: Indicate that we didn't find any function or field using
835 // a special null instance. This is different from a field being null. Callers 835 // a special null instance. This is different from a field being null. Callers
836 // make sure that this null does not leak into Dartland. 836 // make sure that this null does not leak into Dartland.
837 return Object::sentinel().raw(); 837 return Object::sentinel().raw();
838 } 838 }
839 839
840 840
841 static RawAbstractType* InstantiateType(const AbstractType& type, 841 static RawAbstractType* InstantiateType(const AbstractType& type,
842 const AbstractType& instantiator) { 842 const AbstractType& instantiator) {
843 ASSERT(type.IsFinalized()); 843 ASSERT(type.IsFinalized());
844 ASSERT(instantiator.IsFinalized());
845 ASSERT(!type.IsMalformed()); 844 ASSERT(!type.IsMalformed());
846 ASSERT(!instantiator.IsMalformed());
847 845
848 if (type.IsInstantiated()) { 846 if (type.IsInstantiated()) {
849 return type.Canonicalize(); 847 return type.Canonicalize();
850 } 848 }
851 849
850 ASSERT(!instantiator.IsNull());
851 ASSERT(instantiator.IsFinalized());
852 ASSERT(!instantiator.IsMalformed());
853
852 const AbstractTypeArguments& type_args = 854 const AbstractTypeArguments& type_args =
853 AbstractTypeArguments::Handle(instantiator.arguments()); 855 AbstractTypeArguments::Handle(instantiator.arguments());
854 Error& bound_error = Error::Handle(); 856 Error& bound_error = Error::Handle();
855 AbstractType& result = 857 AbstractType& result =
856 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error)); 858 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error));
857 if (!bound_error.IsNull()) { 859 if (!bound_error.IsNull()) {
858 ThrowInvokeError(bound_error); 860 ThrowInvokeError(bound_error);
859 UNREACHABLE(); 861 UNREACHABLE();
860 } 862 }
861 ASSERT(result.IsFinalized()); 863 ASSERT(result.IsFinalized());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 977
976 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) { 978 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) {
977 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); 979 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
978 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 980 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
979 const Class& cls = Class::Handle(ref.GetClassReferent()); 981 const Class& cls = Class::Handle(ref.GetClassReferent());
980 const Function& func = Function::Handle(cls.signature_function()); 982 const Function& func = Function::Handle(cls.signature_function());
981 return CreateParameterMirrorList(func, owner); 983 return CreateParameterMirrorList(func, owner);
982 } 984 }
983 985
984 986
985 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { 987 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 2) {
986 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 988 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
989 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType,
990 instantiator,
991 arguments->NativeArgAt(1));
987 const Class& cls = Class::Handle(ref.GetClassReferent()); 992 const Class& cls = Class::Handle(ref.GetClassReferent());
988 const Function& func = Function::Handle(CallMethod(cls)); 993 const Function& func = Function::Handle(CallMethod(cls));
989 ASSERT(!func.IsNull()); 994 ASSERT(!func.IsNull());
990 return func.result_type(); 995 AbstractType& type = AbstractType::Handle(func.result_type());
996 return InstantiateType(type, instantiator);
991 } 997 }
992 998
993 999
994 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { 1000 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) {
995 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1001 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
996 const Class& klass = Class::Handle(ref.GetClassReferent()); 1002 const Class& klass = Class::Handle(ref.GetClassReferent());
997 const Library& library = Library::Handle(klass.library()); 1003 const Library& library = Library::Handle(klass.library());
998 ASSERT(!library.IsNull()); 1004 ASSERT(!library.IsNull());
999 return CreateLibraryMirror(library); 1005 return CreateLibraryMirror(library);
1000 } 1006 }
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 Instance::null_instance()); 1300 Instance::null_instance());
1295 } 1301 }
1296 1302
1297 1303
1298 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { 1304 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) {
1299 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); 1305 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
1300 return param.bound(); 1306 return param.bound();
1301 } 1307 }
1302 1308
1303 1309
1304 DEFINE_NATIVE_ENTRY(TypeVariableMirror_instantiate_from, 2) {
1305 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
1306 GET_NON_NULL_NATIVE_ARGUMENT(Type, instantiator, arguments->NativeArgAt(1));
1307 ASSERT(param.parameterized_class() == instantiator.type_class());
1308 return InstantiateType(param, instantiator);
1309 }
1310
1311
1312 DEFINE_NATIVE_ENTRY(TypedefMirror_instantiate_from, 2) {
1313 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
1314 GET_NON_NULL_NATIVE_ARGUMENT(Type, instantiator, arguments->NativeArgAt(1));
1315 const Class& cls = Class::Handle(type.type_class());
1316 // We represent typedefs as non-canonical signature classes.
1317 ASSERT(cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass());
1318 return InstantiateType(type, instantiator);
1319 }
1320
1321
1322
1323 DEFINE_NATIVE_ENTRY(TypedefMirror_declaration, 1) { 1310 DEFINE_NATIVE_ENTRY(TypedefMirror_declaration, 1) {
1324 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); 1311 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
1325 const Class& cls = Class::Handle(type.type_class()); 1312 const Class& cls = Class::Handle(type.type_class());
1326 // We represent typedefs as non-canonical signature classes. 1313 // We represent typedefs as non-canonical signature classes.
1327 ASSERT(cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass()); 1314 ASSERT(cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass());
1328 return CreateTypedefMirror(cls, 1315 return CreateTypedefMirror(cls,
1329 AbstractType::Handle(cls.DeclarationType()), 1316 AbstractType::Handle(cls.DeclarationType()),
1330 Bool::True(), // is_declaration 1317 Bool::True(), // is_declaration
1331 Object::null_instance()); 1318 Object::null_instance());
1332 } 1319 }
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 1881
1895 1882
1896 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 2) { 1883 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 2) {
1897 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); 1884 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
1898 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1885 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1899 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1886 const Function& func = Function::Handle(ref.GetFunctionReferent());
1900 return CreateParameterMirrorList(func, owner); 1887 return CreateParameterMirrorList(func, owner);
1901 } 1888 }
1902 1889
1903 1890
1904 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { 1891 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 2) {
1905 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1892 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1906 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1893 const Function& func = Function::Handle(ref.GetFunctionReferent());
1894 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1907 // We handle constructors in Dart code. 1895 // We handle constructors in Dart code.
1908 ASSERT(!func.IsConstructor()); 1896 ASSERT(!func.IsConstructor());
1909 return func.result_type(); 1897 const AbstractType& type = AbstractType::Handle(func.result_type());
1898 return InstantiateType(type, instantiator);
1910 } 1899 }
1911 1900
1912 1901
1913 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) { 1902 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) {
1914 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1903 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1915 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1904 const Function& func = Function::Handle(ref.GetFunctionReferent());
1916 const Script& script = Script::Handle(func.script()); 1905 const Script& script = Script::Handle(func.script());
1917 const TokenStream& stream = TokenStream::Handle(script.tokens()); 1906 const TokenStream& stream = TokenStream::Handle(script.tokens());
1918 const TokenStream::Iterator tkit(stream, func.end_token_pos()); 1907 const TokenStream::Iterator tkit(stream, func.end_token_pos());
1919 intptr_t from_line; 1908 intptr_t from_line;
(...skipping 25 matching lines...) Expand all
1945 const Function& sig_func = Function::Handle(cls.signature_function()); 1934 const Function& sig_func = Function::Handle(cls.signature_function());
1946 const Class& sig_cls = Class::Handle(sig_func.signature_class()); 1935 const Class& sig_cls = Class::Handle(sig_func.signature_class());
1947 1936
1948 AbstractType& referent_type = AbstractType::Handle(sig_cls.DeclarationType()); 1937 AbstractType& referent_type = AbstractType::Handle(sig_cls.DeclarationType());
1949 referent_type = InstantiateType(referent_type, type); 1938 referent_type = InstantiateType(referent_type, type);
1950 1939
1951 return CreateFunctionTypeMirror(sig_cls, referent_type); 1940 return CreateFunctionTypeMirror(sig_cls, referent_type);
1952 } 1941 }
1953 1942
1954 1943
1955 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { 1944 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 3) {
1956 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1945 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1957 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); 1946 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1));
1947 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(2));
1958 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1948 const Function& func = Function::Handle(ref.GetFunctionReferent());
1959 return func.ParameterTypeAt(func.NumImplicitParameters() + pos.Value()); 1949 const AbstractType& type = AbstractType::Handle(
1950 func.ParameterTypeAt(func.NumImplicitParameters() + pos.Value()));
1951 return InstantiateType(type, instantiator);
1960 } 1952 }
1961 1953
1962 1954
1963 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1955 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) {
1964 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1956 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1965 const Field& field = Field::Handle(ref.GetFieldReferent()); 1957 const Field& field = Field::Handle(ref.GetFieldReferent());
1966 return field.type(); 1958 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1959 const AbstractType& type = AbstractType::Handle(field.type());
1960 return InstantiateType(type, instantiator);
1967 } 1961 }
1968 1962
1969 } // namespace dart 1963 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698