gobject-introspection r667 - in trunk: . giscanner tests/scanner



Author: johan
Date: Sat Oct 11 21:16:57 2008
New Revision: 667
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=667&view=rev

Log:
2008-10-09  Andreas Rottmann  <a rottmann gmx at>

    Bug 555712: Struct and union issues

    * giscanner/scannerparser.y (struct_declarator): Use information
    provided about the bit width of a field.
    * giscanner/transformer.py (Transformer._create_member): Pass the
    symbol's const_int member to the created field (it represents the
    bit width).
    * giscanner/girwriter.py (GIRWriter._write_field): Output 'bits'
    field attribute, if present.
    * giscanner/ast.py (Field): Add 'bits' member, specifying the
    width in bits of the field (only relevant for bitfields).
    * tests/*: Updated.

    * giscanner/transformer.py (Transformer._create_typedef_struct)
    (Transformer._create_typedef_union): Add calls to _create_struct()
    and _create_union(), respectively. This causes the scanner to
    generate output for fields of struct and union typedefs.
    * tests/*: Updated.



Modified:
   trunk/ChangeLog
   trunk/giscanner/ast.py
   trunk/giscanner/girwriter.py
   trunk/giscanner/scannerparser.y
   trunk/giscanner/transformer.py
   trunk/tests/scanner/utility-expected.gir
   trunk/tests/scanner/utility.h

Modified: trunk/giscanner/ast.py
==============================================================================
--- trunk/giscanner/ast.py	(original)
+++ trunk/giscanner/ast.py	Sat Oct 11 21:16:57 2008
@@ -266,13 +266,17 @@
 
 class Field(Node):
 
-    def __init__(self, name, typenode, symbol):
+    def __init__(self, name, typenode, symbol, bits=None):
         Node.__init__(self, name)
         self.type = typenode
         self.symbol = symbol
+        self.bits = bits
 
     def __repr__(self):
-        return 'Field(%r, %r)' % (self.name, self.type)
+        if self.bits:
+            return 'Field(%r, %r, %r)' % (self.name, self.type, self.bits)
+        else:
+            return 'Field(%r, %r)' % (self.name, self.type)
 
 
 class Return(Node):

Modified: trunk/giscanner/girwriter.py
==============================================================================
--- trunk/giscanner/girwriter.py	(original)
+++ trunk/giscanner/girwriter.py	Sat Oct 11 21:16:57 2008
@@ -316,6 +316,8 @@
             return
 
         attrs = [('name', field.name)]
+        if field.bits:
+            attrs.append(('bits', str(field.bits)))
         with self.tagcontext('field', attrs):
             self._write_type(field.type)
 

Modified: trunk/giscanner/scannerparser.y
==============================================================================
--- trunk/giscanner/scannerparser.y	(original)
+++ trunk/giscanner/scannerparser.y	Sat Oct 11 21:16:57 2008
@@ -792,6 +792,13 @@
 		$$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
 	  }
 	| declarator ':' constant_expression
+	  {
+		$$ = $1;
+		if ($3->const_int_set) {
+		  $$->const_int_set = TRUE;
+		  $$->const_int = $3->const_int;
+		}
+	  }
 	;
 
 enum_specifier

Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py	(original)
+++ trunk/giscanner/transformer.py	Sat Oct 11 21:16:57 2008
@@ -301,7 +301,7 @@
             node = self._create_callback(symbol)
         else:
             ftype = self._create_type(symbol.base_type)
-            node = Field(symbol.ident, ftype, symbol.ident)
+            node = Field(symbol.ident, ftype, symbol.ident, symbol.const_int)
         return node
 
     def _create_typedef(self, symbol):
@@ -417,6 +417,7 @@
         name = self.strip_namespace_object(symbol.ident)
         struct = Struct(name, symbol.ident)
         self._typedefs_ns[symbol.ident] = struct
+        self._create_struct(symbol)
         return struct
 
     def _create_typedef_union(self, symbol):
@@ -424,6 +425,7 @@
         name = self.strip_namespace_object(name)
         union = Union(name, symbol.ident)
         self._typedefs_ns[symbol.ident] = union
+        self._create_union(symbol)
         return union
 
     def _create_struct(self, symbol):

Modified: trunk/tests/scanner/utility-expected.gir
==============================================================================
--- trunk/tests/scanner/utility-expected.gir	(original)
+++ trunk/tests/scanner/utility-expected.gir	Sat Oct 11 21:16:57 2008
@@ -28,6 +28,26 @@
       <member name="c" value="2" c:identifier="UTILITY_FLAG_C"/>
     </enumeration>
     <record name="Struct" c:type="UtilityStruct">
+      <field name="field">
+        <type name="int" c:type="int"/>
+      </field>
+      <field name="bitfield1" bits="3">
+        <type name="uint" c:type="guint"/>
+      </field>
+      <field name="bitfield2" bits="2">
+        <type name="uint" c:type="guint"/>
+      </field>
     </record>
+    <union name="Union" c:type="UtilityUnion">
+      <field name="pointer">
+        <type name="utf8" c:type="char*"/>
+      </field>
+      <field name="integer">
+        <type name="long" c:type="glong"/>
+      </field>
+      <field name="real">
+        <type name="double" c:type="double"/>
+      </field>
+    </union>
   </namespace>
 </repository>

Modified: trunk/tests/scanner/utility.h
==============================================================================
--- trunk/tests/scanner/utility.h	(original)
+++ trunk/tests/scanner/utility.h	Sat Oct 11 21:16:57 2008
@@ -39,6 +39,15 @@
 typedef struct
 {
   int field;
+  guint bitfield1 : 3;
+  guint bitfield2 : 2;
 } UtilityStruct;
 
+typedef union
+{
+  char *pointer;
+  glong integer;
+  double real;
+} UtilityUnion;
+  
 #endif /* __UTILITY_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]