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)
104 while((p=strchr(s,':')))
114 /*separate the namespace part and then replace rest of
117 separns_replace_sep(const char *base, char **ns, char **name, char r)
120 char *s = g_strdup(base);
124 /* don't eat C++ :: thingies */
125 if (for_cpp && strstr (s, "::") != NULL) {
130 if((p=strchr(s,':')) && p!=s) {
137 while((p=strchr(s,':')))
140 *name = g_strdup(s+1);
146 /* make a macro with some prefix before the name but after
149 make_pre_macro(const char *base, const char *pre)
155 if(strchr(base, ' ')) {
157 v = g_strsplit(base, " ", 0);
158 for(i = 0; v[i] != NULL; i++) {
159 if(*v[i] && strcmp(v[i], "const") != 0) {
166 separns_replace_sep(base, &ns, &name, '_');
168 s = g_strconcat(ns, "_", pre, "_", name,NULL);
170 s = g_strconcat(pre, "_", name, NULL);
182 /* here we will find out how inconsistent gtk really is :) */
183 /* the commented out types mean that these types don't actually
184 exist. so we "emulate them" with an equivalent */
185 typedef struct _OurGtkType OurGtkType;
194 const OurGtkType our_gtk_type_table[] = {
195 { TRUE, "NONE", "void ", "void", NULL, -1 },
196 { TRUE, "CHAR", "gchar ", "gchar", NULL, -1 },
197 { TRUE, "UCHAR", "guchar ", "guchar", NULL, -1 },
198 { TRUE, "UNICHAR", "gunichar ", "gunichar", NULL, -1 },
199 { TRUE, "BOOLEAN", "gboolean ", "gboolean", NULL, -1 },
200 { TRUE, "INT", "gint ", "gint", NULL, -1 },
201 { TRUE, "UINT", "guint ", "guint", NULL, -1 },
202 { TRUE, "LONG", "glong ", "glong", NULL, -1 },
203 { TRUE, "ULONG", "gulong ", "gulong", NULL, -1 },
204 { TRUE, "INT64", "gint64 ", "gint64", NULL, -1 },
205 { TRUE, "UINT64", "guint64 ", "guint64", NULL, -1 },
206 { TRUE, "ENUM", /*"enum"*/"gint ", "gint", NULL, -1 },
207 { TRUE, "FLAGS", /*"flags"*/"guint ", "guint", NULL, -1 },
208 { TRUE, "FLOAT", "gfloat ", "gfloat", NULL, -1 },
209 { TRUE, "DOUBLE", "gdouble ", "gdouble", NULL, -1 },
210 { TRUE, "STRING", /*"string"*/"gchar *", "gchar", "*", -1 },
211 { TRUE, "POINTER", "gpointer ", "gpointer", NULL, -1 },
212 { TRUE, "BOXED", /*"boxed"*/"gpointer ", "gpointer", NULL, -1 },
213 { TRUE, "OBJECT", "GObject *", "GObject", "*", -1 },
214 { TRUE, "PARAM", "GParamSpec *", "GParamSpec", "*", -1 },
216 /* FIXME: VALUE_ARRAY, CLOSURE */
217 /* Note that those have some issues with g_value_ calls etc... so
218 * we can't just add them */
220 /* Do we need this??? */
222 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
224 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
225 SPECIAL_INT_POINTER },
226 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
228 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
230 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
234 { FALSE, NULL, NULL }
237 static GHashTable *type_hash = NULL;
244 if(type_hash) return;
246 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
248 for(i=0; our_gtk_type_table[i].gtkname; i++)
249 g_hash_table_insert(type_hash,
250 our_gtk_type_table[i].gtkname,
251 (gpointer)&our_gtk_type_table[i]);
255 get_cast (const char *type, gboolean simple_only)
261 gtype = g_hash_table_lookup (type_hash, type);
272 get_tree_type (const char *type, gboolean simple_only)
279 gtype = g_hash_table_lookup (type_hash, type);
286 node = node_new (TYPE_NODE,
287 "name", gtype->type_name,
288 "pointer", gtype->type_pointer,
295 mask_special_array (const char *type, gboolean *special_array, gboolean *any_special)
301 gtype = g_hash_table_lookup(type_hash, type);
303 if(gtype && gtype->special >= 0) {
304 special_array[gtype->special] = TRUE;
310 setup_special_array(Class *c, gboolean *special_array)
313 gboolean any_special = FALSE;
315 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
317 for(li=c->nodes; li; li=g_list_next(li)) {
319 if(n->type == METHOD_NODE) {
320 Method *m = (Method *)n;
322 if(m->method != SIGNAL_LAST_METHOD &&
323 m->method != SIGNAL_FIRST_METHOD)
326 for(l=m->gtktypes; l; l=l->next)
327 mask_special_array(l->data, special_array,
329 } else if(n->type == ARGUMENT_NODE) {
330 Argument *a = (Argument *)n;
331 mask_special_array(a->gtktype, special_array,
340 get_type (const Type *t, gboolean postfix_to_stars)
347 s = remove_sep(t->name);
348 gs = g_string_new(s);
352 if (postfix_to_stars) {
354 /*XXX: this is ugly perhaps we can do this whole postfix thing
355 in a nicer way, we just count the number of '[' s and from
356 that we deduce the number of dimensions, so that we can print
358 for (p = t->postfix; p && *p; p++)
359 if(*p == '[') extra++;
361 g_string_append_c(gs, ' ');
363 if (t->pointer != NULL) {
364 g_string_append (gs, t->pointer);
365 for (i=0; i < extra; i++)
366 g_string_append_c (gs, '*');
367 g_string_append_c (gs, ' ');
370 return g_string_free (gs, FALSE);
374 gob_strup (char *str)
377 for (s = str; *s; s++)
378 *s = g_ascii_toupper (*s);
384 gob_strdown (char *str)
387 for (s = str; *s; s++)
388 *s = g_ascii_tolower (*s);