1232950Stheraven/* 2232950Stheraven * Copyright 2010-2012 PathScale, Inc. All rights reserved. 3232950Stheraven * 4232950Stheraven * Redistribution and use in source and binary forms, with or without 5232950Stheraven * modification, are permitted provided that the following conditions are met: 6232950Stheraven * 7232950Stheraven * 1. Redistributions of source code must retain the above copyright notice, 8232950Stheraven * this list of conditions and the following disclaimer. 9232950Stheraven * 10232950Stheraven * 2. Redistributions in binary form must reproduce the above copyright notice, 11232950Stheraven * this list of conditions and the following disclaimer in the documentation 12232950Stheraven * and/or other materials provided with the distribution. 13232950Stheraven * 14232950Stheraven * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15232950Stheraven * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16232950Stheraven * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17232950Stheraven * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 18232950Stheraven * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19232950Stheraven * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20232950Stheraven * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21232950Stheraven * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22232950Stheraven * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23232950Stheraven * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24232950Stheraven * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25232950Stheraven */ 26232950Stheraven 27227825Stheraven#include "typeinfo.h" 28227825Stheraven#include <string.h> 29227825Stheraven#include <stdlib.h> 30227825Stheraven#include <stdio.h> 31227825Stheraven 32227825Stheravenusing std::type_info; 33227825Stheraven 34227825Stheraventype_info::~type_info() {} 35227825Stheraven 36227825Stheravenbool type_info::operator==(const type_info &other) const 37227825Stheraven{ 38227825Stheraven return __type_name == other.__type_name; 39227825Stheraven} 40227825Stheravenbool type_info::operator!=(const type_info &other) const 41227825Stheraven{ 42227825Stheraven return __type_name != other.__type_name; 43227825Stheraven} 44227825Stheravenbool type_info::before(const type_info &other) const 45227825Stheraven{ 46227825Stheraven return __type_name < other.__type_name; 47227825Stheraven} 48227825Stheravenconst char* type_info::name() const 49227825Stheraven{ 50227825Stheraven return __type_name; 51227825Stheraven} 52227825Stheraventype_info::type_info (const type_info& rhs) 53227825Stheraven{ 54227825Stheraven __type_name = rhs.__type_name; 55227825Stheraven} 56227825Stheraventype_info& type_info::operator= (const type_info& rhs) 57227825Stheraven{ 58227825Stheraven return *new type_info(rhs); 59227825Stheraven} 60227825Stheraven 61227825StheravenABI_NAMESPACE::__fundamental_type_info::~__fundamental_type_info() {} 62227825StheravenABI_NAMESPACE::__array_type_info::~__array_type_info() {} 63227825StheravenABI_NAMESPACE::__function_type_info::~__function_type_info() {} 64227825StheravenABI_NAMESPACE::__enum_type_info::~__enum_type_info() {} 65227825StheravenABI_NAMESPACE::__class_type_info::~__class_type_info() {} 66227825StheravenABI_NAMESPACE::__si_class_type_info::~__si_class_type_info() {} 67227825StheravenABI_NAMESPACE::__vmi_class_type_info::~__vmi_class_type_info() {} 68227825StheravenABI_NAMESPACE::__pbase_type_info::~__pbase_type_info() {} 69227825StheravenABI_NAMESPACE::__pointer_type_info::~__pointer_type_info() {} 70227825StheravenABI_NAMESPACE::__pointer_to_member_type_info::~__pointer_to_member_type_info() {} 71227825Stheraven 72227825Stheraven// From libelftc 73227825Stheravenextern "C" char *__cxa_demangle_gnu3(const char *); 74227825Stheraven 75227825Stheravenextern "C" char* __cxa_demangle(const char* mangled_name, 76227825Stheraven char* buf, 77227825Stheraven size_t* n, 78227825Stheraven int* status) 79227825Stheraven{ 80227825Stheraven // TODO: We should probably just be linking against libelf-tc, rather than 81227825Stheraven // copying their code. This requires them to do an actual release, 82227825Stheraven // however, and for our changes to be pushed upstream. We also need to 83227825Stheraven // call a different demangling function here depending on the ABI (e.g. 84227825Stheraven // ARM). 85227825Stheraven char *demangled = __cxa_demangle_gnu3(mangled_name); 86227825Stheraven if (NULL != demangled) 87227825Stheraven { 88227825Stheraven size_t len = strlen(demangled); 89315943Sdim if (!buf || (*n < len+1)) 90255815Stheraven { 91278724Sdim buf = static_cast<char*>(realloc(buf, len+1)); 92255815Stheraven } 93227825Stheraven if (0 != buf) 94227825Stheraven { 95227825Stheraven memcpy(buf, demangled, len); 96227825Stheraven buf[len] = 0; 97232950Stheraven if (n) 98232950Stheraven { 99232950Stheraven *n = len; 100232950Stheraven } 101232950Stheraven if (status) 102232950Stheraven { 103232950Stheraven *status = 0; 104232950Stheraven } 105227825Stheraven } 106227825Stheraven else 107227825Stheraven { 108232950Stheraven if (status) 109232950Stheraven { 110232950Stheraven *status = -1; 111232950Stheraven } 112227825Stheraven } 113227825Stheraven free(demangled); 114227825Stheraven } 115227825Stheraven else 116227825Stheraven { 117232950Stheraven if (status) 118232950Stheraven { 119232950Stheraven *status = -2; 120232950Stheraven } 121227825Stheraven return NULL; 122227825Stheraven } 123227825Stheraven return buf; 124227825Stheraven} 125