+2008-05-03 Johan Dahlin <johan@gnome.org>
+
+ * giscanner/__init__.py:
+ * giscanner/ast.py:
+ * giscanner/girwriter.py:
+ * giscanner/glibtransformer.py:
+ * giscanner/transformer.py:
+ Parse struct fields properly, improve debugging.
+
2008-04-29 Johan Dahlin <johan@gnome.org>
* giscanner/ast.py:
#
# 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.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
#
(CSYMBOL_TYPE_INVALID,
UNARY_MINUS,
UNARY_BITWISE_COMPLEMENT,
UNARY_LOGICAL_NEGATION) = range(6)
+
+def symbol_type_name(symbol_type):
+ return {
+ CSYMBOL_TYPE_INVALID: 'invalid',
+ CSYMBOL_TYPE_CONST: 'const',
+ CSYMBOL_TYPE_OBJECT: 'object',
+ CSYMBOL_TYPE_FUNCTION: 'function',
+ CSYMBOL_TYPE_STRUCT: 'struct',
+ CSYMBOL_TYPE_UNION: 'union',
+ CSYMBOL_TYPE_ENUM: 'enum',
+ CSYMBOL_TYPE_TYPEDEF: 'typedef'
+ }.get(symbol_type)
+
class Parameter(Node):
- def __init__(self, name, type_name):
+ def __init__(self, name, typenode):
Node.__init__(self, name)
- self.type = Type(type_name)
+ self.type = typenode
self.direction = 'in'
self.transfer = False
return
attrs = [('name', field.name),
- ('type', str(field.type))]
+ ('value', str(field.value))]
self.write_tag('field', attrs)
def _write_signal(self, signal):
from . import cgobject
from .odict import odict
from .ast import (Callback, Enum, Function, Parameter, Property, Return,
- Sequence, Struct)
+ Sequence, Struct, Type)
from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
GLibInterface, GLibObject, GLibSignal)
return libname
-
-
class GLibTransformer(object):
def __init__(self, namespace_name):
self._namespace_name = namespace_name
for node in nodes:
self._parse_node(node)
- # Second round, associate GtkButtonClass with GtkButton
+ # Second round
for node in self._output_ns.values():
+ # associate GtkButtonClass with GtkButton
if isinstance(node, Struct):
self._pair_class_struct(node)
return True
def _parse_struct(self, struct):
- self._add_attribute(struct)
+ type_name = self._resolve_type_name(struct.name)
+ node = self._output_ns.get(type_name)
+ if node is None:
+ self._add_attribute(struct, replace=True)
+ return
+ node.fields = struct.fields[:]
def _parse_callback(self, callback):
self._add_attribute(callback)
node = self._output_ns.get(self._resolve_type_name(name))
del self._output_ns[class_node.name]
+ if node is None:
+ return
for field in class_node.fields[1:]:
node.fields.append(field)
+ def _create_type(self, type_id):
+ type_name = cgobject.type_name(type_id)
+ return Type(type_name)
+
def _introspect_type(self, type_id, symbol):
fundamental_type_id = cgobject.type_fundamental(type_id)
if (fundamental_type_id == cgobject.TYPE_ENUM or
name = 'object'
else:
name = 'p%s' % (i-1,)
- signal.parameters.append(
- Parameter(name, cgobject.type_name(parameter)))
+ ptype = self._create_type(parameter)
+ param = Parameter(name, ptype)
+ signal.parameters.append(param)
node.signals.append(signal)
#
import giscanner
+
from giscanner.ast import (Callback, Enum, Function, Member, Parameter,
- Return, Sequence, Struct)
+ Return, Sequence, Struct, Type)
+from giscanner.sourcescanner import SourceSymbol
class Transformer(object):
return name
def _traverse_one(self, symbol, stype=None):
+ assert isinstance(symbol, SourceSymbol), symbol
+
if stype is None:
stype = symbol.type
if stype == giscanner.CSYMBOL_TYPE_FUNCTION:
return self._create_struct(symbol)
elif stype == giscanner.CSYMBOL_TYPE_ENUM:
return self._create_enum(symbol)
+ elif stype == giscanner.CSYMBOL_TYPE_OBJECT:
+ return self._create_object(symbol)
elif stype == giscanner.CSYMBOL_TYPE_UNION:
# Unions are not supported
pass
else:
- print 'BUILDER: unhandled symbol', symbol.type
+ raise NotImplementedError(
+ 'Transformer: unhandled symbol: %r of type %r'
+ % (symbol.ident, giscanner.symbol_type_name(stype)))
def _create_enum(self, symbol):
members = []
return Enum(symbol.ident, members)
+ def _create_object(self, symbol):
+ return Member(symbol.ident, symbol.base_type.name)
+
def _create_function(self, symbol):
directives = symbol.directives()
parameters = list(self._create_parameters(symbol.base_type, directives))
yield self._create_parameter(
child, options.get(child.ident, []))
+ def _create_type(self, source_type):
+ type_name = self._create_source_type(source_type)
+ return Type(type_name)
+
def _create_parameter(self, symbol, options):
- param = Parameter(symbol.ident,
- self._create_source_type(symbol.base_type))
+ ptype = self._create_type(symbol.base_type)
+ param = Parameter(symbol.ident, ptype)
for option in options:
if option in ['in-out', 'inout']:
param.direction = 'inout'
for child in symbol.base_type.child_list:
field = self._traverse_one(child, child.base_type.type)
- struct.fields.append(field)
+ if field:
+ struct.fields.append(field)
return struct
def _create_callback(self, symbol):
<property name="string">
<type name="gchararray" c:type="gchararray"/>
</property>
+ <callback name="virtual_method">
+ <return-value>
+ <type name="gboolean" c:type="gboolean"/>
+ </return-value>
+ <parameters>
+ <parameter name="object">
+ <type name="FooObject*" c:type="FooObject*"/>
+ </parameter>
+ <parameter name="first_param">
+ <type name="int" c:type="int"/>
+ </parameter>
+ </parameters>
+ </callback>
<glib:signal name="signal">
<return-value>
<type name="gchararray" c:type="gchararray"/>
</parameter>
</parameters>
</callback>
- <record name="FooStruct" c:type="FooStruct"/>
+ <record name="FooStruct" c:type="FooStruct">
+ <field name="member" value="int"/>
+ </record>
<record name="FooStructPrivate" c:type="FooStructPrivate"/>
</namespace>
</repository>