scanner: Automatically skip callables which contain a skipped node
authorColin Walters <walters@verbum.org>
Tue, 7 Sep 2010 19:13:06 +0000 (15:13 -0400)
committerColin Walters <walters@verbum.org>
Tue, 7 Sep 2010 19:16:44 +0000 (15:16 -0400)
For legacy library author convenience, propagate (skip) on e.g.
structures to all callables which use them.

giscanner/introspectablepass.py
tests/scanner/Regress-1.0-expected.gir
tests/scanner/regress.h

index 6653c09..290f1d2 100644 (file)
@@ -30,6 +30,7 @@ class IntrospectablePass(object):
     # Public API
 
     def validate(self):
+        self._namespace.walk(self._propagate_callable_skips)
         self._namespace.walk(self._analyze_node)
         self._namespace.walk(self._introspectable_callable_analysis)
         self._namespace.walk(self._introspectable_callable_analysis)
@@ -143,6 +144,24 @@ class IntrospectablePass(object):
             return False
         return target.introspectable and (not target.skip)
 
+    def _propagate_parameter_skip(self, parent, node):
+        if node.type.target_giname is not None:
+            target = self._transformer.lookup_typenode(node.type)
+            if target is None:
+                return
+        else:
+            return
+
+        if target.skip:
+            parent.skip = True
+
+    def _propagate_callable_skips(self, obj, stack):
+        if isinstance(obj, ast.Callable):
+            for param in obj.parameters:
+                self._propagate_parameter_skip(obj, param)
+            self._propagate_parameter_skip(obj, obj.retval)
+        return True
+
     def _analyze_node(self, obj, stack):
         if obj.skip:
             return False
index 8067b12..3fce12b 100644 (file)
@@ -15,6 +15,18 @@ and/or use gtk-doc annotations.  -->
              shared-library="libregress.so"
              c:identifier-prefixes="Regress"
              c:symbol-prefixes="regress">
+    <record name="SkippedStructure"
+            c:type="RegressSkippedStructure"
+            introspectable="0">
+      <doc xml:whitespace="preserve">This should be skipped, and moreover, all function which
+use it should be.</doc>
+      <field name="x" writable="1">
+        <type name="gint" c:type="int"/>
+      </field>
+      <field name="v" writable="1">
+        <type name="gdouble" c:type="double"/>
+      </field>
+    </record>
     <record name="TestBoxed"
             c:type="RegressTestBoxed"
             glib:type-name="RegressTestBoxed"
@@ -831,6 +843,24 @@ case.</doc>
         </parameter>
       </parameters>
     </function>
+    <function name="random_function_with_skipped_structure"
+              c:identifier="regress_random_function_with_skipped_structure"
+              introspectable="0">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="x" transfer-ownership="none">
+          <type name="gint" c:type="int"/>
+        </parameter>
+        <parameter name="foo" transfer-ownership="none">
+          <type name="SkippedStructure" c:type="RegressSkippedStructure*"/>
+        </parameter>
+        <parameter name="v" transfer-ownership="none">
+          <type name="gdouble" c:type="double"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="set_abort_on_error"
               c:identifier="regress_set_abort_on_error">
       <return-value transfer-ownership="none">
index a1b48f2..6fed4ca 100644 (file)
@@ -508,4 +508,20 @@ void regress_test_torture_signature_2 (int                  x,
 GValue *regress_test_date_in_gvalue (void);
 GValue *regress_test_strv_in_gvalue (void);
 
+/**
+ * RegressSkippedStructure: (skip)
+ *
+ * This should be skipped, and moreover, all function which
+ * use it should be.
+ */
+typedef struct
+{
+  int x;
+  double v;
+} RegressSkippedStructure;
+
+void regress_random_function_with_skipped_structure (int x,
+                                                    RegressSkippedStructure *foo,
+                                                    double v);
+
 #endif /* __GITESTTYPES_H__ */