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)
38 const char *fname = NULL;
51 g_assert_not_reached();
57 fprintf(stderr, "%s:%d: %s %s\n", fname, line, w, error);
59 fprintf(stderr, "%s: %s %s\n", fname, w, error);
60 if (exit_on_error && got_error)
65 error_printf(int type, int line, const char *error, ...)
71 s = g_strdup_vprintf(error, ap);
74 error_print(type, line, s);
80 remove_sep(const char *base)
83 char *s = g_strdup(base);
86 /* don't eat C++ :: thingies */
87 if (for_cpp && strstr (s, "::") != NULL)
90 for(p=(char *)base;*p;p++){
99 replace_sep(const char *base, char r)
102 char *s = g_strdup(base);
104 /* don't eat C++ :: thingies */
105 if (for_cpp && strstr (s, "::") != NULL)
109 while ((p=strchr(s,':')) != NULL) {
117 while ((p=strchr(s,':')) != NULL)
128 /*separate the namespace part and then replace rest of
131 separns_replace_sep(const char *base, char **ns, char **name, char r)
134 char *s = g_strdup(base);
138 /* don't eat C++ :: thingies */
139 if (for_cpp && strstr (s, "::") != NULL) {
144 if((p=strchr(s,':')) && p!=s) {
151 while((p=strchr(s,':')))
154 *name = g_strdup(s+1);
160 /* make a macro with some prefix before the name but after
163 make_pre_macro(const char *base, const char *pre)
169 if(strchr(base, ' ')) {
171 v = g_strsplit(base, " ", 0);
172 for(i = 0; v[i] != NULL; i++) {
173 if(*v[i] && strcmp(v[i], "const") != 0) {
180 separns_replace_sep(base, &ns, &name, '_');
182 s = g_strconcat(ns, "_", pre, "_", name,NULL);
184 s = g_strconcat(pre, "_", name, NULL);
196 /* here we will find out how inconsistent gtk really is :) */
197 /* the commented out types mean that these types don't actually
198 exist. so we "emulate them" with an equivalent */
199 typedef struct _OurGtkType OurGtkType;
208 const OurGtkType our_gtk_type_table[] = {
209 { TRUE, "NONE", "void ", "void", NULL, -1 },
210 { TRUE, "CHAR", "gchar ", "gchar", NULL, -1 },
211 { TRUE, "UCHAR", "guchar ", "guchar", NULL, -1 },
212 { TRUE, "UNICHAR", "gunichar ", "gunichar", NULL, -1 },
213 { TRUE, "BOOLEAN", "gboolean ", "gboolean", NULL, -1 },
214 { TRUE, "INT", "gint ", "gint", NULL, -1 },
215 { TRUE, "UINT", "guint ", "guint", NULL, -1 },
216 { TRUE, "LONG", "glong ", "glong", NULL, -1 },
217 { TRUE, "ULONG", "gulong ", "gulong", NULL, -1 },
218 { TRUE, "INT64", "gint64 ", "gint64", NULL, -1 },
219 { TRUE, "UINT64", "guint64 ", "guint64", NULL, -1 },
220 { TRUE, "ENUM", /*"enum"*/"gint ", "gint", NULL, -1 },
221 { TRUE, "FLAGS", /*"flags"*/"guint ", "guint", NULL, -1 },
222 { TRUE, "FLOAT", "gfloat ", "gfloat", NULL, -1 },
223 { TRUE, "DOUBLE", "gdouble ", "gdouble", NULL, -1 },
224 { TRUE, "STRING", /*"string"*/"gchar *", "gchar", "*", -1 },
225 { TRUE, "POINTER", "gpointer ", "gpointer", NULL, -1 },
226 { TRUE, "BOXED", /*"boxed"*/"gpointer ", "gpointer", NULL, -1 },
227 { TRUE, "OBJECT", "GObject *", "GObject", "*", -1 },
228 { TRUE, "PARAM", "GParamSpec *", "GParamSpec", "*", -1 },
230 /* FIXME: VALUE_ARRAY, CLOSURE */
231 /* Note that those have some issues with g_value_ calls etc... so
232 * we can't just add them */
234 /* Do we need this??? */
236 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
238 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
239 SPECIAL_INT_POINTER },
240 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
242 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
244 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
248 { FALSE, NULL, NULL }
251 static GHashTable *type_hash = NULL;
258 if(type_hash) return;
260 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
262 for(i=0; our_gtk_type_table[i].gtkname; i++)
263 g_hash_table_insert(type_hash,
264 our_gtk_type_table[i].gtkname,
265 (gpointer)&our_gtk_type_table[i]);
269 get_cast (const char *type, gboolean simple_only)
275 if(strncmp(type, "BOXED_", 6) == 0)
276 gtype = g_hash_table_lookup (type_hash, "BOXED");
278 gtype = g_hash_table_lookup (type_hash, type);
289 get_tree_type (const char *type, gboolean simple_only)
296 gtype = g_hash_table_lookup (type_hash, type);
303 node = node_new (TYPE_NODE,
304 "name", gtype->type_name,
305 "pointer", gtype->type_pointer,
312 mask_special_array (const char *type, gboolean *special_array, gboolean *any_special)
318 gtype = g_hash_table_lookup(type_hash, type);
320 if(gtype && gtype->special >= 0) {
321 special_array[gtype->special] = TRUE;
327 setup_special_array(Class *c, gboolean *special_array)
330 gboolean any_special = FALSE;
332 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
334 for(li=c->nodes; li; li=g_list_next(li)) {
336 if(n->type == METHOD_NODE) {
337 Method *m = (Method *)n;
339 if(m->method != SIGNAL_LAST_METHOD &&
340 m->method != SIGNAL_FIRST_METHOD)
343 for(l=m->gtktypes; l; l=l->next)
344 mask_special_array(l->data, special_array,
346 } else if(n->type == ARGUMENT_NODE) {
347 Argument *a = (Argument *)n;
348 mask_special_array(a->gtktype, special_array,
357 get_type (const Type *t, gboolean postfix_to_stars)
364 s = remove_sep(t->name);
365 gs = g_string_new(s);
369 if (postfix_to_stars) {
371 /*XXX: this is ugly perhaps we can do this whole postfix thing
372 in a nicer way, we just count the number of '[' s and from
373 that we deduce the number of dimensions, so that we can print
375 for (p = t->postfix; p && *p; p++)
376 if(*p == '[') extra++;
378 g_string_append_c(gs, ' ');
380 if (t->pointer != NULL) {
381 g_string_append (gs, t->pointer);
382 for (i=0; i < extra; i++)
383 g_string_append_c (gs, '*');
384 g_string_append_c (gs, ' ');
387 return g_string_free (gs, FALSE);
391 gob_strup (char *str)
394 for (s = str; *s; s++)
395 *s = g_ascii_toupper (*s);
401 gob_strdown (char *str)
404 for (s = str; *s; s++)
405 *s = g_ascii_tolower (*s);
411 make_me_type (const char *type, const char *alt)
414 return g_strdup (alt);
415 /* HACK! just in case someone made this
416 * work with 2.0.0 by using the TYPE
418 if ((strstr (type, "_TYPE_") != NULL ||
419 strstr (type, "TYPE_") == type) &&
420 strchr (type, ':') == NULL)
421 return g_strdup (type);
422 return make_pre_macro (type, "TYPE");