[gobject-introspection] scanner: add a moved_to property to backcompat functions



commit d84b7babf5adb637342492d13ab127d43317c8be
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Sat Aug 13 12:45:14 2011 +0200

    scanner: add a moved_to property to backcompat functions
    
    Use it to remove backcompat copies of functions that non introspectable
    anyway.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=572408

 giscanner/ast.py                       |    1 +
 giscanner/girparser.py                 |    1 +
 giscanner/girwriter.py                 |    2 ++
 giscanner/introspectablepass.py        |   10 ++++++++++
 giscanner/maintransformer.py           |    6 +++---
 tests/scanner/Foo-1.0-expected.gir     |    4 +++-
 tests/scanner/Regress-1.0-expected.gir |    3 ++-
 7 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 8ca3a4d..252c86b 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -569,6 +569,7 @@ class Function(Callable):
         self.is_constructor = False
         self.shadowed_by = None # C symbol string
         self.shadows = None # C symbol string
+        self.moved_to = None # namespaced function name string
 
     def clone(self):
         clone = copy.copy(self)
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 51de1b1..41e2abd 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -303,6 +303,7 @@ class GIRParser(object):
 
         func.shadows = node.attrib.get('shadows', None)
         func.shadowed_by = node.attrib.get('shadowed-by', None)
+        func.moved_to = node.attrib.get('moved-to', None)
 
         parameters_node = node.find(_corens('parameters'))
         if (parameters_node is not None):
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index b3b7435..ce173fd 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -178,6 +178,8 @@ and/or use gtk-doc annotations. ''')
             attrs.append(('shadowed-by', func.shadowed_by))
         elif func.shadows:
             attrs.append(('shadows', func.shadows))
+        if func.moved_to is not None:
+            attrs.append(('moved-to', func.moved_to))
         self._write_callable(func, tag_name, attrs)
 
     def _write_method(self, method):
diff --git a/giscanner/introspectablepass.py b/giscanner/introspectablepass.py
index 36d70b2..ebb1ded 100644
--- a/giscanner/introspectablepass.py
+++ b/giscanner/introspectablepass.py
@@ -37,6 +37,7 @@ class IntrospectablePass(object):
         self._namespace.walk(self._introspectable_callable_analysis)
         self._namespace.walk(self._introspectable_callable_analysis)
         self._namespace.walk(self._introspectable_pass3)
+        self._namespace.walk(self._remove_non_reachable_backcompat_copies)
 
     def _parameter_warning(self, parent, param, text, position=None):
         # Suppress VFunctions and Callbacks warnings for now
@@ -221,3 +222,12 @@ class IntrospectablePass(object):
             for sig in obj.signals:
                 self._introspectable_callable_analysis(sig, [obj])
         return True
+
+    def _remove_non_reachable_backcompat_copies(self, obj, stack):
+        if obj.skip:
+            return False
+        if (isinstance(obj, ast.Function)
+            and not obj.introspectable
+            and obj.moved_to is not None):
+            self._namespace.remove(obj)
+        return True
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 40dda29..1d26bf1 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -1016,9 +1016,9 @@ method or constructor of some type."""
             new_func = func.clone()
             new_func.name = funcname
             node.static_methods.append(new_func)
-            # TODO: flag func as a backwards-comptability kludge (and maybe
-            # prune it in the introspectable pass if we would have
-            # introspectable=0 anyway).
+            # flag the func as a backwards-comptability kludge (thus it will
+            # get pruned in the introspectable pass if introspectable=0).
+            func.moved_to = node.name + '.' + new_func.name
             return True
 
         return False
diff --git a/tests/scanner/Foo-1.0-expected.gir b/tests/scanner/Foo-1.0-expected.gir
index 950648d..06d15c3 100644
--- a/tests/scanner/Foo-1.0-expected.gir
+++ b/tests/scanner/Foo-1.0-expected.gir
@@ -985,7 +985,8 @@ exposed to language bindings.</doc>
       </return-value>
     </function>
     <function name="interface_static_method"
-              c:identifier="foo_interface_static_method">
+              c:identifier="foo_interface_static_method"
+              moved-to="Interface.static_method">
       <return-value transfer-ownership="none">
         <type name="none" c:type="void"/>
       </return-value>
@@ -1017,6 +1018,7 @@ exposed to language bindings.</doc>
     </function>
     <function name="rectangle_new"
               c:identifier="foo_rectangle_new"
+              moved-to="Rectangle.new"
               introspectable="0">
       <doc xml:whitespace="preserve">This is a C convenience constructor; we have to (skip)
 it because it's not a boxed type.</doc>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 9b4ae8f..33ceeae 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -2372,7 +2372,8 @@ You will give me your credit card number.</doc>
       </parameters>
     </function>
     <function name="test_simple_boxed_a_const_return"
-              c:identifier="regress_test_simple_boxed_a_const_return">
+              c:identifier="regress_test_simple_boxed_a_const_return"
+              moved-to="TestSimpleBoxedA.const_return">
       <return-value transfer-ownership="none">
         <type name="TestSimpleBoxedA" c:type="RegressTestSimpleBoxedA*"/>
       </return-value>



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