xref: /freebsd/contrib/libcxxrt/typeinfo.cc (revision 675be9115aae86ad6b3d877155d4fd7822892105)
1 #include "typeinfo.h"
2 #include <string.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 
6 using std::type_info;
7 
8 type_info::~type_info() {}
9 
10 bool type_info::operator==(const type_info &other) const
11 {
12 	return __type_name == other.__type_name;
13 }
14 bool type_info::operator!=(const type_info &other) const
15 {
16 	return __type_name != other.__type_name;
17 }
18 bool type_info::before(const type_info &other) const
19 {
20 	return __type_name < other.__type_name;
21 }
22 const char* type_info::name() const
23 {
24 	return __type_name;
25 }
26 type_info::type_info (const type_info& rhs)
27 {
28 	__type_name = rhs.__type_name;
29 }
30 type_info& type_info::operator= (const type_info& rhs)
31 {
32 	return *new type_info(rhs);
33 }
34 
35 ABI_NAMESPACE::__fundamental_type_info::~__fundamental_type_info() {}
36 ABI_NAMESPACE::__array_type_info::~__array_type_info() {}
37 ABI_NAMESPACE::__function_type_info::~__function_type_info() {}
38 ABI_NAMESPACE::__enum_type_info::~__enum_type_info() {}
39 ABI_NAMESPACE::__class_type_info::~__class_type_info() {}
40 ABI_NAMESPACE::__si_class_type_info::~__si_class_type_info() {}
41 ABI_NAMESPACE::__vmi_class_type_info::~__vmi_class_type_info() {}
42 ABI_NAMESPACE::__pbase_type_info::~__pbase_type_info() {}
43 ABI_NAMESPACE::__pointer_type_info::~__pointer_type_info() {}
44 ABI_NAMESPACE::__pointer_to_member_type_info::~__pointer_to_member_type_info() {}
45 
46 // From libelftc
47 extern "C" char    *__cxa_demangle_gnu3(const char *);
48 
49 extern "C" char* __cxa_demangle(const char* mangled_name,
50                                 char* buf,
51                                 size_t* n,
52                                 int* status)
53 {
54 	// TODO: We should probably just be linking against libelf-tc, rather than
55 	// copying their code.  This requires them to do an actual release,
56 	// however, and for our changes to be pushed upstream.  We also need to
57 	// call a different demangling function here depending on the ABI (e.g.
58 	// ARM).
59 	char *demangled = __cxa_demangle_gnu3(mangled_name);
60 	if (NULL != demangled)
61 	{
62 		size_t len = strlen(demangled);
63 		buf = (char*)realloc(buf, len+1);
64 		if (0 != buf)
65 		{
66 			memcpy(buf, demangled, len);
67 			buf[len] = 0;
68 			*n = len;
69 			*status = 0;
70 		}
71 		else
72 		{
73 			*status = -1;
74 		}
75 		free(demangled);
76 	}
77 	else
78 	{
79 		*status = -2;
80 		return NULL;
81 	}
82 	return buf;
83 }
84