]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Make gdbus work, temp commit
authorLuca Bruno <lucabru@src.gnome.org>
Tue, 21 May 2013 19:08:05 +0000 (21:08 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 11 Mar 2019 12:52:38 +0000 (13:52 +0100)
codegen/valagdbusclientmodule.vala
codegen/valagdbusclienttransformer.vala
vala/valacodebuilder.vala
vala/valacodetransformer.vala
vala/valasemanticanalyzer.vala

index fa135b07a04b25e3672839f995db3c61da7e2e17..419457a648aa5288f1bf7be36c8fc199e8245741 100644 (file)
@@ -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
index acfb2ae9ff4c86cb5cf26bec6b8c824759065d22..ba3499498ab2cd5ef87fb756921f835af82e2269 100644 (file)
@@ -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;
index 93a72fcb0fe8dcdfca9136189296535b9d164d56..45f4da490bfdf4f5fc8e99516a22d5796e50b8da 100644 (file)
@@ -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);
                }
index 5e22e75b43e147603b64a8976646f52d1b663557..31bed91f3cb2763cd7ede35fc3f30523d9dc84bb 100644 (file)
@@ -29,6 +29,10 @@ public class Vala.CodeTransformer : CodeVisitor {
        public CodeBuilder b;
        public ArrayList<CodeBuilder> builder_stack = new ArrayList<CodeBuilder> ();
        public HashMap<string, CodeNode> wrapper_cache;
+       /* Keep tracks of generated stuff to avoid cycles */
+       public HashSet<CodeNode> unit_generated = new HashSet<CodeNode> ();
+
+       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);
+                       }
+               }
+       }
 }
index e3f178acf09af5de3aa9136a1a582c8430f05942..474ca18c1056cc0dd9c35b4f964ccf2b64203430 100644 (file)
@@ -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;
        }