From 853c670e4b839fd435507201f04d16080590a894 Mon Sep 17 00:00:00 2001 From: George Lebl Date: Mon, 24 Jul 2000 08:16:00 -0800 Subject: [PATCH] Release 1.0.4 --- ChangeLog | 20 ++++ NEWS | 6 + configure | 2 +- configure.in | 2 +- gob.spec | 2 +- src/checks.c | 172 +++++++++++++-------------- src/checks.h | 3 +- src/lexer.c | 108 ++++++++--------- src/lexer.l | 30 ++--- src/main.c | 323 +++++++++++++++++++++++++++++++-------------------- src/out.c | 2 +- src/out.h | 6 +- src/parse.c | 315 +++++++++++++++++++++++++------------------------ src/parse.y | 21 ++-- src/test.gob | 4 + src/util.c | 37 ++++-- src/util.h | 11 +- 17 files changed, 592 insertions(+), 472 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe91ea3..7ebb14a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +Sun Jul 23 18:51:45 2000 George Lebl + + * src/util.[ch], src/main.c, src/checks.c, src/lexer.l, src/parse.y: + make new cleaner error print routines including a printfstyle one. + Use the get_real_id on all method ids even for overrides. When a + signal is added there is also a sizeof check for the signature vs. + argument list with a g_error if it fails. Fix %at{ %} to not + appear twice in all files. + + * src/main.c: Apply patch from Arturo Tena to make things compile + nicely with gcc's -ansi -pedantic + + * src/out.[ch]: constize correctly and use G_GNUC_PRINTF macro for + warnings. + +Fri Jul 21 15:38:10 2000 George Lebl + + * src/main.c: store the private structure pointer so that we + don't look inside the freed object structureafter finalize + Thu Jul 06 02:32:29 2000 George Lebl * Release 1.0.3 diff --git a/NEWS b/NEWS index fdffcc1..3630887 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +1.0.4 + * Fix segfault in finalize + * Minor fixes and improvements + + NOTE: Everyone should update due to the segfault fix! + 1.0.3 * Add "const self", and a _CONST cast macro (Bas van der Linden) * Objects should compile with Glib/GTK+ 1.3 (to become 2.0) diff --git a/configure b/configure index c0f07eb..a2339ed 100755 --- a/configure +++ b/configure @@ -703,7 +703,7 @@ fi PACKAGE=gob -VERSION=1.0.3 +VERSION=1.0.4 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } diff --git a/configure.in b/configure.in index 1ebdb13..9a99c88 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.2) AC_INIT(src/treefuncs.h) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(gob,1.0.3) +AM_INIT_AUTOMAKE(gob,1.0.4) if test -f ../NOINST_GOB ; then DOINSTGOB= diff --git a/gob.spec b/gob.spec index 3a8a30f..5b96604 100644 --- a/gob.spec +++ b/gob.spec @@ -1,4 +1,4 @@ -%define ver 1.0.3 +%define ver 1.0.4 %define rel 1 %define prefix /usr diff --git a/src/checks.c b/src/checks.c index 8bbe1e4..9283309 100644 --- a/src/checks.c +++ b/src/checks.c @@ -41,7 +41,6 @@ check_duplicate(Class *c, Node *node, char *id, int line_no, char *nid; int nline_no; gboolean here_underscore = FALSE; - char *s; if(n->type == METHOD_NODE) { Method *m = (Method *)n; @@ -67,18 +66,18 @@ check_duplicate(Class *c, Node *node, char *id, int line_no, continue; /* this can only happen if the things were methods and * one had an underscore and the other one didn't */ - if(!no_kill_underscores && underscore != here_underscore) - s = g_strdup_printf("symbol '%s' ('_%s') redefined, " - "first defined on line %d. " - "Note that '%s' and '_%s' are " - "eqivalent.", - id, id, line_no, id, id); + if( ! no_kill_underscores && underscore != here_underscore) + error_printf(GOB_ERROR, nline_no, + "symbol '%s' ('_%s') redefined, " + "first defined on line %d. " + "Note that '%s' and '_%s' are " + "eqivalent.", + id, id, line_no, id, id); else - s = g_strdup_printf("symbol '%s' redefined, " - "first defined on line %d", - id, line_no); - print_error(FALSE, s, nline_no); - g_free(s); + error_printf(GOB_ERROR, nline_no, + "symbol '%s' redefined, " + "first defined on line %d", + id, line_no); } } @@ -112,21 +111,19 @@ check_duplicate_override(Class *c, Method *method) for(l = c->nodes; l != NULL; l = g_list_next(l)) { Node *n = l->data; Method *m = (Method *)n; - char *s; if(n->type != METHOD_NODE || m->method != OVERRIDE_METHOD) continue; if(method == m || method->line_no > m->line_no || - strcmp(m->id, method->id) != 0 || + strcmp(get_real_id(m->id), get_real_id(method->id)) != 0 || strcmp(m->otype, method->otype) != 0) continue; - s = g_strdup_printf("override '%s(%s)' redefined, " - "first defined on line %d", - m->id, m->otype, method->line_no); - print_error(FALSE, s, m->line_no); - g_free(s); + error_printf(GOB_ERROR, m->line_no, + "override '%s(%s)' redefined, " + "first defined on line %d", + get_real_id(m->id), m->otype, method->line_no); } } @@ -155,33 +152,31 @@ check_bad_symbols(Class *c) if((m->method == SIGNAL_LAST_METHOD || m->method == SIGNAL_FIRST_METHOD || m->method == VIRTUAL_METHOD) && - strcmp(m->id, "__parent__")==0) { - char *s; - s = g_strdup_printf("'%s' not allowed as an " - "identifier of signal " - "or virtual methods", - m->id); - print_error(FALSE,s,m->line_no); - g_free(s); + (strcmp(m->id, "__parent__")==0 || + strcmp(m->id, "___parent__")==0)) { + error_printf(GOB_ERROR, m->line_no, + "'%s' not allowed as an " + "identifier of signal " + "or virtual methods", + m->id); } if(m->method != INIT_METHOD && m->method != CLASS_INIT_METHOD && - (strcmp(m->id, "init")==0 || - strcmp(m->id, "class_init")==0)) { - print_error(FALSE,"init, or class_init not " + (strcmp(get_real_id(m->id), "init")==0 || + strcmp(get_real_id(m->id), "class_init")==0)) { + error_print(GOB_ERROR, m->line_no, + "init, or class_init not " "allowed as an " "identifier of non-" - "constructor methods", m->line_no); + "constructor methods"); } } else if(n->type == VARIABLE_NODE) { Variable *v = (Variable *)n; if(strcmp(v->id, "_priv")==0 || strcmp(v->id, "__parent__")==0) { - char *s; - s = g_strdup_printf("'%s' not allowed as a " - "data member name", v->id); - print_error(FALSE, s, v->line_no); - g_free(s); + error_printf(GOB_ERROR, v->line_no, + "'%s' not allowed as a " + "data member name", v->id); } } } @@ -195,12 +190,11 @@ check_duplicate_named(Class *c, Node *node, char *id, int line_no) Node *n = l->data; char *nid; int nline_no; - char *s; if(n->type == METHOD_NODE) { Method *m = (Method *)n; if(m->method == SIGNAL_LAST_METHOD || m->method == SIGNAL_FIRST_METHOD) { - nid = m->id; + nid = get_real_id(m->id); nline_no = m->line_no; } else continue; @@ -210,15 +204,15 @@ check_duplicate_named(Class *c, Node *node, char *id, int line_no) nline_no = a->line_no; } else continue; - if(n==node || - line_no>=nline_no || - g_strcasecmp(nid,id)!=0) + if(n == node || + line_no >= nline_no || + g_strcasecmp(nid, id)!=0) continue; - s = g_strdup_printf("named symbol (argument or signal) '%s' " - "redefined, first defined on line %d " - "(case insensitive)", - id,line_no); - print_error(FALSE,s,nline_no); + error_printf(GOB_ERROR, nline_no, + "named symbol (argument or signal) '%s' " + "redefined, first defined on line %d " + "(case insensitive)", + id, line_no); } } @@ -232,10 +226,11 @@ check_duplicate_signals_args(Class *c) Method *m = (Method *)n; if(m->method == SIGNAL_LAST_METHOD || m->method == SIGNAL_FIRST_METHOD) - check_duplicate_named(c,n,m->id,m->line_no); + check_duplicate_named(c, n, get_real_id(m->id), + m->line_no); } else if(n->type == ARGUMENT_NODE) { Argument *a = (Argument *)n; - check_duplicate_named(c,n,a->name,a->line_no); + check_duplicate_named(c, n, a->name, a->line_no); } } } @@ -248,13 +243,12 @@ check_public_new(Class *c) Node *n = l->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; - if((strcmp(m->id,"new")==0) && + if((strcmp(get_real_id(m->id), "new")==0) && (m->method != REGULAR_METHOD || m->scope != PUBLIC_SCOPE)) - print_error(TRUE, + error_print(GOB_WARN, m->line_no, "'new' should be a regular\n" - "public method", - m->line_no); + "public method"); } } } @@ -267,17 +261,16 @@ check_vararg(Class *c) Node *n = l->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; - if(!m->vararg) + if( ! m->vararg) continue; if(m->method == OVERRIDE_METHOD || m->method == SIGNAL_LAST_METHOD || m->method == SIGNAL_FIRST_METHOD || m->method == VIRTUAL_METHOD) { - print_error(FALSE, + error_print(GOB_ERROR, m->line_no, "signals, overrides and virtuals, " "can't have variable argument " - "lists", - m->line_no); + "lists"); } } } @@ -297,10 +290,9 @@ check_firstarg(Class *c) m->method == SIGNAL_LAST_METHOD || m->method == SIGNAL_FIRST_METHOD || m->method == VIRTUAL_METHOD) { - print_error(FALSE, + error_print(GOB_ERROR, m->line_no, "signals, overrides and virtuals, " - "can't have no arguments", - m->line_no); + "can't have no arguments"); } } } @@ -319,11 +311,10 @@ check_nonvoidempty(Class *c) if(!(strcmp(m->mtype->name, "void")==0 && m->mtype->pointer == NULL) && !m->cbuf) { - print_error(TRUE, + error_print(GOB_WARN, m->line_no, "non-void empty method found, " "regular non-void function should " - "not be empty.", - m->line_no); + "not be empty."); /* add a body here, so that the user will also get a warning from gcc, and so that it will at least point him to the prototype of the @@ -349,14 +340,12 @@ check_signal_args(Class *c) continue; for(l=m->gtktypes;l;l=l->next) { - char *s; if(get_cast(l->data, FALSE)) continue; - s = g_strdup_printf("Unknown GTK+ type '%s' " - "among signal types", - (char *)l->data); - print_error(FALSE, s, m->line_no); - g_free(s); + error_printf(GOB_ERROR, m->line_no, + "Unknown GTK+ type '%s' " + "among signal types", + (char *)l->data); } } } @@ -370,17 +359,15 @@ check_argument_types(Class *c) Node *n = l->data; if(n->type == ARGUMENT_NODE) { Argument *a = (Argument *)n; - char *s; if(get_cast(a->gtktype, FALSE)) continue; - s = g_strdup_printf("Unknown GTK+ type '%s' " - "as argument type", - a->gtktype); /* this could perhaps be a warning, but can there really be a type beyond the fundementals? */ - print_error(FALSE, s, a->line_no); - g_free(s); + error_printf(GOB_ERROR, a->line_no, + "Unknown GTK+ type '%s' " + "as argument type", + a->gtktype); } } } @@ -396,8 +383,8 @@ check_func_arg_check_func_arg(Method *m, FuncArg *fa) if(strcmp(fa->atype->name, "void") == 0 && fa->atype->pointer == NULL) { - print_error(FALSE, "Running checks on a void function " - "argument", m->line_no); + error_print(GOB_ERROR, m->line_no, + "Running checks on a void function argument"); return; } @@ -437,13 +424,13 @@ check_func_arg_check_func_arg(Method *m, FuncArg *fa) type_check_error: if(fa->atype->pointer) - s = g_strdup_printf("Cannot check the type of '%s %s'", - fa->atype->name, fa->atype->pointer); + error_printf(GOB_ERROR, m->line_no, + "Cannot check the type of '%s %s'", + fa->atype->name, fa->atype->pointer); else - s = g_strdup_printf("Cannot check the type of '%s'", - fa->atype->name); - print_error(FALSE, s, m->line_no); - g_free(s); + error_printf(GOB_ERROR, m->line_no, + "Cannot check the type of '%s'", + fa->atype->name); } static void @@ -487,13 +474,30 @@ count_signals(Class *c) } int -count_arguments(Class *c) +count_set_arguments(Class *c) +{ + int num = 0; + GList *li; + for(li = c->nodes; li != NULL; li = g_list_next(li)) { + Node *n = li->data; + Argument *a = li->data; + if(n->type == ARGUMENT_NODE && + a->set) + num ++; + } + return num; +} + +int +count_get_arguments(Class *c) { int num = 0; GList *li; for(li = c->nodes; li != NULL; li = g_list_next(li)) { Node *n = li->data; - if(n->type == ARGUMENT_NODE) + Argument *a = li->data; + if(n->type == ARGUMENT_NODE && + a->get) num ++; } return num; diff --git a/src/checks.h b/src/checks.h index a2a5674..ef71b47 100644 --- a/src/checks.h +++ b/src/checks.h @@ -36,7 +36,8 @@ void check_argument_types(Class *c); void check_func_arg_checks(Class *c); int count_signals(Class *c); -int count_arguments(Class *c); +int count_set_arguments(Class *c); +int count_get_arguments(Class *c); int count_overrides(Class *c); int count_privates(Class *c); int count_protecteds(Class *c); diff --git a/src/lexer.c b/src/lexer.c index f1ce73c..fe904e5 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1536,9 +1536,8 @@ YY_RULE_SETUP BEGIN(CLASS_CODE); if(++found_classes > 1) { - print_error(FALSE, - "Only one class per file allowed", - line_no); + error_print(GOB_ERROR, line_no, + "Only one class per file allowed"); } return CLASS; @@ -1549,7 +1548,7 @@ case 52: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 345 "lexer.l" +#line 344 "lexer.l" { int maj = 0,min = 0,pl = 0; int rmaj = 0,rmin = 0,rpl = 0; @@ -1562,151 +1561,146 @@ YY_RULE_SETUP if(rmaj < maj || (rmaj == maj && rmin < min) || (rmaj == maj && rmin == min && rpl < pl)) { - char *s; - s = g_strdup_printf( - "GOB version %d.%d.%d required " - "(this is %s)\n" - "To upgrade your gob, see: " - "http://www.5z.com/jirka/gob.html", - maj,min,pl,VERSION); - print_error(FALSE, s, line_no); - g_free(s); + error_printf(GOB_ERROR, line_no, + "GOB version %d.%d.%d required " + "(this is %s)\n" + "To upgrade your gob, see: " + "http://www.5z.com/jirka/gob.html", + maj, min, pl, VERSION); } } YY_BREAK case 53: YY_RULE_SETUP -#line 369 "lexer.l" +#line 365 "lexer.l" { if(for_cpp) { - char *s; - s = g_strdup_printf("'%s' keyword should not " - "be used when generating " - "C++ code", yytext); - print_error(TRUE, s, line_no); - g_free(s); + error_printf(GOB_WARN, line_no, + "'%s' keyword should not " + "be used when generating " + "C++ code", yytext); } REJECT; } YY_BREAK case 54: YY_RULE_SETUP -#line 381 "lexer.l" +#line 375 "lexer.l" {return FROM;} YY_BREAK case 55: YY_RULE_SETUP -#line 383 "lexer.l" +#line 377 "lexer.l" {return VOID;} YY_BREAK case 56: YY_RULE_SETUP -#line 384 "lexer.l" +#line 378 "lexer.l" {return STRUCT;} YY_BREAK case 57: YY_RULE_SETUP -#line 385 "lexer.l" +#line 379 "lexer.l" {return UNION;} YY_BREAK case 58: YY_RULE_SETUP -#line 386 "lexer.l" +#line 380 "lexer.l" {return ENUM;} YY_BREAK case 59: YY_RULE_SETUP -#line 387 "lexer.l" +#line 381 "lexer.l" {return SIGNED;} YY_BREAK case 60: YY_RULE_SETUP -#line 388 "lexer.l" +#line 382 "lexer.l" {return UNSIGNED;} YY_BREAK case 61: YY_RULE_SETUP -#line 389 "lexer.l" +#line 383 "lexer.l" {return LONG;} YY_BREAK case 62: YY_RULE_SETUP -#line 390 "lexer.l" +#line 384 "lexer.l" {return SHORT;} YY_BREAK case 63: YY_RULE_SETUP -#line 391 "lexer.l" +#line 385 "lexer.l" {return INT;} YY_BREAK case 64: YY_RULE_SETUP -#line 392 "lexer.l" +#line 386 "lexer.l" {return FLOAT;} YY_BREAK case 65: YY_RULE_SETUP -#line 393 "lexer.l" +#line 387 "lexer.l" {return DOUBLE;} YY_BREAK case 66: YY_RULE_SETUP -#line 394 "lexer.l" +#line 388 "lexer.l" {return CHAR;} YY_BREAK case 67: YY_RULE_SETUP -#line 395 "lexer.l" +#line 389 "lexer.l" {return CONST;} YY_BREAK case 68: YY_RULE_SETUP -#line 397 "lexer.l" +#line 391 "lexer.l" {return THREEDOTS;} YY_BREAK case 69: YY_RULE_SETUP -#line 399 "lexer.l" +#line 393 "lexer.l" {yylval.line = line_no; return PUBLIC;} YY_BREAK case 70: YY_RULE_SETUP -#line 400 "lexer.l" +#line 394 "lexer.l" {yylval.line = line_no; return PRIVATE;} YY_BREAK case 71: YY_RULE_SETUP -#line 401 "lexer.l" +#line 395 "lexer.l" {yylval.line = line_no; return PROTECTED;} YY_BREAK case 72: YY_RULE_SETUP -#line 402 "lexer.l" +#line 396 "lexer.l" {yylval.line = line_no; return CLASSWIDE;} YY_BREAK case 73: YY_RULE_SETUP -#line 403 "lexer.l" +#line 397 "lexer.l" {yylval.line = line_no; return ARGUMENT;} YY_BREAK case 74: YY_RULE_SETUP -#line 404 "lexer.l" +#line 398 "lexer.l" {yylval.line = line_no; return VIRTUAL;} YY_BREAK case 75: YY_RULE_SETUP -#line 405 "lexer.l" +#line 399 "lexer.l" {yylval.line = line_no; return SIGNAL;} YY_BREAK case 76: YY_RULE_SETUP -#line 406 "lexer.l" +#line 400 "lexer.l" {yylval.line = line_no; return OVERRIDE;} YY_BREAK case 77: YY_RULE_SETUP -#line 407 "lexer.l" +#line 401 "lexer.l" { yylval.id = g_strdup(yytext); return NUMBER; @@ -1714,7 +1708,7 @@ YY_RULE_SETUP YY_BREAK case 78: YY_RULE_SETUP -#line 411 "lexer.l" +#line 405 "lexer.l" { /* this one is for a classname with a namespace */ yylval.id = g_strdup(yytext); @@ -1723,7 +1717,7 @@ YY_RULE_SETUP YY_BREAK case 79: YY_RULE_SETUP -#line 416 "lexer.l" +#line 410 "lexer.l" { /* this is for a classname with an empty namespace */ yylval.id = g_strdup(yytext); @@ -1732,7 +1726,7 @@ YY_RULE_SETUP YY_BREAK case 80: YY_RULE_SETUP -#line 421 "lexer.l" +#line 415 "lexer.l" { yylval.id = g_strdup(yytext); return TOKEN; @@ -1740,7 +1734,7 @@ YY_RULE_SETUP YY_BREAK case 81: YY_RULE_SETUP -#line 426 "lexer.l" +#line 420 "lexer.l" { yylval.id = g_strdup(yytext); return ARRAY_DIM; @@ -1748,7 +1742,7 @@ YY_RULE_SETUP YY_BREAK case 82: YY_RULE_SETUP -#line 431 "lexer.l" +#line 425 "lexer.l" { BEGIN(CLASS_CODE_I); return '{'; @@ -1756,7 +1750,7 @@ YY_RULE_SETUP YY_BREAK case 83: YY_RULE_SETUP -#line 435 "lexer.l" +#line 429 "lexer.l" { BEGIN(C_CODE); parenth_depth=1; @@ -1769,7 +1763,7 @@ YY_RULE_SETUP YY_BREAK case 84: YY_RULE_SETUP -#line 444 "lexer.l" +#line 438 "lexer.l" { BEGIN(INITIAL); return '}'; @@ -1777,12 +1771,12 @@ YY_RULE_SETUP YY_BREAK case 85: YY_RULE_SETUP -#line 449 "lexer.l" +#line 443 "lexer.l" ; /*ignore*/ YY_BREAK case 86: YY_RULE_SETUP -#line 451 "lexer.l" +#line 445 "lexer.l" { yylval.line = line_no; return yytext[0]; @@ -1790,15 +1784,15 @@ YY_RULE_SETUP YY_BREAK case 87: YY_RULE_SETUP -#line 456 "lexer.l" +#line 450 "lexer.l" ; /*ignore*/ YY_BREAK case 88: YY_RULE_SETUP -#line 458 "lexer.l" +#line 452 "lexer.l" ECHO; YY_BREAK -#line 1802 "lex.yy.c" +#line 1796 "lex.yy.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(COMMENT): case YY_STATE_EOF(C_CODE): @@ -2688,7 +2682,7 @@ int main() return 0; } #endif -#line 458 "lexer.l" +#line 452 "lexer.l" /* Ugly warning avoiding */ diff --git a/src/lexer.l b/src/lexer.l index a33eed0..f45fcc5 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -334,9 +334,8 @@ class { BEGIN(CLASS_CODE); if(++found_classes > 1) { - print_error(FALSE, - "Only one class per file allowed", - line_no); + error_print(GOB_ERROR, line_no, + "Only one class per file allowed"); } return CLASS; @@ -354,26 +353,21 @@ class { if(rmaj < maj || (rmaj == maj && rmin < min) || (rmaj == maj && rmin == min && rpl < pl)) { - char *s; - s = g_strdup_printf( - "GOB version %d.%d.%d required " - "(this is %s)\n" - "To upgrade your gob, see: " - "http://www.5z.com/jirka/gob.html", - maj,min,pl,VERSION); - print_error(FALSE, s, line_no); - g_free(s); + error_printf(GOB_ERROR, line_no, + "GOB version %d.%d.%d required " + "(this is %s)\n" + "To upgrade your gob, see: " + "http://www.5z.com/jirka/gob.html", + maj, min, pl, VERSION); } } class|this { if(for_cpp) { - char *s; - s = g_strdup_printf("'%s' keyword should not " - "be used when generating " - "C++ code", yytext); - print_error(TRUE, s, line_no); - g_free(s); + error_printf(GOB_WARN, line_no, + "'%s' keyword should not " + "be used when generating " + "C++ code", yytext); } REJECT; } diff --git a/src/main.c b/src/main.c index a614e31..e145d64 100644 --- a/src/main.c +++ b/src/main.c @@ -60,7 +60,8 @@ static char *typebase; static char *ptypebase; static int signals = 0; /* number of signals */ -static int arguments = 0; /* number of named arguments */ +static int set_arguments = 0; /* number of named (set) arguments */ +static int get_arguments = 0; /* number of named (get) arguments */ static int overrides = 0; /* number of override methods */ static int privates = 0; /* number of private data members */ static int protecteds = 0; /* number of protected methods */ @@ -164,7 +165,7 @@ get_type(Type *t, gboolean postfix_to_stars) static char * get_gtk_doc(char *id) { - char *val, *s; + char *val; if(!gtk_doc_hash) return NULL; @@ -173,9 +174,7 @@ get_gtk_doc(char *id) if(val) return g_strdup_printf("/**\n * %s_%s:\n%s **/\n", funcbase, get_real_id(id), val); - s = g_strconcat(funcbase, "_", get_real_id(id), NULL); - val = g_hash_table_lookup(gtk_doc_hash, s); - g_free(s); + val = g_hash_table_lookup(gtk_doc_hash, get_real_id(id)); if(val) return g_strdup_printf("/**\n * %s_%s:\n%s **/\n", funcbase, get_real_id(id), val); @@ -334,7 +333,7 @@ add_bad_hack_to_avoid_unused_warnings(Class *c) return; if(!no_gnu) - out_printf(out, "\n\n#ifndef __GNUC__\n"); + out_printf(out, "\n\n#if (!defined __GNUC__) || (defined __GNUC__ && defined __STRICT_ANSI__)\n"); out_printf(out, "/*REALLY BAD HACK\n" " This is to avoid unused warnings if you don't call\n" @@ -364,7 +363,7 @@ add_bad_hack_to_avoid_unused_warnings(Class *c) out_printf(out, "\t___%s_really_bad_hack_to_avoid_warnings();\n", funcbase); if(!no_gnu) - out_printf(out, "}\n#endif /* __GNUC__ */\n\n"); + out_printf(out, "}\n#endif /* !__GNUC__ || (__GNUC__ && __STRICT_ANSI__) */\n\n"); else out_printf(out, "}\n\n"); } @@ -483,8 +482,8 @@ put_priv_method_prot(Method *m) m, FALSE, FALSE, FALSE); g_free(s); } else if(m->scope == PRIVATE_SCOPE || - m->method == INIT_METHOD || - m->method == CLASS_INIT_METHOD) + m->method == INIT_METHOD || + m->method == CLASS_INIT_METHOD) print_method(out, "static ", "", "", " ", no_gnu?";\n":" G_GNUC_UNUSED;\n", m, FALSE, FALSE, TRUE); @@ -520,11 +519,11 @@ make_inits(Class *cl) Method *m = (Method *)n; if(m->method == INIT_METHOD) { if(got_init) - print_error(FALSE, "init defined more then once", m->line_no); + error_print(GOB_ERROR, m->line_no, "init defined more then once"); got_init = TRUE; } else if(m->method == CLASS_INIT_METHOD) { if(got_class_init) - print_error(FALSE, "class_init defined more then once", m->line_no); + error_print(GOB_ERROR, m->line_no, "class_init defined more then once"); got_class_init = TRUE; } } @@ -564,18 +563,16 @@ find_destroy(Class *cl) if(m->method == OVERRIDE_METHOD && strcmp(m->id, "destroy")==0) { if(strcmp(m->otype, "Gtk:Object") != 0) { - print_error(FALSE, + error_print(GOB_ERROR, m->line_no, "destroy method override " "of class other then " - "Gtk:Object", - m->line_no); + "Gtk:Object"); } if(g_list_length(m->args) != 1) { - print_error(FALSE, + error_print(GOB_ERROR, m->line_no, "destroy method override " "with more then one " - "parameter", - m->line_no); + "parameter"); } destroy_handler = m; break; @@ -596,19 +593,19 @@ find_finalize(Class *cl) Method *m = (Method *)n; if(m->method == OVERRIDE_METHOD && strcmp(m->id, "finalize")==0) { - if(strcmp(m->otype, "Gtk:Object") != 0) { - print_error(FALSE, + if(strcmp(m->otype, "Gtk:Object") != 0 && + strcmp(m->otype, "G:Object") != 0) { + error_print(GOB_ERROR, m->line_no, "finalize method override " "of class other then " - "Gtk:Object", - m->line_no); + "Gtk:Object (or G:Object" + "for GTK+ 2.0)"); } if(g_list_length(m->args) != 1) { - print_error(FALSE, + error_print(GOB_ERROR, m->line_no, "finalize method override " "with more then one " - "parameter", - m->line_no); + "parameter"); } finalize_handler = m; break; @@ -766,7 +763,7 @@ add_enums(Class *c) } out_printf(out, "\tLAST_SIGNAL\n};\n\n"); } - if(arguments>0) { + if(set_arguments > 0 || get_arguments > 0) { out_printf(out, "enum {\n\tARG_0"); for(li=c->nodes;li;li=g_list_next(li)) { Node *n = li->data; @@ -898,13 +895,11 @@ make_run_signal_flags(Method *m, gboolean last) break; } /* if we haven't found it in our list */ - if(!flags[i]) { - char *s; - s = g_strdup_printf("Unknown flag '%s' used, " - "perhaps it was misspelled", - flag); - print_error(TRUE, s, m->line_no); - g_free(s); + if( ! flags[i]) { + error_printf(GOB_WARN, m->line_no, + "Unknown flag '%s' used, " + "perhaps it was misspelled", + flag); } g_string_sprintfa(gs, " | GTK_RUN_%s", flag); } @@ -962,19 +957,60 @@ add_signals(Class *c) flags, typebase, get_real_id(m->id), mar, (char *)m->gtktypes->data, - is_none?0:g_list_length(m->gtktypes->next)); + is_none ? 0 : g_list_length(m->gtktypes->next)); g_free(mar); g_free(sig); g_free(flags); - if(!is_none) { + if( ! is_none) { GList *l; - for(l=m->gtktypes->next;l;l=g_list_next(l)) + for(l = m->gtktypes->next; l != NULL; l = l->next) out_printf(out, ",\n\t\t\tGTK_TYPE_%s", (char *)l->data); } out_printf(out, ");\n"); + + if(strcmp(m->gtktypes->data, "NONE") != 0 || + ! is_none) { + GList *gl, *al; + char *sep = ""; + out_printf(out, "\tif("); + if(strcmp(m->gtktypes->data, "NONE") != 0) { + out_printf(out, "%s sizeof(", sep); + print_type(out, m->mtype, FALSE); + out_printf(out, "%s", + m->mtype->postfix ? + m->mtype->postfix : ""); + out_printf(out, ") != sizeof(%s)", + get_cast(m->gtktypes->data, FALSE)); + + sep = " || "; + } + + for(al = m->args->next, gl = m->gtktypes->next; + al != NULL && gl != NULL; + al = al->next, gl = gl->next) { + FuncArg *arg = al->data; + char *gtkarg = gl->data; + + out_printf(out, "%ssizeof(", sep); + print_type(out, arg->atype, FALSE); + out_printf(out, "%s", + arg->atype->postfix ? + arg->atype->postfix : ""); + out_printf(out, ") != sizeof(%s)", + get_cast(gtkarg, FALSE)); + + sep = " || "; + } + out_printf(out, ") {\n" + "\t\tg_error(\"%s line %d: Type mismatch " + "of \\\"%s\\\" signal signature\");\n" + "\t}\n", + filename, m->line_no, get_real_id(m->id)); + + } } out_printf(out, "\tgtk_object_class_add_signals (gtk_object_class,\n" "\t\tobject_signals, LAST_SIGNAL);\n\n"); @@ -1014,12 +1050,12 @@ set_def_handlers(Class *c, char *oname) if(need_destroy && destroy_handler && - strcmp(m->id, "destroy") == 0) + strcmp(get_real_id(m->id), "destroy") == 0) out_printf(out, "\tgtk_object_class->destroy " "= ___destroy;\n"); else if(need_finalize && finalize_handler && - strcmp(m->id, "finalize") == 0) + strcmp(get_real_id(m->id), "finalize") == 0) out_printf(out, "#ifdef G_OBJECT_CLASS\n" "\tg_object_class->finalize = ___finalize;\n" @@ -1029,11 +1065,11 @@ set_def_handlers(Class *c, char *oname) else if(m->cbuf) out_printf(out, "\t%s_class->%s = ___%x_%s_%s;\n", - s, m->id, (guint)m->unique_id, - funcbase, m->id); + s, get_real_id(m->id), (guint)m->unique_id, + funcbase, get_real_id(m->id)); else out_printf(out, "\t%s_class->%s = NULL;\n", - s, m->id); + s, get_real_id(m->id)); } else { if(m->cbuf) out_printf(out, "\t%s->%s = ___real_%s_%s;\n", @@ -1078,6 +1114,8 @@ make_arguments(Class *c) flags = g_string_new("GTK_ARG_READABLE"); else flags = g_string_new("GTK_ARG_WRITABLE"); + + g_assert(a->get || a->set); for(l=a->flags;l;l=g_list_next(l)) { char *flag = l->data; @@ -1085,23 +1123,21 @@ make_arguments(Class *c) if(strcmp(flag, "READWRITE")==0 || strcmp(flag, "READABLE")==0 || strcmp(flag, "WRITABLE")==0) { - print_error(TRUE, "READWRITE, READABLE and " + error_print(GOB_WARN, a->line_no, + "READWRITE, READABLE and " "WRITABLE argument flags are " - "set automatically", a->line_no); + "set automatically"); continue; } - for(i=0;argflags[i];i++) { + for(i = 0; argflags[i]; i++) { if(strcmp(argflags[i], flag)==0) break; } /* if we haven't found it in our list */ - if(!argflags[i]) { - char *s; - s = g_strdup_printf("Unknown flag '%s' used, " - "perhaps it was misspelled", - flag); - print_error(TRUE, s, a->line_no); - g_free(s); + if( ! argflags[i]) { + error_printf(GOB_WARN, a->line_no, + "Unknown flag '%s' used, " + "perhaps it was misspelled", flag); } g_string_sprintfa(flags, " | GTK_ARG_%s", flag); } @@ -1117,9 +1153,11 @@ make_arguments(Class *c) g_string_free(flags, TRUE); } - out_printf(out, - "\n\tgtk_object_class->set_arg = ___object_set_arg;\n" - "\tgtk_object_class->get_arg = ___object_get_arg;\n"); + out_printf(out, "\n"); + if(get_arguments > 0) + out_printf(out, "\tgtk_object_class->get_arg = ___object_get_arg;\n"); + if(set_arguments > 0) + out_printf(out, "\tgtk_object_class->set_arg = ___object_set_arg;\n"); } static void @@ -1199,7 +1237,7 @@ add_destroy(Class *c) c->otype); if(destructors > 0) { - out_printf(out, "\t%s *self G_GNUC_UNUSED = %s (obj_self);\n", + out_printf(out, "\t%s *self = %s (obj_self);\n", typebase, macrobase); } @@ -1230,6 +1268,9 @@ add_destroy(Class *c) } } + out_printf(out, "\treturn;\n"); + if(destructors > 0) + out_printf(out, "\tself = NULL;\n"); out_printf(out, "}\n" "#undef __GOB_FUNCTION__\n\n"); } @@ -1254,6 +1295,7 @@ add_finalize(Class *c) if(privates > 0) { out_printf(out, "\t%s *self = %s (obj_self);\n", typebase, macrobase); + out_printf(out, "\tgpointer priv = self->_priv;\n"); } if(finalize_handler) { @@ -1277,8 +1319,7 @@ add_finalize(Class *c) } if(privates > 0) { - out_printf(out, "\tg_free (self->_priv);\n" - "\tself->_priv = NULL;\n"); + out_printf(out, "\tg_free(priv);\n"); } out_printf(out, "}\n" @@ -1292,6 +1333,9 @@ add_inits(Class *c) for(li=c->nodes;li;li=g_list_next(li)) { Node *n = li->data; Method *m; + + gboolean add_unused_class = FALSE; + if(n->type != METHOD_NODE) continue; m = (Method *)n; @@ -1340,18 +1384,20 @@ add_inits(Class *c) "#define __GOB_FUNCTION__ \"%s::class_init\"\n", c->otype); if(signals > 0 || - arguments > 0 || + set_arguments > 0 || + get_arguments > 0 || need_destroy || need_finalize) { + add_unused_class = TRUE; out_printf(out, "\tGtkObjectClass *" - "gtk_object_class G_GNUC_UNUSED = " + "gtk_object_class = " "(GtkObjectClass*) %s;\n", ((FuncArg *)m->args->data)->name); out_printf(out, "#ifdef G_OBJECT_CLASS\n" "\tGObjectClass *" - "g_object_class G_GNUC_UNUSED = " + "g_object_class = " "(GObjectClass*) %s;\n" "#endif /* G_OBJECT_CLASS */\n", ((FuncArg *)m->args->data)->name); @@ -1370,10 +1416,9 @@ add_inits(Class *c) li = li->next) { Node *n = li->data; Variable *v = (Variable *)n; - if(n->type != VARIABLE_NODE || - v->scope != CLASS_SCOPE) - continue; - print_initializer(m, v); + if(n->type == VARIABLE_NODE && + v->scope == CLASS_SCOPE) + print_initializer(m, v); } } @@ -1401,7 +1446,7 @@ add_inits(Class *c) "\tgtk_object_class->finalize = ___finalize;\n" "#endif /* G_OBJECT_CLASS */\n"); - if(arguments > 0) + if(get_arguments > 0 || set_arguments > 0) make_arguments(c); } else @@ -1413,8 +1458,17 @@ add_inits(Class *c) out_printf(out, "%s\n", m->cbuf); out_addline_outfile(out); out_printf(out, " }\n"); - } else { - out_printf(out, "return;\n"); + } + out_printf(out, "\treturn;\n"); + out_printf(out, + "\t%s = NULL;\n", + ((FuncArg *)m->args->data)->name); + if(add_unused_class) { + out_printf(out, + "\tgtk_object_class = NULL;\n" + "#ifdef G_OBJECT_CLASS\n" + "\tg_object_class = NULL;\n" + "#endif /* G_OBJECT_CLASS */\n"); } out_printf(out, "}\n" "#undef __GOB_FUNCTION__\n"); @@ -1466,7 +1520,7 @@ add_getset_arg(Class *c, gboolean is_set) "((%s)GTK_VALUE_%s(*arg))\n", cast, a->gtktype); } else { - out_printf(out, "#ifdef __GNUC__\n"); + out_printf(out, "#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\n"); if(strcmp(a->gtktype, "OBJECT")==0) { out_printf(out, "#define ARG " "({%s foo = " @@ -1480,11 +1534,11 @@ add_getset_arg(Class *c, gboolean is_set) "foo; })\n", cast, a->gtktype); } - out_printf(out, "#else /* __GNUC__ */\n"); + out_printf(out, "#else /* __GNUC__ && !__STRICT_ANSI__ */\n"); out_printf(out, "#define ARG " "((%s)GTK_VALUE_%s(*arg))\n", cast, a->gtktype); - out_printf(out, "#endif /* __GNUC__ */\n\n"); + out_printf(out, "#endif /* __GNUC__ && !__STRICT_ANSI__ */\n\n"); } out_printf(out, "\t\t{\n"); g_free(cast); @@ -1507,7 +1561,8 @@ add_getset_arg(Class *c, gboolean is_set) out_printf(out, "\t\t}\n\t\tbreak;\n" "#undef ARG\n"); } - out_printf(out, "\tdefault:\n\t\tbreak;\n\t}\n}\n" + out_printf(out, "\tdefault:\n\t\tbreak;\n\t}\n" + "\treturn;\n\tself = NULL;\n\targ = NULL;\n}\n" "#undef __GOB_FUNCTION__\n"); } @@ -1812,13 +1867,13 @@ put_method(Method *m) out_printf(out, "#define PARENT_HANDLER(%s) \\\n" "\t{ if(%s_CLASS(parent_class)->%s) \\\n" "\t\t(* %s_CLASS(parent_class)->%s)(%s); }\n", - args, s, m->id, s, m->id, args); + args, s, get_real_id(m->id), s, get_real_id(m->id), args); } else { out_printf(out, "#define PARENT_HANDLER(%s) \\\n" "\t((%s_CLASS(parent_class)->%s)? \\\n" "\t\t(* %s_CLASS(parent_class)->%s)(%s): \\\n" "\t\t(", - args, s, m->id, s, m->id, args); + args, s, get_real_id(m->id), s, get_real_id(m->id), args); out_printf(out, "("); print_type(out, m->mtype, TRUE); out_printf(out, ")%s))\n", @@ -1886,7 +1941,7 @@ put_argument_nongnu_wrappers(Class *c) { GList *li; - if(arguments<0) + if(get_arguments < 0 && set_arguments < 0) return; for(li=c->nodes;li;li=g_list_next(li)) { @@ -1935,7 +1990,7 @@ put_argument_gnu_wrappers(Class *c) { GList *li; - if(arguments<0) + if(get_arguments < 0 && set_arguments < 0) return; for(li=c->nodes;li;li=g_list_next(li)) { @@ -2204,11 +2259,13 @@ print_class_block(Class *c) out_printf(outh, "};\n\n"); out_printf(out, "/* here are local prototypes */\n"); - if(arguments > 0) { + if(set_arguments > 0) { out_printf(out, "static void ___object_set_arg " "(GtkObject *object, GtkArg *arg, " - "guint arg_id);\n" - "static void ___object_get_arg " + "guint arg_id);\n"); + } + if(get_arguments > 0) { + out_printf(out, "static void ___object_get_arg " "(GtkObject *object, GtkArg *arg, " "guint arg_id);\n"); } @@ -2246,20 +2303,22 @@ print_class_block(Class *c) /* argument wrapping macros */ - if(arguments > 0 && ! no_gnu) { - out_printf(outh, "\n/*\n" - " * Argument wrapping macros\n" - " */\n"); - out_printf(outh, "#ifdef __GNUC__\n"); - put_argument_gnu_wrappers(c); - out_printf(outh, "#else /* __GNUC__ */\n"); - put_argument_nongnu_wrappers(c); - out_printf(outh, "#endif /* __GNUC__ */\n\n"); - } else if(arguments > 0 && no_gnu) { - out_printf(outh, "\n/*\n" - " * Argument wrapping macros\n" - " */\n"); - put_argument_nongnu_wrappers(c); + if(get_arguments > 0 || set_arguments > 0) { + if( ! no_gnu) { + out_printf(outh, "\n/*\n" + " * Argument wrapping macros\n" + " */\n"); + out_printf(outh, "#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\n"); + put_argument_gnu_wrappers(c); + out_printf(outh, "#else /* __GNUC__ && !__STRICT_ANSI__ */\n"); + put_argument_nongnu_wrappers(c); + out_printf(outh, "#endif /* __GNUC__ && !__STRICT_ANSI__ */\n\n"); + } else { + out_printf(outh, "\n/*\n" + " * Argument wrapping macros\n" + " */\n"); + put_argument_nongnu_wrappers(c); + } } if(signals > 0) { @@ -2278,11 +2337,11 @@ print_class_block(Class *c) if(no_gnu) make_method_nongnu_aliases(c); else { - out_printf(out, "\n#ifdef __GNUC__\n"); + out_printf(out, "\n#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\n"); make_method_gnu_aliases(c); - out_printf(out, "#else /* __GNUC__ */\n"); + out_printf(out, "#else /* __GNUC__ && !__STRICT_ANSI__ */\n"); make_method_nongnu_aliases(c); - out_printf(out, "#endif /* __GNUC__ */\n\n"); + out_printf(out, "#endif /* __GNUC__ && !__STRICT_ANSI__ */\n\n"); } } @@ -2299,8 +2358,11 @@ print_class_block(Class *c) add_inits(c); - if(arguments > 0) { + if(set_arguments > 0) { add_getset_arg(c, TRUE); + } + + if(get_arguments > 0) { add_getset_arg(c, FALSE); } @@ -2346,12 +2408,14 @@ print_includes(void) char *p; /* We may need string.h for memset */ - if(destructors > 0) + if(destructors > 0 && + ! g_list_find_custom(include_files, "string.h", (GCompareFunc)strcmp)) { out_printf(out, "#include /* memset() */\n\n"); + } p = g_strconcat(filebase, ".h", NULL); found_header = TRUE; - if(!g_list_find_custom(include_files, p, (GCompareFunc)strcmp)) { + if( ! g_list_find_custom(include_files, p, (GCompareFunc)strcmp)) { out_printf(out, "#include \"%s.h\"\n\n", filebase); found_header = FALSE; } @@ -2360,11 +2424,12 @@ print_includes(void) /* if we are creating a private header see if it was included */ if(outph) { p = g_strconcat(filebase, "-private.h", NULL); - if(!g_list_find_custom(include_files, p, (GCompareFunc)strcmp)) { + if( ! g_list_find_custom(include_files, p, + (GCompareFunc)strcmp)) { out_printf(out, "#include \"%s-private.h\"\n\n", filebase); if(found_header) - print_error(TRUE, + error_printf(GOB_WARN, 0, "Implicit private header include " "added to top of\n" "\tsource file, while public " @@ -2372,7 +2437,7 @@ print_includes(void) "you should\n" "\texplicitly include " "the private header below the " - "public one.", 0); + "public one."); } g_free(p); } @@ -2392,7 +2457,7 @@ print_header_prefixes(void) "#include \"%s.h\"\n\n", p, p, filebase); g_free(p); - if(!no_extern_c) { + if( ! no_extern_c) { out_printf(outh, "#ifdef __cplusplus\n" "extern \"C\" {\n" "#endif /* __cplusplus */\n\n"); @@ -2406,13 +2471,13 @@ print_header_prefixes(void) static void print_header_postfixes(void) { - if(!no_extern_c) + if( ! no_extern_c) out_printf(outh, "\n#ifdef __cplusplus\n" "}\n" "#endif /* __cplusplus */\n"); out_printf(outh, "\n#endif\n"); if(outph) { - if(!no_extern_c) + if( ! no_extern_c) out_printf(outph, "\n#ifdef __cplusplus\n" "}\n" "#endif /* __cplusplus */\n"); @@ -2426,11 +2491,11 @@ print_all_top(void) GList *li; /* print the AT_CCODE blocks */ - for(li=nodes;li;li=g_list_next(li)) { + for(li = nodes; li != NULL; li = li->next) { Node *node = li->data; if(node->type == CCODE_NODE) { CCode *cc = (CCode *)node; - if(cc->cctype==AT_CCODE) + if(cc->cctype == AT_CCODE) print_ccode_block((CCode *)node); } } @@ -2449,7 +2514,7 @@ print_header_top(void) Node *node = li->data; if(node->type == CCODE_NODE) { CCode *cc = (CCode *)node; - if(cc->cctype==HT_CCODE) + if(cc->cctype == HT_CCODE) print_ccode_block((CCode *)node); } } @@ -2476,7 +2541,8 @@ generate_outfiles(void) Node *node = li->data; if(node->type == CCODE_NODE) { CCode *cc = (CCode *)node; - if(cc->cctype!=HT_CCODE) + if(cc->cctype != HT_CCODE && + cc->cctype != AT_CCODE) print_ccode_block((CCode *)node); } else if(node->type == CLASS_NODE) { print_class_block((Class *)node); @@ -2535,8 +2601,9 @@ parse_options(int argc, char *argv[]) filename = NULL; - for(i=1;i /dev/null", hf, hfnew); - if(system(s)==0) { - if(unlink(hfnew)!=0) - print_error(FALSE, - "Can't remove new header file", 0); + if(system(s) == 0) { + if(unlink(hfnew) != 0) + error_printf(GOB_ERROR, 0, + "Can't remove new header file"); g_free(hfnew); g_free(hf); g_free(s); return; } g_free(s); - if(unlink(hf)!=0) - print_error(FALSE, "Can't remove old header file", 0); + if(unlink(hf) != 0) + error_printf(GOB_ERROR, 0, + "Can't remove old header file"); } - if(rename(hfnew, hf)!=0) - print_error(FALSE, "Can't rename new header file", 0); + if(rename(hfnew, hf) != 0) + error_printf(GOB_ERROR, 0, + "Can't rename new header file"); g_free(hfnew); g_free(hf); } @@ -2658,17 +2727,20 @@ main(int argc, char *argv[]) } else filename = "stdin"; + /* This is where parsing is done */ /*yydebug = 1;*/ - if(yyparse()!=0) + if(yyparse() != 0) g_error("Parsing errors, quitting"); - if(!class) - print_error(FALSE, " no class defined", 0); + + if( ! class) + error_print(GOB_ERROR, 0, " no class defined"); exit_on_error = FALSE; signals = count_signals((Class *)class); - arguments = count_arguments((Class *)class); + set_arguments = count_set_arguments((Class *)class); + get_arguments = count_get_arguments((Class *)class); overrides = count_overrides((Class *)class); privates = count_privates((Class *)class); protecteds = count_protecteds((Class *)class); @@ -2717,7 +2789,8 @@ main(int argc, char *argv[]) fclose(outph); } - if(no_touch_headers && !no_write) + if(no_touch_headers && + ! no_write) compare_and_move_header(); return 0; diff --git a/src/out.c b/src/out.c index 0803893..56fe459 100644 --- a/src/out.c +++ b/src/out.c @@ -24,7 +24,7 @@ strchrcnt(char *s, char c) } void -out_printf(FILE *fp, char *format,...) +out_printf(FILE *fp, const char *format,...) { va_list ap; char *s; diff --git a/src/out.h b/src/out.h index 4e9b0f7..f9bce58 100644 --- a/src/out.h +++ b/src/out.h @@ -24,8 +24,8 @@ #include -void out_printf(FILE *fp,char *format,...); -void out_addline_infile(FILE *fp, int line); -void out_addline_outfile(FILE *fp); +void out_printf (FILE *fp, const char *format, ...) G_GNUC_PRINTF (2, 3); +void out_addline_infile (FILE *fp, int line); +void out_addline_outfile (FILE *fp); #endif diff --git a/src/parse.c b/src/parse.c index c41f9e4..9fdfed3 100644 --- a/src/parse.c +++ b/src/parse.c @@ -163,18 +163,18 @@ push_function(int scope, int method, char *oid, char *id, !(g_list_length(funcargs) == 1 && g_list_length(gtktypes) == 2 && strcmp(gtktypes->next->data, "NONE")==0)) { - print_error(TRUE, _("The number of GTK arguments and " - "function arguments for a signal " - "don't seem to match"), line_no); + error_print(GOB_WARN, line_no, + _("The number of GTK arguments and " + "function arguments for a signal " + "don't seem to match")); } if(g_list_length(gtktypes) > 2) { GList *li; for(li = gtktypes->next; li; li = li->next) { if(strcmp(li->data, "NONE")==0) { - print_error(FALSE, + error_print(GOB_ERROR, line_no, _("NONE can only appear in an " - "argument list by itself"), - line_no); + "argument list by itself")); } } } @@ -274,7 +274,6 @@ static Variable * find_var_or_die(const char *id, int line) { GList *li; - char *s; for(li = class_nodes; li != NULL; li = li->next) { Variable *var; @@ -286,8 +285,7 @@ find_var_or_die(const char *id, int line) return var; } - s = g_strdup_printf(_("Variable %s not defined here"), id); - print_error(FALSE, s, line); + error_printf(GOB_ERROR, line, _("Variable %s not defined here"), id); g_assert_not_reached(); return NULL; @@ -313,7 +311,7 @@ set_return_value(char *type, char *val) } -#line 295 "parse.y" +#line 293 "parse.y" typedef union { char *id; GString *cbuf; @@ -445,20 +443,20 @@ static const short yyrhs[] = { 52, #if YYDEBUG != 0 static const short yyrline[] = { 0, - 313, 314, 315, 316, 319, 325, 331, 337, 343, 349, - 357, 358, 361, 366, 373, 378, 379, 387, 398, 399, - 402, 403, 404, 405, 408, 409, 410, 411, 414, 427, - 443, 447, 455, 456, 457, 458, 459, 465, 468, 472, - 508, 537, 612, 621, 627, 628, 631, 634, 640, 644, - 651, 654, 657, 661, 665, 669, 674, 682, 686, 691, - 695, 698, 702, 705, 710, 711, 712, 713, 714, 715, - 716, 717, 718, 721, 722, 723, 726, 727, 728, 732, - 739, 751, 757, 769, 781, 784, 790, 795, 798, 803, - 804, 808, 824, 840, 856, 872, 883, 889, 899, 922, - 933, 952, 958, 959, 965, 966, 977, 988, 999, 1009, - 1019, 1029, 1032, 1033, 1036, 1037, 1040, 1043, 1046, 1054, - 1064, 1065, 1068, 1081, 1085, 1089, 1093, 1097, 1101, 1107, - 1108, 1112 + 311, 312, 313, 314, 317, 323, 329, 335, 341, 347, + 355, 356, 359, 364, 371, 376, 377, 385, 396, 397, + 400, 401, 402, 403, 406, 407, 408, 409, 412, 425, + 441, 445, 453, 454, 455, 456, 457, 463, 466, 470, + 506, 535, 609, 618, 624, 625, 628, 631, 637, 641, + 648, 651, 654, 658, 662, 666, 671, 679, 683, 688, + 692, 695, 699, 702, 707, 708, 709, 710, 711, 712, + 713, 714, 715, 718, 719, 720, 723, 724, 725, 729, + 736, 748, 754, 766, 778, 781, 787, 792, 795, 800, + 801, 805, 821, 837, 853, 869, 880, 886, 896, 919, + 930, 949, 955, 956, 962, 963, 974, 985, 996, 1006, + 1016, 1026, 1029, 1030, 1033, 1034, 1037, 1040, 1043, 1051, + 1061, 1062, 1065, 1078, 1082, 1086, 1090, 1094, 1098, 1104, + 1105, 1109 }; #endif @@ -1224,23 +1222,23 @@ yyreduce: switch (yyn) { case 1: -#line 313 "parse.y" +#line 311 "parse.y" { ; ; break;} case 2: -#line 314 "parse.y" +#line 312 "parse.y" { ; ; break;} case 3: -#line 315 "parse.y" +#line 313 "parse.y" { ; ; break;} case 4: -#line 316 "parse.y" +#line 314 "parse.y" { ; ; break;} case 5: -#line 319 "parse.y" +#line 317 "parse.y" { Node *node = new_ccode(C_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1249,7 +1247,7 @@ case 5: ; break;} case 6: -#line 325 "parse.y" +#line 323 "parse.y" { Node *node = new_ccode(H_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1258,7 +1256,7 @@ case 6: ; break;} case 7: -#line 331 "parse.y" +#line 329 "parse.y" { Node *node = new_ccode(HT_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1267,7 +1265,7 @@ case 7: ; break;} case 8: -#line 337 "parse.y" +#line 335 "parse.y" { Node *node = new_ccode(PH_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1276,7 +1274,7 @@ case 8: ; break;} case 9: -#line 343 "parse.y" +#line 341 "parse.y" { Node *node = new_ccode(A_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1285,7 +1283,7 @@ case 9: ; break;} case 10: -#line 349 "parse.y" +#line 347 "parse.y" { Node *node = new_ccode(AT_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1294,15 +1292,15 @@ case 10: ; break;} case 11: -#line 357 "parse.y" +#line 355 "parse.y" { ; ; break;} case 12: -#line 358 "parse.y" +#line 356 "parse.y" { ; ; break;} case 13: -#line 361 "parse.y" +#line 359 "parse.y" { ((Class *)class)->nodes = class_nodes; class_nodes = NULL; @@ -1310,7 +1308,7 @@ case 13: ; break;} case 14: -#line 366 "parse.y" +#line 364 "parse.y" { ((Class *)class)->nodes = NULL; class_nodes = NULL; @@ -1318,13 +1316,13 @@ case 14: ; break;} case 15: -#line 373 "parse.y" +#line 371 "parse.y" { class = new_class(yyvsp[-3].id,yyvsp[-1].id,chunk_size,NULL); ; break;} case 17: -#line 379 "parse.y" +#line 377 "parse.y" { if(strcmp(yyvsp[-2].id,"chunks") == 0) { chunk_size = g_strdup(yyvsp[0].id); @@ -1335,7 +1333,7 @@ case 17: ; break;} case 18: -#line 387 "parse.y" +#line 385 "parse.y" { if(strcmp(yyvsp[-2].id,"chunks") == 0) { if(atoi(yyvsp[0].id) != 0) @@ -1347,47 +1345,47 @@ case 18: ; break;} case 19: -#line 398 "parse.y" +#line 396 "parse.y" { ; ; break;} case 20: -#line 399 "parse.y" +#line 397 "parse.y" { ; ; break;} case 21: -#line 402 "parse.y" +#line 400 "parse.y" { ; ; break;} case 22: -#line 403 "parse.y" +#line 401 "parse.y" { ; ; break;} case 23: -#line 404 "parse.y" +#line 402 "parse.y" { ; ; break;} case 24: -#line 405 "parse.y" +#line 403 "parse.y" { ; ; break;} case 25: -#line 408 "parse.y" +#line 406 "parse.y" { the_scope = PUBLIC_SCOPE; ; break;} case 26: -#line 409 "parse.y" +#line 407 "parse.y" { the_scope = PRIVATE_SCOPE; ; break;} case 27: -#line 410 "parse.y" +#line 408 "parse.y" { the_scope = PROTECTED_SCOPE; ; break;} case 28: -#line 411 "parse.y" +#line 409 "parse.y" { the_scope = CLASS_SCOPE; ; break;} case 29: -#line 414 "parse.y" +#line 412 "parse.y" { if(strcmp(yyvsp[-1].id, "destroywith")==0) { g_free(yyvsp[-1].id); @@ -1403,7 +1401,7 @@ case 29: ; break;} case 30: -#line 427 "parse.y" +#line 425 "parse.y" { if(strcmp(yyvsp[-2].id, "destroy")==0) { g_free(yyvsp[-2].id); @@ -1420,14 +1418,14 @@ case 30: ; break;} case 31: -#line 443 "parse.y" +#line 441 "parse.y" { initializer = yyvsp[0].id; initializer_line = ccode_line; ; break;} case 32: -#line 447 "parse.y" +#line 445 "parse.y" { initializer = (yyvsp[0].cbuf)->str; initializer_line = ccode_line; @@ -1435,42 +1433,42 @@ case 32: ; break;} case 33: -#line 455 "parse.y" +#line 453 "parse.y" { ; ; break;} case 34: -#line 456 "parse.y" +#line 454 "parse.y" { ; ; break;} case 35: -#line 457 "parse.y" +#line 455 "parse.y" { destructor = NULL; ; break;} case 36: -#line 458 "parse.y" +#line 456 "parse.y" { initializer = NULL; ; break;} case 37: -#line 459 "parse.y" +#line 457 "parse.y" { destructor = NULL; initializer = NULL; ; break;} case 38: -#line 465 "parse.y" +#line 463 "parse.y" { push_variable(yyvsp[-2].id, the_scope,yyvsp[-4].line, NULL); ; break;} case 39: -#line 468 "parse.y" +#line 466 "parse.y" { push_variable(yyvsp[-3].id, the_scope, yyvsp[-5].line, yyvsp[-2].id); ; break;} case 40: -#line 472 "parse.y" +#line 470 "parse.y" { if(strcmp(yyvsp[-6].id,"get")==0 && strcmp(yyvsp[-3].id,"set")==0) { @@ -1509,7 +1507,7 @@ case 40: ; break;} case 41: -#line 508 "parse.y" +#line 506 "parse.y" { if(strcmp(yyvsp[-3].id, "get") == 0) { Node *node; @@ -1541,7 +1539,7 @@ case 41: ; break;} case 42: -#line 537 "parse.y" +#line 535 "parse.y" { Node *node; char *get, *set = NULL; @@ -1568,9 +1566,8 @@ case 42: else if(var->scope == CLASS_SCOPE) { root = "SELF_GET_CLASS(self)"; if(no_self_alias) - print_error(FALSE, - _("Self aliases needed when autolinking to a classwide member"), - yyvsp[-4].line); + error_print(GOB_ERROR, yyvsp[-4].line, + _("Self aliases needed when autolinking to a classwide member")); } else root = "self"; @@ -1617,7 +1614,7 @@ case 42: ; break;} case 43: -#line 612 "parse.y" +#line 609 "parse.y" { if(strcmp(yyvsp[-2].id,"type")!=0) { g_free(yyvsp[-4].id); @@ -1629,81 +1626,81 @@ case 43: ; break;} case 44: -#line 621 "parse.y" +#line 618 "parse.y" { yyval.id = yyvsp[0].id; typestack = g_list_prepend(typestack,NULL); ; break;} case 45: -#line 627 "parse.y" +#line 624 "parse.y" { yyval.list = yyvsp[-1].list; ; break;} case 46: -#line 628 "parse.y" +#line 625 "parse.y" { yyval.list = NULL; ; break;} case 47: -#line 631 "parse.y" +#line 628 "parse.y" { yyval.list = g_list_append(yyvsp[0].list,yyvsp[-2].id); ; break;} case 48: -#line 634 "parse.y" +#line 631 "parse.y" { yyval.list = g_list_append(NULL,yyvsp[0].id); ; break;} case 49: -#line 640 "parse.y" +#line 637 "parse.y" { Node *node = new_type(yyvsp[-1].id, yyvsp[0].id, NULL); typestack = g_list_prepend(typestack,node); ; break;} case 50: -#line 644 "parse.y" +#line 641 "parse.y" { Node *node = new_type(yyvsp[0].id, NULL, NULL); typestack = g_list_prepend(typestack,node); ; break;} case 51: -#line 651 "parse.y" +#line 648 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 52: -#line 654 "parse.y" +#line 651 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 53: -#line 657 "parse.y" +#line 654 "parse.y" { yyval.id = g_strconcat("const ", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 54: -#line 661 "parse.y" +#line 658 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " const", NULL); g_free(yyvsp[-1].id); ; break;} case 55: -#line 665 "parse.y" +#line 662 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " ", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 56: -#line 669 "parse.y" +#line 666 "parse.y" { yyval.id = g_strconcat("const ", yyvsp[-1].id, " ", yyvsp[0].id, NULL); @@ -1711,7 +1708,7 @@ case 56: ; break;} case 57: -#line 674 "parse.y" +#line 671 "parse.y" { yyval.id = g_strconcat(yyvsp[-2].id, " ", yyvsp[-1].id, " const", NULL); @@ -1719,14 +1716,14 @@ case 57: ; break;} case 58: -#line 682 "parse.y" +#line 679 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " ", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 59: -#line 686 "parse.y" +#line 683 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " ", yyvsp[0].id, NULL); g_free(yyvsp[-1].id); @@ -1734,109 +1731,109 @@ case 59: ; break;} case 60: -#line 691 "parse.y" +#line 688 "parse.y" { yyval.id = g_strconcat("const ", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 61: -#line 695 "parse.y" +#line 692 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 62: -#line 698 "parse.y" +#line 695 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " const", NULL); g_free(yyvsp[-1].id); ; break;} case 63: -#line 702 "parse.y" +#line 699 "parse.y" { yyval.id = g_strdup(yyvsp[0].id); ; break;} case 64: -#line 705 "parse.y" +#line 702 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " const", NULL); ; break;} case 65: -#line 710 "parse.y" +#line 707 "parse.y" { yyval.id = "void"; ; break;} case 66: -#line 711 "parse.y" +#line 708 "parse.y" { yyval.id = "char"; ; break;} case 67: -#line 712 "parse.y" +#line 709 "parse.y" { yyval.id = "short"; ; break;} case 68: -#line 713 "parse.y" +#line 710 "parse.y" { yyval.id = "int"; ; break;} case 69: -#line 714 "parse.y" +#line 711 "parse.y" { yyval.id = "long"; ; break;} case 70: -#line 715 "parse.y" +#line 712 "parse.y" { yyval.id = "float"; ; break;} case 71: -#line 716 "parse.y" +#line 713 "parse.y" { yyval.id = "double"; ; break;} case 72: -#line 717 "parse.y" +#line 714 "parse.y" { yyval.id = "signed"; ; break;} case 73: -#line 718 "parse.y" +#line 715 "parse.y" { yyval.id = "unsigned"; ; break;} case 74: -#line 721 "parse.y" +#line 718 "parse.y" { yyval.id = "struct"; ; break;} case 75: -#line 722 "parse.y" +#line 719 "parse.y" { yyval.id = "union"; ; break;} case 76: -#line 723 "parse.y" +#line 720 "parse.y" { yyval.id = "enum"; ; break;} case 77: -#line 726 "parse.y" +#line 723 "parse.y" { yyval.id = g_strdup("*"); ; break;} case 78: -#line 727 "parse.y" +#line 724 "parse.y" { yyval.id = g_strdup("* const"); ; break;} case 79: -#line 728 "parse.y" +#line 725 "parse.y" { yyval.id = g_strconcat("*", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 80: -#line 732 "parse.y" +#line 729 "parse.y" { yyval.id = g_strconcat("* const", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 81: -#line 739 "parse.y" +#line 736 "parse.y" { if(strcmp(yyvsp[-1].id, "first")==0) yyval.sigtype = SIGNAL_FIRST_METHOD; @@ -1851,13 +1848,13 @@ case 81: ; break;} case 82: -#line 751 "parse.y" +#line 748 "parse.y" { yyval.sigtype = SIGNAL_LAST_METHOD; ; break;} case 83: -#line 757 "parse.y" +#line 754 "parse.y" { if(strcmp(yyvsp[-1].id,"first")==0) yyval.sigtype = SIGNAL_FIRST_METHOD; @@ -1872,7 +1869,7 @@ case 83: ; break;} case 84: -#line 769 "parse.y" +#line 766 "parse.y" { if(strcmp(yyvsp[-2].id,"first")==0) yyval.sigtype = SIGNAL_FIRST_METHOD; @@ -1887,46 +1884,46 @@ case 84: ; break;} case 85: -#line 781 "parse.y" +#line 778 "parse.y" { yyval.sigtype = SIGNAL_LAST_METHOD; ; break;} case 86: -#line 784 "parse.y" +#line 781 "parse.y" { /* the_scope was default thus public */ the_scope = PUBLIC_SCOPE; ; break;} case 87: -#line 790 "parse.y" +#line 787 "parse.y" { gtktypes = g_list_prepend(gtktypes, yyvsp[-3].id); ; break;} case 88: -#line 795 "parse.y" +#line 792 "parse.y" { gtktypes = g_list_append(gtktypes, yyvsp[0].id); ; break;} case 89: -#line 798 "parse.y" +#line 795 "parse.y" { gtktypes = g_list_append(gtktypes, yyvsp[0].id); ; break;} case 90: -#line 803 "parse.y" +#line 800 "parse.y" { yyval.cbuf = yyvsp[0].cbuf; ; break;} case 91: -#line 804 "parse.y" +#line 801 "parse.y" { yyval.cbuf = NULL; ; break;} case 92: -#line 808 "parse.y" +#line 805 "parse.y" { if(!has_self) { yyerror(_("signal without 'self' as " @@ -1945,7 +1942,7 @@ case 92: ; break;} case 93: -#line 824 "parse.y" +#line 821 "parse.y" { if(!has_self) { yyerror(_("signal without 'self' as " @@ -1964,7 +1961,7 @@ case 93: ; break;} case 94: -#line 840 "parse.y" +#line 837 "parse.y" { if(!has_self) { yyerror(_("virtual method without 'self' as " @@ -1983,7 +1980,7 @@ case 94: ; break;} case 95: -#line 856 "parse.y" +#line 853 "parse.y" { if(!has_self) { yyerror(_("virtual method without 'self' as " @@ -2002,7 +1999,7 @@ case 95: ; break;} case 96: -#line 872 "parse.y" +#line 869 "parse.y" { if(!has_self) { yyerror(_("virtual method without 'self' as " @@ -2016,7 +2013,7 @@ case 96: ; break;} case 97: -#line 883 "parse.y" +#line 880 "parse.y" { push_function(NO_SCOPE, OVERRIDE_METHOD, yyvsp[-8].id, yyvsp[-5].id, yyvsp[0].cbuf, @@ -2025,7 +2022,7 @@ case 97: ; break;} case 98: -#line 889 "parse.y" +#line 886 "parse.y" { if(the_scope == CLASS_SCOPE) { yyerror(_("a method cannot be of class scope")); @@ -2038,7 +2035,7 @@ case 98: ; break;} case 99: -#line 899 "parse.y" +#line 896 "parse.y" { if(strcmp(yyvsp[-4].id, "init")==0) { push_init_arg(yyvsp[-2].id,FALSE); @@ -2062,7 +2059,7 @@ case 99: ; break;} case 100: -#line 922 "parse.y" +#line 919 "parse.y" { g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; @@ -2076,7 +2073,7 @@ case 100: ; break;} case 101: -#line 933 "parse.y" +#line 930 "parse.y" { g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; @@ -2098,29 +2095,29 @@ case 101: ; break;} case 102: -#line 952 "parse.y" +#line 949 "parse.y" { g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; ; break;} case 103: -#line 958 "parse.y" +#line 955 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 104: -#line 959 "parse.y" +#line 956 "parse.y" { yyval.id = (yyvsp[1].cbuf)->str; g_string_free(yyvsp[1].cbuf, FALSE); ; break;} case 105: -#line 965 "parse.y" +#line 962 "parse.y" { vararg = FALSE; has_self = FALSE; ; break;} case 106: -#line 966 "parse.y" +#line 963 "parse.y" { vararg = FALSE; has_self = TRUE; @@ -2134,7 +2131,7 @@ case 106: ; break;} case 107: -#line 977 "parse.y" +#line 974 "parse.y" { vararg = FALSE; has_self = TRUE; @@ -2148,7 +2145,7 @@ case 107: ; break;} case 108: -#line 988 "parse.y" +#line 985 "parse.y" { vararg = FALSE; has_self = TRUE; @@ -2162,7 +2159,7 @@ case 108: ; break;} case 109: -#line 999 "parse.y" +#line 996 "parse.y" { has_self = TRUE; if(strcmp(yyvsp[-2].id,"self")==0) @@ -2175,7 +2172,7 @@ case 109: ; break;} case 110: -#line 1009 "parse.y" +#line 1006 "parse.y" { has_self = TRUE; if(strcmp(yyvsp[-3].id,"self")==0) @@ -2188,7 +2185,7 @@ case 110: ; break;} case 111: -#line 1019 "parse.y" +#line 1016 "parse.y" { has_self = TRUE; if(strcmp(yyvsp[-2].id,"self")==0) @@ -2201,39 +2198,39 @@ case 111: ; break;} case 112: -#line 1029 "parse.y" +#line 1026 "parse.y" { has_self = FALSE; ; break;} case 113: -#line 1032 "parse.y" +#line 1029 "parse.y" { vararg = TRUE; ; break;} case 114: -#line 1033 "parse.y" +#line 1030 "parse.y" { vararg = FALSE; ; break;} case 115: -#line 1036 "parse.y" +#line 1033 "parse.y" { ; ; break;} case 116: -#line 1037 "parse.y" +#line 1034 "parse.y" { ; ; break;} case 117: -#line 1040 "parse.y" +#line 1037 "parse.y" { push_funcarg(yyvsp[0].id,NULL); ; break;} case 118: -#line 1043 "parse.y" +#line 1040 "parse.y" { push_funcarg(yyvsp[-1].id,yyvsp[0].id); ; break;} case 119: -#line 1046 "parse.y" +#line 1043 "parse.y" { if(strcmp(yyvsp[-2].id,"check")!=0) { yyerror(_("parse error")); @@ -2244,7 +2241,7 @@ case 119: ; break;} case 120: -#line 1054 "parse.y" +#line 1051 "parse.y" { if(strcmp(yyvsp[-2].id,"check")!=0) { yyerror(_("parse error")); @@ -2255,15 +2252,15 @@ case 120: ; break;} case 121: -#line 1064 "parse.y" +#line 1061 "parse.y" { ; ; break;} case 122: -#line 1065 "parse.y" +#line 1062 "parse.y" { ; ; break;} case 123: -#line 1068 "parse.y" +#line 1065 "parse.y" { if(strcmp(yyvsp[0].id,"type")==0) { Node *node = new_check(TYPE_CHECK,NULL); @@ -2279,60 +2276,60 @@ case 123: ; break;} case 124: -#line 1081 "parse.y" +#line 1078 "parse.y" { Node *node = new_check(GT_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 125: -#line 1085 "parse.y" +#line 1082 "parse.y" { Node *node = new_check(LT_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 126: -#line 1089 "parse.y" +#line 1086 "parse.y" { Node *node = new_check(GE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 127: -#line 1093 "parse.y" +#line 1090 "parse.y" { Node *node = new_check(LE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 128: -#line 1097 "parse.y" +#line 1094 "parse.y" { Node *node = new_check(EQ_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 129: -#line 1101 "parse.y" +#line 1098 "parse.y" { Node *node = new_check(NE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 130: -#line 1107 "parse.y" +#line 1104 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 131: -#line 1108 "parse.y" +#line 1105 "parse.y" { yyval.id = g_strconcat("-",yyvsp[0].id,NULL); g_free(yyvsp[0].id); ; break;} case 132: -#line 1112 "parse.y" +#line 1109 "parse.y" { yyval.id = yyvsp[0].id; ; break;} } @@ -2557,5 +2554,5 @@ yyerrhandle: } return 1; } -#line 1115 "parse.y" +#line 1112 "parse.y" diff --git a/src/parse.y b/src/parse.y index f29f9de..ba4615b 100644 --- a/src/parse.y +++ b/src/parse.y @@ -141,18 +141,18 @@ push_function(int scope, int method, char *oid, char *id, !(g_list_length(funcargs) == 1 && g_list_length(gtktypes) == 2 && strcmp(gtktypes->next->data, "NONE")==0)) { - print_error(TRUE, _("The number of GTK arguments and " - "function arguments for a signal " - "don't seem to match"), line_no); + error_print(GOB_WARN, line_no, + _("The number of GTK arguments and " + "function arguments for a signal " + "don't seem to match")); } if(g_list_length(gtktypes) > 2) { GList *li; for(li = gtktypes->next; li; li = li->next) { if(strcmp(li->data, "NONE")==0) { - print_error(FALSE, + error_print(GOB_ERROR, line_no, _("NONE can only appear in an " - "argument list by itself"), - line_no); + "argument list by itself")); } } } @@ -252,7 +252,6 @@ static Variable * find_var_or_die(const char *id, int line) { GList *li; - char *s; for(li = class_nodes; li != NULL; li = li->next) { Variable *var; @@ -264,8 +263,7 @@ find_var_or_die(const char *id, int line) return var; } - s = g_strdup_printf(_("Variable %s not defined here"), id); - print_error(FALSE, s, line); + error_printf(GOB_ERROR, line, _("Variable %s not defined here"), id); g_assert_not_reached(); return NULL; @@ -560,9 +558,8 @@ argument: ARGUMENT flags argtype TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' { else if(var->scope == CLASS_SCOPE) { root = "SELF_GET_CLASS(self)"; if(no_self_alias) - print_error(FALSE, - _("Self aliases needed when autolinking to a classwide member"), - $1); + error_print(GOB_ERROR, $1, + _("Self aliases needed when autolinking to a classwide member")); } else root = "self"; diff --git a/src/test.gob b/src/test.gob index 711ec50..17a8244 100644 --- a/src/test.gob +++ b/src/test.gob @@ -5,6 +5,10 @@ requires 0.93.0 +%at{ +/* ALL TOP */ +%} + %headertop{ /* this should go on the very top of the header */ diff --git a/src/util.c b/src/util.c index ae16914..37abe55 100644 --- a/src/util.c +++ b/src/util.c @@ -31,30 +31,53 @@ #include "util.h" void -print_error(gboolean is_warn, char *error, int line) +error_print(int type, int line, const char *error) { - char *w; - if(is_warn) + char *w = NULL; + + switch(type) { + case GOB_WARN: w = "Warning:"; - else { + break; + case GOB_ERROR: w = "Error:"; got_error = TRUE; + break; + default: + g_assert_not_reached(); } - if(line>0) + if(line > 0) fprintf(stderr, "%s:%d: %s %s\n", filename, line, w, error); else fprintf(stderr, "%s: %s %s\n", filename, w, error); - if((!is_warn || exit_on_warn) && exit_on_error) + if(exit_on_error && + (type == GOB_ERROR || + (type == GOB_WARN && exit_on_warn))) exit(1); } +void +error_printf(int type, int line, const char *error, ...) +{ + va_list ap; + char *s; + + va_start(ap, error); + s = g_strdup_vprintf(error, ap); + va_end(ap); + + error_print(type, line, s); + + g_free(s); +} + char * remove_sep(char *base) { char *p; char *s = g_strdup(base); while((p = strchr(s, ':'))) - strcpy(p,p+1); + strcpy(p, p+1); return s; } diff --git a/src/util.h b/src/util.h index ba7f1b5..9eac446 100644 --- a/src/util.h +++ b/src/util.h @@ -23,8 +23,15 @@ #ifndef _UTIL_H_ #define _UTIL_H_ -/* print an error, or warning (if 'is_warn') referring to 'line' */ -void print_error(gboolean is_warn, char *error, int line); +enum { + GOB_WARN, + GOB_ERROR +}; + +/* print an error, or warning referring to 'line' + * (line can be 0 or negative for no line) */ +void error_print(int type, int line, const char *error); +void error_printf(int type, int line, const char *error, ...) G_GNUC_PRINTF (3, 4); /* remove the : separator from a typename */ char * remove_sep(char *base); -- 2.43.0