]> git.draconx.ca Git - gob-dx.git/blobdiff - src/main.c
Release 0.92.3
[gob-dx.git] / src / main.c
index d86697d83cd8b2852fce037ce075f5740f21628a..d5d299e28a268e64673c09794866d4628d23d4eb 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <sys/stat.h>
 
 #include "tree.h"
@@ -46,6 +47,8 @@ extern GList *nodes;
 
 extern GList *include_files;
 
+extern GHashTable *gtk_doc_hash;
+
 char *filebase;
 static char *funcbase;
 static char *pfuncbase;
@@ -135,6 +138,27 @@ get_type(Type *t, gboolean postfix_to_stars)
        return s;
 }
 
+static char *
+get_gtk_doc(char *id)
+{
+       char *val, *s;
+
+       if(!gtk_doc_hash)
+               return NULL;
+
+       val = g_hash_table_lookup(gtk_doc_hash, id);
+       if(val)
+               return g_strdup_printf("/**\n * %s_%s:\n%s **/\n",
+                                      funcbase, id, val);
+       s = g_strconcat(funcbase, "_", id, NULL);
+       val = g_hash_table_lookup(gtk_doc_hash, s);
+       g_free(s);
+       if(val)
+               return g_strdup_printf("/**\n * %s_%s:\n%s **/\n",
+                                      funcbase, id, val);
+       return NULL;
+}
+
 static void
 print_type(FILE *fp, Type *t, gboolean postfix_to_stars)
 {
@@ -148,7 +172,9 @@ print_type(FILE *fp, Type *t, gboolean postfix_to_stars)
 
 static void
 print_method(FILE *fp, char *typeprefix, char *nameprefix,
-            char *namepostfix,char *postfix, Method *m,
+            char *subnameprefix,
+            char *namepostfix, char *postfix, Method *m,
+            gboolean one_arg_per_line,
             gboolean no_funcbase)
 {
        GList *li;
@@ -156,27 +182,30 @@ print_method(FILE *fp, char *typeprefix, char *nameprefix,
        out_printf(fp,"%s",typeprefix); 
        print_type(fp,m->mtype,TRUE);
        if(no_funcbase)
-               out_printf(fp,"%s%s%s(",
-                          nameprefix,m->id,namepostfix); 
+               out_printf(fp,"%s%s%s%s(",
+                          nameprefix,subnameprefix,m->id,namepostfix); 
        else
-               out_printf(fp,"%s%s_%s%s(",
-                          nameprefix,funcbase,m->id,namepostfix); 
+               out_printf(fp,"%s%s_%s%s%s(",
+                          nameprefix,funcbase,subnameprefix,m->id,
+                          namepostfix); 
        
        if(m->args) {
                for(li=m->args;li;li=g_list_next(li)) {
                        FuncArg *arg = li->data;
                        print_type(fp,arg->atype,FALSE);
                        if(li->next)
-                               out_printf(fp,"%s%s, ",arg->name,
+                               out_printf(fp,"%s%s,%s",arg->name,
                                           arg->atype->postfix?
-                                          arg->atype->postfix:""); 
+                                          arg->atype->postfix:"",
+                                          one_arg_per_line?"\n\t\t\t\t\t":" ");
                        else
                                out_printf(fp,"%s%s",arg->name,
                                           arg->atype->postfix?
                                           arg->atype->postfix:""); 
                }
                if(m->vararg)
-                       out_printf(fp,", ..."); 
+                       out_printf(fp,",%s...",
+                                  one_arg_per_line?"\n\t\t\t\t\t":" "); 
        } else {
                out_printf(fp,"void"); 
        }
@@ -232,7 +261,7 @@ make_method_nongnu_aliases(Class *c)
                        if(for_cpp && strcmp(m->id,"new")==0)
                                continue;
 
-                       print_method(out,"static ","(* ",") ","",m,TRUE);
+                       print_method(out,"static ","(* ","",") ","",m,FALSE,TRUE);
                        out_printf(out," = %s_%s;\n",funcbase,m->id);
 
                        made_aliases = TRUE;
@@ -306,7 +335,12 @@ put_vs_method(Method *m)
           m->method != VIRTUAL_METHOD)
                return;
 
-       print_method(outh,"\t","(* ",") ",";\n",m,TRUE);
+       /* if a signal mark it as such */
+       if(m->method != VIRTUAL_METHOD)
+               print_method(outh,"\t/*signal*/","(* ","",") ",";\n",m,
+                            FALSE,TRUE);
+       else
+               print_method(outh,"\t","(* ","",") ",";\n",m,FALSE,TRUE);
 }
 
 static void
@@ -315,9 +349,47 @@ put_pub_method(Method *m)
        if(m->scope != PUBLIC_SCOPE)
                return;
 
-       print_method(outh,"","\t","\t",";\n",m,FALSE);
+       print_method(outh,"","\t","","\t",";\n",m,TRUE,FALSE);
 }
 
