]> git.draconx.ca Git - gob-dx.git/blobdiff - src/main.c
Release 2.0.3
[gob-dx.git] / src / main.c
index fce8cb00774037ef6ae82508204a0648832462d0..d22a7da7a9a6262d6201d590fefc1e60832d54cc 100644 (file)
@@ -82,8 +82,8 @@ static gboolean made_aliases = FALSE;  /* if we made any shorthand aliases
 static gboolean special_array[SPECIAL_LAST] = {0};
 static gboolean any_special = FALSE;
 
-static gboolean need_shutdown = FALSE;
-static Method * shutdown_handler = NULL;
+static gboolean need_dispose = FALSE;
+static Method * dispose_handler = NULL;
 
 static gboolean need_finalize = FALSE;
 static Method * finalize_handler = NULL;
@@ -310,7 +310,7 @@ make_method_nongnu_aliases(Class *c)
 }
 
 static void
-add_bad_hack_to_avoid_unused_warnings(Class *c)
+add_bad_hack_to_avoid_unused_warnings(const Class *c)
 {
        GList *li;
 
@@ -356,7 +356,7 @@ add_bad_hack_to_avoid_unused_warnings(Class *c)
 }
 
 static void
-put_variable(Variable *v, FILE *fp)
+put_variable(const Variable *v, FILE *fp)
 {
        out_printf(fp, "\t");
        print_type(fp, v->vtype, FALSE);
@@ -526,7 +526,7 @@ put_prot_method(const Method *m)
 }
 
 static void
-put_priv_method_prot(Method *m)
+put_priv_method_prot(const Method *m)
 {
        if(m->method == SIGNAL_LAST_METHOD ||
           m->method == SIGNAL_FIRST_METHOD ||
@@ -636,30 +636,30 @@ make_inits(Class *cl)
 }
 
 static void
-find_shutdown(Class *cl)
+find_dispose(const Class *cl)
 {
        GList *li;
 
-       shutdown_handler = NULL;
+       dispose_handler = NULL;
        for(li=cl->nodes;li;li=g_list_next(li)) {
                Node *n = li->data;
                if(n->type == METHOD_NODE) {
                        Method *m = (Method *)n;
                        if(m->method == OVERRIDE_METHOD &&
-                          strcmp(m->id, "shutdown")==0) {
+                          strcmp(m->id, "dispose")==0) {
                                if(strcmp(m->otype, "G:Object") != 0) {
                                        error_print(GOB_ERROR, m->line_no,
-                                                   "shutdown method override "
+                                                   "dispose method override "
                                                    "of class other then "
                                                    "G:Object");
                                }
                                if(g_list_length(m->args) != 1) {
                                        error_print(GOB_ERROR, m->line_no,
-                                                   "shutdown method override "
+                                                   "dispose method override "
                                                    "with more then one "
                                                    "parameter");
                                }
-                               shutdown_handler = m;
+                               dispose_handler = m;
                                break;
                        }
                }
@@ -667,7 +667,7 @@ find_shutdown(Class *cl)
 }
 
 static void
-find_finalize(Class *cl)
+find_finalize(const Class *cl)
 {
        GList *li;
 
@@ -708,7 +708,7 @@ static GList *eq_signal_methods = NULL;
 
 /* compare a list of strings */
 static gboolean
