From 7c9125f3e75c250e51d5bb9658f730519f103c10 Mon Sep 17 00:00:00 2001 From: George Lebl Date: Sun, 30 Sep 2001 21:46:00 -0800 Subject: [PATCH] Release 1.0.11 --- ChangeLog | 20 +++ NEWS | 4 + configure | 2 +- configure.in | 2 +- gob.spec | 4 +- src/lexer.c | 7 +- src/main.c | 187 ++++++++++++++++++++----- src/parse.c | 384 ++++++++++++++++++++++++++++----------------------- src/parse.y | 84 ++++++++--- src/util.c | 2 +- src/util.h | 2 +- 11 files changed, 463 insertions(+), 235 deletions(-) diff --git a/ChangeLog b/ChangeLog index eb13eb2..a1af12a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +Sat Sep 29 16:31:38 2001 George Lebl + + * Release 1.0.11 + +Sat Sep 29 16:28:13 2001 George Lebl + + * src/util.[ch], src/parse.y: get_cast argument is constant and + make sure not to modify the return value. + +Fri Sep 28 17:10:21 2001 George Lebl + + * src/main.c: backport the signal marshaller stuff from gob-2 as + that apparently changed in gtk proper recently (marshallers in + gtk1 style are no longer supported) + +Fri Sep 28 15:56:37 2001 George Lebl + + * src/parse.y: fix segfaults on export and fix one case where + export was ignored + Sat Jun 30 15:39:27 2001 George Lebl * Release 1.0.10 diff --git a/NEWS b/NEWS index 9f874f9..1d13f84 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.0.11 + * Fix many (export) flag bugs + * Fix GTK+2 object generation + 1.0.10 * (export) flag for arguments to export get/set public methods (Eskil) * private header by default ondemand as documented (Mark Brown) diff --git a/configure b/configure index 84f9a48..3121185 100755 --- a/configure +++ b/configure @@ -703,7 +703,7 @@ fi PACKAGE=gob -VERSION=1.0.10 +VERSION=1.0.11 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 339608c..5449685 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.10) +AM_INIT_AUTOMAKE(gob,1.0.11) dnl dnl An utter hack to allow embedding of gob inside other packages. diff --git a/gob.spec b/gob.spec index dcf1b47..fdb2038 100644 --- a/gob.spec +++ b/gob.spec @@ -1,7 +1,7 @@ Summary: GOB, The GTK+ Object Builder Name: gob -Version: 1.0.10 -Release: 1 +Version: 1.0.11 +Release: SNAP Copyright: GPL Group: Development/Tools Source: %{name}-%{version}.tar.gz diff --git a/src/lexer.c b/src/lexer.c index 7335379..883456c 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -9,6 +9,7 @@ #define YY_FLEX_MINOR_VERSION 5 #include +#include /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ @@ -22,7 +23,6 @@ #ifdef __cplusplus #include -#include /* Use prototypes in function declarations. */ #define YY_USE_PROTOS @@ -2379,11 +2379,6 @@ YY_BUFFER_STATE b; } -#ifndef YY_ALWAYS_INTERACTIVE -#ifndef YY_NEVER_INTERACTIVE -extern int isatty YY_PROTO(( int )); -#endif -#endif #ifdef YY_USE_PROTOS void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) diff --git a/src/main.c b/src/main.c index 0cdd6ff..9e3d4bc 100644 --- a/src/main.c +++ b/src/main.c @@ -677,7 +677,7 @@ find_same_type_signal(Method *m) } static void -print_signal_marsal_args(Method *m) +print_signal_marsal_args_gtk1 (Method *m) { if(strcmp(m->gtktypes->next->data, "NONE")!=0) { GList *li; @@ -698,6 +698,146 @@ print_signal_marsal_args(Method *m) out_printf(out, ",\n\t\tfunc_data);\n}\n\n"); } +static void +add_marshal_gtk1 (Method *m, const char *mname) +{ + out_printf(out, "\nstatic void\n" + "___marshal_%s (GtkObject * object,\n" + "\tGtkSignalFunc func,\n" + "\tgpointer func_data,\n" + "\tGtkArg * args)\n" + "{\n", mname); + + if(strcmp(m->gtktypes->data, "NONE")==0) { + out_printf(out, "\t___%s rfunc;\n\n" + "\trfunc = (___%s)func;\n\n" + "\t(*rfunc)((%s *)object", mname, mname, typebase); + } else { + const char *retcast = get_cast(m->gtktypes->data, FALSE); + gboolean is_none = (strcmp(m->gtktypes->next->data, "NONE")==0); + out_printf(out, + "\t___%s rfunc;\n\t" + "%s *retval;\n\n" + "\trfunc = (___%s)func;\n\n" + "\tretval = GTK_RETLOC_%s(args[%d]);\n\n" + "\t*retval = (*rfunc)((%s *)object", + mname, retcast, mname, + (char *)m->gtktypes->data, + g_list_length(m->gtktypes) - (is_none ? 2 : 1), + typebase); + } + print_signal_marsal_args_gtk1 (m); +} + +static const char * +gtk2_debool (const char *s) +{ + if (strcmp (s, "BOOL") == 0) + return "BOOLEAN"; + else + return s; +} + +static void +print_signal_marsal_args_gtk2 (Method *m) +{ + if (strcmp (m->gtktypes->next->data, "NONE") != 0) { + GList *li; + int i; + for (i = 0, li = m->gtktypes->next; + li != NULL; + i++, li = li->next) { + char *get_func = g_strdup_printf + ("g_value_get_%s", + (char *)gtk2_debool (li->data)); + g_strdown (get_func); + out_printf (out, ",\n\t\t(%s) " + "%s (param_values + %d)", + get_cast (li->data, FALSE), + get_func, i + 1); + g_free (get_func); + } + } + out_printf (out, ",\n\t\tdata2);\n"); +} + +static void +add_marshal_gtk2 (Method *m, const char *mname) +{ + gboolean ret_none; + gboolean arglist_none; + const char *retcast; + + ret_none = strcmp (m->gtktypes->data, "NONE") == 0; + arglist_none = strcmp (m->gtktypes->next->data, "NONE") == 0; + + if (ret_none) + retcast = NULL; + else + retcast = get_cast (m->gtktypes->data, FALSE); + + out_printf (out, "\nstatic void\n" + "___marshal_%s (GClosure *closure,\n" + "\tGValue *return_value,\n" + "\tguint n_param_values,\n" + "\tconst GValue *param_values,\n" + "\tgpointer invocation_hint,\n" + "\tgpointer marshal_data)\n" + "{\n", mname); + + if ( ! ret_none) + out_printf (out, "\t%s v_return;\n", retcast); + + out_printf (out, "\tregister ___%s callback;\n" + "\tregister GCClosure *cc = (GCClosure*) closure;\n" + "\tregister gpointer data1, data2;\n\n", + mname); + + out_printf (out, "\tg_return_if_fail (n_param_values == %d);\n\n", + arglist_none ? 1 : g_list_length (m->gtktypes)); + + out_printf (out, + "\tif (G_CCLOSURE_SWAP_DATA (closure)) {\n" + "\t\tdata1 = closure->data;\n" + "\t\tdata2 = g_value_peek_pointer (param_values + 0);\n" + "\t} else {\n" + "\t\tdata1 = g_value_peek_pointer (param_values + 0);\n" + "\t\tdata2 = closure->data;\n" + "\t}\n\n"); + + out_printf (out, "\tcallback = (___%s) " + "(marshal_data != NULL ? marshal_data : cc->callback);" + "\n\n", mname); + + if (ret_none) { + out_printf (out, "\tcallback ((%s *)data1", typebase); + } else { + out_printf (out, "\tv_return = callback ((%s *)data1", + typebase); + } + + print_signal_marsal_args_gtk2 (m); + + if ( ! ret_none) { + /* FIXME: This code is so fucking ugly it hurts */ + gboolean take_ownership = + (strcmp ((char *)m->gtktypes->data, "STRING") == 0 || + strcmp ((char *)m->gtktypes->data, "BOXED") == 0); + char *set_func = g_strdup_printf ("g_value_set_%s%s", + (char *)gtk2_debool (m->gtktypes->data), + take_ownership ? + "_take_ownership" : ""); + g_strdown (set_func); + + out_printf (out, "\n\t%s (return_value, v_return);\n", + set_func); + + g_free (set_func); + } + out_printf (out, "}\n\n"); +} + + static void add_signal_prots(Method *m) @@ -730,44 +870,23 @@ add_signal_prots(Method *m) g_hash_table_insert(marsh, m, s); eq_signal_methods = g_list_prepend(eq_signal_methods, m); - + /* we know that we'll know all the gtktypes (so get_cast can't fail) */ out_printf(out, "\ntypedef %s (*___%s) (%s *, ", get_cast(m->gtktypes->data, FALSE), s, typebase); - if(strcmp(m->gtktypes->next->data, "NONE")!=0) { - for(li=m->gtktypes->next; li; li=g_list_next(li)) + if (strcmp (m->gtktypes->next->data, "NONE") != 0) { + for (li = m->gtktypes->next; li != NULL; li = li->next) out_printf(out, "%s, ", get_cast(li->data, FALSE)); } - out_printf(out, "gpointer);\n"); + out_printf (out, "gpointer);\n"); - out_printf(out, "\nstatic void\n" - "___marshal_%s (GtkObject * object,\n" - "\tGtkSignalFunc func,\n" - "\tgpointer func_data,\n" - "\tGtkArg * args)\n" - "{\n", s); - - if(strcmp(m->gtktypes->data, "NONE")==0) { - out_printf(out, "\t___%s rfunc;\n\n" - "\trfunc = (___%s)func;\n\n" - "\t(*rfunc)((%s *)object", s, s, typebase); - } else { - const char *retcast = get_cast(m->gtktypes->data, FALSE); - gboolean is_none = (strcmp(m->gtktypes->next->data, "NONE")==0); - out_printf(out, - "\t___%s rfunc;\n\t" - "%s *retval;\n\n" - "\trfunc = (___%s)func;\n\n" - "\tretval = GTK_RETLOC_%s(args[%d]);\n\n" - "\t*retval = (*rfunc)((%s *)object", - s, retcast, s, - (char *)m->gtktypes->data, - g_list_length(m->gtktypes) - (is_none ? 2 : 1), - typebase); - } - print_signal_marsal_args(m); + out_printf (out, "\n#ifdef G_OBJECT_CLASS\n"); + add_marshal_gtk2 (m, s); + out_printf (out, "#else /* ! G_OBJECT_CLASS */\n"); + add_marshal_gtk1 (m, s); + out_printf (out, "#endif /* G_OBJECT_CLASS */\n\n"); } static void @@ -1087,8 +1206,10 @@ add_signals(Class *c) } } - out_printf(out, "\tgtk_object_class_add_signals (gtk_object_class,\n" - "\t\tobject_signals, LAST_SIGNAL);\n\n"); + out_printf (out, "#ifndef G_OBJECT_CLASS\n"); + out_printf (out, "\tgtk_object_class_add_signals (gtk_object_class,\n" + "\t\tobject_signals, LAST_SIGNAL);\n"); + out_printf (out, "#endif /* ! G_OBJECT_CLASS */\n\n"); } static void diff --git a/src/parse.c b/src/parse.c index 2d9d349..d8e8db7 100644 --- a/src/parse.c +++ b/src/parse.c @@ -316,20 +316,38 @@ set_return_value(char *type, char *val) } static void -export_accessors (char *var_name, - GString *get_cbuf, +export_accessors (const char *var_name, + const char *get_cbuf, int get_lineno, - GString *set_cbuf, + const char *set_cbuf, int set_lineno, Type *type, + const char *gtktype, int lineno) { - if (get_cbuf) { + if (type == NULL) { + char *cast = g_strdup (get_cast (gtktype, FALSE)); + char *p = strchr (cast, ' '); + if (p != NULL) { + *p = '\0'; + p++; + } + /* leak, but we don't really care any more */ + type = (Type *)new_type (cast, + g_strdup (p), + NULL); + } + + if (get_cbuf != NULL) { char *get_id = g_strdup_printf ("get_%s", var_name); - GString *get_cbuf_copy = g_string_new (get_cbuf->str); + GString *get_cbuf_copy = g_string_new (get_cbuf); char *tmp; - Node *node1 = new_type (type->name, type->pointer, type->postfix); - Node *node3 = new_type (class->class.otype, "*", NULL); + Node *node1 = new_type (g_strdup (type->name), + g_strdup (type->pointer), + g_strdup (type->postfix)); + Node *node3 = new_type (g_strdup (class->class.otype), + g_strdup ("*"), + NULL); tmp = g_strdup_printf ("\t%s%s ARG;\n", type->name, @@ -351,12 +369,18 @@ export_accessors (char *var_name, lineno, FALSE, NULL); } - if (set_cbuf) { + if (set_cbuf != NULL) { char *set_id = g_strdup_printf ("set_%s", var_name); - GString *set_cbuf_copy = g_string_new (set_cbuf->str); - Node *node1 = new_type (type->name, type->pointer, type->postfix); - Node *node2 = new_type ("void", NULL, NULL); - Node *node3 = new_type (class->class.otype, "*", NULL); + GString *set_cbuf_copy = g_string_new (set_cbuf); + Node *node1 = new_type (g_strdup (type->name), + g_strdup (type->pointer), + g_strdup (type->postfix)); + Node *node2 = new_type (g_strdup ("void"), + NULL, + NULL); + Node *node3 = new_type (g_strdup (class->class.otype), + g_strdup ("*"), + NULL); typestack = g_list_prepend (typestack, node2); typestack = g_list_prepend (typestack, node1); @@ -373,7 +397,7 @@ export_accessors (char *var_name, } -#line 355 "parse.y" +#line 379 "parse.y" typedef union { char *id; GString *cbuf; @@ -506,20 +530,20 @@ static const short yyrhs[] = { 52, #if YYDEBUG != 0 static const short yyrline[] = { 0, - 373, 374, 375, 376, 379, 385, 391, 397, 403, 409, - 417, 418, 421, 426, 433, 439, 440, 452, 466, 467, - 470, 471, 479, 480, 481, 484, 485, 486, 487, 490, - 503, 519, 523, 531, 532, 533, 534, 535, 541, 544, - 549, 600, 648, 731, 739, 741, 750, 756, 757, 760, - 763, 769, 773, 780, 783, 786, 790, 794, 798, 803, - 811, 815, 820, 824, 827, 831, 834, 839, 840, 841, - 842, 843, 844, 845, 846, 847, 850, 851, 852, 855, - 856, 857, 861, 868, 880, 886, 898, 910, 913, 919, - 924, 927, 932, 933, 937, 953, 969, 985, 1001, 1012, - 1018, 1028, 1051, 1062, 1081, 1087, 1088, 1094, 1095, 1106, - 1117, 1128, 1138, 1148, 1158, 1161, 1162, 1165, 1166, 1169, - 1172, 1175, 1183, 1193, 1194, 1197, 1210, 1214, 1218, 1222, - 1226, 1230, 1236, 1237, 1241 + 397, 398, 399, 400, 403, 409, 415, 421, 427, 433, + 441, 442, 445, 450, 457, 463, 464, 476, 490, 491, + 494, 495, 503, 504, 505, 508, 509, 510, 511, 514, + 527, 543, 547, 555, 556, 557, 558, 559, 565, 568, + 573, 637, 689, 775, 783, 785, 794, 800, 801, 804, + 807, 813, 817, 824, 827, 830, 834, 838, 842, 847, + 855, 859, 864, 868, 871, 875, 878, 883, 884, 885, + 886, 887, 888, 889, 890, 891, 894, 895, 896, 899, + 900, 901, 905, 912, 924, 930, 942, 954, 957, 963, + 968, 971, 976, 977, 981, 997, 1013, 1029, 1045, 1056, + 1062, 1072, 1095, 1106, 1125, 1131, 1132, 1138, 1139, 1150, + 1161, 1172, 1182, 1192, 1202, 1205, 1206, 1209, 1210, 1213, + 1216, 1219, 1227, 1237, 1238, 1241, 1254, 1258, 1262, 1266, + 1270, 1274, 1280, 1281, 1285 }; #endif @@ -1289,23 +1313,23 @@ yyreduce: switch (yyn) { case 1: -#line 373 "parse.y" +#line 397 "parse.y" { ; ; break;} case 2: -#line 374 "parse.y" +#line 398 "parse.y" { ; ; break;} case 3: -#line 375 "parse.y" +#line 399 "parse.y" { ; ; break;} case 4: -#line 376 "parse.y" +#line 400 "parse.y" { ; ; break;} case 5: -#line 379 "parse.y" +#line 403 "parse.y" { Node *node = new_ccode(C_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1314,7 +1338,7 @@ case 5: ; break;} case 6: -#line 385 "parse.y" +#line 409 "parse.y" { Node *node = new_ccode(H_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1323,7 +1347,7 @@ case 6: ; break;} case 7: -#line 391 "parse.y" +#line 415 "parse.y" { Node *node = new_ccode(HT_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1332,7 +1356,7 @@ case 7: ; break;} case 8: -#line 397 "parse.y" +#line 421 "parse.y" { Node *node = new_ccode(PH_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1341,7 +1365,7 @@ case 8: ; break;} case 9: -#line 403 "parse.y" +#line 427 "parse.y" { Node *node = new_ccode(A_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1350,7 +1374,7 @@ case 9: ; break;} case 10: -#line 409 "parse.y" +#line 433 "parse.y" { Node *node = new_ccode(AT_CCODE,(yyvsp[0].cbuf)->str, ccode_line); @@ -1359,15 +1383,15 @@ case 10: ; break;} case 11: -#line 417 "parse.y" +#line 441 "parse.y" { ; ; break;} case 12: -#line 418 "parse.y" +#line 442 "parse.y" { ; ; break;} case 13: -#line 421 "parse.y" +#line 445 "parse.y" { ((Class *)class)->nodes = class_nodes; class_nodes = NULL; @@ -1375,7 +1399,7 @@ case 13: ; break;} case 14: -#line 426 "parse.y" +#line 450 "parse.y" { ((Class *)class)->nodes = NULL; class_nodes = NULL; @@ -1383,14 +1407,14 @@ case 14: ; break;} case 15: -#line 433 "parse.y" +#line 457 "parse.y" { class = new_class (yyvsp[-3].id, yyvsp[-1].id, bonobo_x_class, chunk_size, NULL); ; break;} case 17: -#line 440 "parse.y" +#line 464 "parse.y" { if(strcmp(yyvsp[-3].id,"chunks") == 0) { g_free (chunk_size); @@ -1405,7 +1429,7 @@ case 17: ; break;} case 18: -#line 452 "parse.y" +#line 476 "parse.y" { if(strcmp(yyvsp[-3].id,"chunks") == 0) { g_free (chunk_size); @@ -1420,19 +1444,19 @@ case 18: ; break;} case 19: -#line 466 "parse.y" +#line 490 "parse.y" { ; ; break;} case 20: -#line 467 "parse.y" +#line 491 "parse.y" { ; ; break;} case 21: -#line 470 "parse.y" +#line 494 "parse.y" { ; ; break;} case 22: -#line 471 "parse.y" +#line 495 "parse.y" { if (strcmp (yyvsp[-1].id, "BonoboX") != 0) { g_free(yyvsp[-1].id); @@ -1443,35 +1467,35 @@ case 22: ; break;} case 23: -#line 479 "parse.y" +#line 503 "parse.y" { ; ; break;} case 24: -#line 480 "parse.y" +#line 504 "parse.y" { ; ; break;} case 25: -#line 481 "parse.y" +#line 505 "parse.y" { ; ; break;} case 26: -#line 484 "parse.y" +#line 508 "parse.y" { the_scope = PUBLIC_SCOPE; ; break;} case 27: -#line 485 "parse.y" +#line 509 "parse.y" { the_scope = PRIVATE_SCOPE; ; break;} case 28: -#line 486 "parse.y" +#line 510 "parse.y" { the_scope = PROTECTED_SCOPE; ; break;} case 29: -#line 487 "parse.y" +#line 511 "parse.y" { the_scope = CLASS_SCOPE; ; break;} case 30: -#line 490 "parse.y" +#line 514 "parse.y" { if(strcmp(yyvsp[-1].id, "destroywith")==0) { g_free(yyvsp[-1].id); @@ -1487,7 +1511,7 @@ case 30: ; break;} case 31: -#line 503 "parse.y" +#line 527 "parse.y" { if(strcmp(yyvsp[-2].id, "destroy")==0) { g_free(yyvsp[-2].id); @@ -1504,14 +1528,14 @@ case 31: ; break;} case 32: -#line 519 "parse.y" +#line 543 "parse.y" { initializer = yyvsp[0].id; initializer_line = ccode_line; ; break;} case 33: -#line 523 "parse.y" +#line 547 "parse.y" { initializer = (yyvsp[0].cbuf)->str; initializer_line = ccode_line; @@ -1519,42 +1543,42 @@ case 33: ; break;} case 34: -#line 531 "parse.y" +#line 555 "parse.y" { ; ; break;} case 35: -#line 532 "parse.y" +#line 556 "parse.y" { ; ; break;} case 36: -#line 533 "parse.y" +#line 557 "parse.y" { destructor = NULL; ; break;} case 37: -#line 534 "parse.y" +#line 558 "parse.y" { initializer = NULL; ; break;} case 38: -#line 535 "parse.y" +#line 559 "parse.y" { destructor = NULL; initializer = NULL; ; break;} case 39: -#line 541 "parse.y" +#line 565 "parse.y" { push_variable(yyvsp[-2].id, the_scope,yyvsp[-4].line, NULL); ; break;} case 40: -#line 544 "parse.y" +#line 568 "parse.y" { push_variable(yyvsp[-3].id, the_scope, yyvsp[-5].line, yyvsp[-2].id); ; break;} case 41: -#line 549 "parse.y" +#line 573 "parse.y" { if(strcmp(yyvsp[-6].id,"get")==0 && strcmp(yyvsp[-3].id,"set")==0) { @@ -1571,10 +1595,12 @@ case 41: if (yyvsp[-7].id) { export_accessors (yyvsp[-8].id, - yyvsp[-4].cbuf, yyvsp[-5].line, - yyvsp[-1].cbuf, yyvsp[-2].line, + (yyvsp[-4].cbuf)->str, yyvsp[-5].line, + (yyvsp[-1].cbuf)->str, yyvsp[-2].line, type, + yyvsp[-9].id, yyvsp[-11].line); + g_free (yyvsp[-7].id); } g_string_free (yyvsp[-4].cbuf, FALSE); @@ -1590,6 +1616,17 @@ case 41: (yyvsp[-1].cbuf)->str,yyvsp[-2].line, (yyvsp[-4].cbuf)->str,yyvsp[-5].line, yyvsp[-11].line); + + if (yyvsp[-7].id) { + export_accessors (yyvsp[-8].id, + (yyvsp[-1].cbuf)->str, yyvsp[-2].line, + (yyvsp[-4].cbuf)->str, yyvsp[-5].line, + type, + yyvsp[-9].id, + yyvsp[-11].line); + g_free (yyvsp[-7].id); + } + g_string_free (yyvsp[-1].cbuf, FALSE); g_string_free (yyvsp[-4].cbuf, FALSE); class_nodes = g_list_append(class_nodes,node); @@ -1608,7 +1645,7 @@ case 41: ; break;} case 42: -#line 600 "parse.y" +#line 637 "parse.y" { if(strcmp(yyvsp[-3].id, "get") == 0) { Node *node; @@ -1620,10 +1657,12 @@ case 42: yyvsp[-8].line); if (yyvsp[-4].id) { export_accessors (yyvsp[-5].id, - yyvsp[-1].cbuf, yyvsp[-2].line, + (yyvsp[-1].cbuf)->str, yyvsp[-2].line, NULL, 0, type, + yyvsp[-6].id, yyvsp[-8].line); + g_free (yyvsp[-4].id); } g_string_free (yyvsp[-1].cbuf, FALSE); @@ -1639,9 +1678,11 @@ case 42: if (yyvsp[-4].id) { export_accessors (yyvsp[-5].id, NULL, 0, - yyvsp[-1].cbuf, yyvsp[-2].line, + (yyvsp[-1].cbuf)->str, yyvsp[-2].line, type, + yyvsp[-6].id, yyvsp[-8].line); + g_free (yyvsp[-4].id); } g_string_free (yyvsp[-1].cbuf, FALSE); @@ -1659,7 +1700,7 @@ case 42: ; break;} case 43: -#line 648 "parse.y" +#line 689 "parse.y" { Node *node; char *get, *set = NULL; @@ -1714,11 +1755,12 @@ case 43: g_assert_not_reached(); } - if(strcmp (yyvsp[0].id, "stringlink")==0) { + if (strcmp (yyvsp[0].id, "stringlink")==0) { get = g_strdup_printf("ARG = g_strdup(%s->%s);", root, yyvsp[-2].id); - } else + } else { /* For everything else, get is just straight assignment */ get = g_strdup_printf("ARG = %s->%s;", root, yyvsp[-2].id); + } g_free (yyvsp[0].id); @@ -1733,17 +1775,19 @@ case 43: yyvsp[-5].line); if (yyvsp[-1].id) { export_accessors (yyvsp[-2].id, - g_string_new (get), yyvsp[-5].line, - g_string_new (set), yyvsp[-5].line, + get, yyvsp[-5].line, + set, yyvsp[-5].line, type, + yyvsp[-3].id, yyvsp[-5].line); + g_free (yyvsp[-1].id); } class_nodes = g_list_append(class_nodes,node); ; break;} case 44: -#line 731 "parse.y" +#line 775 "parse.y" { if (strcmp (yyvsp[-1].id, "export")!=0) { g_free (yyvsp[-1].id); @@ -1754,11 +1798,11 @@ case 44: ; break;} case 45: -#line 739 "parse.y" +#line 783 "parse.y" { yyval.id = NULL; ; break;} case 46: -#line 741 "parse.y" +#line 785 "parse.y" { if(strcmp(yyvsp[-2].id,"type")!=0) { g_free(yyvsp[-4].id); @@ -1770,81 +1814,81 @@ case 46: ; break;} case 47: -#line 750 "parse.y" +#line 794 "parse.y" { yyval.id = yyvsp[0].id; typestack = g_list_prepend(typestack,NULL); ; break;} case 48: -#line 756 "parse.y" +#line 800 "parse.y" { yyval.list = yyvsp[-1].list; ; break;} case 49: -#line 757 "parse.y" +#line 801 "parse.y" { yyval.list = NULL; ; break;} case 50: -#line 760 "parse.y" +#line 804 "parse.y" { yyval.list = g_list_append(yyvsp[0].list,yyvsp[-2].id); ; break;} case 51: -#line 763 "parse.y" +#line 807 "parse.y" { yyval.list = g_list_append(NULL,yyvsp[0].id); ; break;} case 52: -#line 769 "parse.y" +#line 813 "parse.y" { Node *node = new_type(yyvsp[-1].id, yyvsp[0].id, NULL); typestack = g_list_prepend(typestack,node); ; break;} case 53: -#line 773 "parse.y" +#line 817 "parse.y" { Node *node = new_type(yyvsp[0].id, NULL, NULL); typestack = g_list_prepend(typestack,node); ; break;} case 54: -#line 780 "parse.y" +#line 824 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 55: -#line 783 "parse.y" +#line 827 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 56: -#line 786 "parse.y" +#line 830 "parse.y" { yyval.id = g_strconcat("const ", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 57: -#line 790 "parse.y" +#line 834 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " const", NULL); g_free(yyvsp[-1].id); ; break;} case 58: -#line 794 "parse.y" +#line 838 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " ", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 59: -#line 798 "parse.y" +#line 842 "parse.y" { yyval.id = g_strconcat("const ", yyvsp[-1].id, " ", yyvsp[0].id, NULL); @@ -1852,7 +1896,7 @@ case 59: ; break;} case 60: -#line 803 "parse.y" +#line 847 "parse.y" { yyval.id = g_strconcat(yyvsp[-2].id, " ", yyvsp[-1].id, " const", NULL); @@ -1860,14 +1904,14 @@ case 60: ; break;} case 61: -#line 811 "parse.y" +#line 855 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " ", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 62: -#line 815 "parse.y" +#line 859 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " ", yyvsp[0].id, NULL); g_free(yyvsp[-1].id); @@ -1875,109 +1919,109 @@ case 62: ; break;} case 63: -#line 820 "parse.y" +#line 864 "parse.y" { yyval.id = g_strconcat("const ", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 64: -#line 824 "parse.y" +#line 868 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 65: -#line 827 "parse.y" +#line 871 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " const", NULL); g_free(yyvsp[-1].id); ; break;} case 66: -#line 831 "parse.y" +#line 875 "parse.y" { yyval.id = g_strdup(yyvsp[0].id); ; break;} case 67: -#line 834 "parse.y" +#line 878 "parse.y" { yyval.id = g_strconcat(yyvsp[-1].id, " const", NULL); ; break;} case 68: -#line 839 "parse.y" +#line 883 "parse.y" { yyval.id = "void"; ; break;} case 69: -#line 840 "parse.y" +#line 884 "parse.y" { yyval.id = "char"; ; break;} case 70: -#line 841 "parse.y" +#line 885 "parse.y" { yyval.id = "short"; ; break;} case 71: -#line 842 "parse.y" +#line 886 "parse.y" { yyval.id = "int"; ; break;} case 72: -#line 843 "parse.y" +#line 887 "parse.y" { yyval.id = "long"; ; break;} case 73: -#line 844 "parse.y" +#line 888 "parse.y" { yyval.id = "float"; ; break;} case 74: -#line 845 "parse.y" +#line 889 "parse.y" { yyval.id = "double"; ; break;} case 75: -#line 846 "parse.y" +#line 890 "parse.y" { yyval.id = "signed"; ; break;} case 76: -#line 847 "parse.y" +#line 891 "parse.y" { yyval.id = "unsigned"; ; break;} case 77: -#line 850 "parse.y" +#line 894 "parse.y" { yyval.id = "struct"; ; break;} case 78: -#line 851 "parse.y" +#line 895 "parse.y" { yyval.id = "union"; ; break;} case 79: -#line 852 "parse.y" +#line 896 "parse.y" { yyval.id = "enum"; ; break;} case 80: -#line 855 "parse.y" +#line 899 "parse.y" { yyval.id = g_strdup("*"); ; break;} case 81: -#line 856 "parse.y" +#line 900 "parse.y" { yyval.id = g_strdup("* const"); ; break;} case 82: -#line 857 "parse.y" +#line 901 "parse.y" { yyval.id = g_strconcat("*", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 83: -#line 861 "parse.y" +#line 905 "parse.y" { yyval.id = g_strconcat("* const", yyvsp[0].id, NULL); g_free(yyvsp[0].id); ; break;} case 84: -#line 868 "parse.y" +#line 912 "parse.y" { if(strcmp(yyvsp[-1].id, "first")==0) yyval.sigtype = SIGNAL_FIRST_METHOD; @@ -1992,13 +2036,13 @@ case 84: ; break;} case 85: -#line 880 "parse.y" +#line 924 "parse.y" { yyval.sigtype = SIGNAL_LAST_METHOD; ; break;} case 86: -#line 886 "parse.y" +#line 930 "parse.y" { if(strcmp(yyvsp[-1].id,"first")==0) yyval.sigtype = SIGNAL_FIRST_METHOD; @@ -2013,7 +2057,7 @@ case 86: ; break;} case 87: -#line 898 "parse.y" +#line 942 "parse.y" { if(strcmp(yyvsp[-2].id,"first")==0) yyval.sigtype = SIGNAL_FIRST_METHOD; @@ -2028,46 +2072,46 @@ case 87: ; break;} case 88: -#line 910 "parse.y" +#line 954 "parse.y" { yyval.sigtype = SIGNAL_LAST_METHOD; ; break;} case 89: -#line 913 "parse.y" +#line 957 "parse.y" { /* the_scope was default thus public */ the_scope = PUBLIC_SCOPE; ; break;} case 90: -#line 919 "parse.y" +#line 963 "parse.y" { gtktypes = g_list_prepend(gtktypes, yyvsp[-3].id); ; break;} case 91: -#line 924 "parse.y" +#line 968 "parse.y" { gtktypes = g_list_append(gtktypes, yyvsp[0].id); ; break;} case 92: -#line 927 "parse.y" +#line 971 "parse.y" { gtktypes = g_list_append(gtktypes, yyvsp[0].id); ; break;} case 93: -#line 932 "parse.y" +#line 976 "parse.y" { yyval.cbuf = yyvsp[0].cbuf; ; break;} case 94: -#line 933 "parse.y" +#line 977 "parse.y" { yyval.cbuf = NULL; ; break;} case 95: -#line 937 "parse.y" +#line 981 "parse.y" { if(!has_self) { yyerror(_("signal without 'self' as " @@ -2086,7 +2130,7 @@ case 95: ; break;} case 96: -#line 953 "parse.y" +#line 997 "parse.y" { if(!has_self) { yyerror(_("signal without 'self' as " @@ -2105,7 +2149,7 @@ case 96: ; break;} case 97: -#line 969 "parse.y" +#line 1013 "parse.y" { if(!has_self) { yyerror(_("virtual method without 'self' as " @@ -2124,7 +2168,7 @@ case 97: ; break;} case 98: -#line 985 "parse.y" +#line 1029 "parse.y" { if(!has_self) { yyerror(_("virtual method without 'self' as " @@ -2143,7 +2187,7 @@ case 98: ; break;} case 99: -#line 1001 "parse.y" +#line 1045 "parse.y" { if(!has_self) { yyerror(_("virtual method without 'self' as " @@ -2157,7 +2201,7 @@ case 99: ; break;} case 100: -#line 1012 "parse.y" +#line 1056 "parse.y" { push_function(NO_SCOPE, OVERRIDE_METHOD, yyvsp[-8].id, yyvsp[-5].id, yyvsp[0].cbuf, @@ -2166,7 +2210,7 @@ case 100: ; break;} case 101: -#line 1018 "parse.y" +#line 1062 "parse.y" { if(the_scope == CLASS_SCOPE) { yyerror(_("a method cannot be of class scope")); @@ -2179,7 +2223,7 @@ case 101: ; break;} case 102: -#line 1028 "parse.y" +#line 1072 "parse.y" { if(strcmp(yyvsp[-4].id, "init")==0) { push_init_arg(yyvsp[-2].id,FALSE); @@ -2203,7 +2247,7 @@ case 102: ; break;} case 103: -#line 1051 "parse.y" +#line 1095 "parse.y" { g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; @@ -2217,7 +2261,7 @@ case 103: ; break;} case 104: -#line 1062 "parse.y" +#line 1106 "parse.y" { g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; @@ -2239,29 +2283,29 @@ case 104: ; break;} case 105: -#line 1081 "parse.y" +#line 1125 "parse.y" { g_free(onerror); onerror = NULL; g_free(defreturn); defreturn = NULL; ; break;} case 106: -#line 1087 "parse.y" +#line 1131 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 107: -#line 1088 "parse.y" +#line 1132 "parse.y" { yyval.id = (yyvsp[1].cbuf)->str; g_string_free(yyvsp[1].cbuf, FALSE); ; break;} case 108: -#line 1094 "parse.y" +#line 1138 "parse.y" { vararg = FALSE; has_self = FALSE; ; break;} case 109: -#line 1095 "parse.y" +#line 1139 "parse.y" { vararg = FALSE; has_self = TRUE; @@ -2275,7 +2319,7 @@ case 109: ; break;} case 110: -#line 1106 "parse.y" +#line 1150 "parse.y" { vararg = FALSE; has_self = TRUE; @@ -2289,7 +2333,7 @@ case 110: ; break;} case 111: -#line 1117 "parse.y" +#line 1161 "parse.y" { vararg = FALSE; has_self = TRUE; @@ -2303,7 +2347,7 @@ case 111: ; break;} case 112: -#line 1128 "parse.y" +#line 1172 "parse.y" { has_self = TRUE; if(strcmp(yyvsp[-2].id,"self")==0) @@ -2316,7 +2360,7 @@ case 112: ; break;} case 113: -#line 1138 "parse.y" +#line 1182 "parse.y" { has_self = TRUE; if(strcmp(yyvsp[-3].id,"self")==0) @@ -2329,7 +2373,7 @@ case 113: ; break;} case 114: -#line 1148 "parse.y" +#line 1192 "parse.y" { has_self = TRUE; if(strcmp(yyvsp[-2].id,"self")==0) @@ -2342,39 +2386,39 @@ case 114: ; break;} case 115: -#line 1158 "parse.y" +#line 1202 "parse.y" { has_self = FALSE; ; break;} case 116: -#line 1161 "parse.y" +#line 1205 "parse.y" { vararg = TRUE; ; break;} case 117: -#line 1162 "parse.y" +#line 1206 "parse.y" { vararg = FALSE; ; break;} case 118: -#line 1165 "parse.y" +#line 1209 "parse.y" { ; ; break;} case 119: -#line 1166 "parse.y" +#line 1210 "parse.y" { ; ; break;} case 120: -#line 1169 "parse.y" +#line 1213 "parse.y" { push_funcarg(yyvsp[0].id,NULL); ; break;} case 121: -#line 1172 "parse.y" +#line 1216 "parse.y" { push_funcarg(yyvsp[-1].id,yyvsp[0].id); ; break;} case 122: -#line 1175 "parse.y" +#line 1219 "parse.y" { if(strcmp(yyvsp[-2].id,"check")!=0) { yyerror(_("parse error")); @@ -2385,7 +2429,7 @@ case 122: ; break;} case 123: -#line 1183 "parse.y" +#line 1227 "parse.y" { if(strcmp(yyvsp[-2].id,"check")!=0) { yyerror(_("parse error")); @@ -2396,15 +2440,15 @@ case 123: ; break;} case 124: -#line 1193 "parse.y" +#line 1237 "parse.y" { ; ; break;} case 125: -#line 1194 "parse.y" +#line 1238 "parse.y" { ; ; break;} case 126: -#line 1197 "parse.y" +#line 1241 "parse.y" { if(strcmp(yyvsp[0].id,"type")==0) { Node *node = new_check(TYPE_CHECK,NULL); @@ -2420,60 +2464,60 @@ case 126: ; break;} case 127: -#line 1210 "parse.y" +#line 1254 "parse.y" { Node *node = new_check(GT_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 128: -#line 1214 "parse.y" +#line 1258 "parse.y" { Node *node = new_check(LT_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 129: -#line 1218 "parse.y" +#line 1262 "parse.y" { Node *node = new_check(GE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 130: -#line 1222 "parse.y" +#line 1266 "parse.y" { Node *node = new_check(LE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 131: -#line 1226 "parse.y" +#line 1270 "parse.y" { Node *node = new_check(EQ_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 132: -#line 1230 "parse.y" +#line 1274 "parse.y" { Node *node = new_check(NE_CHECK,yyvsp[0].id); checks = g_list_append(checks,node); ; break;} case 133: -#line 1236 "parse.y" +#line 1280 "parse.y" { yyval.id = yyvsp[0].id; ; break;} case 134: -#line 1237 "parse.y" +#line 1281 "parse.y" { yyval.id = g_strconcat("-",yyvsp[0].id,NULL); g_free(yyvsp[0].id); ; break;} case 135: -#line 1241 "parse.y" +#line 1285 "parse.y" { yyval.id = yyvsp[0].id; ; break;} } @@ -2698,5 +2742,5 @@ yyerrhandle: } return 1; } -#line 1244 "parse.y" +#line 1288 "parse.y" diff --git a/src/parse.y b/src/parse.y index 09a871e..0bc9836 100644 --- a/src/parse.y +++ b/src/parse.y @@ -294,20 +294,38 @@ set_return_value(char *type, char *val) } static void -export_accessors (char *var_name, - GString *get_cbuf, +export_accessors (const char *var_name, + const char *get_cbuf, int get_lineno, - GString *set_cbuf, + const char *set_cbuf, int set_lineno, Type *type, + const char *gtktype, int lineno) { - if (get_cbuf) { + if (type == NULL) { + char *cast = g_strdup (get_cast (gtktype, FALSE)); + char *p = strchr (cast, ' '); + if (p != NULL) { + *p = '\0'; + p++; + } + /* leak, but we don't really care any more */ + type = (Type *)new_type (cast, + g_strdup (p), + NULL); + } + + if (get_cbuf != NULL) { char *get_id = g_strdup_printf ("get_%s", var_name); - GString *get_cbuf_copy = g_string_new (get_cbuf->str); + GString *get_cbuf_copy = g_string_new (get_cbuf); char *tmp; - Node *node1 = new_type (type->name, type->pointer, type->postfix); - Node *node3 = new_type (class->class.otype, "*", NULL); + Node *node1 = new_type (g_strdup (type->name), + g_strdup (type->pointer), + g_strdup (type->postfix)); + Node *node3 = new_type (g_strdup (class->class.otype), + g_strdup ("*"), + NULL); tmp = g_strdup_printf ("\t%s%s ARG;\n", type->name, @@ -329,12 +347,18 @@ export_accessors (char *var_name, lineno, FALSE, NULL); } - if (set_cbuf) { + if (set_cbuf != NULL) { char *set_id = g_strdup_printf ("set_%s", var_name); - GString *set_cbuf_copy = g_string_new (set_cbuf->str); - Node *node1 = new_type (type->name, type->pointer, type->postfix); - Node *node2 = new_type ("void", NULL, NULL); - Node *node3 = new_type (class->class.otype, "*", NULL); + GString *set_cbuf_copy = g_string_new (set_cbuf); + Node *node1 = new_type (g_strdup (type->name), + g_strdup (type->pointer), + g_strdup (type->postfix)); + Node *node2 = new_type (g_strdup ("void"), + NULL, + NULL); + Node *node3 = new_type (g_strdup (class->class.otype), + g_strdup ("*"), + NULL); typestack = g_list_prepend (typestack, node2); typestack = g_list_prepend (typestack, node1); @@ -562,10 +586,12 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE '; if ($5) { export_accessors ($4, - $8, $7, - $11, $10, + ($8)->str, $7, + ($11)->str, $10, type, + $3, $1); + g_free ($5); } g_string_free ($8, FALSE); @@ -581,6 +607,17 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE '; ($11)->str,$10, ($8)->str,$7, $1); + + if ($5) { + export_accessors ($4, + ($11)->str, $10, + ($8)->str, $7, + type, + $3, + $1); + g_free ($5); + } + g_string_free ($11, FALSE); g_string_free ($8, FALSE); class_nodes = g_list_append(class_nodes,node); @@ -608,10 +645,12 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE '; $1); if ($5) { export_accessors ($4, - $8, $7, + ($8)->str, $7, NULL, 0, type, + $3, $1); + g_free ($5); } g_string_free ($8, FALSE); @@ -627,9 +666,11 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE '; if ($5) { export_accessors ($4, NULL, 0, - $8, $7, + ($8)->str, $7, type, + $3, $1); + g_free ($5); } g_string_free ($8, FALSE); @@ -699,11 +740,12 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE '; g_assert_not_reached(); } - if(strcmp ($6, "stringlink")==0) { + if (strcmp ($6, "stringlink")==0) { get = g_strdup_printf("ARG = g_strdup(%s->%s);", root, $4); - } else + } else { /* For everything else, get is just straight assignment */ get = g_strdup_printf("ARG = %s->%s;", root, $4); + } g_free ($6); @@ -718,10 +760,12 @@ argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE '; $1); if ($5) { export_accessors ($4, - g_string_new (get), $1, - g_string_new (set), $1, + get, $1, + set, $1, type, + $3, $1); + g_free ($5); } class_nodes = g_list_append(class_nodes,node); diff --git a/src/util.c b/src/util.c index 2455132..0e8ad94 100644 --- a/src/util.c +++ b/src/util.c @@ -216,7 +216,7 @@ init_type_hash(void) } const char * -get_cast(char *type, gboolean simple_only) +get_cast(const char *type, gboolean simple_only) { OurGtkType *gtype; diff --git a/src/util.h b/src/util.h index 20692b0..31dfca4 100644 --- a/src/util.h +++ b/src/util.h @@ -47,7 +47,7 @@ void separns_replace_sep(const char *base, char **ns, char **name, char r); char * make_pre_macro(const char *base,const char *pre); /* get a name usable for a cast from a GTK+ type (without GTK_TYPE_)*/ -const char * get_cast(char *type, gboolean simple_only); +const char * get_cast(const char *type, gboolean simple_only); enum { SPECIAL_2POINTER, -- 2.43.2