The demangle class library contains a small class hierarchy that client programs can use to demangle names and examine the resulting parts of the name. It also provides a C-language interface for use in C programs. Although it is a C++ library, it uses no external C++ features, so you can link it directly to C programs. The demangle library is included as part of libC.a, and is automatically linked, when required, if libC.a is linked.
To demangle a name (represented as a character array), create a dynamic instance of the Name class, providing the character string to the class's constructor. For example, if the compiler mangled X::f(int) to the mangled name f__1XFi, in order to demangle the name, use the following code:
char *rest; Name *name = Demangle(“f__1XFi”, rest) ;
If the supplied character string is not a name that requires demangling, because the original name was not mangled, the Demangle function returns NULL.
Once your program has constructed an instance of class Name, the program could query the instance to find out what kind of name it is, using the Kind method. Using the example of the mangled name f__1XFi, the following code:
name->Kind()
returns MemberFunction.
| To return... | ...use this code: | Result |
|---|---|---|
| The name of the function's qualifier | ((MemberFunctionName *)name)->Scope()->Text() | X |
| The unqualified name of the function | ((MemberFunctionName *)name)->RootName() | f |
| The fully qualified name of the function | ((MemberFunctionName *)name)->Text() | X::f(int) |
For further details about the demangle library and the C++ interface, see the comments in the library's header file, /usr/vacpp/include/demangle.h.