typeinfo.cc revision 227825
120425Ssteve#include "typeinfo.h"
220425Ssteve#include <string.h>
320425Ssteve#include <stdlib.h>
420425Ssteve#include <stdio.h>
520425Ssteve
620425Ssteveusing std::type_info;
720425Ssteve
820425Sstevetype_info::~type_info() {}
920425Ssteve
1020425Sstevebool type_info::operator==(const type_info &other) const
1120425Ssteve{
1220425Ssteve	return __type_name == other.__type_name;
1320425Ssteve}
1420425Sstevebool type_info::operator!=(const type_info &other) const
1520425Ssteve{
1620425Ssteve	return __type_name != other.__type_name;
1720425Ssteve}
1820425Sstevebool type_info::before(const type_info &other) const
1920425Ssteve{
2020425Ssteve	return __type_name < other.__type_name;
2120425Ssteve}
2220425Ssteveconst char* type_info::name() const
2320425Ssteve{
2420425Ssteve	return __type_name;
2520425Ssteve}
2620425Sstevetype_info::type_info (const type_info& rhs)
2720425Ssteve{
2832066Salex	__type_name = rhs.__type_name;
2950471Speter}
3020425Sstevetype_info& type_info::operator= (const type_info& rhs)
3120425Ssteve{
32206759Sjilles	return *new type_info(rhs);
3390111Simp}
3490111Simp
35ABI_NAMESPACE::__fundamental_type_info::~__fundamental_type_info() {}
36ABI_NAMESPACE::__array_type_info::~__array_type_info() {}
37ABI_NAMESPACE::__function_type_info::~__function_type_info() {}
38ABI_NAMESPACE::__enum_type_info::~__enum_type_info() {}
39ABI_NAMESPACE::__class_type_info::~__class_type_info() {}
40ABI_NAMESPACE::__si_class_type_info::~__si_class_type_info() {}
41ABI_NAMESPACE::__vmi_class_type_info::~__vmi_class_type_info() {}
42ABI_NAMESPACE::__pbase_type_info::~__pbase_type_info() {}
43ABI_NAMESPACE::__pointer_type_info::~__pointer_type_info() {}
44ABI_NAMESPACE::__pointer_to_member_type_info::~__pointer_to_member_type_info() {}
45
46// From libelftc
47extern "C" char    *__cxa_demangle_gnu3(const char *);
48
49extern "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