gobject-introspection r743 - in trunk: . girepository giscanner tests tests/scanner tools



Author: tko
Date: Fri Oct 17 14:58:37 2008
New Revision: 743
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=743&view=rev

Log:
2008-10-17  Tommi Komulainen  <tommi komulainen iki fi>

	Bug 556732 â generate gir files consistently

	* giscanner/ast.py (Field): add readable and writable properties
	* giscanner/girparser.py (_parse_field): copy 'readable' and
	'writable' attributes
	* giscanner/transformer.py (_create_member): create fields as
	read-write
	* giscanner/glibtransformer.py (_introspect_object,
	_pair_class_struct): make object instance and class fields
	read-only
	* giscanner/girwriter.py (_write_field):
	* tools/generate.c (write_field_info): write field 'readable'
	and 'writable' attributes only if non-default (read-only)
	* girepository/girparser.c (start_field): in the absence of
	attributes assume fields are read-only
	* tests/boxed.gir:
	* tests/struct.gir: remove redundant readable="1" from fields
	* tests/scanner/foo-1.0-expected.gir:
	* tests/scanner/utility-1.0-expected.gir: add writable="1" to
	all record and union fields

Modified:
   trunk/ChangeLog
   trunk/girepository/girparser.c
   trunk/giscanner/ast.py
   trunk/giscanner/girparser.py
   trunk/giscanner/girwriter.py
   trunk/giscanner/glibtransformer.py
   trunk/giscanner/transformer.py
   trunk/tests/boxed.gir
   trunk/tests/scanner/foo-1.0-expected.gir
   trunk/tests/scanner/utility-1.0-expected.gir
   trunk/tests/struct.gir
   trunk/tools/generate.c

Modified: trunk/girepository/girparser.c
==============================================================================
--- trunk/girepository/girparser.c	(original)
+++ trunk/girepository/girparser.c	Fri Oct 17 14:58:37 2008
@@ -839,15 +839,11 @@
   field = (GIrNodeField *)g_ir_node_new (G_IR_NODE_FIELD);
   ctx->current_typed = (GIrNode*) field;
   ((GIrNode *)field)->name = g_strdup (name);
-  if (readable && strcmp (readable, "1") == 0)
-    field->readable = TRUE;
-  else
-    field->readable = FALSE;
-  
-  if (writable && strcmp (writable, "1") == 0)
-    field->writable = TRUE;
-  else
-    field->writable = FALSE;
+  /* Fields are assumed to be read-only.
+   * (see also girwriter.py and generate.c)
+   */
+  field->readable = readable == NULL || strcmp (readable, "0") == 0;
+  field->writable = writable != NULL && strcmp (writable, "1") == 0;
   
   if (bits)
     field->bits = atoi (bits);

Modified: trunk/giscanner/ast.py
==============================================================================
--- trunk/giscanner/ast.py	(original)
+++ trunk/giscanner/ast.py	Fri Oct 17 14:58:37 2008
@@ -319,10 +319,12 @@
 
 class Field(Node):
 
-    def __init__(self, name, typenode, symbol, bits=None):
+    def __init__(self, name, typenode, symbol, readable, writable, bits=None):
         Node.__init__(self, name)
         self.type = typenode
         self.symbol = symbol
+        self.readable = readable
+        self.writable = writable
         self.bits = bits
 
     def __repr__(self):

Modified: trunk/giscanner/girparser.py
==============================================================================
--- trunk/giscanner/girparser.py	(original)
+++ trunk/giscanner/girparser.py	Fri Oct 17 14:58:37 2008
@@ -245,6 +245,8 @@
         return Field(node.attrib['name'],
                      type_node,
                      type_node.ctype,
+                     node.attrib.get('readable') != '0',
+                     node.attrib.get('writable') == '1',
                      node.attrib.get('bits'))
 
     def _parse_property(self, node):

Modified: trunk/giscanner/girwriter.py
==============================================================================
--- trunk/giscanner/girwriter.py	(original)
+++ trunk/giscanner/girwriter.py	Fri Oct 17 14:58:37 2008
@@ -327,6 +327,12 @@
             return
 
         attrs = [('name', field.name)]
+        # Fields are assumed to be read-only
+        # (see also girparser.c and generate.c)
+        if not field.readable:
+            attrs.append(('readable', '0'))
+        if field.writable:
+            attrs.append(('writable', '1'))
         if field.bits:
             attrs.append(('bits', str(field.bits)))
         with self.tagcontext('field', attrs):

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Fri Oct 17 14:58:37 2008
@@ -26,7 +26,7 @@
 from . import cgobject
 from .ast import (Callback, Constant, Enum, Function, Member, Namespace,
                   Parameter, Property, Return, Struct, Type, Alias, Array,
-                  Union, type_name_from_ctype,
+                  Union, Field, type_name_from_ctype,
                   default_array_types, TYPE_UINT8, PARAM_DIRECTION_IN)
 from .transformer import Names
 from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