+/* I'm starting not to like this idea */
+#if 0
+static void
+put_signal_connect(Method *m)
+{
+       if(m->method != SIGNAL_LAST_METHOD &&
+          m->method != SIGNAL_FIRST_METHOD)
+               return;
+
+       out_printf(outh, "guint \t%s_%s__connect_full\t(%s *object,\n"
+                  "\t\t\t\t\tconst char *name,\n"
+                  "\t\t\t\t\tGtkSignalFunc func,\n"
+                  "\t\t\t\t\tGtkCallbackMarshal marshal,\n"
+                  "\t\t\t\t\tgpointer data,\n"
+                  "\t\t\t\t\tGtkDestroyNotify destroy_func,\n"
+                  "\t\t\t\t\tgboolean object_signal,\n"
+                  "\t\t\t\t\tgboolean after);\n",
+                  funcbase, m->id, typebase);
+
+       out_printf(outh, "#define %s_%s__connect(object,name,func,data) "
+                  "%s_%s__connect_full((object),(name),(func),NULL,"
+                  "(data),NULL,FALSE,FALSE)\n",
+                  funcbase, m->id, funcbase, m->id);
+       out_printf(outh, "#define %s_%s__connect_after(object,name,func,data) "
+                  "%s__connect_%s_full((object),(name),(func),NULL,"
+                  "(data),NULL,FALSE,TRUE)\n",
+                  funcbase, m->id, funcbase, m->id);
+
+       out_printf(outh, "guint \t%s_%s__connect_while_alive\t(%s *object,\n"
+                  "\t\t\t\t\tconst char *name,\n"
+                  "\t\t\t\t\tGtkSignalFunc func,\n"
+                  "\t\t\t\t\tgpointer data,\n"
+                  "\t\t\t\t\tGtkObject *alive_object);\n\n",
+                  funcbase, m->id, typebase);
+}
+#endif
+
+
 static void
 put_prot_method(Method *m)
 {
@@ -325,9 +397,9 @@ put_prot_method(Method *m)
                return;
 
        if(outph)
-               print_method(outph,"","\t","\t",";\n",m,FALSE);
+               print_method(outph,"","\t","","\t",";\n",m,FALSE,FALSE);
        else
-               print_method(out,"","\t","\t",";\n",m,FALSE);
+               print_method(out,"","\t","","\t",";\n",m,FALSE,FALSE);
 }
 
 static void
@@ -337,7 +409,9 @@ put_priv_method_prot(Method *m)
           m->method == SIGNAL_FIRST_METHOD ||
           m->method == VIRTUAL_METHOD) {
                if(m->cbuf)
-                       print_method(out,"static ","___real_"," ",";\n",m,FALSE);
+                       print_method(out,
+                                    "static ", "___real_", "", " ", ";\n",
+                                    m, FALSE, FALSE);
        }
 
        if(m->scope == PRIVATE_SCOPE ||
@@ -345,9 +419,9 @@ put_priv_method_prot(Method *m)
           m->method == CLASS_INIT_METHOD ||
           (m->method == OVERRIDE_METHOD &&
            m->cbuf))
-               print_method(out,"static ",""," ",
-                            no_gnu?";\n":" ___NO_UNUSED_WARNING;\n"
-                            ,m,FALSE);
+               print_method(out, "static ", "", "", " ",
+                            no_gnu?";\n":" G_GNUC_UNUSED;\n",
+                            m, FALSE, FALSE);
 }
 
 static GList *
@@ -646,12 +720,12 @@ add_overrides(Class *c, char *oname, gboolean did_gtk_obj)
        GHashTable *done;
        char *s;
        
-       done = g_hash_table_new(g_str_hash,g_str_equal);
+       done = g_hash_table_new(g_str_hash, g_str_equal);
        if(did_gtk_obj) {
                s = g_strdup("GtkObject"); /* This was already done */
-               g_hash_table_insert(done,s,s);
+               g_hash_table_insert(done, s, s);
        }
