[Vala] [RFC, PATCH] add async keyword to vapigen
- From: Philipp Zabel <philipp zabel gmail com>
- To: vala-list gnome org
- Subject: [Vala] [RFC, PATCH] add async keyword to vapigen
- Date: Thu, 24 Sep 2009 22:21:36 +0200
Hi, the following patch adds support for an "async" attribute to
vapigen. This can be used in metadata to fix up the binding of
asynchronous methods that don't end in _async like this:
diff --git a/vapi/packages/gio-2.0/gio-2.0.metadata b/vapi/packages/gio-2.0/gio-2.0.metadata
index 1ca9522..e458e86 100644
--- a/vapi/packages/gio-2.0/gio-2.0.metadata
+++ b/vapi/packages/gio-2.0/gio-2.0.metadata
@@ -48,6 +48,7 @@ GFileMonitor::changed.other_file nullable="1"
g_file_monitor_directory hidden="1"
g_file_monitor_dir hidden="1"
g_file_monitor_file hidden="1"
+g_file_mount_enclosing_volume async="1"
g_file_move.progress_callback_data hidden="1"
g_file_new_for_commandline_arg transfer_ownership="1"
g_file_new_for_path transfer_ownership="1"
Or would it be better to make the parser recognize asynchronous
functions that don't end in _async?
regards
Philipp
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index 6cb068f..efa49dd 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -1148,7 +1148,13 @@ public class Vala.GIdlParser : CodeVisitor {
void handle_async_methods (ObjectTypeSymbol type_symbol) {
foreach (Method m in type_symbol.get_methods ()) {
if (m.coroutine) {
- var finish_method = type_symbol.scope.lookup (m.name.substring (0,
m.name.length - "_async".length) + "_finish") as Method;
+ 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;
if (finish_method != null) {
m.return_type = finish_method.return_type.copy ();
foreach (var param in finish_method.get_parameters ()) {
@@ -1520,6 +1526,11 @@ public class Vala.GIdlParser : CodeVisitor {
}
} else if (nv[0] == "vfunc_name") {
m.vfunc_name = eval (nv[1]);
+ } else if (nv[0] == "async") {
+ if (eval (nv[1]) == "1") {
+ // force async function, even if it doesn't end in _async
+ m.coroutine = true;
+ }
}
}
}
@@ -1558,7 +1569,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
}
- if (param type interface == "GAsyncReadyCallback" && symbol.has_suffix ("_async")) {
+ if (param type interface == "GAsyncReadyCallback" && (symbol.has_suffix ("_async")
|| m.coroutine)) {
// async method
m.coroutine = true;
continue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]