2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008 Johan Dahlin
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
21 from .ast import (Bitfield, Class, Enum, Interface, Member, Node,
22 Property, Struct, Union, Record)
24 type_names, default_array_types,
25 TYPE_STRING, TYPE_INT8, TYPE_UINT8, TYPE_SHORT, TYPE_USHORT,
26 TYPE_INT16, TYPE_UINT16, TYPE_INT, TYPE_UINT, TYPE_UINT32,
27 TYPE_INT32, TYPE_LONG, TYPE_ULONG, TYPE_INT64, TYPE_UINT64,
28 TYPE_FLOAT, TYPE_DOUBLE, TYPE_BOOLEAN, TYPE_ANY, TYPE_SSIZET,
33 type_names['gchararray'] = TYPE_STRING
34 type_names['gint8'] = TYPE_INT8
35 type_names['guint8'] = TYPE_UINT8
36 type_names['gint16'] = TYPE_INT16
37 type_names['guint16'] = TYPE_UINT16
38 type_names['gint'] = TYPE_INT
39 type_names['guint'] = TYPE_UINT
40 type_names['gint32'] = TYPE_INT32
41 type_names['guint32'] = TYPE_UINT32
42 type_names['glong'] = TYPE_LONG
43 type_names['gulong'] = TYPE_ULONG
44 type_names['gint64'] = TYPE_INT64
45 type_names['guint64'] = TYPE_UINT64
46 type_names['gfloat'] = TYPE_FLOAT
47 type_names['gdouble'] = TYPE_DOUBLE
48 type_names['gchar*'] = TYPE_STRING
49 type_names['gboolean'] = TYPE_BOOLEAN
50 type_names['gpointer'] = TYPE_ANY
51 type_names['gconstpointer'] = TYPE_ANY
52 type_names['gsize'] = TYPE_SIZET
53 type_names['gssize'] = TYPE_SSIZET
54 type_names['gchar'] = TYPE_INT8
55 type_names['guchar'] = TYPE_UINT8
56 type_names['gshort'] = TYPE_SHORT
57 type_names['gushort'] = TYPE_USHORT
59 # It's not very nice to duplicate the array types from ast.py,
60 # but a clean fix is hard without essentially hardcoding
61 # char * again inside transformer.py
62 default_array_types['guint8*'] = TYPE_UINT8
63 default_array_types['gchar**'] = TYPE_STRING
65 class GLibRecord(Record):
66 def __init__(self, *args, **kwargs):
67 Record.__init__(self, *args, **kwargs)
70 def from_record(cls, record):
71 obj = cls(record.name, record.symbol)
72 obj.fields = record.fields
73 obj.constructors = record.constructors
74 obj.disguised = record.disguised
76 obj.methods = record.methods
77 # If true, this record defines the FooClass C structure
78 # for some Foo GObject (or similar for GInterface)
79 obj.is_gtype_struct_for = False
84 def __init__(self, name, type_name, members, get_type):
85 Enum.__init__(self, name, type_name, members)
86 self.ctype = type_name
87 self.type_name = type_name
88 self.get_type = get_type
89 self.error_quark = None
92 return 'GlibEnum(%r, %r, %r)' % (self.name, self.members,
96 class GLibFlags(Bitfield):
98 def __init__(self, name, type_name, members, get_type):
99 Bitfield.__init__(self, name, type_name, members)
100 self.ctype = type_name
101 self.type_name = type_name
102 self.get_type = get_type
105 return 'GlibFlags(%r, %r, %r)' % (self.name, self.members,
109 class GLibEnumMember(Member):
111 def __init__(self, name, value, symbol, nick):
112 Member.__init__(self, name, value, symbol)
116 class GLibObject(Class):
118 def __init__(self, name, parent, type_name, get_type,
119 is_abstract, ctype=None):
120 Class.__init__(self, name, parent, is_abstract)
121 self.type_name = type_name
122 self.get_type = get_type
124 self.ctype = ctype or type_name
129 def __init__(self, type_name, get_type):
130 self.type_name = type_name
131 self.get_type = get_type
134 class GLibBoxedStruct(Struct, GLibBoxed):
136 def __init__(self, name, type_name, get_type, ctype=None):
137 Struct.__init__(self, name, ctype or type_name)
138 GLibBoxed.__init__(self, type_name, get_type)
141 class GLibBoxedUnion(Union, GLibBoxed):
143 def __init__(self, name, type_name, get_type, ctype=None):
144 Union.__init__(self, name, ctype or type_name)
145 GLibBoxed.__init__(self, type_name, get_type)
148 class GLibBoxedOther(Node, GLibBoxed):
150 def __init__(self, name, type_name, get_type):
151 Node.__init__(self, name)
152 GLibBoxed.__init__(self, type_name, get_type)
153 self.constructors = []
155 self.ctype = type_name
158 class GLibInterface(Interface):
160 def __init__(self, name, parent, type_name, get_type,
162 Interface.__init__(self, name, parent)
163 self.type_name = type_name
164 self.get_type = get_type
166 self.ctype = ctype or type_name
169 class GLibProperty(Property):
173 class GLibSignal(Node):
175 def __init__(self, name, retval):
176 Node.__init__(self, name)