Start using abstract type instead of the raw C types. Register a bunch of
authorJohan Dahlin <jdahlin@async.com.br>
Fri, 20 Jun 2008 01:33:09 +0000 (01:33 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Fri, 20 Jun 2008 01:33:09 +0000 (01:33 +0000)
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.

svn path=/trunk/; revision=290

ChangeLog
giscanner/ast.py
giscanner/girwriter.py
giscanner/glibast.py
giscanner/glibtransformer.py
giscanner/transformer.py
tests/parser/Foo-expected.gir

index c3f1f4444ce127fda8c24bc19181f24a97b16389..7df9267226e9889cab391c1c6bed772946924d77 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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:
index 8f40d63f716d51890ae0515bace6ad7088a46003..80d5f968930d92ca6bc156c49095af76ee71dd8f 100644 (file)
@@ -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
+
index 58eeccd069e1f0d957d91039d6891cdeeca0f2d2..389c05fac77619f1823ece35c6279fa95b8c86b0 100644 (file)
@@ -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)
 
index 50d51c346bafa103a6e2f5e5dfed1026753282b8..db886db925bbfd7ac521048fefdafd431ab1eae3 100644 (file)
 #
 
 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):
index dc4ba0b84975b1dac517164d0f9a5fd0385b8718..f84f0c6c1c5492e49d526a4905801367c49379fc 100644 (file)
@@ -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()):
index 7562e157787c8d1f6429521cd989bd4e62455562..5a6b021bff07ace1a6451de5ebb7d2c474fadd60 100644 (file)
@@ -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:
index c9edac3c1ae235be3c3edcc9f2c7ac62a7c512ff..ec144cb586312eb2868f1582c22fcec2463ceacf 100644 (file)
@@ -10,7 +10,7 @@
     </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"
@@ -25,7 +25,7 @@
       </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">
@@ -45,7 +45,7 @@
       </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">
@@ -68,7 +68,7 @@
       </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">
@@ -81,7 +81,7 @@
       </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">
@@ -94,7 +94,7 @@
       </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>