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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 args.SetAt(2, String::Handle(cls.Name())); | 246 args.SetAt(2, String::Handle(cls.Name())); |
247 args.SetAt(3, Bool::Get(cls.IsGeneric())); | 247 args.SetAt(3, Bool::Get(cls.IsGeneric())); |
248 args.SetAt(4, cls.IsGeneric() ? is_declaration : Bool::False()); | 248 args.SetAt(4, cls.IsGeneric() ? is_declaration : Bool::False()); |
249 args.SetAt(5, owner_mirror); | 249 args.SetAt(5, owner_mirror); |
250 return CreateMirror(Symbols::_LocalTypedefMirror(), args); | 250 return CreateMirror(Symbols::_LocalTypedefMirror(), args); |
251 } | 251 } |
252 | 252 |
253 | 253 |
254 static RawInstance* CreateFunctionTypeMirror(const AbstractType& type) { | 254 static RawInstance* CreateFunctionTypeMirror(const AbstractType& type) { |
255 ASSERT(type.IsFunctionType()); | 255 ASSERT(type.IsFunctionType()); |
256 const Class& cls = Class::Handle(FunctionType::Cast(type).scope_class()); | 256 const Class& cls = Class::Handle(Type::Cast(type).type_class()); |
257 const Function& func = Function::Handle(FunctionType::Cast(type).signature()); | 257 const Function& func = Function::Handle(Type::Cast(type).signature()); |
258 const Array& args = Array::Handle(Array::New(3)); | 258 const Array& args = Array::Handle(Array::New(3)); |
259 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 259 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
260 args.SetAt(1, MirrorReference::Handle(MirrorReference::New(func))); | 260 args.SetAt(1, MirrorReference::Handle(MirrorReference::New(func))); |
261 args.SetAt(2, type); | 261 args.SetAt(2, type); |
262 return CreateMirror(Symbols::_LocalFunctionTypeMirror(), args); | 262 return CreateMirror(Symbols::_LocalFunctionTypeMirror(), args); |
263 } | 263 } |
264 | 264 |
265 | 265 |
266 static RawInstance* CreateMethodMirror(const Function& func, | 266 static RawInstance* CreateMethodMirror(const Function& func, |
267 const Instance& owner_mirror, | 267 const Instance& owner_mirror, |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 AbstractType& ref_type = AbstractType::Handle(TypeRef::Cast(type).type()); | 536 AbstractType& ref_type = AbstractType::Handle(TypeRef::Cast(type).type()); |
537 ASSERT(!ref_type.IsTypeRef()); | 537 ASSERT(!ref_type.IsTypeRef()); |
538 ASSERT(ref_type.IsCanonical()); | 538 ASSERT(ref_type.IsCanonical()); |
539 return CreateTypeMirror(ref_type); | 539 return CreateTypeMirror(ref_type); |
540 } | 540 } |
541 ASSERT(type.IsFinalized()); | 541 ASSERT(type.IsFinalized()); |
542 PROPAGATE_IF_MALFORMED(type); | 542 PROPAGATE_IF_MALFORMED(type); |
543 ASSERT(type.IsCanonical() || type.IsTypeParameter() || type.IsBoundedType()); | 543 ASSERT(type.IsCanonical() || type.IsTypeParameter() || type.IsBoundedType()); |
544 | 544 |
545 if (type.IsFunctionType()) { | 545 if (type.IsFunctionType()) { |
546 const Class& scope_class = | 546 const Class& scope_class = Class::Handle(Type::Cast(type).type_class()); |
547 Class::Handle(FunctionType::Cast(type).scope_class()); | |
548 if (scope_class.IsTypedefClass()) { | 547 if (scope_class.IsTypedefClass()) { |
549 return CreateTypedefMirror(scope_class, | 548 return CreateTypedefMirror(scope_class, |
550 type, Bool::False(), Object::null_instance()); | 549 type, Bool::False(), Object::null_instance()); |
551 } else { | 550 } else { |
552 return CreateFunctionTypeMirror(type); | 551 return CreateFunctionTypeMirror(type); |
553 } | 552 } |
554 } | 553 } |
555 if (type.HasResolvedTypeClass()) { | 554 if (type.HasResolvedTypeClass()) { |
556 const Class& cls = Class::Handle(type.type_class()); | 555 const Class& cls = Class::Handle(type.type_class()); |
557 // Handle void and dynamic types. | 556 // Handle void and dynamic types. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 VerifyMethodKindShifts(); | 818 VerifyMethodKindShifts(); |
820 | 819 |
821 return CreateIsolateMirror(); | 820 return CreateIsolateMirror(); |
822 } | 821 } |
823 | 822 |
824 | 823 |
825 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { | 824 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { |
826 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 825 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
827 PROPAGATE_IF_MALFORMED(type); | 826 PROPAGATE_IF_MALFORMED(type); |
828 ASSERT(type.IsFinalized()); | 827 ASSERT(type.IsFinalized()); |
829 ASSERT(type.IsFunctionType() || type.HasResolvedTypeClass()); | 828 ASSERT(type.HasResolvedTypeClass()); |
830 const Class& cls = Class::Handle(type.type_class()); | 829 const Class& cls = Class::Handle(type.type_class()); |
831 ASSERT(!cls.IsNull()); | 830 ASSERT(!cls.IsNull()); |
832 if (cls.IsDynamicClass() || cls.IsVoidClass() || cls.IsTypedefClass()) { | 831 if (cls.IsDynamicClass() || cls.IsVoidClass() || cls.IsTypedefClass()) { |
833 Exceptions::ThrowArgumentError(type); | 832 Exceptions::ThrowArgumentError(type); |
834 UNREACHABLE(); | 833 UNREACHABLE(); |
835 } | 834 } |
836 return CreateClassMirror(cls, | 835 return CreateClassMirror(cls, |
837 AbstractType::Handle(cls.DeclarationType()), | 836 AbstractType::Handle(cls.DeclarationType()), |
838 Bool::True(), // is_declaration | 837 Bool::True(), // is_declaration |
839 Object::null_instance()); | 838 Object::null_instance()); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 // ObjectMirror.evaluate this will need to be separated. | 1277 // ObjectMirror.evaluate this will need to be separated. |
1279 ASSERT(result.IsClosure()); | 1278 ASSERT(result.IsClosure()); |
1280 const Function& func = Function::Handle(Closure::Cast(result).function()); | 1279 const Function& func = Function::Handle(Closure::Cast(result).function()); |
1281 func.set_is_visible(false); | 1280 func.set_is_visible(false); |
1282 func.set_is_debuggable(false); | 1281 func.set_is_debuggable(false); |
1283 | 1282 |
1284 return result.raw(); | 1283 return result.raw(); |
1285 } | 1284 } |
1286 | 1285 |
1287 DEFINE_NATIVE_ENTRY(TypedefMirror_declaration, 1) { | 1286 DEFINE_NATIVE_ENTRY(TypedefMirror_declaration, 1) { |
1288 GET_NON_NULL_NATIVE_ARGUMENT(FunctionType, type, arguments->NativeArgAt(0)); | 1287 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); |
1289 const Class& cls = Class::Handle(type.scope_class()); | 1288 ASSERT(type.IsFunctionType()); |
| 1289 const Class& cls = Class::Handle(type.type_class()); |
1290 ASSERT(cls.IsTypedefClass()); | 1290 ASSERT(cls.IsTypedefClass()); |
1291 return CreateTypedefMirror(cls, | 1291 return CreateTypedefMirror(cls, |
1292 AbstractType::Handle(cls.DeclarationType()), | 1292 AbstractType::Handle(cls.DeclarationType()), |
1293 Bool::True(), // is_declaration | 1293 Bool::True(), // is_declaration |
1294 Object::null_instance()); | 1294 Object::null_instance()); |
1295 } | 1295 } |
1296 | 1296 |
1297 DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 5) { | 1297 DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 5) { |
1298 // Argument 0 is the mirror, which is unused by the native. It exists | 1298 // Argument 0 is the mirror, which is unused by the native. It exists |
1299 // because this native is an instance method in order to be polymorphic | 1299 // because this native is an instance method in order to be polymorphic |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2036 // information is not available. | 2036 // information is not available. |
2037 script.GetTokenLocation(token_pos, &from_line, NULL); | 2037 script.GetTokenLocation(token_pos, &from_line, NULL); |
2038 } | 2038 } |
2039 // We should always have at least the line number. | 2039 // We should always have at least the line number. |
2040 ASSERT(from_line != 0); | 2040 ASSERT(from_line != 0); |
2041 return CreateSourceLocation(uri, from_line, from_col); | 2041 return CreateSourceLocation(uri, from_line, from_col); |
2042 } | 2042 } |
2043 | 2043 |
2044 | 2044 |
2045 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { | 2045 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { |
2046 GET_NON_NULL_NATIVE_ARGUMENT(FunctionType, type, arguments->NativeArgAt(0)); | 2046 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); |
2047 const Class& cls = Class::Handle(type.scope_class()); | 2047 ASSERT(type.IsFunctionType()); |
| 2048 const Class& cls = Class::Handle(type.type_class()); |
2048 ASSERT(cls.IsTypedefClass()); | 2049 ASSERT(cls.IsTypedefClass()); |
2049 const Function& sig_func = Function::Handle(cls.signature_function()); | 2050 const Function& sig_func = Function::Handle(cls.signature_function()); |
2050 FunctionType& referent_type = FunctionType::Handle(sig_func.SignatureType()); | 2051 Type& referent_type = Type::Handle(sig_func.SignatureType()); |
2051 // If the scope class of the function type is not generic, replace it with | 2052 // If the scope class of the function type is not generic, replace it with |
2052 // Closure class (Function::SignatureType() keeps it). | 2053 // Closure class (Function::SignatureType() keeps it). |
2053 ASSERT(cls.raw() == referent_type.scope_class()); | 2054 ASSERT(cls.raw() == referent_type.type_class()); |
2054 if (!cls.IsGeneric()) { | 2055 if (!cls.IsGeneric()) { |
2055 referent_type = FunctionType::New( | 2056 referent_type = Type::New( |
2056 Class::Handle(Isolate::Current()->object_store()->closure_class()), | 2057 Class::Handle(Isolate::Current()->object_store()->closure_class()), |
2057 TypeArguments::Handle(referent_type.arguments()), | 2058 TypeArguments::Handle(referent_type.arguments()), |
2058 sig_func, | |
2059 referent_type.token_pos()); | 2059 referent_type.token_pos()); |
| 2060 referent_type.set_signature(sig_func); |
2060 referent_type ^= ClassFinalizer::FinalizeType( | 2061 referent_type ^= ClassFinalizer::FinalizeType( |
2061 cls, referent_type, ClassFinalizer::kCanonicalize); | 2062 cls, referent_type, ClassFinalizer::kCanonicalize); |
2062 } | 2063 } |
2063 referent_type ^= InstantiateType(referent_type, type); | 2064 referent_type ^= InstantiateType(referent_type, type); |
2064 return CreateFunctionTypeMirror(referent_type); | 2065 return CreateFunctionTypeMirror(referent_type); |
2065 } | 2066 } |
2066 | 2067 |
2067 | 2068 |
2068 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 3) { | 2069 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 3) { |
2069 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 2070 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
(...skipping 16 matching lines...) Expand all Loading... |
2086 | 2087 |
2087 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { | 2088 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { |
2088 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2089 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
2089 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2090 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
2090 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); | 2091 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); |
2091 } | 2092 } |
2092 | 2093 |
2093 #endif // !PRODUCT | 2094 #endif // !PRODUCT |
2094 | 2095 |
2095 } // namespace dart | 2096 } // namespace dart |
OLD | NEW |