@@ -461,6 +461,12 @@
             del self._names.names[maybe_class.name]
             return
 
+        # Object class fields are assumed to be read-only
+        # (see also _introspect_object and transformer.py)
+        for field in maybe_class.fields:
+            if isinstance(field, Field):
+                field.writable = False
+
         name = self._resolve_type_name(name)
         resolved = self._transformer.strip_namespace_object(name)
         pair_class = self._get_attribute(resolved)
@@ -540,6 +546,11 @@
         struct = self._get_attribute(node.name)
         if struct is not None:
             node.fields = struct.fields
+            for field in node.fields:
+                if isinstance(field, Field):
+                    # Object instance fields are assumed to be read-only
+                    # (see also _pair_class_struct and transformer.py)
+                    field.writable = False
 
         self._add_attribute(node, replace=True)
         self._register_internal_type(type_name, node)

Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py	(original)
+++ trunk/giscanner/transformer.py	Fri Oct 17 14:58:37 2008
@@ -310,7 +310,10 @@
             node = self._create_callback(symbol)
         else:
             ftype = self._create_type(symbol.base_type, {})
-            node = Field(symbol.ident, ftype, symbol.ident, symbol.const_int)
+            # Fields are assumed to be read-write
+            # (except for Objects, see also glibtransformer.py)
+            node = Field(symbol.ident, ftype, symbol.ident,
+                       readable=True, writable=True, bits=symbol.const_int)
         return node
 
     def _create_typedef(self, symbol):

Modified: trunk/tests/boxed.gir
==============================================================================
--- trunk/tests/boxed.gir	(original)
+++ trunk/tests/boxed.gir	Fri Oct 17 14:58:37 2008
@@ -5,13 +5,13 @@
             xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
   <namespace name="Foo" version="1.0">
     <glib:boxed glib:name="BoxedType1" glib:type-name="boxed1" glib:get-type="boxed1_get_type" deprecated="1">
-      <field name="field1" readable="1" writable="1" offset="0">
+      <field name="field1" writable="1" offset="0">
         <type name="uint32"/>
       </field>
-      <field name="field2" readable="1" writable="1" offset="4">
+      <field name="field2" writable="1" offset="4">
         <type name="uint32"/>
       </field>
-      <field name="field3" readable="1" writable="1" offset="8">
+      <field name="field3" writable="1" offset="8">
         <type name="uint32"/>
       </field>
       <method name="frob_boxed1" c:identifier="frob_boxed1">

Modified: trunk/tests/scanner/foo-1.0-expected.gir
==============================================================================
--- trunk/tests/scanner/foo-1.0-expected.gir	(original)
+++ trunk/tests/scanner/foo-1.0-expected.gir	Fri Oct 17 14:58:37 2008
@@ -316,26 +316,26 @@
       </parameters>
     </callback>
     <record name="Struct" c:type="FooStruct">
-      <field name="priv">
+      <field name="priv" writable="1">
         <type name="StructPrivate" c:type="FooStructPrivate*"/>
       </field>
-      <field name="member">
+      <field name="member" writable="1">
         <type name="int" c:type="int"/>
       </field>
     </record>
     <record name="StructPrivate" c:type="FooStructPrivate">
     </record>
     <record name="Rectangle" c:type="FooRectangle">
-      <field name="x">
+      <field name="x" writable="1">
         <type name="int" c:type="gint"/>
       </field>
-      <field name="y">
+      <field name="y" writable="1">
         <type name="int" c:type="gint"/>
       </field>
-      <field name="width">
+      <field name="width" writable="1">
         <type name="int" c:type="gint"/>
       </field>
-      <field name="height">
+      <field name="height" writable="1">
         <type name="int" c:type="gint"/>
       </field>
     </record>
@@ -392,26 +392,26 @@
       </parameters>
     </function>
     <record name="EventAny" c:type="FooEventAny">
-      <field name="send_event">
+      <field name="send_event" writable="1">
         <type name="int8" c:type="gint8"/>
       </field>
     </record>
     <record name="EventExpose" c:type="FooEventExpose">
-      <field name="send_event">
+      <field name="send_event" writable="1">
         <type name="int8" c:type="gint8"/>
       </field>
-      <field name="count">
+      <field name="count" writable="1">
         <type name="int" c:type="gint"/>
       </field>
     </record>
     <union name="Event" c:type="FooEvent">
-      <field name="type">
+      <field name="type" writable="1">
         <type name="int" c:type="int"/>
       </field>
-      <field name="any">
+      <field name="any" writable="1">
         <type name="EventAny" c:type="FooEventAny"/>
       </field>
-      <field name="expose">
+      <field name="expose" writable="1">
         <type name="EventExpose" c:type="FooEventExpose"/>
       </field>
     </union>
@@ -419,10 +419,10 @@
             c:type="FooBRect"
             glib:type-name="FooBRect"
             glib:get-type="foo_brect_get_type">
-      <field name="x">
+      <field name="x" writable="1">
         <type name="double" c:type="double"/>
       </field>
