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