Usermode/libc++ - Exception handling implemented (partially)
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / typeinfo.cc
1 /*
2  * Acess2 C++ Library
3  * - By John Hodge (thePowersGang)
4  *
5  * typeinfo.cc
6  * - typeid and dynamic_cast
7  */
8 #include <typeinfo>
9 #include <cxxabi.h>
10 #include <acess/sys.h>
11 #include <cstdlib>
12
13 namespace std {
14
15 type_info::~type_info()
16 {
17         // nop
18 }
19
20 bool type_info::operator==(const type_info& other) const
21 {
22         //_SysDebug("type_info::operator== - '%s' == '%s'", this->__type_name, other.__type_name);
23         return this->__type_name == other.__type_name;
24 }
25
26 bool type_info::operator!=(const type_info& other) const
27 {
28         //_SysDebug("type_info::operator!= - '%s' != '%s'", this->__type_name, other.__type_name);
29         return this->__type_name != other.__type_name;
30 }
31
32 bool type_info::before(const type_info& other) const
33 {
34         //_SysDebug("type_info::before - '%s' < '%s'", this->__type_name, other.__type_name);
35         return this->__type_name < other.__type_name;
36 }
37
38 const char *type_info::name() const
39 {
40         return this->__type_name;
41 }
42
43 // Private
44 type_info::type_info(const type_info& rhs):
45         __type_name(rhs.__type_name)
46 {
47 }
48 type_info& type_info::operator=(const type_info& rhs)
49 {
50         __type_name = rhs.__type_name;
51         return *this;
52 }
53
54 bool type_info::is_class() const
55 {
56         if( typeid(*this) == typeid(::__cxxabiv1::__class_type_info) )
57                 return true;
58         if( is_subclass() )
59                 return true;
60         return false;
61 }
62
63 bool type_info::is_subclass() const
64 {
65         if( typeid(*this) == typeid(::__cxxabiv1::__si_class_type_info) )
66                 return true;
67         if( typeid(*this) == typeid(::__cxxabiv1::__vmi_class_type_info) )
68                 return true;
69         return false;
70 }
71
72 // Acess-defined
73 bool type_info::__is_child(const type_info &poss_child, unsigned long &offset) const
74 {
75         // Check #1: Child is same type
76         if( poss_child == *this ) {
77                 offset = 0;
78                 return true;
79         }
80
81         _SysDebug("typeids = this:%s , poss_child:%s", typeid(*this).name(), typeid(poss_child).name());
82         
83         // Check #2: This type must be a class
84         if( !this->is_class() ) {
85                 return false;
86         }
87         // Check #3: Child class must be a subclass
88         if( !poss_child.is_subclass() ) {
89                 return false;
90         }
91         
92         if( typeid(poss_child) == typeid(::__cxxabiv1::__si_class_type_info) ) {
93                 auto &si_poss_child = reinterpret_cast<const ::__cxxabiv1::__si_class_type_info&>(poss_child);
94                 // Single inheritance
95                 _SysDebug("type_info::__is_child - Single inheritance");
96                 return __is_child( *si_poss_child.__base_type, offset );
97         }
98         else if( typeid(poss_child) == typeid(::__cxxabiv1::__vmi_class_type_info) ) {
99                 // Multiple inheritance
100                 _SysDebug("TODO: type_info::__is_child - Multiple inheritance");
101                 abort();
102         }
103         else {
104                 // Oops!
105                 _SysDebug("ERROR: type_info::__is_child - Reported subclass type, but not a subclass %s",
106                         typeid(poss_child).name()
107                         );
108                 abort();
109         }
110 }
111
112
113 // NOTE: Not defined by the C++ ABI, but is similar to one defined by GCC (__cxa_type_match
114 //bool __acess_type_match(std::typeinfo& possibly_derived, const std::typeinfo& base_type)
115 //{
116 //      return false;
117 //}
118
119 };      // namespace std

UCC git Repository :: git.ucc.asn.au