This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: type_info::name


On Mar  3, 2000, "Martin v. Loewis" <martin@loewis.home.cs.tu-berlin.de> wrote:

>> > Is there a possibility to get a readable class name from type_info::name?
>> 
>> You can link your program with libiberty and use the symbol name
>> demangler in there.

> Can you? What function do I call, and what do I pass it?

I was just dumbly repeating what I had heard before, like a parrot :-)

> I've tried, and it would not demangle, because it expects a mangled
> method or function.

You're probably right.  In any case, you figured out how to do it
right with c++filt, so it's probably just a matter of applying the
same technique when calling cplus_demangle.

In fact, you can simply prepend `__' to the type name, and you'll get
the default constructor for the type (even if doesn't have one):

% echo __t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0 | c++filt
basic_string<char, string_char_traits<char>, __default_alloc_template<1, 0> >::basic_string(void)

So you just have to strip the text after the last two `::'s.

Unfortunately, this doesn't work for built-in types.

Another option, that appears to work for both built-in and
user-defined types, is to prepend foo__F to the symbol name, then
strip the initial `foo(' and the trailing ')' from the resulting
string.

It would definitely be nice to export this functionality directly from
cplus-dem.c.

-- 
Alexandre Oliva     http://www.ic.unicamp.br/~oliva/     Enjoy Guaranį
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]