427f8e908a4e587ff486d7ddb6c34fdf489b8c68
[gnome.gobject-introspection] / girepository / girnode.h
1 /* GObject introspection: Parsed GIR
2  *
3  * Copyright (C) 2005 Matthias Clasen
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __G_IR_NODE_H__
22 #define __G_IR_NODE_H__
23
24 #include <glib.h>
25
26 #include "girmodule.h"
27
28 G_BEGIN_DECLS
29
30 typedef struct _GIrTypelibBuild GIrTypelibBuild;
31 typedef struct _GIrNode GIrNode; 
32 typedef struct _GIrNodeFunction GIrNodeFunction;
33 typedef struct _GIrNodeParam GIrNodeParam;
34 typedef struct _GIrNodeType GIrNodeType;
35 typedef struct _GIrNodeInterface GIrNodeInterface;
36 typedef struct _GIrNodeSignal GIrNodeSignal;
37 typedef struct _GIrNodeProperty GIrNodeProperty;
38 typedef struct _GIrNodeVFunc GIrNodeVFunc;
39 typedef struct _GIrNodeField GIrNodeField;
40 typedef struct _GIrNodeValue GIrNodeValue;
41 typedef struct _GIrNodeEnum GIrNodeEnum;
42 typedef struct _GIrNodeBoxed GIrNodeBoxed;
43 typedef struct _GIrNodeStruct GIrNodeStruct;
44 typedef struct _GIrNodeConstant GIrNodeConstant;
45 typedef struct _GIrNodeErrorDomain GIrNodeErrorDomain;
46 typedef struct _GIrNodeXRef GIrNodeXRef;
47 typedef struct _GIrNodeUnion GIrNodeUnion;
48
49 struct _GIrTypelibBuild {
50   GIrModule  *module;
51   GList       *modules;
52   GHashTable  *strings;
53   GHashTable  *types;
54   GList       *offset_ordered_nodes;
55   guint32      n_attributes;
56   guchar      *data; 
57 };
58
59 typedef enum 
60 {
61   G_IR_NODE_INVALID      =  0,
62   G_IR_NODE_FUNCTION     =  1,
63   G_IR_NODE_CALLBACK     =  2,
64   G_IR_NODE_STRUCT       =  3,
65   G_IR_NODE_BOXED        =  4,
66   G_IR_NODE_ENUM         =  5,
67   G_IR_NODE_FLAGS        =  6, 
68   G_IR_NODE_OBJECT       =  7,
69   G_IR_NODE_INTERFACE    =  8,
70   G_IR_NODE_CONSTANT     =  9,
71   G_IR_NODE_ERROR_DOMAIN = 10,
72   G_IR_NODE_UNION        = 11,
73   G_IR_NODE_PARAM        = 12,
74   G_IR_NODE_TYPE         = 13,
75   G_IR_NODE_PROPERTY     = 14,
76   G_IR_NODE_SIGNAL       = 15,
77   G_IR_NODE_VALUE        = 16,
78   G_IR_NODE_VFUNC        = 17,
79   G_IR_NODE_FIELD        = 18,
80   G_IR_NODE_XREF         = 19
81 } GIrNodeTypeId;
82
83 struct _GIrNode
84 {
85   GIrNodeTypeId type;
86   gchar *name;
87
88   guint32 offset; /* Assigned as we build the typelib */
89
90   GHashTable *attributes;
91 };
92
93 struct _GIrNodeXRef
94 {
95   GIrNode node;
96
97   gchar *namespace;
98 };
99
100 struct _GIrNodeFunction
101 {
102   GIrNode node;
103
104   gboolean deprecated;
105   gboolean is_varargs; /* Not in typelib yet */ 
106
107   gboolean is_method;
108   gboolean is_setter;
109   gboolean is_getter;
110   gboolean is_constructor;
111   gboolean wraps_vfunc;
112   gboolean throws;
113
114   gchar *symbol;
115
116   GIrNodeParam *result;
117   GList *parameters;
118 };
119
120 struct _GIrNodeType 
121 {
122   GIrNode node;
123
124   gboolean is_pointer;
125   gboolean is_basic;
126   gboolean is_array;
127   gboolean is_glist;
128   gboolean is_gslist;
129   gboolean is_ghashtable;
130   gboolean is_interface;
131   gboolean is_error;
132   gint tag;
133
134   gchar *unparsed;
135
136   gboolean zero_terminated;
137   gboolean has_length;
138   gint length;
139   gboolean has_size;
140   gint size;
141   
142   GIrNodeType *parameter_type1;
143   GIrNodeType *parameter_type2;  
144
145   gchar *interface;
146   gchar **errors;
147 };
148
149 struct _GIrNodeParam 
150 {
151   GIrNode node;
152
153   gboolean in;
154   gboolean out;
155   gboolean dipper;
156   gboolean optional;
157   gboolean retval;
158   gboolean allow_none;
159   gboolean transfer;
160   gboolean shallow_transfer;
161   GIScopeType scope;
162   
163   gint8 closure;
164   gint8 destroy;
165   
166   GIrNodeType *type;
167 };
168
169 struct _GIrNodeProperty
170 {
171   GIrNode node;
172
173   gboolean deprecated;
174
175   gchar *name;
176   gboolean readable;
177   gboolean writable;
178   gboolean construct;
179   gboolean construct_only;
180   
181   GIrNodeType *type;
182 };
183
184 struct _GIrNodeSignal 
185 {
186   GIrNode node;
187
188   gboolean deprecated;
189
190   gboolean run_first;
191   gboolean run_last;
192   gboolean run_cleanup;
193   gboolean no_recurse;
194   gboolean detailed;
195   gboolean action;
196   gboolean no_hooks;
197   
198   gboolean has_class_closure;
199   gboolean true_stops_emit;
200   
201   gint class_closure;
202   
203   GList *parameters;
204   GIrNodeParam *result;    
205 };
206
207 struct _GIrNodeVFunc 
208 {
209   GIrNode node;
210
211   gboolean is_varargs; /* Not in typelib yet */ 
212   gboolean must_chain_up;
213   gboolean must_be_implemented;
214   gboolean must_not_be_implemented;
215   gboolean is_class_closure;
216   
217   char *invoker;
218
219   GList *parameters;
220   GIrNodeParam *result;      
221
222   gint offset;
223 };
224
225 struct _GIrNodeField
226 {
227   GIrNode node;
228
229   gboolean readable;
230   gboolean writable;
231   gint bits;
232   gint offset;
233   GIrNodeFunction *callback;
234   
235   GIrNodeType *type;
236 };
237
238 struct _GIrNodeInterface
239 {
240   GIrNode node;
241
242   gboolean abstract;
243   gboolean deprecated;
244
245   gchar *gtype_name;
246   gchar *gtype_init;
247
248   gchar *parent;
249   gchar *glib_type_struct;
250   
251   GList *interfaces;
252   GList *prerequisites;
253
254   gint alignment;
255   gint size;
256   
257   GList *members;
258 };
259
260 struct _GIrNodeValue
261 {
262   GIrNode node;
263
264   gboolean deprecated;
265
266   gint32 value;
267 };
268
269 struct _GIrNodeConstant
270 {
271   GIrNode node;
272
273   gboolean deprecated;
274
275   GIrNodeType *type;
276   
277   gchar *value;
278 };
279
280 struct _GIrNodeEnum
281 {
282   GIrNode node;
283
284   gboolean deprecated;
285   gint storage_type;
286
287   gchar *gtype_name;
288   gchar *gtype_init;
289
290   GList *values;
291 };
292
293 struct _GIrNodeBoxed
294
295   GIrNode node;
296
297   gboolean deprecated;
298
299   gchar *gtype_name;
300   gchar *gtype_init;
301
302   gint alignment;
303   gint size;
304   
305   GList *members;
306 };
307
308 struct _GIrNodeStruct
309 {
310   GIrNode node;
311
312   gboolean deprecated;
313   gboolean disguised;
314   gboolean is_gtype_struct;
315
316   gchar *gtype_name;
317   gchar *gtype_init;
318
319   gint alignment;
320   gint size;
321   
322   GList *members;
323 };
324
325 struct _GIrNodeUnion
326 {
327   GIrNode node;
328
329   gboolean deprecated;
330   
331   GList *members;
332   GList *discriminators;
333
334   gchar *gtype_name;
335   gchar *gtype_init;
336
337   gint alignment;
338   gint size;
339
340   gint discriminator_offset;
341   GIrNodeType *discriminator_type;
342 };
343
344
345 struct _GIrNodeErrorDomain
346 {
347   GIrNode node;
348
349   gboolean deprecated;
350   
351   gchar *name;
352   gchar *getquark;
353   gchar *codes;
354 };
355
356
357 GIrNode * g_ir_node_new             (GIrNodeTypeId type);
358 void      g_ir_node_free            (GIrNode    *node);
359 guint32   g_ir_node_get_size        (GIrNode    *node);
360 guint32   g_ir_node_get_full_size   (GIrNode    *node);
361 guint32   g_ir_node_get_attribute_size (GIrNode *node);
362 void      g_ir_node_build_typelib   (GIrNode         *node,
363                                      GIrNode         *parent,
364                                      GIrTypelibBuild *build,
365                                      guint32         *offset,
366                                      guint32         *offset2);
367 int       g_ir_node_cmp             (GIrNode    *node,
368                                      GIrNode    *other);
369 gboolean  g_ir_node_can_have_member (GIrNode    *node);
370 void      g_ir_node_add_member      (GIrNode         *node,
371                                      GIrNodeFunction *member);
372 guint32   write_string              (const gchar *str,
373                                      GHashTable  *strings, 
374                                      guchar      *data,
375                                      guint32     *offset);
376
377 const gchar * g_ir_node_param_direction_string (GIrNodeParam * node);
378 const gchar * g_ir_node_type_to_string         (GIrNodeTypeId type);
379
380 gboolean g_ir_find_node (GIrModule  *module,
381                          GList      *modules,
382                          const char *name,
383                          GIrNode   **node_out,
384                          GIrModule **module_out);
385
386 /* In giroffsets.c */
387
388 void g_ir_node_compute_offsets (GIrNode   *node,
389                                 GIrModule *module,
390                                 GList     *modules);
391
392
393 G_END_DECLS
394
395 #endif  /* __G_IR_NODE_H__ */