Re: Is there a class name macro?
On Sep 17, 10:06 am, tony_in_da...@y ahoo.co.uk wrote:
std::string less_pretty(con st char pretty_func[])
{
const char* p = strrchr(pretty_ func, '(');
BOOTSTRAP_ASSER T(p);
const char* end = p;
while (p[-1] != ':' && p[-1] != ' ')
--p;
BOOTSTRAP_ASSER T(p pretty_func); // should always be space after
type...
const char* fn_name = p;
if (p[-1] == ':')
{
p -= 2;
BOOTSTRAP_ASSER T(p pretty_func && *p == ':');
while (p pretty_func && (isalnum(p[-1]) || p[-1] == '_'))
--p;
// simplify constructors "idn::idn() " back to idn()...
if (strncmp(p, fn_name, fn_name - p - sizeof(" ")) == 0)
p = fn_name;
}
// std::cerr << "less_prett y('" << pretty_func << "') return '"
// << std::string(p, end - p) << "'\n";
return std::string(p, end - p);
}
On Sep 17, 10:06 am, tony_in_da...@y ahoo.co.uk wrote:
On Sep 16, 10:22 am, Peng Yu <PengYu...@gmai l.comwrote:
>
Your question almost answers itself. Just do a little parsing on the
__PRETTY_FUNCTI ON__ string to extract the class name. From quick
thought, I can't see any issue with scanning for '(' then working
backwards to "::" then taking the preceding identifier. You've got it
easy, as the types are already resolved for you - raw source code can
have templated types being instantiated with arbitrary expressions
also containing "(" etc..
__PRETTY_FUNCTI ON__ is a macro that gives function name, etc. I'm
wondering if there is a macro to get the class name inside a member
function.
wondering if there is a macro to get the class name inside a member
function.
Your question almost answers itself. Just do a little parsing on the
__PRETTY_FUNCTI ON__ string to extract the class name. From quick
thought, I can't see any issue with scanning for '(' then working
backwards to "::" then taking the preceding identifier. You've got it
easy, as the types are already resolved for you - raw source code can
have templated types being instantiated with arbitrary expressions
also containing "(" etc..
{
const char* p = strrchr(pretty_ func, '(');
BOOTSTRAP_ASSER T(p);
const char* end = p;
while (p[-1] != ':' && p[-1] != ' ')
--p;
BOOTSTRAP_ASSER T(p pretty_func); // should always be space after
type...
const char* fn_name = p;
if (p[-1] == ':')
{
p -= 2;
BOOTSTRAP_ASSER T(p pretty_func && *p == ':');
while (p pretty_func && (isalnum(p[-1]) || p[-1] == '_'))
--p;
// simplify constructors "idn::idn() " back to idn()...
if (strncmp(p, fn_name, fn_name - p - sizeof(" ")) == 0)
p = fn_name;
}
// std::cerr << "less_prett y('" << pretty_func << "') return '"
// << std::string(p, end - p) << "'\n";
return std::string(p, end - p);
}
Comment