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