[vala/wip/transform: 141/169] Fix passing BusName and manage unhandled GErrors



commit 025eabab5c2bb865a74b51bbdfec0f854968557c
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat May 4 15:35:04 2013 +0200

    Fix passing BusName and manage unhandled GErrors

 codegen/valagdbusclienttransformer.vala |    5 ++++
 codegen/valagdbusservertransformer.vala |   16 +++++++++++---
 vala/valacatchclause.vala               |    2 +-
 vala/valacodebuilder.vala               |   33 +++++++++++++++++++++++++++++++
 vala/valacodetransformer.vala           |   16 +++-----------
 vala/valaerrortype.vala                 |    2 +-
 6 files changed, 56 insertions(+), 18 deletions(-)
---
diff --git a/codegen/valagdbusclienttransformer.vala b/codegen/valagdbusclienttransformer.vala
index f708cff..611a551 100644
--- a/codegen/valagdbusclienttransformer.vala
+++ b/codegen/valagdbusclienttransformer.vala
@@ -267,7 +267,12 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
                        // first try cached value
                        var result = b.add_temp_declaration (null, expression (@"get_cached_property 
(\"$dbus_name\")"));
                        b.open_if (expression (@"$result == null"));
+
+                       b.open_try ();
                        b.add_expression (expression (@"$result = call_sync 
(\"org.freedesktop.DBus.Properties.Get\", new Variant (\"(ss)\", \"$dbus_iface_name\", \"$dbus_name\"), 
GLib.DBusCallFlags.NONE, $timeout, null)"));
+                       b.add_catch_uncaught_error ();
+                       b.close ();
+
                        b.add_expression (expression (@"$result.get (\"(v)\", out $result)"));
                        b.close ();
 
diff --git a/codegen/valagdbusservertransformer.vala b/codegen/valagdbusservertransformer.vala
index ed214f1..14404f5 100644
--- a/codegen/valagdbusservertransformer.vala
+++ b/codegen/valagdbusservertransformer.vala
@@ -47,11 +47,12 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
 
                var iter = b.add_temp_declaration (null, expression ("arguments.iterator ()"));
 
-               var call = (MethodCall) expression (@"object.$(m.name) ()");
-               var finish_call = call;
+               MethodCall call;
+               MethodCall finish_call; 
                Method ready = null;
                CodeBuilder ready_builder = null;
                if (m.coroutine) {
+                       call = (MethodCall) expression (@"object.$(m.name).begin ()");
                        wrapper_method (new VoidType (), "gdbus_server_async_ready " + m.get_full_name (), 
out ready);
                        ready.add_parameter (new Parameter ("source_object", data_type ("GLib.Object", 
false)));
                        ready.add_parameter (new Parameter ("res", data_type ("GLib.AsyncResult", false)));
@@ -59,6 +60,8 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
                        ready_builder = new CodeBuilder.for_subroutine (ready);
 
                        finish_call = (MethodCall) expression (@"(($object_type) source_object).$(m.name).end 
(res)");
+               } else {
+                       call = finish_call = (MethodCall) expression (@"object.$(m.name) ()");
                }
 
                var out_args = new string[0];
@@ -70,11 +73,13 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
                        if (param.variable_type is ObjectType) {
                                type_name = param.variable_type.data_type.get_full_name ();
                        }
+
                        if (type_name == "GLib.Cancellable") {
                                call.add_argument (expression ("null"));
                                continue;
                        }
                        if (type_name == "GLib.BusName") {
+                               call.add_argument (expression ("(BusName) invocation.get_sender ()"));
                                continue;
                        }
 
@@ -111,8 +116,8 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
                } else {
                        b.add_expression (finish_call);
                }
-               b.add_catch (data_type ("GLib.Error"), "e");
-               b.add_expression (expression ("invocation.return_gerror (e)"));
+               b.add_catch_all ("_invocation_gerror_");
+               b.add_expression (expression ("invocation.return_gerror (_invocation_gerror_)"));
                b.add_return ();
                b.close ();
 
@@ -129,7 +134,10 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
                if (fd_list != null) {
                        b.add_expression (expression (@"$reply.set_unix_fd_list ($fd_list)"));
                }
+               b.open_try ();
                b.add_expression (expression (@"invocation.get_connection ().send_message ($reply, 
GLib.DBusSendMessageFlags.NONE, null)"));
+               b.add_catch_uncaught_error ();
+               b.close ();
 
                if (m.coroutine) {
                        pop_builder ();
diff --git a/vala/valacatchclause.vala b/vala/valacatchclause.vala
index 9816891..1c8dec6 100644
--- a/vala/valacatchclause.vala
+++ b/vala/valacatchclause.vala
@@ -123,7 +123,7 @@ public class Vala.CatchClause : CodeNode {
                        }
 
                        if (variable_name != null) {
-                               error_variable = new LocalVariable (error_type.copy (), variable_name);
+                               error_variable = new LocalVariable (error_type.copy (), variable_name, null, 
source_reference);
 
                                body.add_local_variable (error_variable);
 
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index 05801e6..ff43017 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -203,6 +203,16 @@ public class Vala.CodeBuilder {
                stmt.add_catch_clause (new CatchClause (error_type, variable_name, current_block, 
source_reference));
        }
 
+       public void add_catch_all (string? variable_name) {
+               add_catch (data_type ("GLib.Error"), variable_name);
+       }
+
+       public void add_catch_uncaught_error () {
+               add_catch_all ("_uncaught_error_");
+               add_expression (expression ("GLib.critical (_uncaught_error_.message)"));
+               add_expression (expression ("GLib.critical (\"file %s: line %d: uncaught error: %s (%s, 
%d)\", GLib.Log.FILE, GLib.Log.LINE, _uncaught_error_.message, _uncaught_error_.domain.to_string(), 
_uncaught_error_.code)"));
+       }
+
        public void add_statement (Statement statement) {
                current_block.add_statement (statement);
        }
@@ -247,4 +257,27 @@ public class Vala.CodeBuilder {
                        current_block = top as Block;
                } while (current_block == null);
        }
+
+       /* Utilities for building the code */
+
+       public Expression expression (string str) {
+               return new Parser().parse_expression_string (str, source_reference);
+       }
+
+       // only qualified types, will slightly simplify the work of SymbolResolver
+       public static Symbol symbol_from_string (string symbol_string) {
+               Symbol sym = CodeContext.get().root;
+               foreach (unowned string s in symbol_string.split (".")) {
+                       sym = sym.scope.lookup (s);
+               }
+               return sym;
+       }
+
+       // only qualified types, will slightly simplify the work of SymbolResolver
+       public static DataType data_type (string s, bool value_owned = true, bool nullable = false) {
+               DataType type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) symbol_from_string 
(s));
+               type.value_owned = value_owned;
+               type.nullable = nullable;
+               return type;
+       }
 }
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index 8773d51..5e22e75 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -96,24 +96,16 @@ public class Vala.CodeTransformer : CodeVisitor {
                return false;
        }
 
-       public Symbol symbol_from_string (string symbol_string) {
-               Symbol sym = context.root;
-               foreach (unowned string s in symbol_string.split (".")) {
-                       sym = sym.scope.lookup (s);
-               }
-               return sym;
+       public Symbol symbol_from_string (string s) {
+               return CodeBuilder.symbol_from_string (s);
        }
 
-       // only qualified types, will slightly simplify the work of SymbolResolver
        public DataType data_type (string s, bool value_owned = true, bool nullable = false) {
-               DataType type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) symbol_from_string 
(s));
-               type.value_owned = value_owned;
-               type.nullable = nullable;
-               return type;
+               return CodeBuilder.data_type (s, value_owned, nullable);
        }
 
        public Expression expression (string str) {
-               return new Parser ().parse_expression_string (str, b.source_reference);
+               return b.expression (str);
        }
 
        public void check (CodeNode node) {
diff --git a/vala/valaerrortype.vala b/vala/valaerrortype.vala
index c7c9f93..d7826e4 100644
--- a/vala/valaerrortype.vala
+++ b/vala/valaerrortype.vala
@@ -112,7 +112,7 @@ public class Vala.ErrorType : ReferenceType {
        }
 
        public override Symbol? get_member (string member_name) {
-               var root_symbol = source_reference.file.context.root;
+               var root_symbol = CodeContext.get().root;
                var gerror_symbol = root_symbol.scope.lookup ("GLib").scope.lookup ("Error");
                return gerror_symbol.scope.lookup (member_name);
        }


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