[vala] Support .connect() and .connect_after() for dynamic signals



commit 222c8d0495a44c11570329efb1ecb2460575044d
Author: Luca Bruno <lethalman88 gmail com>
Date:   Sat Mar 13 23:16:30 2010 +0100

    Support .connect() and .connect_after() for dynamic signals
    
    Fixes bug 607936.

 vala/valamemberaccess.vala |   14 ++++++++++++++
 vala/valamethodcall.vala   |   14 ++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 99b4819..e910333 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -371,6 +371,20 @@ public class Vala.MemberAccess : Expression {
 						dynamic_object_type.type_symbol.scope.add (null, prop);
 						symbol_reference = prop;
 					}
+				} else if (parent_node is MemberAccess && inner is MemberAccess && parent_node.parent_node is MethodCall) {
+					var ma = (MemberAccess) parent_node;
+					if (ma.member_name == "connect" || ma.member_name == "connect_after") {
+						// dynamic signal
+						var s = new DynamicSignal (inner.value_type, member_name, new VoidType (), source_reference);
+						var mcall = (MethodCall) parent_node.parent_node;
+						// the first argument is the handler
+						if (mcall.get_argument_list().size > 0) {
+							s.handler = mcall.get_argument_list()[0];
+						}
+						s.access = SymbolAccessibility.PUBLIC;
+						dynamic_object_type.type_symbol.scope.add (null, s);
+						symbol_reference = s;
+					}
 				}
 				if (symbol_reference == null) {
 					// dynamic property read access
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 047df7e..4b99a25 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -514,6 +514,20 @@ public class Vala.MethodCall : Expression {
 			if (m.returns_floating_reference) {
 				value_type.floating_reference = true;
 			}
+
+			var dynamic_sig = m.parent_symbol as DynamicSignal;
+			if (dynamic_sig != null && dynamic_sig.handler != null) {
+				bool first = true;
+				foreach (FormalParameter param in dynamic_sig.handler.value_type.get_parameters ()) {
+					if (first) {
+						// skip sender parameter
+						first = false;
+					} else {
+						dynamic_sig.add_parameter (param.copy ());
+					}
+				}
+				dynamic_sig.handler.target_type = new DelegateType (dynamic_sig.get_delegate (new ObjectType ((ObjectTypeSymbol) dynamic_sig.parent_symbol), this));
+			}
 		} else if (mtype is DelegateType) {
 			var d = ((DelegateType) mtype).delegate_symbol;
 			foreach (DataType error_type in d.get_error_types ()) {



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