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);
85 /* don't eat C++ :: thingies */
86 if (for_cpp && strstr (s, "::") != NULL)
89 while((p = strchr(s, ':')))
95 replace_sep(const char *base, char r)
98 char *s = g_strdup(base);
100 /* don't eat C++ :: thingies */
101 if (for_cpp && strstr (s, "::") != NULL)
105 while ((p=strchr(s,':')) != NULL) {
113 while ((p=strchr(s,':')) != NULL)
124 /*separate the namespace part and then replace rest of
127 separns_replace_sep(const char *base, char **ns, char **name, char r)
130 char *s = g_strdup(base);
134 /* don't eat C++ :: thingies */
135 if (for_cpp && strstr (s, "::") != NULL) {
140 if((p=strchr(s,':')) && p!=s) {
147 while((p=strchr(s,':')))
150 *name = g_strdup(s+1);
156 /* make a macro with some prefix before the name but after
159 make_pre_macro(const char *base, const char *pre)
165 if(strchr(base, ' ')) {
167 v = g_strsplit(base, " ", 0);
168 for(i = 0; v[i] != NULL; i++) {
169 if(*v[i] && strcmp(v[i], "const") != 0) {
176 separns_replace_sep(base, &ns, &name, '_');
178 s = g_strconcat(ns, "_", pre, "_", name,NULL);
180 s = g_strconcat(pre, "_", name, NULL);
192 /* here we will find out how inconsistent gtk really is :) */
193 /* the commented out types mean that these types don't actually
194 exist. so we "emulate them" with an equivalent */
195 typedef struct _OurGtkType OurGtkType;
204 const OurGtkType our_gtk_type_table[] = {
205 { TRUE, "NONE", "void ", "void", NULL, -1 },
206 { TRUE, "CHAR", "gchar ", "gchar", NULL, -1 },
207 { TRUE, "UCHAR", "guchar ", "guchar", NULL, -1 },
208 { TRUE, "UNICHAR", "gunichar ", "gunichar", NULL, -1 },
209 { TRUE, "BOOLEAN", "gboolean ", "gboolean", NULL, -1 },
210 { TRUE, "INT", "gint ", "gint", NULL, -1 },
211 { TRUE, "UINT", "guint ", "guint", NULL, -1 },
212 { TRUE, "LONG", "glong ", "glong", NULL, -1 },
213 { TRUE, "ULONG", "gulong ", "gulong", NULL, -1 },
214 { TRUE, "INT64", "gint64 ", "gint64", NULL, -1 },
215 { TRUE, "UINT64", "guint64 ", "guint64", NULL, -1 },
216 { TRUE, "ENUM", /*"enum"*/"gint ", "gint", NULL, -1 },
217 { TRUE, "FLAGS", /*"flags"*/"guint ", "guint", NULL, -1 },
218 { TRUE, "FLOAT", "gfloat ", "gfloat", NULL, -1 },
219 { TRUE, "DOUBLE", "gdouble ", "gdouble", NULL, -1 },
220 { TRUE, "STRING", /*"string"*/"gchar *", "gchar", "*", -1 },
221 { TRUE, "POINTER", "gpointer ", "gpointer", NULL, -1 },
222 { TRUE, "BOXED", /*"boxed"*/"gpointer ", "gpointer", NULL, -1 },
223 { TRUE, "OBJECT", "GObject *", "GObject", "*", -1 },
224 { TRUE, "PARAM", "GParamSpec *", "GParamSpec", "*", -1 },
226 /* FIXME: VALUE_ARRAY, CLOSURE */
227 /* Note that those have some issues with g_value_ calls etc... so
228 * we can't just add them */
230 /* Do we need this??? */
232 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
234 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
235 SPECIAL_INT_POINTER },
236 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
238 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
240 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
244 { FALSE, NULL, NULL }
247 static GHashTable *type_hash = NULL;
254 if(type_hash) return;
256 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
258 for(i=0; our_gtk_type_table[i].gtkname; i++)
259 g_hash_table_insert(type_hash,
260 our_gtk_type_table[i].gtkname,
261 (gpointer)&our_gtk_type_table[i]);
265 get_cast (const char *type, gboolean simple_only)
271 gtype = g_hash_table_lookup (type_hash, type);
282 get_tree_type (const char *type, gboolean simple_only)
289 gtype = g_hash_table_lookup (type_hash, type);
296 node = node_new (TYPE_NODE,
297 "name", gtype->type_name,
298 "pointer", gtype->type_pointer,
305 mask_special_array (const char *type, gboolean *special_array, gboolean *any_special)
311 gtype = g_hash_table_lookup(type_hash, type);
313 if(gtype && gtype->special >= 0) {
314 special_array[gtype->special] = TRUE;
320 setup_special_array(Class *c, gboolean *special_array)
323 gboolean any_special = FALSE;
325 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
327 for(li=c->nodes; li; li=g_list_next(li)) {
329 if(n->type == METHOD_NODE) {
330 Method *m = (Method *)n;
332 if(m->method != SIGNAL_LAST_METHOD &&
333 m->method != SIGNAL_FIRST_METHOD)
336 for(l=m->gtktypes; l; l=l->next)
337 mask_special_array(l->data, special_array,
339 } else if(n->type == ARGUMENT_NODE) {
340 Argument *a = (Argument *)n;
341 mask_special_array(a->gtktype, special_array,
350 get_type (const Type *t, gboolean postfix_to_stars)
357 s = remove_sep(t->name);
358 gs = g_string_new(s);
362 if (postfix_to_stars) {
364 /*XXX: this is ugly perhaps we can do this whole postfix thing
365 in a nicer way, we just count the number of '[' s and from
366 that we deduce the number of dimensions, so that we can print
368 for (p = t->postfix; p && *p; p++)
369 if(*p == '[') extra++;
371 g_string_append_c(gs, ' ');
373 if (t->pointer != NULL) {
374 g_string_append (gs, t->pointer);
375 for (i=0; i < extra; i++)
376 g_string_append_c (gs, '*');
377 g_string_append_c (gs, ' ');
380 return g_string_free (gs, FALSE);
384 gob_strup (char *str)
387 for (s = str; *s; s++)
388 *s = g_ascii_toupper (*s);
394 gob_strdown (char *str)
397 for (s = str; *s; s++)
398 *s = g_ascii_tolower (*s);
404 make_me_type (const char *type, const char *alt)
407 return g_strdup (alt);
408 /* HACK! just in case someone made this
409 * work with 2.0.0 by using the TYPE
411 if ((strstr (type, "_TYPE_") != NULL ||
412 strstr (type, "TYPE_") == type) &&
413 strchr (type, ':') == NULL)
414 return g_strdup (type);
415 return make_pre_macro (type, "TYPE");