+2008-06-19 Johan Dahlin <jdahlin@async.com.br>
+
+ * giscanner/ast.py:
+ * giscanner/girwriter.py:
+ * giscanner/glibast.py:
+ * giscanner/glibtransformer.py:
+ * giscanner/transformer.py:
+ * tests/parser/Foo-expected.gir:
+ Start using abstract type instead of the raw C types.
+ Register a bunch of glib types we care about.
+
2008-06-19 Rob Taylor <rob.taylor@codethink.co.uk>
* AUTHORS:
PARAM_DIRECTION_OUT = 'out'
PARAM_DIRECTION_INOUT = 'inout'
-
+type_names = {}
+
+# C
+type_names['char'] = TYPE_CHAR
+type_names['unsigned char'] = TYPE_UCHAR
+type_names['short'] = TYPE_INT16
+type_names['unsigned short'] = TYPE_UINT16
+type_names['int'] = TYPE_INT32
+type_names['unsigned int'] = TYPE_UINT32
+type_names['long'] = TYPE_LONG
+type_names['unsigned long'] = TYPE_ULONG
+type_names['float'] = TYPE_FLOAT
+type_names['double'] = TYPE_DOUBLE
+type_names['char*'] = TYPE_STRING
+type_names['void*'] = TYPE_ANY
+type_names['void'] = TYPE_NONE
+type_names['size_t'] = TYPE_SIZE
+type_names['ssize_t'] = TYPE_SSIZE
+
+
+def type_name_from_ctype(ctype):
+ return type_names.get(ctype, ctype)
+
+
class Node(object):
def __init__(self, name=None):
self.name = name
class Type(Node):
- def __init__(self, name):
+ def __init__(self, name, ctype=None):
Node.__init__(self, name)
- self.ctype = name
+ self.ctype = ctype
class Parameter(Node):
class Property(Node):
- def __init__(self, name, type_name):
+ def __init__(self, name, type_name, ctype=None):
Node.__init__(self, name)
- self.type = Type(type_name)
+ self.type = Type(type_name, ctype)
def __repr__(self):
return '%s(%r, %r, %r)' % (
class Sequence(Type):
# Subclass, because a Sequence is a kind of Type
- def __init__(self, name, element_type):
- Type.__init__(self, name)
+ def __init__(self, name, ctype, element_type):
+ Type.__init__(self, name, ctype)
self.element_type = element_type
self.transfer = False
+
# FIXME: figure out if type references a basic type
# or a boxed/class/interface etc. and skip
# writing the ctype if the latter.
- if 1:
+ if type.ctype is not None:
attrs.append(('c:type', type.ctype))
self.write_tag('type', attrs)
#
from .ast import Class, Enum, Interface, Member, Node, Property, Struct
-
+from .ast import (
+ type_names,
+ TYPE_STRING, TYPE_INT8, TYPE_UINT8, TYPE_INT16, TYPE_UINT16,
+ TYPE_INT32, TYPE_UINT32, TYPE_INT32, TYPE_UINT32, TYPE_LONG,
+ TYPE_ULONG, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, TYPE_BOOLEAN,
+ TYPE_ANY, TYPE_SIZE, TYPE_SSIZE)
+
+# Glib type names
+type_names['gchararray'] = TYPE_STRING
+type_names['gint8'] = TYPE_INT8
+type_names['guint8'] = TYPE_UINT8
+type_names['gint16'] = TYPE_INT16
+type_names['guint16'] = TYPE_UINT16
+type_names['gint'] = TYPE_INT32
+type_names['gyint'] = TYPE_UINT32
+type_names['gint32'] = TYPE_INT32
+type_names['guint32'] = TYPE_UINT32
+type_names['glong'] = TYPE_LONG
+type_names['gulong'] = TYPE_ULONG
+type_names['gfloat'] = TYPE_FLOAT
+type_names['gdouble'] = TYPE_DOUBLE
+type_names['gchar*'] = TYPE_STRING
+type_names['gboolean'] = TYPE_BOOLEAN
+type_names['gpointer'] = TYPE_ANY
+type_names['gsize'] = TYPE_SIZE
+type_names['gssize'] = TYPE_SSIZE
class GLibEnum(Enum):
def __init__(self, name, members, type_name, get_type):
from . import cgobject
from .odict import odict
from .ast import (Callback, Enum, Function, Member, Namespace, Parameter,
- Property, Return, Sequence, Struct, Type)
+ Property, Return, Sequence, Struct, Type,
+ type_name_from_ctype)
from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
GLibInterface, GLibObject, GLibSignal)
from .utils import resolve_libtool, to_underscores
node.fields.append(field)
def _create_type(self, type_id):
- type_name = cgobject.type_name(type_id)
- return Type(type_name)
+ ctype = cgobject.type_name(type_id)
+ type_name = type_name_from_ctype(ctype)
+ return Type(type_name, ctype)
def _introspect_type(self, type_id, symbol):
fundamental_type_id = cgobject.type_fundamental(type_id)
for pspec in pspecs:
if pspec.owner_type != type_id:
continue
+ ctype = cgobject.type_name(pspec.value_type)
node.properties.append(Property(
pspec.name,
- cgobject.type_name(pspec.value_type)))
+ type_name_from_ctype(ctype),
+ ctype,
+ ))
def _introspect_signals(self, node, type_id):
for signal_info in cgobject.signal_list(type_id):
- rtype = Type(cgobject.type_name(signal_info.return_type))
+ rtype = self._create_type(signal_info.return_type)
return_ = Return(rtype)
signal = GLibSignal(signal_info.signal_name, return_)
for i, parameter in enumerate(signal_info.get_params()):
from giscanner.ast import (Callback, Enum, Function, Namespace, Member,
Parameter, Return, Sequence, Struct, Field,
- Type)
+ Type, type_name_from_ctype)
from giscanner.sourcescanner import (
SourceSymbol, ctype_name, symbol_type_name, CTYPE_POINTER,
CTYPE_BASIC_TYPE, CTYPE_UNION, CTYPE_ARRAY,
return node
def _create_type(self, source_type):
- type_name = self._create_source_type(source_type)
- return Type(type_name)
+ ctype = self._create_source_type(source_type)
+ type_name = type_name_from_ctype(ctype)
+ return Type(type_name, ctype)
def _create_parameter(self, symbol, options):
ptype = self._create_type(symbol.base_type)
def _create_return(self, source_type, options=None):
if not options:
options = []
- rtype = Type(self._create_source_type(source_type))
+ rtype = self._create_type(source_type)
rtype = self._resolve_param_type(rtype)
return_ = Return(rtype)
for option in options:
elif option.startswith('seq '):
value, element_options = option[3:].split(None, 2)
element_type = self._parse_type_annotation(value)
- seq = Sequence(rtype.name, element_type)
+ seq = Sequence(rtype.name,
+ type_name_from_ctype(rtype.name),
+ element_type)
seq.transfer = True
return_.type = seq
else:
</interface>
<function name="init" c:identifier="foo_init">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
</function>
<class name="Object"
</constructor>
<method name="method" c:identifier="foo_object_method">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
<parameters>
<parameter name="object">
</method>
<method name="out" c:identifier="foo_object_out">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
<parameters>
<parameter name="object">
</method>
<method name="inout" c:identifier="foo_object_inout">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
<parameters>
<parameter name="object">
</method>
<method name="inout2" c:identifier="foo_object_inout2">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
<parameters>
<parameter name="object">
</method>
<method name="inout3" c:identifier="foo_object_inout3">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
<parameters>
<parameter name="object">
</method>
<method name="in" c:identifier="foo_object_in">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
<parameters>
<parameter name="object">
</method>
<method name="calleeowns" c:identifier="foo_object_calleeowns">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
<parameters>
<parameter name="object">
</method>
<method name="calleesowns" c:identifier="foo_object_calleesowns">
<return-value>
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</return-value>
<parameters>
<parameter name="object">
</parameters>
</method>
<property name="string">
- <type name="gchararray" c:type="gchararray"/>
+ <type name="string" c:type="gchararray"/>
</property>
<callback name="virtual_method">
<return-value>
- <type name="gboolean" c:type="gboolean"/>
+ <type name="boolean" 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"/>
+ <type name="int32" c:type="int"/>
</parameter>
</parameters>
</callback>
<glib:signal name="signal">
<return-value>
- <type name="gchararray" c:type="gchararray"/>
+ <type name="string" c:type="gchararray"/>
</return-value>
<parameters>
<parameter name="object">
<type name="GObject" c:type="GObject"/>
</parameter>
<parameter name="p0">
- <type name="gpointer" c:type="gpointer"/>
+ <type name="any" c:type="gpointer"/>
</parameter>
</parameters>
</glib:signal>
</enumeration>
<function name="enum_type_method" c:identifier="foo_enum_type_method">
<return-value>
- <type name="int" c:type="int"/>
+ <type name="int32" c:type="int"/>
</return-value>
<parameters>
<parameter name="foo_enum">
</constructor>
<method name="method" c:identifier="foo_boxed_method">
<return-value>
- <type name="void" c:type="void"/>
+ <type name="none" c:type="void"/>
</return-value>
<parameters>
<parameter name="boxed">
</glib:boxed>
<callback name="FooCallback">
<return-value>
- <type name="gboolean" c:type="gboolean"/>
+ <type name="boolean" c:type="gboolean"/>
</return-value>
<parameters>
<parameter name="foo">
<type name="FooObject*" c:type="FooObject*"/>
</parameter>
<parameter name="b">
- <type name="gboolean" c:type="gboolean"/>
+ <type name="boolean" c:type="gboolean"/>
</parameter>
<parameter name="data">
- <type name="gpointer" c:type="gpointer"/>
+ <type name="any" c:type="gpointer"/>
</parameter>
</parameters>
</callback>
<type name="FooStructPrivate*" c:type="FooStructPrivate*"/>
</field>
<field name="member">
- <type name="int" c:type="int"/>
+ <type name="int32" c:type="int"/>
</field>
</record>
<record name="FooStructPrivate" c:type="FooStructPrivate"/>
<record name="FooRectangle" c:type="FooRectangle">
<field name="x">
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</field>
<field name="y">
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</field>
<field name="width">
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</field>
<field name="height">
- <type name="gint" c:type="gint"/>
+ <type name="int32" c:type="gint"/>
</field>
</record>
</namespace>