| 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/mirrors.h" | 5 #include "lib/mirrors.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/bootstrap_natives.h" | 8 #include "vm/bootstrap_natives.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 // Invoke the getter and return the result. | 703 // Invoke the getter and return the result. |
| 704 const Object& result = Object::Handle( | 704 const Object& result = Object::Handle( |
| 705 DartEntry::InvokeFunction(getter, Object::empty_array())); | 705 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 706 return ReturnResult(result); | 706 return ReturnResult(result); |
| 707 } | 707 } |
| 708 return field.StaticValue(); | 708 return field.StaticValue(); |
| 709 } | 709 } |
| 710 | 710 |
| 711 static RawAbstractType* InstantiateType(const AbstractType& type, | 711 static RawAbstractType* InstantiateType(const AbstractType& type, |
| 712 const AbstractType& instantiator) { | 712 const AbstractType& instantiator) { |
| 713 // Generic function type parameters are not reified, but mapped to dynamic. |
| 713 ASSERT(type.IsFinalized()); | 714 ASSERT(type.IsFinalized()); |
| 714 PROPAGATE_IF_MALFORMED(type); | 715 PROPAGATE_IF_MALFORMED(type); |
| 715 ASSERT(type.IsCanonical() || type.IsTypeParameter() || type.IsBoundedType()); | 716 ASSERT(type.IsCanonical() || type.IsTypeParameter() || type.IsBoundedType()); |
| 716 | 717 |
| 717 // TODO(regis): Support uninstantiated type referring to function type params. | 718 if (type.IsInstantiated()) { |
| 718 if (!type.IsInstantiated(kFunctions)) { | |
| 719 UNIMPLEMENTED(); | |
| 720 } | |
| 721 | |
| 722 if (type.IsInstantiated() || instantiator.IsNull()) { | |
| 723 // TODO(regis): Shouldn't type parameters be replaced by dynamic? | |
| 724 return type.Canonicalize(); | 719 return type.Canonicalize(); |
| 725 } | 720 } |
| 726 | 721 TypeArguments& instantiator_type_args = TypeArguments::Handle(); |
| 727 ASSERT(!instantiator.IsNull()); | 722 if (!instantiator.IsNull()) { |
| 728 ASSERT(instantiator.IsFinalized()); | 723 ASSERT(instantiator.IsFinalized()); |
| 729 PROPAGATE_IF_MALFORMED(instantiator); | 724 PROPAGATE_IF_MALFORMED(instantiator); |
| 730 | 725 instantiator_type_args = instantiator.arguments(); |
| 731 const TypeArguments& instantiator_type_args = | 726 } |
| 732 TypeArguments::Handle(instantiator.arguments()); | |
| 733 Error& bound_error = Error::Handle(); | 727 Error& bound_error = Error::Handle(); |
| 734 AbstractType& result = AbstractType::Handle(type.InstantiateFrom( | 728 AbstractType& result = AbstractType::Handle(type.InstantiateFrom( |
| 735 instantiator_type_args, Object::null_type_arguments(), &bound_error, NULL, | 729 instantiator_type_args, Object::null_type_arguments(), &bound_error, NULL, |
| 736 NULL, Heap::kOld)); | 730 NULL, Heap::kOld)); |
| 737 if (!bound_error.IsNull()) { | 731 if (!bound_error.IsNull()) { |
| 738 Exceptions::PropagateError(bound_error); | 732 Exceptions::PropagateError(bound_error); |
| 739 UNREACHABLE(); | 733 UNREACHABLE(); |
| 740 } | 734 } |
| 741 ASSERT(result.IsFinalized()); | 735 ASSERT(result.IsFinalized()); |
| 742 return result.Canonicalize(); | 736 return result.Canonicalize(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 library = klass.library(); | 878 library = klass.library(); |
| 885 } else if (decl.IsFunction() && !Function::Cast(decl).IsSignatureFunction()) { | 879 } else if (decl.IsFunction() && !Function::Cast(decl).IsSignatureFunction()) { |
| 886 klass = Function::Cast(decl).origin(); | 880 klass = Function::Cast(decl).origin(); |
| 887 library = klass.library(); | 881 library = klass.library(); |
| 888 } else if (decl.IsField()) { | 882 } else if (decl.IsField()) { |
| 889 klass = Field::Cast(decl).Origin(); | 883 klass = Field::Cast(decl).Origin(); |
| 890 library = klass.library(); | 884 library = klass.library(); |
| 891 } else if (decl.IsLibrary()) { | 885 } else if (decl.IsLibrary()) { |
| 892 library ^= decl.raw(); | 886 library ^= decl.raw(); |
| 893 } else if (decl.IsTypeParameter()) { | 887 } else if (decl.IsTypeParameter()) { |
| 888 if (TypeParameter::Cast(decl).IsFunctionTypeParameter()) { |
| 889 // TODO(regis): Fully support generic functions. |
| 890 return Object::empty_array().raw(); |
| 891 } |
| 894 klass ^= TypeParameter::Cast(decl).parameterized_class(); | 892 klass ^= TypeParameter::Cast(decl).parameterized_class(); |
| 895 library = klass.library(); | 893 library = klass.library(); |
| 896 } else { | 894 } else { |
| 897 return Object::empty_array().raw(); | 895 return Object::empty_array().raw(); |
| 898 } | 896 } |
| 899 | 897 |
| 900 const Object& metadata = Object::Handle(library.GetMetadata(decl)); | 898 const Object& metadata = Object::Handle(library.GetMetadata(decl)); |
| 901 if (metadata.IsError()) { | 899 if (metadata.IsError()) { |
| 902 Exceptions::PropagateError(Error::Cast(metadata)); | 900 Exceptions::PropagateError(Error::Cast(metadata)); |
| 903 } | 901 } |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 for (intptr_t i = 0; i < num_params; i++) { | 1193 for (intptr_t i = 0; i < num_params; i++) { |
| 1196 arg_type ^= args.TypeAt(i + num_inherited_args); | 1194 arg_type ^= args.TypeAt(i + num_inherited_args); |
| 1197 type_mirror = CreateTypeMirror(arg_type); | 1195 type_mirror = CreateTypeMirror(arg_type); |
| 1198 result.SetAt(i, type_mirror); | 1196 result.SetAt(i, type_mirror); |
| 1199 } | 1197 } |
| 1200 return result.raw(); | 1198 return result.raw(); |
| 1201 } | 1199 } |
| 1202 | 1200 |
| 1203 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { | 1201 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { |
| 1204 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 1202 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 1205 const Class& owner = Class::Handle(param.parameterized_class()); | 1203 Class& owner = Class::Handle(param.parameterized_class()); |
| 1206 const AbstractType& type = AbstractType::Handle(owner.DeclarationType()); | 1204 AbstractType& type = AbstractType::Handle(); |
| 1205 if (owner.IsNull()) { |
| 1206 // TODO(regis): Fully support generic functions. For now, reify function |
| 1207 // type parameters to dynamic and map their function owner to Null class. |
| 1208 ASSERT(param.IsFunctionTypeParameter()); |
| 1209 type = Type::NullType(); |
| 1210 owner = type.type_class(); |
| 1211 } else { |
| 1212 type = owner.DeclarationType(); |
| 1213 } |
| 1207 return CreateClassMirror(owner, type, | 1214 return CreateClassMirror(owner, type, |
| 1208 Bool::True(), // is_declaration | 1215 Bool::True(), // is_declaration |
| 1209 Instance::null_instance()); | 1216 Instance::null_instance()); |
| 1210 } | 1217 } |
| 1211 | 1218 |
| 1212 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { | 1219 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { |
| 1213 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 1220 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 1214 return param.bound(); | 1221 return param.bound(); |
| 1215 } | 1222 } |
| 1216 | 1223 |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 return Instance::null(); // Synthetic. | 1950 return Instance::null(); // Synthetic. |
| 1944 } | 1951 } |
| 1945 script = cls.script(); | 1952 script = cls.script(); |
| 1946 token_pos = cls.token_pos(); | 1953 token_pos = cls.token_pos(); |
| 1947 } else if (decl.IsField()) { | 1954 } else if (decl.IsField()) { |
| 1948 const Field& field = Field::Cast(decl); | 1955 const Field& field = Field::Cast(decl); |
| 1949 script = field.Script(); | 1956 script = field.Script(); |
| 1950 token_pos = field.token_pos(); | 1957 token_pos = field.token_pos(); |
| 1951 } else if (decl.IsTypeParameter()) { | 1958 } else if (decl.IsTypeParameter()) { |
| 1952 const TypeParameter& type_var = TypeParameter::Cast(decl); | 1959 const TypeParameter& type_var = TypeParameter::Cast(decl); |
| 1960 if (type_var.IsFunctionTypeParameter()) { |
| 1961 // TODO(regis): Support generic functions. |
| 1962 return Instance::null(); |
| 1963 } |
| 1953 const Class& owner = Class::Handle(zone, type_var.parameterized_class()); | 1964 const Class& owner = Class::Handle(zone, type_var.parameterized_class()); |
| 1954 script = owner.script(); | 1965 script = owner.script(); |
| 1955 token_pos = type_var.token_pos(); | 1966 token_pos = type_var.token_pos(); |
| 1956 } else if (decl.IsLibrary()) { | 1967 } else if (decl.IsLibrary()) { |
| 1957 const Library& lib = Library::Cast(decl); | 1968 const Library& lib = Library::Cast(decl); |
| 1958 if (lib.raw() == Library::NativeWrappersLibrary()) { | 1969 if (lib.raw() == Library::NativeWrappersLibrary()) { |
| 1959 return Instance::null(); // No source. | 1970 return Instance::null(); // No source. |
| 1960 } | 1971 } |
| 1961 const Array& scripts = Array::Handle(zone, lib.LoadedScripts()); | 1972 const Array& scripts = Array::Handle(zone, lib.LoadedScripts()); |
| 1962 for (intptr_t i = 0; i < scripts.Length(); i++) { | 1973 for (intptr_t i = 0; i < scripts.Length(); i++) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 | 2038 |
| 2028 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { | 2039 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { |
| 2029 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2040 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
| 2030 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2041 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
| 2031 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); | 2042 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); |
| 2032 } | 2043 } |
| 2033 | 2044 |
| 2034 #endif // !DART_PRECOMPILED_RUNTIME | 2045 #endif // !DART_PRECOMPILED_RUNTIME |
| 2035 | 2046 |
| 2036 } // namespace dart | 2047 } // namespace dart |
| OLD | NEW |