vala r1474 - in trunk: . vala



Author: juergbi
Date: Wed May 28 23:30:19 2008
New Revision: 1474
URL: http://svn.gnome.org/viewvc/vala?rev=1474&view=rev

Log:
2008-05-29  Juerg Billeter  <j bitron ch>

	* vala/valamethod.vala:
	* vala/valaparser.vala:
	* vala/valasignal.vala:

	Add support for overriding default method handlers of signals
	that have been declared with the `virtual' modifier


Modified:
   trunk/ChangeLog
   trunk/vala/valamethod.vala
   trunk/vala/valaparser.vala
   trunk/vala/valasignal.vala

Modified: trunk/vala/valamethod.vala
==============================================================================
--- trunk/vala/valamethod.vala	(original)
+++ trunk/vala/valamethod.vala	Wed May 28 23:30:19 2008
@@ -547,6 +547,20 @@
 				_base_method = base_method;
 				return;
 			}
+		} else if (sym is Signal) {
+			var sig = (Signal) sym;
+			if (sig.is_virtual) {
+				var base_method = sig.get_method_handler ();
+				string invalid_match;
+				if (!compatible (base_method, out invalid_match)) {
+					error = true;
+					Report.error (source_reference, "overriding method `%s' is incompatible with base method `%s': %s.".printf (get_full_name (), base_method.get_full_name (), invalid_match));
+					return;
+				}
+
+				_base_method = base_method;
+				return;
+			}
 		}
 
 		if (cl.base_class != null) {

Modified: trunk/vala/valaparser.vala
==============================================================================
--- trunk/vala/valaparser.vala	(original)
+++ trunk/vala/valaparser.vala	Wed May 28 23:30:19 2008
@@ -2238,13 +2238,16 @@
 	Signal parse_signal_declaration (Gee.List<Attribute>? attrs) throws ParseError {
 		var begin = get_location ();
 		var access = parse_access_modifier ();
-		parse_member_declaration_modifiers ();
+		var flags = parse_member_declaration_modifiers ();
 		expect (TokenType.SIGNAL);
 		var type = parse_type ();
 		string id = parse_identifier ();
 		var sig = new Signal (id, type, get_src_com (begin));
 		sig.access = access;
 		set_attributes (sig, attrs);
+		if (ModifierFlags.VIRTUAL in flags) {
+			sig.is_virtual = true;
+		}
 		expect (TokenType.OPEN_PARENS);
 		if (current () != TokenType.CLOSE_PARENS) {
 			do {

Modified: trunk/vala/valasignal.vala
==============================================================================
--- trunk/vala/valasignal.vala	(original)
+++ trunk/vala/valasignal.vala	Wed May 28 23:30:19 2008
@@ -42,9 +42,15 @@
 	 * Specifies whether this signal has an emitter wrapper function.
 	 */
 	public bool has_emitter { get; set; }
+	
+	/**
+	 * Specifies whether this signal has virtual method handler.
+	 */
+	public bool is_virtual { get; set; }
 
 	private Gee.List<FormalParameter> parameters = new ArrayList<FormalParameter> ();
 	private Delegate generated_delegate;
+	private Method generated_method;
 
 	private string cname;
 	
@@ -195,4 +201,23 @@
 			return_type = new_type;
 		}
 	}
+
+	public Method get_method_handler () {
+		assert (is_virtual);
+
+		if (generated_method == null) {
+			generated_method = new Method (name, return_type, source_reference);
+			generated_method.is_virtual = true;
+			generated_method.vfunc_name = name;
+
+			foreach (FormalParameter param in parameters) {
+				generated_method.add_parameter (param);
+			}
+
+			parent_symbol.scope.add (null, generated_method);
+		}
+		
+		return generated_method;
+	}
 }
+



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