9e3713120de5a6aa37b53c1300009308b22f11f3
[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 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 #include <gio/gio.h>
29
30 G_BEGIN_DECLS
31
32 typedef struct _GISourceComment GISourceComment;
33 typedef struct _GISourceScanner GISourceScanner;
34 typedef struct _GISourceSymbol GISourceSymbol;
35 typedef struct _GISourceType GISourceType;
36
37 typedef enum
38 {
39   CSYMBOL_TYPE_INVALID,
40   CSYMBOL_TYPE_ELLIPSIS,
41   CSYMBOL_TYPE_CONST,
42   CSYMBOL_TYPE_OBJECT,
43   CSYMBOL_TYPE_FUNCTION,
44   CSYMBOL_TYPE_STRUCT,
45   CSYMBOL_TYPE_UNION,
46   CSYMBOL_TYPE_ENUM,
47   CSYMBOL_TYPE_TYPEDEF,
48   CSYMBOL_TYPE_MEMBER
49 } GISourceSymbolType;
50
51 typedef enum
52 {
53   CTYPE_INVALID,
54   CTYPE_VOID,
55   CTYPE_BASIC_TYPE,
56   CTYPE_TYPEDEF,
57   CTYPE_STRUCT,
58   CTYPE_UNION,
59   CTYPE_ENUM,
60   CTYPE_POINTER,
61   CTYPE_ARRAY,
62   CTYPE_FUNCTION
63 } GISourceTypeType;
64
65 typedef enum
66 {
67   STORAGE_CLASS_NONE = 0,
68   STORAGE_CLASS_TYPEDEF = 1 << 1,
69   STORAGE_CLASS_EXTERN = 1 << 2,
70   STORAGE_CLASS_STATIC = 1 << 3,
71   STORAGE_CLASS_AUTO = 1 << 4,
72   STORAGE_CLASS_REGISTER = 1 << 5
73 } StorageClassSpecifier;
74
75 typedef enum
76 {
77   TYPE_QUALIFIER_NONE = 0,
78   TYPE_QUALIFIER_CONST = 1 << 1,
79   TYPE_QUALIFIER_RESTRICT = 1 << 2,
80   TYPE_QUALIFIER_VOLATILE = 1 << 3,
81   TYPE_QUALIFIER_EXTENSION = 1 << 4
82 } TypeQualifier;
83
84 typedef enum
85 {
86   FUNCTION_NONE = 0,
87   FUNCTION_INLINE = 1 << 1
88 } FunctionSpecifier;
89
90 typedef enum
91 {
92   UNARY_ADDRESS_OF,
93   UNARY_POINTER_INDIRECTION,
94   UNARY_PLUS,
95   UNARY_MINUS,
96   UNARY_BITWISE_COMPLEMENT,
97   UNARY_LOGICAL_NEGATION
98 } UnaryOperator;
99
100 struct _GISourceComment
101 {
102   char *comment;
103   char *filename;
104   int line;
105 };
106
107 struct _GISourceScanner
108 {
109   GFile *current_file;
110   gboolean macro_scan;
111   gboolean private; /* set by gtk-doc comment <private>/<public> */
112   gboolean flags; /* set by gtk-doc comment <flags> */
113   GSList *symbols;
114   GHashTable *files;
115   GSList *comments; /* _GIComment */
116   GHashTable *typedef_table;
117   gboolean skipping;
118   GQueue conditionals;
119 };
120
121 struct _GISourceSymbol
122 {
123   int ref_count;
124   GISourceSymbolType type;
125   char *ident;
126   GISourceType *base_type;
127   gboolean const_int_set;
128   gboolean private;
129   gint64 const_int; /* 64-bit we can handle signed and unsigned 32-bit values */
130   gboolean const_int_is_unsigned;
131   char *const_string;
132   gboolean const_double_set;
133   double const_double;
134   gboolean const_boolean_set;
135   int const_boolean;
136   char *source_filename;
137   int line;
138 };
139
140 struct _GISourceType
141 {
142   GISourceTypeType type;
143   StorageClassSpecifier storage_class_specifier;
144   TypeQualifier type_qualifier;
145   FunctionSpecifier function_specifier;
146   char *name;
147   GISourceType *base_type;
148   GList *child_list; /* list of GISourceSymbol */
149   gboolean is_bitfield;
150 };
151
152 GISourceScanner *   gi_source_scanner_new              (void);
153 gboolean            gi_source_scanner_lex_filename     (GISourceScanner  *igenerator,
154                                                         const gchar      *filename);
155 gboolean            gi_source_scanner_parse_file       (GISourceScanner  *igenerator,
156                                                         FILE             *file);
157 void                gi_source_scanner_parse_macros     (GISourceScanner  *scanner,
158                                                         GList            *filenames);
159 void                gi_source_scanner_set_macro_scan   (GISourceScanner  *scanner,
160                                                         gboolean          macro_scan);
161 GSList *            gi_source_scanner_get_symbols      (GISourceScanner  *scanner);
162 GSList *            gi_source_scanner_get_comments     (GISourceScanner  *scanner);
163 void                gi_source_scanner_free             (GISourceScanner  *scanner);
164
165 GISourceSymbol *    gi_source_symbol_new               (GISourceSymbolType  type, GFile *file, int line);
166 gboolean            gi_source_symbol_get_const_boolean (GISourceSymbol     *symbol);
167 GISourceSymbol *    gi_source_symbol_ref               (GISourceSymbol     *symbol);
168 void                gi_source_symbol_unref             (GISourceSymbol     *symbol);
169 GISourceSymbol *    gi_source_symbol_copy              (GISourceSymbol     *symbol);
170
171 /* Private */
172 void                gi_source_scanner_add_symbol       (GISourceScanner  *scanner,
173                                                         GISourceSymbol   *symbol);
174 void                gi_source_scanner_take_comment     (GISourceScanner *scanner,
175                                                         GISourceComment *comment);
176 gboolean            gi_source_scanner_is_typedef       (GISourceScanner  *scanner,
177                                                         const char       *name);
178 void                gi_source_symbol_merge_type        (GISourceSymbol   *symbol,
179                                                         GISourceType     *type);
180 GISourceType *      gi_source_type_new                 (GISourceTypeType  type);
181 GISourceType *      gi_source_type_copy                (GISourceType     *type);
182 GISourceType *      gi_source_basic_type_new           (const char       *name);
183 GISourceType *      gi_source_typedef_new              (const char       *name);
184 GISourceType *      gi_source_struct_new               (const char       *name);
185 GISourceType *      gi_source_union_new                (const char       *name);
186 GISourceType *      gi_source_enum_new                 (const char       *name);
187 GISourceType *      gi_source_pointer_new              (GISourceType     *base_type);
188 GISourceType *      gi_source_array_new                (GISourceSymbol   *size);
189 GISourceType *      gi_source_function_new             (void);
190
191 void ctype_free (GISourceType * type);
192
193 G_END_DECLS
194
195 #endif /* __SOURCE_SCANNER_H__ */