-      <field name="y">
+      <field name="y" writable="1">
         <type name="double" c:type="double"/>
       </field>
       <constructor name="new" c:identifier="foo_brect_new">
@@ -453,13 +453,13 @@
            c:type="FooBUnion"
            glib:type-name="FooBUnion"
            glib:get-type="foo_bunion_get_type">
-      <field name="type">
+      <field name="type" writable="1">
         <type name="int" c:type="int"/>
       </field>
-      <field name="v">
+      <field name="v" writable="1">
         <type name="double" c:type="double"/>
       </field>
-      <field name="rect">
+      <field name="rect" writable="1">
         <type name="BRect" c:type="FooBRect*"/>
       </field>
       <constructor name="new" c:identifier="foo_bunion_new">
@@ -475,7 +475,7 @@
       </method>
     </union>
     <union name="Union" c:type="_FooUnion">
-      <field name="foo">
+      <field name="foo" writable="1">
         <type name="int" c:type="int"/>
       </field>
     </union>

Modified: trunk/tests/scanner/utility-1.0-expected.gir
==============================================================================
--- trunk/tests/scanner/utility-1.0-expected.gir	(original)
+++ trunk/tests/scanner/utility-1.0-expected.gir	Fri Oct 17 14:58:37 2008
@@ -32,24 +32,24 @@
       <member name="c" value="2" c:identifier="UTILITY_FLAG_C"/>
     </enumeration>
     <record name="Struct" c:type="UtilityStruct">
-      <field name="field">
+      <field name="field" writable="1">
         <type name="int" c:type="int"/>
       </field>
-      <field name="bitfield1" bits="3">
+      <field name="bitfield1" writable="1" bits="3">
         <type name="uint" c:type="guint"/>
       </field>
-      <field name="bitfield2" bits="2">
+      <field name="bitfield2" writable="1" bits="2">
         <type name="uint" c:type="guint"/>
       </field>
     </record>
     <union name="Union" c:type="UtilityUnion">
-      <field name="pointer">
+      <field name="pointer" writable="1">
         <type name="utf8" c:type="char*"/>
       </field>
-      <field name="integer">
+      <field name="integer" writable="1">
         <type name="long" c:type="glong"/>
       </field>
-      <field name="real">
+      <field name="real" writable="1">
         <type name="double" c:type="double"/>
       </field>
     </union>

Modified: trunk/tests/struct.gir
==============================================================================
--- trunk/tests/struct.gir	(original)
+++ trunk/tests/struct.gir	Fri Oct 17 14:58:37 2008
@@ -5,27 +5,27 @@
             xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
   <namespace name="Foo" version="1.0">
     <record name="FooStruct">
-      <field name="foo_int" readable="1" writable="1" offset="0">
+      <field name="foo_int" writable="1" offset="0">
         <type name="int"/>
       </field>
-      <field name="foo_int64" readable="1" writable="1" offset="4">
+      <field name="foo_int64" writable="1" offset="4">
         <type name="int64"/>
       </field>
-      <field name="foo_uint" readable="1" writable="1" offset="12">
+      <field name="foo_uint" writable="1" offset="12">
         <type name="uint"/>
       </field>
-      <field name="foo_uint64" readable="1" writable="1" offset="16">
+      <field name="foo_uint64" writable="1" offset="16">
         <type name="uint64"/>
       </field>
-      <field name="string" readable="1" writable="1" offset="24">
+      <field name="string" writable="1" offset="24">
         <type name="utf8"/>
       </field>
     </record>
     <record name="FooStruct2">
-      <field name="sub" readable="1" writable="1" offset="0">
+      <field name="sub" writable="1" offset="0">
         <type name="FooStruct"/>
       </field>
-      <field name="string" readable="1" writable="1" offset="24">
+      <field name="string" writable="1" offset="24">
         <type name="utf8"/>
       </field>
     </record>

Modified: trunk/tools/generate.c
==============================================================================
--- trunk/tools/generate.c	(original)
+++ trunk/tools/generate.c	Fri Oct 17 14:58:37 2008
@@ -338,10 +338,16 @@
   offset = g_field_info_get_offset (info);
 
   xml_start_element (file, "field");
-  xml_printf (file, " name=\"%s\" readable=\"%s\" writable=\"%s\"",
-	     name, 
-	     flags & GI_FIELD_IS_READABLE ? "1" : "0", 
-	     flags & GI_FIELD_IS_WRITABLE ? "1" : "0");
+  xml_printf (file, " name=\"%s\"", name);
+
+  /* Fields are assumed to be read-only
+   * (see also girwriter.py and girparser.c)
+   */
+  if (!(flags & GI_FIELD_IS_READABLE))
+    xml_printf (file, " readable=\"0\"");
+  if (flags & GI_FIELD_IS_WRITABLE)
+    xml_printf (file, " writable=\"1\"");
+
   if (size)
     xml_printf (file, " bits=\"%d\"", size);
 



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