[vala/wip/transform: 144/169] Make gdbus work, temp commit
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 144/169] Make gdbus work, temp commit
- Date: Thu, 17 Nov 2016 09:33:39 +0000 (UTC)
commit 583449c5093fff430d8d093ee2adea3bc7192735
Author: Luca Bruno <lucabru src gnome org>
Date: Tue May 21 21:08:05 2013 +0200
Make gdbus work, temp commit
codegen/valagdbusclientmodule.vala | 5 +++-
codegen/valagdbusclienttransformer.vala | 33 +++++++++++++++++++++++++-----
vala/valacodebuilder.vala | 4 +-
vala/valacodetransformer.vala | 18 ++++++++++++++++
vala/valasemanticanalyzer.vala | 8 +++++++
5 files changed, 59 insertions(+), 9 deletions(-)
---
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 17f5d45..2460c4c 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 9f7466c..e27d016 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 ff43017..8d3fec4 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 5e22e75..31bed91 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -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);
+ }
+ }
+ }
}
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 03ad952..0b3edeb 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -157,6 +157,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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]