Bug 557786 - support fixed size arrays
[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_ELLIPSIS,
40   CSYMBOL_TYPE_CONST,
41   CSYMBOL_TYPE_OBJECT,
42   CSYMBOL_TYPE_FUNCTION,
43   CSYMBOL_TYPE_STRUCT,
44   CSYMBOL_TYPE_UNION,
45   CSYMBOL_TYPE_ENUM,
46   CSYMBOL_TYPE_TYPEDEF,
47   CSYMBOL_TYPE_MEMBER
48 } GISourceSymbolType;
49
50 typedef enum
51 {
52   CTYPE_INVALID,
53   CTYPE_VOID,
54   CTYPE_BASIC_TYPE,
55   CTYPE_TYPEDEF,
56   CTYPE_STRUCT,
57   CTYPE_UNION,
58   CTYPE_ENUM,
59   CTYPE_POINTER,
60   CTYPE_ARRAY,
61   CTYPE_FUNCTION
62 } GISourceTypeType;
63
64 typedef enum
65 {
66   STORAGE_CLASS_NONE = 0,
67   STORAGE_CLASS_TYPEDEF = 1 << 1,
68   STORAGE_CLASS_EXTERN = 1 << 2,
69   STORAGE_CLASS_STATIC = 1 << 3,
70   STORAGE_CLASS_AUTO = 1 << 4,
71   STORAGE_CLASS_REGISTER = 1 << 5
72 } StorageClassSpecifier;
73
74 typedef enum
75 {
76   TYPE_QUALIFIER_NONE = 0,
77   TYPE_QUALIFIER_CONST = 1 << 1,
78   TYPE_QUALIFIER_RESTRICT = 1 << 2,
79   TYPE_QUALIFIER_VOLATILE = 1 << 3,
80   TYPE_QUALIFIER_EXTENSION = 1 << 4
81 } TypeQualifier;
82
83 typedef enum
84 {
85   FUNCTION_NONE = 0,
86   FUNCTION_INLINE = 1 << 1
87 } FunctionSpecifier;
88
89 typedef enum
90 {
91   UNARY_ADDRESS_OF,
92   UNARY_POINTER_INDIRECTION,
93   UNARY_PLUS,
94   UNARY_MINUS,
95   UNARY_BITWISE_COMPLEMENT,
96   UNARY_LOGICAL_NEGATION
97 } UnaryOperator;
98
99 struct _GISourceScanner
100 {
101   char *current_filename;
102   gboolean macro_scan;
103   GSList *symbols;
104   GList *filenames;
105   GHashTable *directives_map;
106   GHashTable *typedef_table;
107   GHashTable *struct_or_union_or_enum_table;
108 };
109
110 struct _GISourceSymbol
111 {
112   int ref_count;
113   GISourceSymbolType type;
114   int id;
115   char *ident;
116   GISourceType *base_type;
117   gboolean const_int_set;
118   int const_int;
119   char *const_string;
120   GSList *directives; /* list of GISourceDirective */
121 };
122
123 struct _GISourceType
124 {
125   GISourceTypeType type;
126   StorageClassSpecifier storage_class_specifier;
127   TypeQualifier type_qualifier;
128   FunctionSpecifier function_specifier;
129   char *name;
130   GISourceType *base_type;
131   GList *child_list; /* list of GISourceSymbol */
132 };
133
134 struct _GISourceDirective
135 {
136   char *name;
137   char *value;
138   GSList *options; /* list of options (key=value) */
139 };
140
141 GISourceScanner *   gi_source_scanner_new              (void);
142 gboolean            gi_source_scanner_lex_filename     (GISourceScanner  *igenerator,
143                                                         const gchar      *filename);
144 gboolean            gi_source_scanner_parse_file       (GISourceScanner  *igenerator,
145                                                         FILE             *file);
146 void                gi_source_scanner_parse_macros     (GISourceScanner  *scanner,
147                                                         GList            *filenames);
148 void                gi_source_scanner_set_macro_scan   (GISourceScanner  *scanner,
149                                                         gboolean          macro_scan);
150 GSList *            gi_source_scanner_get_symbols      (GISourceScanner  *scanner);
151 GSList *            gi_source_scanner_get_directives   (GISourceScanner  *scanner,
152                                                         const gchar      *name);
153 void                gi_source_scanner_free             (GISourceScanner  *scanner);
154
155 GISourceSymbol *    gi_source_symbol_new               (GISourceSymbolType  type);
156 gboolean            gi_source_symbol_get_const_boolean (GISourceSymbol     *symbol);
157 GISourceSymbol *    gi_source_symbol_ref               (GISourceSymbol     *symbol);
158 void                gi_source_symbol_unref             (GISourceSymbol     *symbol);
159
160 GISourceDirective * gi_source_directive_new            (const gchar        *name,
161                                                         const gchar        *value,
162                                                         GSList             *options);
163 void                gi_source_directive_free           (GISourceDirective  *directive);
164
165 /* Private */
166 void                gi_source_scanner_add_symbol       (GISourceScanner  *scanner,
167                                                         GISourceSymbol   *symbol);
168 gboolean            gi_source_scanner_is_typedef       (GISourceScanner  *scanner,
169                                                         const char       *name);
170 void                gi_source_symbol_merge_type        (GISourceSymbol   *symbol,
171                                                         GISourceType     *type);
172 GISourceType *      gi_source_type_new                 (GISourceTypeType  type);
173 GISourceType *      gi_source_type_copy                (GISourceType     *type);
174 GISourceType *      gi_source_basic_type_new           (const char       *name);
175 GISourceType *      gi_source_typedef_new              (const char       *name);
176 GISourceType *      gi_source_struct_new               (const char       *name);
177 GISourceType *      gi_source_union_new                (const char       *name);
178 GISourceType *      gi_source_enum_new                 (const char       *name);
179 GISourceType *      gi_source_pointer_new              (GISourceType     *base_type);
180 GISourceType *      gi_source_array_new                (GISourceSymbol   *size);
181 GISourceType *      gi_source_function_new             (void);
182
183 G_END_DECLS
184
185 #endif /* __SOURCE_SCANNER_H__ */