2 * Copyright (C) 1999-2000 the Free Software Foundation.
3 * Copyright (C) 2000 Eazel, Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
29 #include "treefuncs.h"
35 error_print(int type, int line, const char *error)
48 g_assert_not_reached();
51 fprintf(stderr, "%s:%d: %s %s\n", filename, line, w, error);
53 fprintf(stderr, "%s: %s %s\n", filename, w, error);
56 (type == GOB_WARN && exit_on_warn)))
61 error_printf(int type, int line, const char *error, ...)
67 s = g_strdup_vprintf(error, ap);
70 error_print(type, line, s);
76 remove_sep(const char *base)
79 char *s = g_strdup(base);
80 while((p = strchr(s, ':')))
86 replace_sep(const char *base, char r)
89 char *s = g_strdup(base);
90 while((p=strchr(s,':')))
100 /*separate the namespace part and then replace rest of
103 separns_replace_sep(const char *base, char **ns, char **name, char r)
106 char *s = g_strdup(base);
108 if((p=strchr(s,':')) && p!=s) {
115 while((p=strchr(s,':')))
118 *name = g_strdup(s+1);
124 /* make a macro with some prefix before the name but after
127 make_pre_macro(const char *base, const char *pre)
133 if(strchr(base, ' ')) {
135 v = g_strsplit(base, " ", 0);
136 for(i = 0; v[i] != NULL; i++) {
137 if(*v[i] && strcmp(v[i], "const") != 0) {
144 separns_replace_sep(base, &ns, &name, '_');
146 s = g_strconcat(ns, "_", pre, "_", name,NULL);
148 s = g_strconcat(pre, "_", name, NULL);
160 /* here we will find out how inconsistent gtk really is :) */
161 /* the commented out types mean that these types don't actually
162 exist. so we "emulate them" with an equivalent */
163 typedef struct _OurGtkType OurGtkType;
172 const OurGtkType our_gtk_type_table[] = {
173 { TRUE, "NONE", "void ", "void", NULL, -1 },
174 { TRUE, "CHAR", "gchar ", "gchar", NULL, -1 },
175 { TRUE, "UCHAR", "guchar ", "guchar", NULL, -1 },
176 { TRUE, "BOOLEAN", "gboolean ", "gboolean", NULL, -1 },
177 { TRUE, "INT", "gint ", "gint", NULL, -1 },
178 { TRUE, "UINT", "guint ", "guint", NULL, -1 },
179 { TRUE, "LONG", "glong ", "glong", NULL, -1 },
180 { TRUE, "ULONG", "gulong ", "gulong", NULL, -1 },
181 { TRUE, "ENUM", /*"enum"*/"gint ", "gint", NULL, -1 },
182 { TRUE, "FLAGS", /*"flags"*/"guint ", "guint", NULL, -1 },
183 { TRUE, "FLOAT", "gfloat ", "gfloat", NULL, -1 },
184 { TRUE, "DOUBLE", "gdouble ", "gdouble", NULL, -1 },
185 { TRUE, "STRING", /*"string"*/"gchar *", "gchar", "*", -1 },
186 { TRUE, "POINTER", "gpointer ", "gpointer", NULL, -1 },
187 { TRUE, "BOXED", /*"boxed"*/"gpointer ", "gpointer", NULL, -1 },
188 { TRUE, "OBJECT", "GObject *", "GObject", "*", -1 },
189 { TRUE, "PARAM", "GParamSpec *", "GParamSpec", "*", -1 },
191 /* FIXME: VALUE_ARRAY, CLOSURE, UNICHAR */
192 /* Note that those have some issues with g_value_ calls etc... so
193 * we can't just add them */
195 /* Do we need this??? */
197 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
199 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
200 SPECIAL_INT_POINTER },
201 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
203 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
205 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
209 { FALSE, NULL, NULL }
212 static GHashTable *type_hash = NULL;
219 if(type_hash) return;
221 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
223 for(i=0; our_gtk_type_table[i].gtkname; i++)
224 g_hash_table_insert(type_hash,
225 our_gtk_type_table[i].gtkname,
226 (gpointer)&our_gtk_type_table[i]);
230 get_cast (const char *type, gboolean simple_only)
236 gtype = g_hash_table_lookup (type_hash, type);
247 get_tree_type (const char *type, gboolean simple_only)
254 gtype = g_hash_table_lookup (type_hash, type);
261 node = node_new (TYPE_NODE,
262 "name", gtype->type_name,
263 "pointer", gtype->type_pointer,
270 mask_special_array(char *type, gboolean *special_array, gboolean *any_special)
276 gtype = g_hash_table_lookup(type_hash, type);
278 if(gtype && gtype->special >= 0) {
279 special_array[gtype->special] = TRUE;
285 setup_special_array(Class *c, gboolean *special_array)
288 gboolean any_special = FALSE;
290 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
292 for(li=c->nodes; li; li=g_list_next(li)) {
294 if(n->type == METHOD_NODE) {
295 Method *m = (Method *)n;
297 if(m->method != SIGNAL_LAST_METHOD &&
298 m->method != SIGNAL_FIRST_METHOD)
301 for(l=m->gtktypes; l; l=l->next)
302 mask_special_array(l->data, special_array,
304 } else if(n->type == ARGUMENT_NODE) {
305 Argument *a = (Argument *)n;
306 mask_special_array(a->gtktype, special_array,