[gobject-introspection] maintransformer: don't pair methods if the symbol prefix does not match with a final underscore



commit 6432c9213bff425d7d0f2be39df59337588caff3
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Feb 25 18:55:37 2014 +0100

    maintransformer: don't pair methods if the symbol prefix does not match with a final underscore
    
    In cases like g_resources_register() and gdk_events_get_angle(),
    the c_symbol_prefix of the first parameter (resp. g_resource and
    gdk_event) is a prefix of the symbol, but the next character is
    not _, so that should not be considered a method.
    For backward compatibility reasons, we still generate one, but
    then it's not included in the documentation (because of moved_to)

 giscanner/maintransformer.py           |   34 +++++++++++++++++++++++++------
 tests/scanner/Regress-1.0-expected.gir |   29 +++++++++++++++++++++++++++
 tests/scanner/regress.c                |   10 +++++++++
 tests/scanner/regress.h                |    3 ++
 4 files changed, 69 insertions(+), 7 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index e6f0468..d9811cf 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -1023,15 +1023,35 @@ method or constructor of some type."""
         uscored_prefix = self._get_uscored_prefix(func, subsymbol)
         target = self._transformer.lookup_typenode(func.parameters[0].type)
 
-        func.instance_parameter = func.parameters.pop(0)
-        self._namespace.float(func)
-
-        if not func.is_method:
+        if not func.is_method and not subsymbol.startswith(uscored_prefix + '_'):
+            # Uh oh! This function starts with uscored_prefix, but not
+            # uscored_prefix + '_', so if we split, we're splitting on something
+            # which is not _
+            # Examples of this are g_resources_register() (splits as
+            # g_resource + _register) and gdk_events_get_angle() (splits as
+            # gdk_event + _get_angle).
+            # As the C name suggests, these are not methods, but for backward
+            # compatibility reasons we need to create a method with the old
+            # name, and a moved-to annotation pointing to the new variant.
+
+            newfunc = func.clone()
+            newfunc.moved_to = func.name
+            newfunc.instance_parameter = newfunc.parameters.pop(0)
             subsym_idx = func.symbol.find(subsymbol)
-            func.name = func.symbol[(subsym_idx + len(uscored_prefix) + 1):]
-            func.is_method = True
+            newfunc.name = func.symbol[(subsym_idx + len(uscored_prefix) + 1):]
+            newfunc.is_method = True
+
+            target.methods.append(newfunc)
+        else:
+            func.instance_parameter = func.parameters.pop(0)
+            self._namespace.float(func)
+
+            if not func.is_method:
+                subsym_idx = func.symbol.find(subsymbol)
+                func.name = func.symbol[(subsym_idx + len(uscored_prefix) + 1):]
+                func.is_method = True
 
-        target.methods.append(func)
+            target.methods.append(func)
 
     def _get_uscored_prefix(self, func, subsymbol):
         # Here we check both the c_symbol_prefix and (if that fails),
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 5ba2be8..d25e41c 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -2140,6 +2140,18 @@ use it should be.</doc>
           </parameter>
         </parameters>
       </constructor>
+      <method name="_not_a_method"
+              c:identifier="regress_test_boxeds_not_a_method"
+              moved-to="test_boxeds_not_a_method">
+        <return-value transfer-ownership="none">
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <instance-parameter name="boxed" transfer-ownership="none">
+            <type name="TestBoxed" c:type="RegressTestBoxed*"/>
+          </instance-parameter>
+        </parameters>
+      </method>
       <method name="copy" c:identifier="regress_test_boxed_copy">
         <return-value transfer-ownership="full">
           <type name="TestBoxed" c:type="RegressTestBoxed*"/>
@@ -5109,6 +5121,23 @@ libgnome-keyring.</doc>
         </parameter>
       </parameters>
     </function>
+    <function name="test_boxeds_not_a_method"
+              c:identifier="regress_test_boxeds_not_a_method">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="boxed" transfer-ownership="none">
+          <type name="TestBoxed" c:type="RegressTestBoxed*"/>
+        </parameter>
+      </parameters>
+    </function>
+    <function name="test_boxeds_not_a_static"
+              c:identifier="regress_test_boxeds_not_a_static">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+    </function>
     <function name="test_cairo_context_full_return"
               c:identifier="regress_test_cairo_context_full_return">
       <return-value transfer-ownership="full">
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index 4507bc6..1bad36e 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -1872,6 +1872,16 @@ regress_test_boxed_equals (RegressTestBoxed *boxed,
          regress_test_simple_boxed_a_equals(&other->nested_a, &boxed->nested_a));
 }
 
+void
+regress_test_boxeds_not_a_method (RegressTestBoxed *boxed)
+{
+}
+
+void
+regress_test_boxeds_not_a_static (void)
+{
+}
+
 static void
 regress_test_boxed_free (RegressTestBoxed *boxed)
 {
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index e6ae1c2..ad2cb1f 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -426,6 +426,9 @@ RegressTestBoxed *regress_test_boxed_copy     (RegressTestBoxed *boxed);
 gboolean   regress_test_boxed_equals   (RegressTestBoxed *boxed,
                                        RegressTestBoxed *other);
 
+void       regress_test_boxeds_not_a_method (RegressTestBoxed *boxed);
+void       regress_test_boxeds_not_a_static (void);
+
 typedef struct _RegressTestBoxedB RegressTestBoxedB;
 
 struct _RegressTestBoxedB


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