[vala/staging] girwriter: Fix ctype of out-parameters for DelegateType



commit 31b4c86ca68b43e4b8f700b47600c3b4a9d6280b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Oct 19 13:56:53 2018 +0200

    girwriter: Fix ctype of out-parameters for DelegateType
    
    Properly set data_type property of DelegateType and drop superfluous
    conditional code paths for DelegateType.

 codegen/valagirwriter.vala               |  4 ----
 tests/girwriter/GirTest-1.0.gir-expected |  8 ++++----
 vala/valadelegatetype.vala               |  1 +
 vala/valasemanticanalyzer.vala           | 11 ++---------
 4 files changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 7c2ebc7f0..11782d1c7 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -1350,10 +1350,6 @@ public class Vala.GIRWriter : CodeVisitor {
                                write_indent ();
                                buffer.append_printf ("</%s>\n", is_array ? "array" : "type");
                        }
-               } else if (type is DelegateType) {
-                       var deleg_type = (DelegateType) type;
-                       write_indent ();
-                       buffer.append_printf ("<type name=\"%s\" c:type=\"%s\"/>\n", gi_type_name 
(deleg_type.delegate_symbol), get_ccode_name (type));
                } else if (type is GenericType) {
                        // generic type parameters not supported in GIR
                        write_indent ();
diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected
index 18f275596..fb6b30060 100644
--- a/tests/girwriter/GirTest-1.0.gir-expected
+++ b/tests/girwriter/GirTest-1.0.gir-expected
@@ -348,7 +348,7 @@
                                        <type name="gpointer" c:type="void*"/>
                                </parameter>
                                <parameter name="result_target_destroy_notify" direction="out" 
transfer-ownership="none" scope="call">
-                                       <type name="GLib.DestroyNotify" c:type="GDestroyNotify"/>
+                                       <type name="GLib.DestroyNotify" c:type="GDestroyNotify*"/>
                                </parameter>
                        </parameters>
                </method>
@@ -372,7 +372,7 @@
                                        <type name="gpointer" c:type="void*"/>
                                </parameter>
                                <parameter name="result_target_destroy_notify" direction="out" 
transfer-ownership="none" scope="call">
-                                       <type name="GLib.DestroyNotify" c:type="GDestroyNotify"/>
+                                       <type name="GLib.DestroyNotify" c:type="GDestroyNotify*"/>
                                </parameter>
                        </parameters>
                </method>
@@ -387,13 +387,13 @@
                                        <type name="gint" c:type="gint"/>
                                </parameter>
                                <parameter name="d" direction="out" transfer-ownership="none" closure="2" 
scope="notified" destroy="3">
-                                       <type name="GirTest.DelegateTest" c:type="GirTestDelegateTest"/>
+                                       <type name="GirTest.DelegateTest" c:type="GirTestDelegateTest*"/>
                                </parameter>
                                <parameter name="d_target" direction="out" transfer-ownership="none" 
allow-none="1">
                                        <type name="gpointer" c:type="void*"/>
                                </parameter>
                                <parameter name="d_target_destroy_notify" direction="out" 
transfer-ownership="none" scope="call">
-                                       <type name="GLib.DestroyNotify" c:type="GDestroyNotify"/>
+                                       <type name="GLib.DestroyNotify" c:type="GDestroyNotify*"/>
                                </parameter>
                                <parameter name="result_length1" direction="out" transfer-ownership="none">
                                        <type name="gint" c:type="gint*"/>
diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala
index 0f4edfdb3..06d0a61a7 100644
--- a/vala/valadelegatetype.vala
+++ b/vala/valadelegatetype.vala
@@ -32,6 +32,7 @@ public class Vala.DelegateType : CallableType {
 
        public DelegateType (Delegate delegate_symbol) {
                this.delegate_symbol = delegate_symbol;
+               this.data_type = delegate_symbol;
                this.is_called_once = (delegate_symbol.get_attribute_string ("CCode", "scope") == "async");
        }
 
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index c0c075f9a..b27bbf1ed 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -766,9 +766,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        instance_type = instance_pointer_type.base_type;
                }
 
-               if (instance_type is DelegateType && ((DelegateType) instance_type).delegate_symbol == 
type_symbol) {
-                       return instance_type;
-               } else if (instance_type.data_type == type_symbol) {
+               if (instance_type.data_type == type_symbol) {
                        return instance_type;
                }
 
@@ -847,12 +845,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                        return new InvalidType ();
                                }
 
-                               int param_index;
-                               if (instance_type is DelegateType) {
-                                       param_index = ((DelegateType) 
instance_type).delegate_symbol.get_type_parameter_index (generic_type.type_parameter.name);
-                               } else {
-                                       param_index = instance_type.data_type.get_type_parameter_index 
(generic_type.type_parameter.name);
-                               }
+                               var param_index = instance_type.data_type.get_type_parameter_index 
(generic_type.type_parameter.name);
                                if (param_index == -1) {
                                        Report.error (node_reference.source_reference, "internal error: 
unknown type parameter %s".printf (generic_type.type_parameter.name));
                                        node_reference.error = true;


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