[vala/wip/signal-emit: 1/3] wip




commit 561923a719e945b6adf55ba9dc1b8ff9920f500f
Author: Lorenz Wildberg <lorenz wild-fisch de>
Date:   Sat Dec 4 19:05:42 2021 +0000

    wip

 codegen/valaccodemethodcallmodule.vala | 10 +++++++++-
 codegen/valagsignalmodule.vala         |  3 ++-
 vala/valasignaltype.vala               | 13 +++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 94c31007b..044894276 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -41,6 +41,14 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                var itype = expr.call.value_type;
                params = itype.get_parameters ();
 
+               // signal.emit () calls are treated like signal ()
+               if (ma != null && ma.member_name == "emit") {
+                       ma = ((MemberAccess) expr.call).inner as MemberAccess;
+                       ccall = new CCodeFunctionCall (get_cvalue (ma));
+                       itype = ma.value_type;
+               }
+
+
                if (itype is MethodType) {
                        assert (ma != null);
                        m = ((MethodType) itype).method_symbol;
@@ -63,7 +71,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                        if (ma != null && ma.inner is BaseAccess && sig_type.signal_symbol.is_virtual) {
                                m = sig_type.signal_symbol.default_handler;
                        } else {
-                               ccall = (CCodeFunctionCall) get_cvalue (expr.call);
+                               ccall = (CCodeFunctionCall) get_cvalue (ma);
                        }
                } else if (itype is ObjectType) {
                        // constructor
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index cfd4a5da8..e79bea787 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -576,7 +576,8 @@ public class Vala.GSignalModule : GObjectModule {
        public override void visit_method_call (MethodCall expr) {
                var method_type = expr.call.value_type as MethodType;
 
-               if (method_type == null || !(method_type.method_symbol.parent_symbol is Signal)) {
+               // emit () calls are ignored
+               if (method_type == null || !(method_type.method_symbol.parent_symbol is Signal) || 
method_type.method_symbol.name == "emit") {
                        // no signal connect/disconnect call
                        base.visit_method_call (expr);
                        return;
diff --git a/vala/valasignaltype.vala b/vala/valasignaltype.vala
index ca90186fc..93867ac54 100644
--- a/vala/valasignaltype.vala
+++ b/vala/valasignaltype.vala
@@ -35,6 +35,7 @@ public class Vala.SignalType : CallableType {
        Method? connect_method;
        Method? connect_after_method;
        Method? disconnect_method;
+       Method? emit_method;
 
        public SignalType (Signal signal_symbol, SourceReference? source_reference = null) {
                base (signal_symbol, source_reference);
@@ -104,6 +105,16 @@ public class Vala.SignalType : CallableType {
                return disconnect_method;
        }
 
+       unowned Method get_emit_method () {
+               if (emit_method == null) {
+                       emit_method = new Method ("emit", signal_symbol.return_type, source_reference);
+                       emit_method.access = SymbolAccessibility.PUBLIC;
+                       emit_method.external = true;
+                       emit_method.owner = signal_symbol.scope;
+               }
+               return emit_method;
+       }
+
        public override Symbol? get_member (string member_name) {
                if (member_name == "connect") {
                        return get_connect_method ();
@@ -111,6 +122,8 @@ public class Vala.SignalType : CallableType {
                        return get_connect_after_method ();
                } else if (member_name == "disconnect") {
                        return get_disconnect_method ();
+               } else if (member_name == "emit") {
+                       return get_emit_method ();
                }
                return null;
        }


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