Add pyflakes.py and run it in make check. Update the source code to fix
[platform/upstream/gobject-introspection.git] / giscanner / glibast.py
1 # -*- Mode: Python -*-
2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008  Johan Dahlin
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program 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
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 # 02110-1301, USA.
19 #
20
21 from .ast import Class, Enum, Interface, Member, Node, Property, Struct
22 from .ast import (
23     type_names,
24     TYPE_STRING, TYPE_INT8, TYPE_UINT8, TYPE_INT16, TYPE_UINT16,
25     TYPE_UINT32, TYPE_INT32, TYPE_LONG, TYPE_ULONG, TYPE_FLOAT,
26     TYPE_DOUBLE, TYPE_BOOLEAN, TYPE_ANY, TYPE_SIZE, TYPE_SSIZE)
27
28 # Glib type names
29 type_names['gchararray'] = TYPE_STRING
30 type_names['gint8'] = TYPE_INT8
31 type_names['guint8'] = TYPE_UINT8
32 type_names['gint16'] = TYPE_INT16
33 type_names['guint16'] = TYPE_UINT16
34 type_names['gint'] = TYPE_INT32
35 type_names['guint'] = TYPE_UINT32
36 type_names['gint32'] = TYPE_INT32
37 type_names['guint32'] = TYPE_UINT32
38 type_names['glong'] = TYPE_LONG
39 type_names['gulong'] = TYPE_ULONG
40 type_names['gfloat'] = TYPE_FLOAT
41 type_names['gdouble'] = TYPE_DOUBLE
42 type_names['gchar*'] = TYPE_STRING
43 type_names['gboolean'] = TYPE_BOOLEAN
44 type_names['gpointer'] = TYPE_ANY
45 type_names['gsize'] = TYPE_SIZE
46 type_names['gssize'] = TYPE_SSIZE
47
48
49 class GLibEnum(Enum):
50
51     def __init__(self, name, type_name, members, get_type):
52         Enum.__init__(self, name, type_name, members)
53         self.ctype = type_name
54         self.type_name = type_name
55         self.get_type = get_type
56
57     def __repr__(self):
58         return '%s(%r, %r, %r)' % (
59             self.__class__.__name__,
60             self.name,
61             self.members,
62             self.get_type)
63
64
65 class GLibFlags(GLibEnum):
66     pass
67
68
69 class GLibEnumMember(Member):
70
71     def __init__(self, name, value, symbol, nick):
72         Member.__init__(self, name, value, symbol)
73         self.nick = nick
74
75
76 class GLibObject(Class):
77
78     def __init__(self, name, parent, type_name, get_type):
79         Class.__init__(self, name, parent)
80         self.ctype = type_name
81         self.type_name = type_name
82         self.get_type = get_type
83         self.signals = []
84
85
86 class GLibBoxed(Struct):
87
88     def __init__(self, name, type_name, get_type):
89         Struct.__init__(self, name, get_type)
90         self.ctype = name
91         self.constructors = []
92         self.methods = []
93         self.type_name = type_name
94         self.symbol = type_name
95         self.get_type = get_type
96
97
98 class GLibInterface(Interface):
99
100     def __init__(self, name, parent, type_name, get_type):
101         Interface.__init__(self, name, parent)
102         self.ctype = type_name
103         self.type_name = type_name
104         self.get_type = get_type
105         self.signals = []
106
107
108 class GLibProperty(Property):
109     pass
110
111
112 class GLibSignal(Node):
113
114     def __init__(self, name, retval):
115         Node.__init__(self, name)
116         self.retval = retval
117         self.parameters = []