[vala/wip/gdk-pixbuf: 1/2] WIP girparser: Handle anonymous delegate not backed by virtual-method or signal




commit 9acb9746e4fa34854c27668e9828b69f1321f900
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Jan 13 17:44:38 2021 +0100

    WIP girparser: Handle anonymous delegate not backed by virtual-method or signal

 vala/valagirparser.vala | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 65de9ea85..c7bc64600 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1136,6 +1136,16 @@ public class Vala.GirParser : CodeVisitor {
                                                var d = ((DelegateType) field.variable_type).delegate_symbol;
                                                parser.process_virtual_method_field (this, d, 
parent.gtype_struct_for);
                                                merged = true;
+                                       } else if (field.variable_type is DelegateType) {
+                                               // anonymous delegate
+                                               var d = ((DelegateType) field.variable_type).delegate_symbol;
+                                               if (!d.get_attribute_bool ("CCode", "has_typedef", true)) {
+                                                       if (d.has_target && !metadata.has_argument 
(ArgumentType.DELEGATE_TARGET)) {
+                                                               field.set_attribute_bool ("CCode", 
"delegate_target", false);
+                                                       }
+                                                       d.name = parent.symbol.name + 
Symbol.lower_case_to_camel_case (d.name) + "Func";
+                                                       get_parent_namespace (this).add_delegate (d);
+                                               }
                                        } else if (field.variable_type is ArrayType) {
                                                Node array_length;
                                                if (metadata.has_argument (ArgumentType.ARRAY_LENGTH_FIELD)) {
@@ -1598,6 +1608,17 @@ public class Vala.GirParser : CodeVisitor {
                return sym is ObjectTypeSymbol || sym is Struct || sym is Namespace || sym is ErrorDomain || 
sym is Enum;
        }
 
+       static unowned Namespace get_parent_namespace (Node node) {
+               unowned Node? n = node.parent;
+               while (n != null) {
+                       if (n.symbol is Namespace) {
+                               return (Namespace) n.symbol;
+                       }
+                       n = n.parent;
+               }
+               assert_not_reached ();
+       }
+
        UnresolvedSymbol? parse_symbol_from_string (string symbol_string, SourceReference? source_reference = 
null) {
                UnresolvedSymbol? sym = null;
                foreach (unowned string s in symbol_string.split (".")) {
@@ -3194,6 +3215,9 @@ public class Vala.GirParser : CodeVisitor {
                if (symbol_type == "callback") {
                        s = new Delegate (name, return_type, current.source_reference);
                        ((Delegate) s).has_target = false;
+                       if (old_current.symbol is Field) {
+                               s.set_attribute_bool ("CCode", "has_typedef", false);
+                       }
                } else if (symbol_type == "constructor") {
                        if (name == "new") {
                                name = null;


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