X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc%2B%2B.so_src%2Ftypeinfo.cc;h=993df3cc5c60df7590ad0f47ca94479b73264c5f;hb=bdfe14e5648c39d8b7e50d5ecd4a6b0ad24321e5;hp=c7cb5bc634467beee85c50ea700898bb1792cfd8;hpb=1a4752fe23a96f47fb83c57861aa991681fa98b0;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc++.so_src/typeinfo.cc b/Usermode/Libraries/libc++.so_src/typeinfo.cc index c7cb5bc6..993df3cc 100644 --- a/Usermode/Libraries/libc++.so_src/typeinfo.cc +++ b/Usermode/Libraries/libc++.so_src/typeinfo.cc @@ -6,7 +6,9 @@ * - typeid and dynamic_cast */ #include +#include #include +#include namespace std { @@ -17,19 +19,19 @@ type_info::~type_info() bool type_info::operator==(const type_info& other) const { - _SysDebug("type_info::operator== - '%s' == '%s'", this->__type_name, other.__type_name); + //_SysDebug("type_info::operator== - '%s' == '%s'", this->__type_name, other.__type_name); return this->__type_name == other.__type_name; } bool type_info::operator!=(const type_info& other) const { - _SysDebug("type_info::operator!= - '%s' != '%s'", this->__type_name, other.__type_name); + //_SysDebug("type_info::operator!= - '%s' != '%s'", this->__type_name, other.__type_name); return this->__type_name != other.__type_name; } bool type_info::before(const type_info& other) const { - _SysDebug("type_info::before - '%s' < '%s'", this->__type_name, other.__type_name); + //_SysDebug("type_info::before - '%s' < '%s'", this->__type_name, other.__type_name); return this->__type_name < other.__type_name; } @@ -49,5 +51,69 @@ type_info& type_info::operator=(const type_info& rhs) return *this; } +bool type_info::is_class() const +{ + if( typeid(*this) == typeid(::__cxxabiv1::__class_type_info) ) + return true; + if( is_subclass() ) + return true; + return false; +} + +bool type_info::is_subclass() const +{ + if( typeid(*this) == typeid(::__cxxabiv1::__si_class_type_info) ) + return true; + if( typeid(*this) == typeid(::__cxxabiv1::__vmi_class_type_info) ) + return true; + return false; +} + +// Acess-defined +bool type_info::__is_child(const type_info &poss_child, unsigned long &offset) const +{ + // Check #1: Child is same type + if( poss_child == *this ) { + offset = 0; + return true; + } + + _SysDebug("typeids = this:%s , poss_child:%s", typeid(*this).name(), typeid(poss_child).name()); + + // Check #2: This type must be a class + if( !this->is_class() ) { + return false; + } + // Check #3: Child class must be a subclass + if( !poss_child.is_subclass() ) { + return false; + } + + if( typeid(poss_child) == typeid(::__cxxabiv1::__si_class_type_info) ) { + auto &si_poss_child = reinterpret_cast(poss_child); + // Single inheritance + _SysDebug("type_info::__is_child - Single inheritance"); + return __is_child( *si_poss_child.__base_type, offset ); + } + else if( typeid(poss_child) == typeid(::__cxxabiv1::__vmi_class_type_info) ) { + // Multiple inheritance + _SysDebug("TODO: type_info::__is_child - Multiple inheritance"); + abort(); + } + else { + // Oops! + _SysDebug("ERROR: type_info::__is_child - Reported subclass type, but not a subclass %s", + typeid(poss_child).name() + ); + abort(); + } +} + + +// NOTE: Not defined by the C++ ABI, but is similar to one defined by GCC (__cxa_type_match +//bool __acess_type_match(std::typeinfo& possibly_derived, const std::typeinfo& base_type) +//{ +// return false; +//} }; // namespace std