]> git.draconx.ca Git - gob-dx.git/blobdiff - src/main.c
Release 0.91.2
[gob-dx.git] / src / main.c
index 3a1655470a518212c4e40d5bb7d0c01f7d80809a..751c0642113f52804caa73a1422c5d71b87ed4d3 100644 (file)
@@ -60,6 +60,10 @@ static int arguments = 0; /* number of named arguments */
 static int overrides = 0; /* number of override functions */
 static int privates = 0; /* number of private data members */
 
+static gboolean made_aliases = FALSE;  /* if we made any shorthand aliases
+                                         and need the REALLY UGLY HACK to
+                                         avoid warnings */
+
 FILE *out = NULL;
 FILE *outh = NULL;
 FILE *outph = NULL;
@@ -269,6 +273,8 @@ make_method_pointers(Class *c)
 
                        print_method(out,"static ","(* ",") ","",m,TRUE);
                        out_printf(out," = %s_%s;\n",funcbase,m->id);
+
+                       made_aliases = TRUE;
                }
        }
        out_printf(out,"\n");
@@ -278,6 +284,10 @@ static void
 add_bad_hack_to_avoid_unused_warnings(Class *c)
 {
        GList *li;
+
+       /* if we haven't had any methods, just return */
+       if(!made_aliases)
+               return;
        
        out_printf(out,"\n\n/*REALLY BAD HACK\n"
                   "  This is to avoid unused warnings if you don't call\n"
@@ -356,13 +366,13 @@ put_priv_method_prot(Method *m)
        if(m->scope == PRIVATE_SIGNAL_LAST_METHOD ||
           m->scope == PRIVATE_SIGNAL_FIRST_METHOD ||
           m->scope == PRIVATE_VIRTUAL_METHOD) {
-               if(m->cbuf)
+               if(m->cbuf && *m->cbuf->str)
                        print_method(out,"static ","_real_"," ",";\n",m,FALSE);
                print_method(out,"static ",""," ",";\n",m,FALSE);
        } else if(m->scope == SIGNAL_LAST_METHOD ||
                  m->scope == SIGNAL_FIRST_METHOD ||
                  m->scope == VIRTUAL_METHOD) {
-               if(!m->cbuf)
+               if(!m->cbuf || !*m->cbuf->str)
                        return;
                print_method(out,"static ","_real_"," ",";\n",m,FALSE);
        } else {
@@ -774,7 +784,7 @@ set_def_handlers(Class *c, char *oname)
                        out_printf(out,"\t%s_class->%s = %s_%s;\n",
                                s,m->id,funcbase,m->id);
                } else {
-                       if(m->cbuf)
+                       if(m->cbuf && *m->cbuf->str)
                                out_printf(out,"\t%s->%s = _real_%s_%s;\n",
                                        oname,m->id,funcbase,m->id);
                        else
@@ -887,7 +897,7 @@ add_inits(Class *c)
                } else
                        continue;
 
-               if(m->cbuf) {
+               if(m->cbuf && *m->cbuf->str) {
                        out_printf(out," {\n");
                        out_addline_infile(out,m->ccode_line);
                        out_printf(out,"%s\n",m->cbuf->str);
@@ -1055,6 +1065,9 @@ put_method(Method *m)
 {
        char *s;
        int private = FALSE;
+       int is_void;
+       is_void = (strcmp(m->mtype->name,"void")==0 &&
+                  m->mtype->stars == 0);
        out_printf(out,"\n");
        switch(m->scope) {
        case PUBLIC_SCOPE:
@@ -1108,7 +1121,7 @@ put_method(Method *m)
                                "\treturn return_val;\n}\n");
                }
 
-               if(!m->cbuf)
+               if(!m->cbuf || !*m->cbuf->str)
                        break;
                out_addline_infile(out,m->line_no);
                print_method(out,"static ","\n_real_"," ","\n",m,FALSE);
@@ -1152,7 +1165,7 @@ put_method(Method *m)
                                m->onerror?m->onerror:"0");
                }
 
-               if(!m->cbuf)
+               if(!m->cbuf || !*m->cbuf->str)
                        break;
                out_addline_infile(out,m->line_no);
                print_method(out,"static ","\n_real_"," ","\n",m,FALSE);
@@ -1163,10 +1176,22 @@ put_method(Method *m)
                print_method(out,"static ","\n"," ","\n",m,FALSE);
                s = replace_sep(m->otype,'_');
                g_strup(s);
-               out_printf(out,"#define PARENT_HANDLER(args...) \\\n"
-                          "\t{ if(%s_CLASS(parent_class)->%s) \\\n"
-                          "\t\t(* %s_CLASS(parent_class)->%s)(##args); }\n",
-                          s,m->id,s,m->id);
+               if(is_void) {
+                       out_printf(out,"#define PARENT_HANDLER(args...) \\\n"
+                                  "\t{ if(%s_CLASS(parent_class)->%s) \\\n"
+                                  "\t\t(* %s_CLASS(parent_class)->%s)(##args); }\n",
+                                  s,m->id,s,m->id);
+               } else {
+                       out_printf(out,"#define PARENT_HANDLER(args...) \\\n"
+                                  "\t((%s_CLASS(parent_class)->%s)? \\\n"
+                                  "\t\t(* %s_CLASS(parent_class)->%s)(##args): \\\n"
+                                  "\t\t(",
+                                  s,m->id,s,m->id);
+                       out_printf(out,"(");
+                       print_type(out,m->mtype,TRUE);
+                       out_printf(out,")%s))\n",
+                                  m->onerror?m->onerror:"0");
+               }
                g_free(s);
                print_method_body(m,TRUE);
                out_printf(out,"#undef PARENT_HANDLER\n");