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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
# -*- Mode: Python -*-
# GObject-Introspection - a framework for introspecting GObject libraries
# Copyright (C) 2008 Johan Dahlin
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
"""AST nodes
This file descbribes abstract data type nodes independent on the
implementation language.
These can later on be extended (eg subclassed) with additional information
which is language/library/domain specific.
"""
##
## Types
##
# Basic types
TYPE_INT8 = 'int8'
TYPE_UINT8 = 'uint8'
TYPE_INT16 = 'int16'
TYPE_UINT16 = 'uint16'
TYPE_INT32 = 'int32'
TYPE_UINT32 = 'uint32'
TYPE_INT64 = 'int64'
TYPE_UINT64 = 'uint64'
TYPE_LONG = 'long'
TYPE_ULONG = 'ulong'
# Floating-point
TYPE_FLOAT = 'float'
TYPE_DOUBLE = 'double'
# Higher-level data types
TYPE_NONE = 'none'
TYPE_ANY = 'any' # CORBA Any/Variant/GValue, holds anything.
TYPE_BOOLEAN = 'boolean' # True/False
TYPE_STRING = 'string' # Sequence of characters
TYPE_SEQUENCE = 'sequence' # Sequence of something
TYPE_CHAR = 'char' # Character
TYPE_UCHAR = 'uchar' # Unsigned Character
TYPE_SIZE = 'size' # Size type (memory, buffer etc)
TYPE_SSIZE = 'ssize'
# Wide/Unicode
TYPE_UCHAR = 'uchar'
TYPE_USTRING = 'ustring'
# Domain specific, but practically useful
TYPE_FILENAME = 'filename'
##
## Parameters
##
PARAM_DIRECTION_IN = 'in'
PARAM_DIRECTION_OUT = 'out'
PARAM_DIRECTION_INOUT = 'inout'
type_names = {}
# C
type_names['char'] = TYPE_CHAR
type_names['unsigned char'] = TYPE_UCHAR
type_names['short'] = TYPE_INT16
type_names['unsigned short'] = TYPE_UINT16
type_names['int'] = TYPE_INT32
type_names['unsigned int'] = TYPE_UINT32
type_names['long'] = TYPE_LONG
type_names['unsigned long'] = TYPE_ULONG
type_names['float'] = TYPE_FLOAT
type_names['double'] = TYPE_DOUBLE
type_names['char*'] = TYPE_STRING
type_names['void*'] = TYPE_ANY
type_names['void'] = TYPE_NONE
type_names['size_t'] = TYPE_SIZE
type_names['ssize_t'] = TYPE_SSIZE
def type_name_from_ctype(ctype):
return type_names.get(ctype, ctype)
class Node(object):
def __init__(self, name=None):
self.name = name
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.name)
class Namespace(Node):
def __init__(self, name):
Node.__init__(self, name)
self.nodes = []
def __repr__(self):
return '%s(%r, %r)' % (self.__class__.__name__, self.name,
self.nodes)
class Function(Node):
def __init__(self, name, retval, parameters, symbol):
Node.__init__(self, name)
self.retval = retval
self.parameters = parameters
self.symbol = symbol
def __repr__(self):
return '%s(%r, %r, %r)' % (self.__class__.__name__,
self.name, self.retval,
self.parameters)
class VFunction(Function):
pass
class Type(Node):
def __init__(self, name, ctype=None):
Node.__init__(self, name)
self.ctype = ctype
class Parameter(Node):
def __init__(self, name, typenode):
Node.__init__(self, name)
self.type = typenode
self.direction = PARAM_DIRECTION_IN
self.transfer = False
def __repr__(self):
return 'Parameter(%r, %r)' % (self.name, self.type)
class Enum(Node):
def __init__(self, name, symbol, members):
Node.__init__(self, name)
self.symbol = symbol
self.members = members
def __repr__(self):
return 'Enum(%r, %r)' % (self.name, self.members)
class Member(Node):
def __init__(self, name, value, symbol):
Node.__init__(self, name)
self.value = value
self.symbol = symbol
def __repr__(self):
return 'Member(%r, %r)' % (self.name, self.value)
class Struct(Node):
def __init__(self, name, symbol):
Node.__init__(self, name)
self.fields = []
self.symbol = symbol
class Field(Node):
def __init__(self, name, typenode, symbol):
Node.__init__(self, name)
self.type = typenode
self.symbol = symbol
def __repr__(self):
return 'Field(%r, %r)' % (self.name, self.type)
class Return(Node):
def __init__(self, rtype):
Node.__init__(self)
self.type = rtype
self.transfer = False
def __repr__(self):
return 'Return(%r)' % (self.type,)
class Class(Node):
def __init__(self, name, parent):
Node.__init__(self, name)
self.ctype = name
self.parent = parent
self.methods = []
self.constructors = []
self.properties = []
self.fields = []
def __repr__(self):
return '%s(%r, %r, %r)' % (
self.__class__.__name__,
self.name, self.parent, self.methods)
class Interface(Node):
def __init__(self, name):
Node.__init__(self, name)
self.methods = []
self.properties = []
self.fields = []
def __repr__(self):
return '%s(%r, %r)' % (
self.__class__.__name__,
self.name, self.methods)
class Constant(Node):
def __init__(self, name, type_name, value):
Node.__init__(self, name)
self.type = Type(type_name)
self.value = value
def __repr__(self):
return 'Constant(%r, %r, %r)' % (
self.name, self.type, self.value)
class Property(Node):
def __init__(self, name, type_name, ctype=None):
Node.__init__(self, name)
self.type = Type(type_name, ctype)
def __repr__(self):
return '%s(%r, %r, %r)' % (
self.__class__.__name__,
self.name, self.type, self.value)
# FIXME: Inherit from Function
class Callback(Node):
def __init__(self, name, retval, parameters):
Node.__init__(self, name)
self.retval = retval
self.parameters = parameters
def __repr__(self):
return 'Callback(%r, %r, %r)' % (
self.name, self.retval, self.parameters)
class Sequence(Type):
# Subclass, because a Sequence is a kind of Type
def __init__(self, name, ctype, element_type):
Type.__init__(self, name, ctype)
self.element_type = element_type
self.transfer = False
|