From: Luca Bruno Date: Tue, 21 May 2013 19:08:05 +0000 (+0200) Subject: Make gdbus work, temp commit X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d306b41933faf4d0bb9483161fb0a541ac706403;p=thirdparty%2Fvala.git Make gdbus work, temp commit --- diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala index fa135b07a..419457a64 100644 --- a/codegen/valagdbusclientmodule.vala +++ b/codegen/valagdbusclientmodule.vala @@ -77,7 +77,10 @@ public class Vala.GDBusClientModule : GDBusModule { return; } - proxy_type = new CCodeIdentifier ("%s_PROXY".printf (get_ccode_type_id (iface))); + var proxy_class = (Class) CodeBuilder.symbol_from_string (iface.name + "Proxy", iface.parent_symbol); + generate_class_declaration (proxy_class, cfile); + + proxy_type = new CCodeIdentifier (get_ccode_type_id (proxy_class)); dbus_iface_name = new CCodeConstant ("\"%s\"".printf (get_dbus_name (iface))); } else { // use runtime type information for generic methods diff --git a/codegen/valagdbusclienttransformer.vala b/codegen/valagdbusclienttransformer.vala index acfb2ae9f..ba3499498 100644 --- a/codegen/valagdbusclienttransformer.vala +++ b/codegen/valagdbusclienttransformer.vala @@ -311,7 +311,9 @@ public class Vala.GDBusClientTransformer : GVariantTransformer { } public override void visit_interface (Interface iface) { - base.visit_interface (iface); + if (is_visited (iface)) { + base.visit_interface (iface); + } string dbus_iface_name = get_dbus_name (iface); if (dbus_iface_name == null) { @@ -334,7 +336,7 @@ public class Vala.GDBusClientTransformer : GVariantTransformer { var proxy = new Class (iface.name + "Proxy", iface.source_reference, null); proxy.add_base_type (data_type ("GLib.DBusProxy")); proxy.add_base_type (SemanticAnalyzer.get_data_type_for_symbol (iface)); - proxy.access = iface.access; + proxy.access = SymbolAccessibility.PRIVATE; iface.parent_symbol.add_class (proxy); generate_dbus_proxy_methods (proxy, iface); @@ -345,13 +347,32 @@ public class Vala.GDBusClientTransformer : GVariantTransformer { } public override void visit_method_call (MethodCall expr) { - var m = expr.call.symbol_reference as DynamicMethod; - if (m == null || m.dynamic_type.data_type != symbol_from_string ("GLib.DBusProxy")) { - // not a dynamic dbus call + var m = expr.call.symbol_reference as Method; + if (m is DynamicMethod && ((DynamicMethod) m).dynamic_type.data_type == symbol_from_string ("GLib.DBusProxy")) { + generate_dynamic_dbus_call (expr); + } else if (m != null && m == symbol_from_string ("GLib.Bus.get_proxy")) { + generate_get_proxy_call (expr); + } else { base.visit_method_call (expr); - return; } + } + + private void generate_get_proxy_call (MethodCall expr) { + var ma = (MemberAccess) expr.call; + var type_arg = ma.get_type_arguments ().get (0); + var object_type = type_arg as ObjectType; + if (object_type != null && object_type.type_symbol is Interface) { + var iface = (Interface) object_type.type_symbol; + if (get_dbus_name (iface) != null) { + current_namespace = context.analyzer.get_current_namespace (expr); + accept_external (iface); + } + } + base.visit_method_call (expr); + } + private void generate_dynamic_dbus_call (MethodCall expr) { + var m = (DynamicMethod) expr.call.symbol_reference; push_builder (new CodeBuilder (context, expr.parent_statement, expr.source_reference)); Method wrapper; diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala index 93a72fcb0..45f4da490 100644 --- a/vala/valacodebuilder.vala +++ b/vala/valacodebuilder.vala @@ -265,8 +265,8 @@ public class Vala.CodeBuilder { } // only qualified types, will slightly simplify the work of SymbolResolver - public static Symbol symbol_from_string (string symbol_string) { - Symbol sym = CodeContext.get().root; + public static Symbol symbol_from_string (string symbol_string, Symbol? parent_symbol = null) { + Symbol sym = parent_symbol != null ? parent_symbol : CodeContext.get().root; foreach (unowned string s in symbol_string.split (".")) { sym = sym.scope.lookup (s); } diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala index 5e22e75b4..31bed91f3 100644 --- a/vala/valacodetransformer.vala +++ b/vala/valacodetransformer.vala @@ -29,6 +29,10 @@ public class Vala.CodeTransformer : CodeVisitor { public CodeBuilder b; public ArrayList builder_stack = new ArrayList (); public HashMap wrapper_cache; + /* Keep tracks of generated stuff to avoid cycles */ + public HashSet unit_generated = new HashSet (); + + public Namespace current_namespace = null; public void push_builder (CodeBuilder builder) { builder_stack.add (b); @@ -115,4 +119,18 @@ public class Vala.CodeTransformer : CodeVisitor { } node.accept (this); } + + public bool is_visited (CodeNode node) { + var file = node.source_reference.file; + return file.file_type == SourceFileType.SOURCE || (context.header_filename != null && file.file_type == SourceFileType.FAST); + } + + public void accept_external (CodeNode node) { + if (node.source_reference != null) { + if (!is_visited (node) && !unit_generated.contains (node)) { + unit_generated.add (node); + check (node); + } + } + } } diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index e3f178acf..474ca18c1 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -156,6 +156,14 @@ public class Vala.SemanticAnalyzer : CodeVisitor { return (TypeSymbol) sym; } + public unowned Namespace? get_current_namespace (CodeNode node) { + unowned Symbol sym = get_current_symbol (node); + while (sym != null && !(sym is Namespace)) { + sym = sym.parent_symbol; + } + return (Namespace) sym; + } + public unowned Class? get_current_class (CodeNode node) { return get_current_type_symbol (node) as Class; }