60f214b7806c86d4f8720dd9066a5078c5b854a9
[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)
23 from .ast import (
24     type_names, default_array_types,
25     TYPE_STRING, TYPE_INT8, TYPE_UINT8, TYPE_INT16, TYPE_UINT16,
26     TYPE_INT, TYPE_UINT, TYPE_UINT32, TYPE_INT32, TYPE_LONG,
27     TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_FLOAT,
28     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_INT16
57 type_names['gushort'] = TYPE_UINT16
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
66 class GLibEnum(Enum):
67
68     def __init__(self, name, type_name, members, get_type):
69         Enum.__init__(self, name, type_name, members)
70         self.ctype = type_name
71         self.type_name = type_name
72         self.get_type = get_type
73
74     def __repr__(self):
75         return 'GlibEnum(%r, %r, %r)' % (self.name, self.members,
76                                          self.get_type)
77
78
79 class GLibFlags(Bitfield):
80
81     def __init__(self, name, type_name, members, get_type):
82         Bitfield.__init__(self, name, type_name, members)
83         self.ctype = type_name
84         self.type_name = type_name
85         self.get_type = get_type
86
87     def __repr__(self):
88         return 'GlibFlags(%r, %r, %r)' % (self.name, self.members,
89                                           self.get_type)
90
91
92 class GLibEnumMember(Member):
93
94     def __init__(self, name, value, symbol, nick):
95         Member.__init__(self, name, value, symbol)
96         self.nick = nick
97
98
99 class GLibObject(Class):
100
101     def __init__(self, name, parent, type_name, get_type,
102                  is_abstract, ctype=None):
103         Class.__init__(self, name, parent, is_abstract)
104         self.type_name = type_name
105         self.get_type = get_type
106         self.signals = []
107         self.ctype = ctype or type_name
108
109
110 class GLibBoxed:
111
112     def __init__(self, type_name, get_type):
113         self.constructors = []
114         self.methods = []
115         self.type_name = type_name
116         self.get_type = get_type
117
118
119 class GLibBoxedStruct(Struct, GLibBoxed):
120
121     def __init__(self, name, type_name, get_type, ctype=None):
122         Struct.__init__(self, name, ctype or type_name)
123         GLibBoxed.__init__(self, type_name, get_type)
124
125
126 class GLibBoxedUnion(Union, GLibBoxed):
127
128     def __init__(self, name, type_name, get_type, ctype=None):
129         Union.__init__(self, name, ctype or type_name)
130         GLibBoxed.__init__(self, type_name, get_type)
131
132
133 class GLibBoxedOther(Node, GLibBoxed):
134
135     def __init__(self, name, type_name, get_type):
136         Node.__init__(self, name)
137         GLibBoxed.__init__(self, type_name, get_type)
138         self.ctype = type_name
139         self.doc = None
140
141 class GLibInterface(Interface):
142
143     def __init__(self, name, parent, type_name, get_type,
144                  ctype=None):
145         Interface.__init__(self, name, parent)
146         self.type_name = type_name
147         self.get_type = get_type
148         self.signals = []
149         self.ctype = ctype or type_name
150
151
152 class GLibProperty(Property):
153     pass
154
155
156 class GLibSignal(Node):
157
158     def __init__(self, name, retval):
159         Node.__init__(self, name)
160         self.retval = retval
161         self.parameters = []
162         self.doc = None