Get __PRETTY_FUNCTION__ working for overloaded functions.

This commit is contained in:
Bill Currie 2011-01-13 16:22:27 +09:00
parent 0c9522b1ca
commit c4d19e6ebc
2 changed files with 37 additions and 1 deletions

View file

@ -430,8 +430,17 @@ new_function (def_t *func, const char *nice_name)
f->s_name = ReuseString (func->name);
f->s_file = pr.source_file;
f->def = func;
if (!(f->name = nice_name))
if (!(f->name = nice_name)) {
const char *s;
f->name = f->def->name;
if ((s = strchr (f->name, '|'))) {
int l = (intptr_t) (s - f->name);
dstring_t *str = dstring_newstr ();
print_type_str (str, f->def->type);
f->name = save_string (va ("%s %.*s", str->str, l, f->name));
dstring_delete (str);
}
}
return f;
}

View file

@ -0,0 +1,27 @@
void printf (string fmt, ...) = #0;
@overload void test (integer x)
{
printf ("\"%s\" %s %d %s\n",
__PRETTY_FUNCTION__, __FUNCTION__, __LINE__, __FILE__);
}
@overload void test (void)
{
printf ("\"%s\" %s %d %s\n",
__PRETTY_FUNCTION__, __FUNCTION__, __LINE__, __FILE__);
}
void foo (void)
{
printf ("\"%s\" %s %d %s\n",
__PRETTY_FUNCTION__, __FUNCTION__, __LINE__, __FILE__);
}
integer main ()
{
test (1);
test ();
foo ();
return 0;
}