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);
81 /* don't eat C++ :: thingies */
82 if (for_cpp && strstr (s, "::") != NULL)
85 while((p = strchr(s, ':')))
91 replace_sep(const char *base, char r)
94 char *s = g_strdup(base);
96 /* don't eat C++ :: thingies */
97 if (for_cpp && strstr (s, "::") != NULL)
100 while((p=strchr(s,':')))
110 /*separate the namespace part and then replace rest of
113 separns_replace_sep(const char *base, char **ns, char **name, char r)
116 char *s = g_strdup(base);
120 /* don't eat C++ :: thingies */
121 if (for_cpp && strstr (s, "::") != NULL) {
126 if((p=strchr(s,':')) && p!=s) {
133 while((p=strchr(s,':')))
136 *name = g_strdup(s+1);
142 /* make a macro with some prefix before the name but after
145 make_pre_macro(const char *base, const char *pre)
151 if(strchr(base, ' ')) {
153 v = g_strsplit(base, " ", 0);
154 for(i = 0; v[i] != NULL; i++) {
155 if(*v[i] && strcmp(v[i], "const") != 0) {
162 separns_replace_sep(base, &ns, &name, '_');
164 s = g_strconcat(ns, "_", pre, "_", name,NULL);
166 s = g_strconcat(pre, "_", name, NULL);
178 /* here we will find out how inconsistent gtk really is :) */
179 /* the commented out types mean that these types don't actually
180 exist. so we "emulate them" with an equivalent */
181 typedef struct _OurGtkType OurGtkType;
190 const OurGtkType our_gtk_type_table[] = {
191 { TRUE, "NONE", "void ", "void", NULL, -1 },
192 { TRUE, "CHAR", "gchar ", "gchar", NULL, -1 },
193 { TRUE, "UCHAR", "guchar ", "guchar", NULL, -1 },
194 { TRUE, "UNICHAR", "gunichar ", "gunichar", NULL, -1 },
195 { TRUE, "BOOLEAN", "gboolean ", "gboolean", NULL, -1 },
196 { TRUE, "INT", "gint ", "gint", NULL, -1 },
197 { TRUE, "UINT", "guint ", "guint", NULL, -1 },
198 { TRUE, "LONG", "glong ", "glong", NULL, -1 },
199 { TRUE, "ULONG", "gulong ", "gulong", NULL, -1 },
200 { TRUE, "INT64", "gint64 ", "gint64", NULL, -1 },
201 { TRUE, "UINT64", "guint64 ", "guint64", NULL, -1 },
202 { TRUE, "ENUM", /*"enum"*/"gint ", "gint", NULL, -1 },
203 { TRUE, "FLAGS", /*"flags"*/"guint ", "guint", NULL, -1 },
204 { TRUE, "FLOAT", "gfloat ", "gfloat", NULL, -1 },
205 { TRUE, "DOUBLE", "gdouble ", "gdouble", NULL, -1 },
206 { TRUE, "STRING", /*"string"*/"gchar *", "gchar", "*", -1 },
207 { TRUE, "POINTER", "gpointer ", "gpointer", NULL, -1 },
208 { TRUE, "BOXED", /*"boxed"*/"gpointer ", "gpointer", NULL, -1 },
209 { TRUE, "OBJECT", "GObject *", "GObject", "*", -1 },
210 { TRUE, "PARAM", "GParamSpec *", "GParamSpec", "*", -1 },
212 /* FIXME: VALUE_ARRAY, CLOSURE */
213 /* Note that those have some issues with g_value_ calls etc... so
214 * we can't just add them */
216 /* Do we need this??? */
218 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
220 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
221 SPECIAL_INT_POINTER },
222 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
224 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
226 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
230 { FALSE, NULL, NULL }
233 static GHashTable *type_hash = NULL;
240 if(type_hash) return;
242 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
244 for(i=0; our_gtk_type_table[i].gtkname; i++)
245 g_hash_table_insert(type_hash,
246 our_gtk_type_table[i].gtkname,
247 (gpointer)&our_gtk_type_table[i]);
251 get_cast (const char *type, gboolean simple_only)
257 gtype = g_hash_table_lookup (type_hash, type);
268 get_tree_type (const char *type, gboolean simple_only)
275 gtype = g_hash_table_lookup (type_hash, type);
282 node = node_new (TYPE_NODE,
283 "name", gtype->type_name,
284 "pointer", gtype->type_pointer,
291 mask_special_array (const char *type, gboolean *special_array, gboolean *any_special)
297 gtype = g_hash_table_lookup(type_hash, type);
299 if(gtype && gtype->special >= 0) {
300 special_array[gtype->special] = TRUE;
306 setup_special_array(Class *c, gboolean *special_array)
309 gboolean any_special = FALSE;
311 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
313 for(li=c->nodes; li; li=g_list_next(li)) {
315 if(n->type == METHOD_NODE) {
316 Method *m = (Method *)n;
318 if(m->method != SIGNAL_LAST_METHOD &&
319 m->method != SIGNAL_FIRST_METHOD)
322 for(l=m->gtktypes; l; l=l->next)
323 mask_special_array(l->data, special_array,
325 } else if(n->type == ARGUMENT_NODE) {
326 Argument *a = (Argument *)n;
327 mask_special_array(a->gtktype, special_array,
336 get_type (const Type *t, gboolean postfix_to_stars)
343 s = remove_sep(t->name);
344 gs = g_string_new(s);
348 if (postfix_to_stars) {
350 /*XXX: this is ugly perhaps we can do this whole postfix thing
351 in a nicer way, we just count the number of '[' s and from
352 that we deduce the number of dimensions, so that we can print
354 for (p = t->postfix; p && *p; p++)
355 if(*p == '[') extra++;
357 g_string_append_c(gs, ' ');
359 if (t->pointer != NULL) {
360 g_string_append (gs, t->pointer);
361 for (i=0; i < extra; i++)
362 g_string_append_c (gs, '*');
363 g_string_append_c (gs, ' ');
366 return g_string_free (gs, FALSE);