Add a new source type enum for member. Use __repr__ for improved debugging
[platform/upstream/gobject-introspection.git] / giscanner / sourcescanner.h
1 /* GObject introspection: public scanner api
2  *
3  * Copyright (C) 2007 Jürg Billeter
4  * Copyright (C) 2008 Johan Dahlin
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22
23 #ifndef __SOURCE_SCANNER_H__
24 #define __SOURCE_SCANNER_H__
25
26 #include <glib.h>
27 #include <stdio.h>
28
29 G_BEGIN_DECLS
30
31 typedef struct _GISourceScanner GISourceScanner;
32 typedef struct _GISourceSymbol GISourceSymbol;
33 typedef struct _GISourceType GISourceType;
34 typedef struct _GISourceDirective GISourceDirective;
35
36 typedef enum
37 {
38   CSYMBOL_TYPE_INVALID,
39   CSYMBOL_TYPE_CONST,
40   CSYMBOL_TYPE_OBJECT,
41   CSYMBOL_TYPE_FUNCTION,
42   CSYMBOL_TYPE_STRUCT,
43   CSYMBOL_TYPE_UNION,
44   CSYMBOL_TYPE_ENUM,
45   CSYMBOL_TYPE_TYPEDEF,
46   CSYMBOL_TYPE_MEMBER
47 } GISourceSymbolType;
48
49 typedef enum
50 {
51   CTYPE_INVALID,
52   CTYPE_VOID,
53   CTYPE_BASIC_TYPE,
54   CTYPE_TYPEDEF,
55   CTYPE_STRUCT,
56   CTYPE_UNION,
57   CTYPE_ENUM,
58   CTYPE_POINTER,
59   CTYPE_ARRAY,
60   CTYPE_FUNCTION
61 } GISourceTypeType;
62
63 typedef enum
64 {
65   STORAGE_CLASS_NONE = 0,
66   STORAGE_CLASS_TYPEDEF = 1 << 1,
67   STORAGE_CLASS_EXTERN = 1 << 2,
68   STORAGE_CLASS_STATIC = 1 << 3,
69   STORAGE_CLASS_AUTO = 1 << 4,
70   STORAGE_CLASS_REGISTER = 1 << 5
71 } StorageClassSpecifier;
72
73 typedef enum
74 {
75   TYPE_QUALIFIER_NONE = 0,
76   TYPE_QUALIFIER_CONST = 1 << 1,
77   TYPE_QUALIFIER_RESTRICT = 1 << 2,
78   TYPE_QUALIFIER_VOLATILE = 1 << 3
79 } TypeQualifier;
80
81 typedef enum
82 {
83   FUNCTION_NONE = 0,
84   FUNCTION_INLINE = 1 << 1
85 } FunctionSpecifier;
86
87 typedef enum
88 {
89   UNARY_ADDRESS_OF,
90   UNARY_POINTER_INDIRECTION,
91   UNARY_PLUS,
92   UNARY_MINUS,
93   UNARY_BITWISE_COMPLEMENT,
94   UNARY_LOGICAL_NEGATION
95 } UnaryOperator;
96
97 struct _GISourceScanner
98 {
99   char *current_filename;
100   gboolean macro_scan;
101   GSList *symbols;
102   GList *filenames;
103   GHashTable *directives_map;
104   GHashTable *typedef_table;
105   GHashTable *struct_or_union_or_enum_table;
106 };
107
108 struct _GISourceSymbol
109 {
110   int ref_count;
111   GISourceSymbolType type;
112   int id;
113   char *ident;
114   GISourceType *base_type;
115   gboolean const_int_set;
116   int const_int;
117   char *const_string;
118   GSList *directives; /* list of GISourceDirective */
119 };
120
121 struct _GISourceType
122 {
123   GISourceTypeType type;
124   StorageClassSpecifier storage_class_specifier;
125   TypeQualifier type_qualifier;
126   FunctionSpecifier function_specifier;
127   char *name;
128   GISourceType *base_type;
129   GList *child_list; /* list of GISourceSymbol */
130 };
131
132 struct _GISourceDirective
133 {
134   char *name;
135   char *value;
136   GSList *options; /* list of options (key=value) */
137 };
138
139 GISourceScanner *   gi_source_scanner_new              (void);
140 gboolean            gi_source_scanner_lex_filename     (GISourceScanner  *igenerator,
141                                                         const gchar      *filename);
142 gboolean            gi_source_scanner_parse_file       (GISourceScanner  *igenerator,
143                                                         FILE             *file);
144 void                gi_source_scanner_set_macro_scan   (GISourceScanner  *scanner,
145                                                         gboolean          macro_scan);
146 GSList *            gi_source_scanner_get_symbols      (GISourceScanner  *scanner);
147 GSList *            gi_source_scanner_get_directives   (GISourceScanner  *scanner,
148                                                         const gchar      *name);
149 void                gi_source_scanner_free             (GISourceScanner  *scanner);
150
151 GISourceSymbol *    gi_source_symbol_new               (GISourceSymbolType  type);
152 gboolean            gi_source_symbol_get_const_boolean (GISourceSymbol     *symbol);
153 GISourceSymbol *    gi_source_symbol_ref               (GISourceSymbol     *symbol);
154 void                gi_source_symbol_unref             (GISourceSymbol     *symbol);
155
156 GISourceDirective * gi_source_directive_new            (const gchar        *name,
157                                                         const gchar        *value,
158                                                         GSList             *options);
159 void                gi_source_directive_free           (GISourceDirective  *directive);
160
161 /* Private */
162 GISourceType *      gi_source_array_new                (void);
163 void                gi_source_scanner_add_symbol       (GISourceScanner  *scanner,
164                                                         GISourceSymbol   *symbol);
165 gboolean            gi_source_scanner_is_typedef       (GISourceScanner  *scanner,
166                                                         const char       *name);
167 void                gi_source_symbol_merge_type        (GISourceSymbol   *symbol,
168                                                         GISourceType     *type);
169 GISourceType *      gi_source_type_new                 (GISourceTypeType  type);
170 GISourceType *      gi_source_type_copy                (GISourceType     *type);
171 GISourceType *      gi_source_basic_type_new           (const char       *name);
172 GISourceType *      gi_source_typedef_new              (const char       *name);
173 GISourceType *      gi_source_struct_new               (const char       *name);
174 GISourceType *      gi_source_union_new                (const char       *name);
175 GISourceType *      gi_source_enum_new                 (const char       *name);
176 GISourceType *      gi_source_pointer_new              (GISourceType     *base_type);
177 GISourceType *      gi_source_array_new                (void);
178 GISourceType *      gi_source_function_new             (void);
179
180 G_END_DECLS
181
182 #endif /* __SOURCE_SCANNER_H__ */