/*1* Copyright 2010-2012 PathScale, Inc. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5*6* 1. Redistributions of source code must retain the above copyright notice,7* this list of conditions and the following disclaimer.8*9* 2. Redistributions in binary form must reproduce the above copyright notice,10* this list of conditions and the following disclaimer in the documentation11* and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS14* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,15* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR17* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,18* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;20* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,21* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF23* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include "typeinfo.h"27#include <string.h>28#include <stdlib.h>29#include <stdio.h>3031using std::type_info;3233type_info::~type_info() {}3435bool type_info::operator==(const type_info &other) const36{37return __type_name == other.__type_name;38}39bool type_info::operator!=(const type_info &other) const40{41return __type_name != other.__type_name;42}43bool type_info::before(const type_info &other) const44{45return __type_name < other.__type_name;46}47const char* type_info::name() const48{49return __type_name;50}51type_info::type_info (const type_info& rhs)52{53__type_name = rhs.__type_name;54}55type_info& type_info::operator= (const type_info& rhs)56{57return *new type_info(rhs);58}5960ABI_NAMESPACE::__fundamental_type_info::~__fundamental_type_info() {}61ABI_NAMESPACE::__array_type_info::~__array_type_info() {}62ABI_NAMESPACE::__function_type_info::~__function_type_info() {}63ABI_NAMESPACE::__enum_type_info::~__enum_type_info() {}64ABI_NAMESPACE::__class_type_info::~__class_type_info() {}65ABI_NAMESPACE::__si_class_type_info::~__si_class_type_info() {}66ABI_NAMESPACE::__vmi_class_type_info::~__vmi_class_type_info() {}67ABI_NAMESPACE::__pbase_type_info::~__pbase_type_info() {}68ABI_NAMESPACE::__pointer_type_info::~__pointer_type_info() {}69ABI_NAMESPACE::__pointer_to_member_type_info::~__pointer_to_member_type_info() {}7071// From libelftc72extern "C" char *__cxa_demangle_gnu3(const char *);7374extern "C" char* __cxa_demangle(const char* mangled_name,75char* buf,76size_t* n,77int* status)78{79// TODO: We should probably just be linking against libelf-tc, rather than80// copying their code. This requires them to do an actual release,81// however, and for our changes to be pushed upstream. We also need to82// call a different demangling function here depending on the ABI (e.g.83// ARM).84char *demangled = __cxa_demangle_gnu3(mangled_name);85if (NULL != demangled)86{87size_t len = strlen(demangled);88if (!buf || (*n < len+1))89{90buf = static_cast<char*>(realloc(buf, len+1));91}92if (0 != buf)93{94memcpy(buf, demangled, len);95buf[len] = 0;96if (n)97{98*n = len;99}100if (status)101{102*status = 0;103}104}105else106{107if (status)108{109*status = -1;110}111}112free(demangled);113}114else115{116if (status)117{118*status = -2;119}120return NULL;121}122return buf;123}124125126