From b4dd1b0a89dd74ab36be65f939fad9e0a8d2e830 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 13 Jan 2011 15:30:46 +0900 Subject: [PATCH 1/4] Add some diagnostic variables. __PRETTY_FUNCTION__ __FUNCTION__ __LINE__ and __FILE__ --- tools/qfcc/source/expr.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 5f51defa5..591ae4fb9 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -136,6 +136,25 @@ convert_name (expr_t *e) expr_t *new; class_t *class; + if (!strcmp (name, "__PRETTY_FUNCTION__") + && current_func) { + new = new_string_expr (current_func->name); + goto convert; + } + if (!strcmp (name, "__FUNCTION__") + && current_func) { + new = new_string_expr (current_func->def->name); + goto convert; + } + if (!strcmp (name, "__LINE__")) { + new = new_integer_expr (e->line); + goto convert; + } + if (!strcmp (name, "__FILE__")) { + new = new_string_expr (G_GETSTR (e->file)); + goto convert; + } + /// Convert name to enum (integer constant). new = get_enum (name); if (new) From 0c9522b1ca8b7f53caa9a99ac7d0c793f19d9d3d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 13 Jan 2011 16:21:31 +0900 Subject: [PATCH 2/4] Fix overloaded functions. --- tools/qfcc/source/function.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 9a73a40c5..939d1551f 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -262,6 +262,7 @@ find_function (expr_t *fexpr, expr_t *params) memset (&type, 0, sizeof (type)); + type.type = ev_func; for (e = params; e; e = e->next) { if (e->type == ex_error) return e; From c4d19e6ebc3f54042977347902917768a9c5db9e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 13 Jan 2011 16:22:27 +0900 Subject: [PATCH 3/4] Get __PRETTY_FUNCTION__ working for overloaded functions. --- tools/qfcc/source/function.c | 11 ++++++++++- tools/qfcc/test/file-line.r | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tools/qfcc/test/file-line.r diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 939d1551f..dfee01552 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -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; } diff --git a/tools/qfcc/test/file-line.r b/tools/qfcc/test/file-line.r new file mode 100644 index 000000000..3491f77f5 --- /dev/null +++ b/tools/qfcc/test/file-line.r @@ -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; +} From c0b8d0febeffb6f7f08a04cf69764bf4e89509db Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 13 Jan 2011 16:34:25 +0900 Subject: [PATCH 4/4] Test __PRETTY_FUNCTION__ in methods, too. --- tools/qwaq/test.r | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/qwaq/test.r b/tools/qwaq/test.r index 865212252..dd3fd9512 100644 --- a/tools/qwaq/test.r +++ b/tools/qwaq/test.r @@ -34,7 +34,8 @@ -run { print ("Hello world\n"); - printf ("%i %p\n", self, &self.x); + printf ("%i %p [%s %s]\n", self, &self.x, [self description], + __PRETTY_FUNCTION__); } @end