summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/ast.py38
-rw-r--r--giscanner/girwriter.py2
-rw-r--r--giscanner/glibast.py27
-rw-r--r--giscanner/glibtransformer.py15
-rw-r--r--giscanner/transformer.py13
5 files changed, 76 insertions, 19 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 8f40d63f..80d5f968 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -72,7 +72,30 @@ PARAM_DIRECTION_IN = 'in'
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
@@ -108,9 +131,9 @@ class VFunction(Function):
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):
@@ -212,9 +235,9 @@ class Constant(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)' % (
@@ -236,7 +259,8 @@ class Callback(Node):
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
+
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 58eeccd0..389c05fa 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -118,7 +118,7 @@ class GIRWriter(XMLWriter):
# 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)
diff --git a/giscanner/glibast.py b/giscanner/glibast.py
index 50d51c34..db886db9 100644
--- a/giscanner/glibast.py
+++ b/giscanner/glibast.py
@@ -19,7 +19,32 @@
#
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):
diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py
index dc4ba0b8..f84f0c6c 100644
--- a/giscanner/glibtransformer.py
+++ b/giscanner/glibtransformer.py
@@ -24,7 +24,8 @@ import os
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
@@ -228,8 +229,9 @@ class GLibTransformer(object):
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)
@@ -314,13 +316,16 @@ class GLibTransformer(object):
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()):
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 7562e157..5a6b021b 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -20,7 +20,7 @@
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,
@@ -205,8 +205,9 @@ class Transformer(object):
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)
@@ -228,7 +229,7 @@ class Transformer(object):
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:
@@ -237,7 +238,9 @@ class Transformer(object):
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: