[vala/wip/signal-emit: 2/3] simplify




commit 5cc1db62a7d02d75e598b2af277a59df14a183e4
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Dec 6 09:36:18 2021 +0100

    simplify

 codegen/valaccodemethodcallmodule.vala | 10 +---------
 codegen/valagsignalmodule.vala         |  5 ++---
 vala/valamemberaccess.vala             | 14 ++++++++++++++
 3 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 044894276..94c31007b 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -41,14 +41,6 @@ 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;
@@ -71,7 +63,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 (ma);
+                               ccall = (CCodeFunctionCall) get_cvalue (expr.call);
                        }
                } else if (itype is ObjectType) {
                        // constructor
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index e79bea787..4186859cf 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -537,7 +537,7 @@ public class Vala.GSignalModule : GObjectModule {
                        return new CCodeMemberAccess.pointer (vcast, m.name);
                }
 
-               if (!sig.external_package && expr.source_reference.file == sig.source_reference.file) {
+               if (!sig.external_package && expr.source_reference.file == sig.source_reference.file && !(sig 
is DynamicSignal)) {
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_emit"));
                        ccall.add_argument (pub_inst);
                        ccall.add_argument (get_signal_id_cexpression (sig));
@@ -576,8 +576,7 @@ public class Vala.GSignalModule : GObjectModule {
        public override void visit_method_call (MethodCall expr) {
                var method_type = expr.call.value_type as MethodType;
 
-               // emit () calls are ignored
-               if (method_type == null || !(method_type.method_symbol.parent_symbol is Signal) || 
method_type.method_symbol.name == "emit") {
+               if (method_type == null || !(method_type.method_symbol.parent_symbol is Signal)) {
                        // no signal connect/disconnect call
                        base.visit_method_call (expr);
                        return;
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index c8b3b267b..e735cd9a3 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -390,6 +390,13 @@ public class Vala.MemberAccess : Expression {
                                }
                        }
 
+                       if (inner.value_type is SignalType && member_name == "emit") {
+                               // transform foo.sig.emit() to foo.sig()
+                               //FIXME? context.analyzer.replaced_nodes.add (this);
+                               parent_node.replace_expression (this, inner);
+                               return true;
+                       }
+
                        if (inner is MemberAccess) {
                                unowned MemberAccess ma = (MemberAccess) inner;
                                if (ma.prototype_access) {
@@ -499,6 +506,13 @@ public class Vala.MemberAccess : Expression {
                                                s.access = SymbolAccessibility.PUBLIC;
                                                dynamic_object_type.type_symbol.scope.add (null, s);
                                                symbol_reference = s;
+                                       } else if (ma.member_name == "emit") {
+                                               // dynamic signal
+                                               var s = new DynamicSignal (inner.value_type, member_name, new 
VoidType (), source_reference);
+                                               s.access = SymbolAccessibility.PUBLIC;
+                                               s.add_parameter (new Parameter.with_ellipsis ());
+                                               dynamic_object_type.type_symbol.scope.add (null, s);
+                                               symbol_reference = s;
                                        } else if (ma.member_name == "disconnect") {
                                                error = true;
                                                Report.error (ma.source_reference, "Use 
SignalHandler.disconnect() to disconnect from dynamic signal");


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