|
Boost : |
From: Carlo Wood (carlo_at_[hidden])
Date: 2002-09-05 23:17:01
Ok... what about this:
# headerfile "demangler.h"
namespace boost {
namespace demangler {
// Stuff that I determine.
}
#ifndef BOOST_DEMANGLER_NOINTERFACE // Normally undefined.
std::string demangle(std::string const& symbol);
std::string demangle(std::type_info const& type);
std::string demangle_symbol(char const* symbol);
std::string demangle_type(char const* type);
#endif
} // namespace boost
The 'Stuff that I determine' will then of course
provide an interface that allows to pass an Allocator.
It will be an interface for (other) C++ gurus that
write C++ system libraries on a daily basis ;) :p
(not user-friendly, but powerful and flexible).
I am *completely* open for the interface outside
of namespace demangler, so just tell me what it
should be.
-- Carlo Wood <carlo_at_[hidden]> PS As an example, here follows the implementation of the last two prototypes: namespace boost { std::string demangle_symbol(char const* in) { std::string result; bool failure = false; // // <mangled-name> ::= _Z <encoding> // char const* inp = in; if (*inp != '_') failure = true; else if (*++inp != 'Z') failure = true; else { ++inp; // Skip 'Z' int cnt; if ((cnt = demangler::instance<std::allocator<char> >:: decode_encoding(result, inp, INT_MAX)) < 0 || // Failure to decode encoding, inp[cnt] != 0) // or excess input characters? failure = true; } if (failure) result = in; // Failure to demangle, return the mangled name. return result; } std::string demangle_type(char const* in) { std::string result; if (in == NULL) result = "(null)"; else { demangler::instance<std::allocator<char> > workspace(in, INT_MAX); if (!workspace.decode_type(result) || // Failure to decode type, workspace.current() != 0) // or excess input characters? result = in; // Return the mangled name. } return result; } } // namespace boost from which you can see that the public interface of the guru-stuff is: namespace boost { namespace demangler { template<typename Allocator> class instance { public: static int decode_encoding(std::basic_string<char, std::char_traits<char>, Allocator>& output, char const* input, int maxlen); // Decode an encoding. maxlen is the maximum length of the input string that will be read. If input is // zero terminated, then maxlen can be INT_MAX. explicit instance(char const* input, int maxlen); // Create instance so you can call `decode_type'. bool decode_type(std::basic_string<char, std::char_traits<char>, Allocator>& output, qualifiers_ct<Allocator>* qualifiers = NULL); // Decode a type; qualifiers must be NULL if you are a mortal. char current(void) const; // Read current input character (must be 0 after `decode_type' returns). }; } }
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk