123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #include "typeinfo.h"
- #include <stdio.h>
- using namespace ABI_NAMESPACE;
- struct vtable_header
- {
-
- ptrdiff_t leaf_offset;
-
- const __class_type_info *type;
- };
- #define ADD_TO_PTR(x, off) (__typeof__(x))(((char*)x) + off)
- bool std::type_info::__do_catch(std::type_info const *ex_type,
- void **exception_object,
- unsigned int outer) const
- {
- const type_info *type = this;
- if (type == ex_type)
- {
- return true;
- }
- if (const __class_type_info *cti = dynamic_cast<const __class_type_info *>(type))
- {
- return ex_type->__do_upcast(cti, exception_object);
- }
- return false;
- }
- bool __pbase_type_info::__do_catch(std::type_info const *ex_type,
- void **exception_object,
- unsigned int outer) const
- {
- if (ex_type == this)
- {
- return true;
- }
- if (!ex_type->__is_pointer_p())
- {
-
- return false;
- }
- if (!(outer & 1))
- {
-
-
- return false;
- }
-
- if (!(__flags & __const_mask))
- {
- outer &= ~1;
- }
- const __pbase_type_info *ptr_type =
- static_cast<const __pbase_type_info*>(ex_type);
- if (ptr_type->__flags & ~__flags)
- {
-
- return false;
- }
-
- if(*__pointee == typeid(void))
- {
- return true;
- }
- return __pointee->__do_catch(ptr_type->__pointee, exception_object, outer);
- }
- void *__class_type_info::cast_to(void *obj, const struct __class_type_info *other) const
- {
- if (this == other)
- {
- return obj;
- }
- return 0;
- }
- void *__si_class_type_info::cast_to(void *obj, const struct __class_type_info *other) const
- {
- if (this == other)
- {
- return obj;
- }
- return __base_type->cast_to(obj, other);
- }
- bool __si_class_type_info::__do_upcast(const __class_type_info *target,
- void **thrown_object) const
- {
- if (this == target)
- {
- return true;
- }
- return __base_type->__do_upcast(target, thrown_object);
- }
- void *__vmi_class_type_info::cast_to(void *obj, const struct __class_type_info *other) const
- {
- if (__do_upcast(other, &obj))
- {
- return obj;
- }
- return 0;
- }
- bool __vmi_class_type_info::__do_upcast(const __class_type_info *target,
- void **thrown_object) const
- {
- if (this == target)
- {
- return true;
- }
- for (unsigned int i=0 ; i<__base_count ; i++)
- {
- const __base_class_type_info *info = &__base_info[i];
- ptrdiff_t offset = info->offset();
-
-
-
-
-
-
-
- void *obj = *thrown_object;
- if (info->isVirtual())
- {
-
- ptrdiff_t *off = *(ptrdiff_t**)obj;
-
- off = ADD_TO_PTR(off, offset);
- offset = *off;
- }
- void *cast = ADD_TO_PTR(obj, offset);
- if (info->__base_type == target ||
- (info->__base_type->__do_upcast(target, &cast)))
- {
- *thrown_object = cast;
- return true;
- }
- }
- return 0;
- }
- extern "C" void* __dynamic_cast(const void *sub,
- const __class_type_info *src,
- const __class_type_info *dst,
- ptrdiff_t src2dst_offset)
- {
- char *vtable_location = *(char**)sub;
- const vtable_header *header =
- (const vtable_header*)(vtable_location - sizeof(vtable_header));
- void *leaf = ADD_TO_PTR((void*)sub, header->leaf_offset);
- return header->type->cast_to(leaf, dst);
- }
|