Simplify Gio-2.0.gir rules
[gnome.gobject-introspection] / giscanner / glibast.py
1 # -*- Mode: Python -*-
2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008  Johan Dahlin
4 #
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.
9 #
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.
14 #
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.
19 #
20
21 from .ast import (Bitfield, Class, Enum, Interface, Member, Node,
22                   Property, Struct, Union, Record)
23 from .ast import (
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,
29     TYPE_SIZET)
30
31
32 # Glib type names
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
58
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
64
65 class GLibRecord(Record):
66     def __init__(self, *args, **kwargs):
67         Record.__init__(self, *args, **kwargs)
68
69     @classmethod
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
75         obj.doc = record.doc
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
80         return obj
81
82 class GLibEnum(Enum):
83
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
90
91     def __repr__(self):
92         return 'GlibEnum(%r, %r, %r)' % (self.name, self.members,
93                                          self.get_type)
94
95
96 class GLibFlags(Bitfield):
97
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
103
104     def __repr__(self):
105         return 'GlibFlags(%r, %r, %r)' % (self.name, self.members,
106                                           self.get_type)
107
108
109 class GLibEnumMember(Member):
110
111     def __init__(self, name, value, symbol, nick):
112         Member.__init__(self, name, value, symbol)
113         self.nick = nick
114
115
116 class GLibObject(Class):
117
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
123         self.signals = []
124         self.ctype = ctype or type_name
125
126
127 class GLibBoxed:
128
129     def __init__(self, type_name, get_type):
130         self.type_name = type_name
131         self.get_type = get_type
132
133
134 class GLibBoxedStruct(Struct, GLibBoxed):
135
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)
139
140
141 class GLibBoxedUnion(Union, GLibBoxed):
142
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)
146
147
148 class GLibBoxedOther(Node, GLibBoxed):
149
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 = []
154         self.methods = []
155         self.ctype = type_name
156         self.doc = None
157
158 class GLibInterface(Interface):
159
160     def __init__(self, name, parent, type_name, get_type,
161                  ctype=None):
162         Interface.__init__(self, name, parent)
163         self.type_name = type_name
164         self.get_type = get_type
165         self.signals = []
166         self.ctype = ctype or type_name
167
168
169 class GLibProperty(Property):
170     pass
171
172
173 class GLibSignal(Node):
174
175     def __init__(self, name, retval):
176         Node.__init__(self, name)
177         self.retval = retval
178         self.parameters = []
179         self.doc = None