[vala] girparser: Handle asynchronous methods



commit cb4601c7339a4d4aa3079b74e6fbd467c3779268
Author: Jürg Billeter <j bitron ch>
Date:   Thu Jul 8 21:57:31 2010 +0200

    girparser: Handle asynchronous methods
    
    Fixes bug 623255.

 vala/valagirparser.vala |   56 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 3f77a15..1069bf3 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -745,6 +745,8 @@ public class Vala.GirParser : CodeVisitor {
 			}
 		}
 
+		handle_async_methods (cl);
+
 		end_element ("class");
 		return cl;
 	}
@@ -821,10 +823,64 @@ public class Vala.GirParser : CodeVisitor {
 			}
 		}
 
+		handle_async_methods (iface);
+
 		end_element ("interface");
 		return iface;
 	}
 
+	void handle_async_methods (ObjectTypeSymbol type_symbol) {
+		var methods = type_symbol.get_methods ();
+		for (int method_n = 0 ; method_n < methods.size ; method_n++) {
+			var m = methods.get (method_n);
+
+			if (m.coroutine) {
+				string finish_method_base;
+				if (m.name.has_suffix ("_async")) {
+					finish_method_base = m.name.substring (0, m.name.length - "_async".length);
+				} else {
+					finish_method_base = m.name;
+				}
+				var finish_method = type_symbol.scope.lookup (finish_method_base + "_finish") as Method;
+
+				// check if the method is using non-standard finish method name
+				if (finish_method == null) {
+					var method_cname = m.get_finish_cname ();
+					foreach (Method method in type_symbol.get_methods ()) {
+						if (method.get_cname () == method_cname) {
+							finish_method = method;
+							break;
+						}
+					}
+				}
+
+				if (finish_method != null) {
+					m.return_type = finish_method.return_type.copy ();
+					m.no_array_length = finish_method.no_array_length;
+					m.array_null_terminated = finish_method.array_null_terminated;
+					foreach (var param in finish_method.get_parameters ()) {
+						if (param.direction == ParameterDirection.OUT) {
+							var async_param = param.copy ();
+							if (m.scope.lookup (param.name) != null) {
+								// parameter name conflict
+								async_param.name += "_out";
+							}
+							m.add_parameter (async_param);
+						}
+					}
+					foreach (DataType error_type in finish_method.get_error_types ()) {
+						m.add_error_type (error_type.copy ());
+					}
+					if (methods.index_of (finish_method) < method_n) {
+						method_n--;
+					}
+					type_symbol.scope.remove (finish_method.name);
+					methods.remove (finish_method);
+				}
+			}
+		}
+	}
+
 	Field parse_field () {
 		start_element ("field");
 		string name = reader.get_attribute ("name");



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