From: Michal Hruby Date: Tue, 5 Apr 2011 20:38:56 +0000 (+0200) Subject: gidlparser: Support error types for delegates X-Git-Tag: 0.13.0~251 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fkeep-around%2F1df2c050ba29c84026a14e7ee23fa6bcd00b1044;p=thirdparty%2Fvala.git gidlparser: Support error types for delegates Fixes bug 644420. --- diff --git a/vapi/gio-2.0.vapi b/vapi/gio-2.0.vapi index a9da0a17a..3f719a713 100644 --- a/vapi/gio-2.0.vapi +++ b/vapi/gio-2.0.vapi @@ -2476,11 +2476,11 @@ namespace GLib { [CCode (cheader_filename = "gio/gio.h")] public delegate bool CancellableSourceFunc (GLib.Cancellable cancellable); [CCode (cheader_filename = "gio/gio.h")] - public delegate unowned GLib.Variant DBusInterfaceGetPropertyFunc (GLib.DBusConnection connection, string sender, string object_path, string interface_name, string property_name, GLib.Error error); + public delegate unowned GLib.Variant DBusInterfaceGetPropertyFunc (GLib.DBusConnection connection, string sender, string object_path, string interface_name, string property_name) throws GLib.Error; [CCode (cheader_filename = "gio/gio.h")] public delegate void DBusInterfaceMethodCallFunc (GLib.DBusConnection connection, string sender, string object_path, string interface_name, string method_name, GLib.Variant parameters, GLib.DBusMethodInvocation invocation); [CCode (cheader_filename = "gio/gio.h")] - public delegate bool DBusInterfaceSetPropertyFunc (GLib.DBusConnection connection, string sender, string object_path, string interface_name, string property_name, GLib.Variant value, GLib.Error error); + public delegate bool DBusInterfaceSetPropertyFunc (GLib.DBusConnection connection, string sender, string object_path, string interface_name, string property_name, GLib.Variant value) throws GLib.Error; [CCode (cheader_filename = "gio/gio.h")] public delegate unowned GLib.DBusMessage DBusMessageFilterFunction (GLib.DBusConnection connection, GLib.DBusMessage message, bool incoming); [CCode (cheader_filename = "gio/gio.h")] diff --git a/vapi/gtk+-2.0.vapi b/vapi/gtk+-2.0.vapi index 7d27503aa..889232b78 100644 --- a/vapi/gtk+-2.0.vapi +++ b/vapi/gtk+-2.0.vapi @@ -7474,7 +7474,7 @@ namespace Gtk { [CCode (cheader_filename = "gtk/gtk.h")] public delegate int RecentSortFunc (Gtk.RecentInfo a, Gtk.RecentInfo b); [CCode (cheader_filename = "gtk/gtk.h", instance_pos = 5.9)] - public delegate bool TextBufferDeserializeFunc (Gtk.TextBuffer register_buffer, Gtk.TextBuffer content_buffer, Gtk.TextIter iter, [CCode (array_length_type = "gsize")] uint8[] data, bool create_tags, GLib.Error error); + public delegate bool TextBufferDeserializeFunc (Gtk.TextBuffer register_buffer, Gtk.TextBuffer content_buffer, Gtk.TextIter iter, [CCode (array_length_type = "gsize")] uint8[] data, bool create_tags) throws GLib.Error; [CCode (cheader_filename = "gtk/gtk.h")] public delegate uchar TextBufferSerializeFunc (Gtk.TextBuffer register_buffer, Gtk.TextBuffer content_buffer, Gtk.TextIter start, Gtk.TextIter end, size_t length); [CCode (cheader_filename = "gtk/gtk.h")] diff --git a/vapi/libgda-4.0.vapi b/vapi/libgda-4.0.vapi index e0068d238..e60392a93 100644 --- a/vapi/libgda-4.0.vapi +++ b/vapi/libgda-4.0.vapi @@ -2056,21 +2056,21 @@ namespace Gda { [CCode (cheader_filename = "libgda/libgda.h")] public delegate void ServerProviderExecCallback (Gda.ServerProvider provider, Gda.Connection cnc, uint task_id, GLib.Object result_obj, GLib.Error error); [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] - public delegate bool SqlForeachFunc (Gda.SqlAnyPart p1, void* p2, GLib.Error p3); + public delegate bool SqlForeachFunc (Gda.SqlAnyPart p1, void* p2) throws GLib.Error; [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] - public delegate unowned string SqlRenderingExpr (Gda.SqlExpr expr, Gda.SqlRenderingContext context, bool is_default, bool is_null, GLib.Error error); + public delegate unowned string SqlRenderingExpr (Gda.SqlExpr expr, Gda.SqlRenderingContext context, bool is_default, bool is_null) throws GLib.Error; [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] - public delegate unowned string SqlRenderingFunc (Gda.SqlAnyPart node, Gda.SqlRenderingContext context, GLib.Error error); + public delegate unowned string SqlRenderingFunc (Gda.SqlAnyPart node, Gda.SqlRenderingContext context) throws GLib.Error; [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] - public delegate unowned string SqlRenderingPSpecFunc (Gda.SqlParamSpec pspec, Gda.SqlExpr expr, Gda.SqlRenderingContext context, bool is_default, bool is_null, GLib.Error error); + public delegate unowned string SqlRenderingPSpecFunc (Gda.SqlParamSpec pspec, Gda.SqlExpr expr, Gda.SqlRenderingContext context, bool is_default, bool is_null) throws GLib.Error; [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] - public delegate unowned string SqlRenderingValue (GLib.Value value, Gda.SqlRenderingContext context, GLib.Error error); + public delegate unowned string SqlRenderingValue (GLib.Value value, Gda.SqlRenderingContext context) throws GLib.Error; [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] public delegate bool SqlReservedKeywordsFunc (string word); [CCode (cheader_filename = "libgda/libgda.h")] public delegate void VConnectionHubFunc (Gda.Connection cnc, string ns); [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] - public delegate unowned GLib.List VconnectionDataModelCreateColumnsFunc (Gda.VconnectionDataModelSpec p1, GLib.Error p2); + public delegate unowned GLib.List VconnectionDataModelCreateColumnsFunc (Gda.VconnectionDataModelSpec p1) throws GLib.Error; [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] public delegate unowned Gda.DataModel VconnectionDataModelCreateModelFunc (Gda.VconnectionDataModelSpec p1); [CCode (cheader_filename = "libgda/libgda.h", has_target = false)] diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala index 740fb0bc5..a0b775def 100644 --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -452,6 +452,8 @@ public class Vala.GIdlParser : CodeVisitor { cb.access = SymbolAccessibility.PUBLIC; bool check_has_target = true; + bool suppress_throws = false; + string? error_types = null; var attributes = get_attributes (node.name); if (attributes != null) { @@ -478,6 +480,12 @@ public class Vala.GIdlParser : CodeVisitor { return_type = new ArrayType (return_type, 1, return_type.source_reference); cb.return_type = return_type; } + } else if (nv[0] == "throws") { + if (eval (nv[1]) == "0") { + suppress_throws = true; + } + } else if (nv[0] == "error_types") { + error_types = eval (nv[1]); } else if (nv[0] == "array_length_type") { cb.array_length_type = eval (nv[1]); } else if (nv[0] == "type_name") { @@ -514,6 +522,14 @@ public class Vala.GIdlParser : CodeVisitor { // hide user_data parameter for instance delegates cb.has_target = true; } else { + // check for GError parameter + if (suppress_throws == false && param_is_exception (param)) { + if (error_types == null) + cb.add_error_type (parse_type (param.type)); + remaining_params--; + continue; + } + string param_name = param_node.name; if (param_name == "string") { // avoid conflict with string type @@ -604,7 +620,14 @@ public class Vala.GIdlParser : CodeVisitor { remaining_params--; } - + + if (suppress_throws == false && error_types != null) { + var type_args = eval (error_types).split (","); + foreach (string type_arg in type_args) { + cb.add_error_type (parse_type_from_string (type_arg, true)); + } + } + return cb; } @@ -2156,6 +2179,7 @@ public class Vala.GIdlParser : CodeVisitor { continue; } + // check for GError parameter if (suppress_throws == false && param_is_exception (param)) { if (error_types == null) m.add_error_type (parse_type (param.type));