-is_list_equal(GList *a, GList *b)
+is_list_equal(const GList *a, const GList *b)
 {
        for(;a && b; a=a->next, b=b->next) {
                if(strcmp(a->data, b->data)!=0) {
@@ -722,7 +722,7 @@ is_list_equal(GList *a, GList *b)
 }
 
 static Method *
-find_same_type_signal(Method *m)
+find_same_type_signal(const Method *m)
 {
        GList *li;
        for(li=eq_signal_methods;li;li=li->next) {
@@ -734,7 +734,7 @@ find_same_type_signal(Method *m)
 }
 
 static void
-print_signal_marsal_args (Method *m)
+print_signal_marsal_args (const Method *m)
 {
        if (strcmp (m->gtktypes->next->data, "NONE") != 0) {
                GList *li;
@@ -742,8 +742,15 @@ print_signal_marsal_args (Method *m)
                for (i = 0, li = m->gtktypes->next;
                     li != NULL;
                     i++, li = li->next) {
-                       char *get_func = g_strdup_printf
-                               ("g_value_get_%s", (char *)li->data);
+                       char *get_func;
+
+                       if (strcmp (li->data, "UNICHAR") == 0)
+                               /* hack because glib is braindamaged */
+                               get_func = g_strdup ("g_value_get_uint");
+                       else
+                               get_func = g_strdup_printf
+                                       ("g_value_get_%s", (char *)li->data);
+
                        g_strdown (get_func);
                        out_printf (out, ",\n\t\t(%s) "
                                    "%s (param_values + %d)",
@@ -857,9 +864,16 @@ add_signal_prots(Method *m)
                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 *)m->gtktypes->data,
-                                                 take_ownership ?
+               char *set_func;
+
+
+               if (strcmp (m->gtktypes->data, "UNICHAR") == 0)
+                       /* hack because glib is braindamaged */
+                       set_func = g_strdup ("g_value_set_uint");
+               else
+                       set_func = g_strdup_printf ("g_value_set_%s%s",
+                                                   (char *)m->gtktypes->data,
+                                                   take_ownership ?
                                                    "_take_ownership" : ""); 
                g_strdown (set_func);
 
@@ -1299,7 +1313,7 @@ add_signals(Class *c)
                if(strcmp(m->gtktypes->data, "NONE") != 0 ||
                   ! is_none) {
                        GList *gl, *al;
-                       char *sep = "";
+                       const char *sep = "";
                        out_printf(out, "\tif(");
                        if(strcmp(m->gtktypes->data, "NONE") != 0) {
                                out_printf(out, "%s sizeof(", sep);
@@ -1371,11 +1385,11 @@ set_def_handlers(Class *c, const char *oname)
                        s = replace_sep (m->otype, '_');
                        g_strdown (s);
 
-                       if (need_shutdown &&
-                           shutdown_handler != NULL &&
-                           strcmp (m->id, "shutdown") == 0)
-                               out_printf (out, "\tg_object_class->shutdown "
-                                           "= ___shutdown;\n");
+                       if (need_dispose &&
+                           dispose_handler != NULL &&
+                           strcmp (m->id, "dispose") == 0)
+                               out_printf (out, "\tg_object_class->dispose "
+                                           "= ___dispose;\n");
                        else if (need_finalize &&
                                finalize_handler &&
                                strcmp(m->id, "finalize") == 0)
@@ -1954,7 +1968,7 @@ print_initializer(Method *m, Variable *v)
 static void
 print_destructor (Variable *v)
 {
-       char *root;
+       const char *root;
 
        if(v->destructor == NULL)
                return;
@@ -1995,13 +2009,13 @@ print_destructor (Variable *v)
 }
 
 static void
-add_shutdown (Class *c)
+add_dispose (Class *c)
 {
        out_printf(out, "\nstatic void\n"
-                  "___shutdown (GObject *obj_self)\n"
+                  "___dispose (GObject *obj_self)\n"
                   "{\n");
        out_printf(out,
-                  "#define __GOB_FUNCTION__ \"%s::shutdown\"\n",
+                  "#define __GOB_FUNCTION__ \"%s::dispose\"\n",
                   c->otype);
 
        if (unreftors > 0) {
@@ -2009,18 +2023,18 @@ add_shutdown (Class *c)
                            typebase, macrobase);
        }
 
-       if (shutdown_handler != NULL) {
+       if (dispose_handler != NULL) {
                /* so we get possible bad argument warning */
-               if (shutdown_handler->line_no > 0)
-                       out_addline_infile (out, shutdown_handler->line_no);
-               out_printf (out, "\t___%x_%s_shutdown(obj_self);\n",
-                           (guint)shutdown_handler->unique_id, funcbase);
-               if (shutdown_handler->line_no > 0)
+               if (dispose_handler->line_no > 0)
+                       out_addline_infile (out, dispose_handler->line_no);
+               out_printf (out, "\t___%x_%s_dispose(obj_self);\n",
+                           (guint)dispose_handler->unique_id, funcbase);
+               if (dispose_handler->line_no > 0)
                        out_addline_outfile (out);
        } else {
                out_printf (out,
-                           "\tif (G_OBJECT_CLASS (parent_class)->shutdown) \\\n"
-                           "\t\t(* G_OBJECT_CLASS (parent_class)->shutdown) (obj_self);\n");
+                           "\tif (G_OBJECT_CLASS (parent_class)->dispose) \\\n"
+                           "\t\t(* G_OBJECT_CLASS (parent_class)->dispose) (obj_self);\n");
        }
 
        if (unreftors > 0) {
@@ -2194,7 +2208,7 @@ add_inits(Class *c)
                        if (set_properties > 0 ||
                            get_properties > 0 ||
                            signals > 0 ||
-                           need_shutdown ||
+                           need_dispose ||
                            need_finalize) {
                                out_printf(out,
                                           "\tGObjectClass *"
@@ -2236,9 +2250,9 @@ add_inits(Class *c)
 
                        /* if there are no handlers for these things, we
                         * need to set them up here */
-                       if(need_shutdown && !shutdown_handler)
-                               out_printf(out, "\tg_object_class->shutdown "
-                                          "= ___shutdown;\n");
+                       if(need_dispose && !dispose_handler)
+                               out_printf(out, "\tg_object_class->dispose "
+                                          "= ___dispose;\n");
                        if(need_finalize && !finalize_handler)
                                out_printf(out, "\tg_object_class->finalize = "
                                           "___finalize;\n");
@@ -2295,6 +2309,12 @@ add_argument (Argument *a, gboolean is_set)
        the_type_lower = g_strdup (a->gtktype);
        g_strdown (the_type_lower);
 
+       /* HACK because there is no g_value_set/get for unichar */
+       if (strcmp (the_type_lower, "unichar") == 0) {
+               g_free (the_type_lower);
+               the_type_lower = g_strdup ("uint");
+       }
+
        if (is_set) {
                char *cast;
 
@@ -2570,9 +2590,13 @@ put_signal_args (Method *m)
                            "\tg_value_init (&___param_values[%d], G_TYPE_%s);\n",
                            i, i, (char *)ali->data);
 
-               set_func = g_strdup_printf ("g_value_set%s_%s",
-                                           do_static ? "_static" : "",
-                                           (char *)ali->data);
+               if (strcmp (ali->data, "UNICHAR") == 0)
+                       /* hack because glib is braindamaged */
+                       set_func = g_strdup ("g_value_set_uint");
+               else
+                       set_func = g_strdup_printf ("g_value_set%s_%s",
+                                                   do_static ? "_static" : "",
+                                                   (char *)ali->data);
                g_strdown (set_func);
 
                out_printf (out, "\t%s (&___param_values[%d], (%s) %s);\n\n",
@@ -2584,20 +2608,18 @@ put_signal_args (Method *m)
 }
 
 static char *
-get_arg_names_for_macro(Method *m)
+get_arg_names_for_macro (Method *m)
 {
-       char *p;
+       const char *sep;
        GList *li;
        GString *gs = g_string_new(NULL);
-       p = "";
+       sep = "";
        for(li=m->args;li;li=g_list_next(li)) {
                FuncArg *arg = li->data;
-               g_string_sprintfa(gs, "%s___%s", p, arg->name);
-               p = ",";
+               g_string_sprintfa (gs, "%s___%s", sep, arg->name);
+               sep = ",";
        }
-       p = gs->str;
-       g_string_free(gs, FALSE);
-       return p;
+       return g_string_free (gs, FALSE);
 }
 
 static void
@@ -2679,9 +2701,13 @@ put_method(Method *m)
                                if (cast == NULL)
                                        cast = get_type (m->mtype, TRUE);
 
-                               set_func = g_strdup_printf ("g_value_set%s_%s",
-                                                           do_static ? "_static" : "",
-                                                           (char *)m->gtktypes->data);
+                               if (strcmp (m->gtktypes->data, "UNICHAR") == 0)
+                                       /* hack because glib is braindamaged */
+                                       set_func = g_strdup ("g_value_set_uint");
+                               else
+                                       set_func = g_strdup_printf ("g_value_set%s_%s",
+                                                                   do_static ? "_static" : "",
+                                                                   (char *)m->gtktypes->data);
                                g_strdown (set_func);
 
                                out_printf (out, "\t%s (&___return_val, (%s) (%s));\n",
@@ -2705,8 +2731,14 @@ put_method(Method *m)
 
                if (strcmp (m->gtktypes->data, "NONE") != 0) {
                        char *cast = g_strdup (get_cast (m->gtktypes->data, FALSE));
-                       char *getfunc = g_strdup_printf ("g_value_get_%s",
-                                                        (char *)m->gtktypes->data);
+                       char *getfunc;
+
+                       if (strcmp (m->gtktypes->data, "UNICHAR") == 0)
+                               /* hack because glib is braindamaged */
+                               getfunc = g_strdup ("g_value_get_uint");
+                       else
+                               getfunc = g_strdup_printf ("g_value_get_%s",
+                                                          (char *)m->gtktypes->data);
                        g_strdown (getfunc);
 
                        if (cast == NULL)
@@ -3249,12 +3281,7 @@ print_class_block(Class *c)
                    " */\n");
 
        if ( ! overrode_get_type) {
-               out_printf (outh, "GType\t%s_get_type\t(void)", funcbase);
-               if ( ! no_gnu) {
-                       out_printf (outh, " G_GNUC_CONST;\n");
-               } else {
-                       out_printf (outh, ";\n");
-               }
+               out_printf (outh, "GType\t%s_get_type\t(void);", funcbase);
        }
 
        for(li = c->nodes; li != NULL; li = li->next) {
@@ -3354,8 +3381,8 @@ print_class_block(Class *c)
                    no_gnu ? "" : " G_GNUC_UNUSED",
                    typebase, typebase, typebase, funcbase);
 
-       if (need_shutdown)
-               add_shutdown (c);
+       if (need_dispose)
+               add_dispose (c);
 
        if (need_finalize)
                add_finalize (c);
@@ -4061,8 +4088,8 @@ main(int argc, char *argv[])
        make_bases ();
        make_inits ((Class *)class);
        if(unreftors > 0) {
-               need_shutdown = TRUE;
-               find_shutdown ((Class *)class);
+               need_dispose = TRUE;
+               find_dispose ((Class *)class);
        }
        if (destructors > 0 ||
            privates > 0) {