-       for(li=c->nodes;li;li=g_list_next(li)) {
+       for(li=c->nodes; li; li=g_list_next(li)) {
                Node *n = li->data;
                char *f;
                Method *m = (Method *)n;
@@ -866,7 +940,8 @@ add_inits(Class *c)
                if(m->method == INIT_METHOD) {
                        if(m->line_no>0)
                                out_addline_infile(out,m->line_no);
-                       print_method(out,"static ","\n"," ","\n",m,FALSE);
+                       print_method(out, "static ", "\n", "", " ", "\n",
+                                    m, FALSE, FALSE);
                        if(m->line_no>0)
                                out_addline_outfile(out);
                        out_printf(out,"{\n");
@@ -878,8 +953,9 @@ add_inits(Class *c)
                        }
                } else if(m->method == CLASS_INIT_METHOD) {
                        if(m->line_no>0)
-                               out_addline_infile(out,m->line_no);
-                       print_method(out,"static ","\n"," ","\n",m,FALSE);
+                               out_addline_infile(out, m->line_no);
+                       print_method(out, "static ", "\n", "", " ", "\n",
+                                    m, FALSE, FALSE);
                        if(m->line_no>0)
                                out_addline_outfile(out);
                        out_printf(out,"{\n");
@@ -1135,19 +1211,26 @@ get_arg_names_for_macro(Method *m)
 static void
 put_method(Method *m)
 {
-       char *s,*args;
+       char *s,*args,*doc;
        gboolean is_void;
        is_void = (strcmp(m->mtype->name,"void")==0 &&
                   m->mtype->stars == 0);
        out_printf(out,"\n");
+       doc = get_gtk_doc(m->id);
+       if(doc) {
+               out_printf(out, "%s", doc);
+               g_free(doc);
+       }
        switch(m->method) {
        case REGULAR_METHOD:
                if(m->line_no>0)
                        out_addline_infile(out,m->line_no);
                if(m->scope == PRIVATE_SCOPE)
-                       print_method(out,"static ","\n"," ","\n",m,FALSE);
+                       print_method(out,"static ","\n",""," ","\n",
+                                    m,FALSE,FALSE);
                else /* PUBLIC, PROTECTED */
-                       print_method(out,"","\n"," ","\n",m,FALSE);
+                       print_method(out, "", "\n", "", " ", "\n",
+                                    m, FALSE, FALSE);
                print_method_body(m,TRUE);
                break;
        case SIGNAL_FIRST_METHOD:
@@ -1155,9 +1238,10 @@ put_method(Method *m)
                if(m->line_no>0)
                        out_addline_infile(out,m->line_no);
                if(m->scope == PRIVATE_SCOPE)
-                       print_method(out,"static ","\n"," ","\n",m,FALSE);
-               else
-                       print_method(out,"","\n"," ","\n",m,FALSE);
+                       print_method(out,"static ","\n",""," ","\n",
+                                    m,FALSE,FALSE);
+               else /* PUBLIC, PROTECTED */
+                       print_method(out,"","\n",""," ","\n",m,FALSE,FALSE);
                out_addline_outfile(out);
                out_printf(out,"{\n");
                s = g_strdup(m->id);
@@ -1188,16 +1272,18 @@ put_method(Method *m)
                        break;
                if(m->line_no>0)
                        out_addline_infile(out,m->line_no);
-               print_method(out,"static ","\n___real_"," ","\n",m,FALSE);
+               print_method(out,"static ","\n___real_",""," ","\n",
+                            m,FALSE,FALSE);
                print_method_body(m,FALSE);
                break;
        case VIRTUAL_METHOD:
                if(m->line_no>0)
                        out_addline_infile(out,m->line_no);
                if(m->scope==PRIVATE_SCOPE)
-                       print_method(out,"static ","\n"," ","\n",m,FALSE);
-               else
-                       print_method(out,"","\n"," ","\n",m,FALSE);
+                       print_method(out,"static ","\n",""," ","\n",
+                                    m,FALSE,FALSE);
+               else /* PUBLIC, PROTECTED */
+                       print_method(out,"","\n",""," ","\n",m,FALSE,FALSE);
                out_addline_outfile(out);
                out_printf(out,"{\n"
                        "\t%sClass *klass;\n",typebase);
@@ -1235,7 +1321,8 @@ put_method(Method *m)
                        break;
                if(m->line_no>0)
                        out_addline_infile(out,m->line_no);
-               print_method(out,"static ","\n___real_"," ","\n",m,FALSE);
+               print_method(out,"static ","\n___real_",""," ","\n",
+                            m,FALSE,FALSE);
                print_method_body(m,FALSE);
                break;
        case OVERRIDE_METHOD:
@@ -1243,7 +1330,8 @@ put_method(Method *m)
                        break;
                if(m->line_no>0)
                        out_addline_infile(out,m->line_no);
-               print_method(out,"static ","\n"," ","\n",m,FALSE);
+               print_method(out,"static ","\n",""," ","\n",
+                            m,FALSE,FALSE);
                s = replace_sep(m->otype,'_');
                g_strup(s);
                args = get_arg_names_for_macro(m);
@@ -1449,7 +1537,10 @@ print_class_block(Class *c)
                   "gpointer c; "
                   "} ___threepointertype;\n");
 
-       out_printf(outh,"\n#define %s\t"
+       out_printf(outh, "\n/*\n"
+                  " * Type checking and casting macros\n"
+                  " */\n");
+       out_printf(outh,"#define %s\t"
                   "(%s_get_type())\n",
                   macrotype,funcbase);
        out_printf(outh,"#define %s(obj)\t"
@@ -1462,20 +1553,15 @@ print_class_block(Class *c)
                   "GTK_CHECK_TYPE((obj), %s_get_type ())\n\n",
                   macrois,funcbase);
 
-       /* argument wrapping macros */
-       if(arguments>0 && !no_gnu) {
-               out_printf(outh,"\n#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) {
-               put_argument_nongnu_wrappers(c);
+       if(privates>0) {
+               out_printf(outh, "\n/* Private structure type */\n");
+               out_printf(outh,"typedef struct _%sPrivate %sPrivate;\n",
+                          typebase,typebase);
        }
 
-       if(privates>0)
-               out_printf(outh,"\ntypedef struct _%sPrivate %sPrivate;\n",typebase,typebase);
-
+       out_printf(outh, "\n/*\n"
+                  " * Main object structure\n"
+                  " */\n");
        s = replace_sep(c->otype,'_');
        g_strup(s);
        out_printf(outh,"#ifndef __TYPEDEF_%s__\n"
@@ -1530,7 +1616,10 @@ print_class_block(Class *c)
                out_printf(outfp,"};\n");
        }
 
-       out_printf(outh,"\ntypedef struct _%sClass %sClass;\n",
+       out_printf(outh, "\n/*\n"
+                  " * Class definition\n"
+                  " */\n");
+       out_printf(outh,"typedef struct _%sClass %sClass;\n",
                   typebase,typebase);
        out_printf(outh,
                   "struct _%sClass {\n\t%sClass __parent__;\n",
@@ -1542,17 +1631,7 @@ print_class_block(Class *c)
        }
        out_printf(outh,"};\n\n");
 
-       out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
-
        out_printf(out,"/* here are local prototypes */\n");
-       if(!no_gnu) {
-               out_printf(out,"#ifdef __GNUC__\n"
-                          "#define ___NO_UNUSED_WARNING "
-                          "__attribute__ ((__unused__))\n"
-                          "#else /* __GNUC__ */\n"
-                          "#define ___NO_UNUSED_WARNING\n"
-                          "#endif /* __GNUC__ */\n");
-       }
        if(arguments>0) {
                out_printf(out,"static void ___object_set_arg "
                           "(GtkObject *object, GtkArg *arg, "
@@ -1562,6 +1641,11 @@ print_class_block(Class *c)
                           "guint arg_id);\n");
        }
 
+       out_printf(outh, "\n/*\n"
+                  " * Public methods\n"
+                  " */\n");
+
+       out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
        for(l=c->nodes;l;l=g_list_next(l)) {
                Node *n = l->data;
                if(n->type == METHOD_NODE) {
@@ -1571,6 +1655,41 @@ print_class_block(Class *c)
                }
        }
 
+/* this idea is less and less apealing to me */
+#if 0
+       if(!no_signal_connect) {
+               if(signals>0) {
+                       out_printf(outh, "\n/*\n"
+                                  " * Signal connection methods\n"
+                                  " */\n");
+               }
+
+               for(l=c->nodes;l;l=g_list_next(l)) {
+                       Node *n = l->data;
+                       if(n->type == METHOD_NODE)
+                               put_signal_connect((Method *)n);
+               }
+       }
+#endif
+
+
+       /* 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(signals>0) {
                for(l=c->nodes;l;l=g_list_next(l)) {
                        Node *n = l->data;
@@ -1579,9 +1698,6 @@ print_class_block(Class *c)
                }
        }
 
-       if(!no_gnu)
-               out_printf(out,"#undef ___NO_UNUSED_WARNING\n");
-
        add_enums(c);
 
        add_get_type();