[vala/wip/transform: 9/9] Fix raw variants
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 9/9] Fix raw variants
- Date: Mon, 29 Oct 2018 07:54:05 +0000 (UTC)
commit a2eae0c91f343760abb53ac6f1fd287faba4f86d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Oct 28 22:20:24 2018 +0100
Fix raw variants
codegen/valagdbusclienttransformer.vala | 22 ++++++++++++++--------
codegen/valagdbusservertransformer.vala | 12 ++++++++----
2 files changed, 22 insertions(+), 12 deletions(-)
---
diff --git a/codegen/valagdbusclienttransformer.vala b/codegen/valagdbusclienttransformer.vala
index 68f0cab92..df7a91123 100644
--- a/codegen/valagdbusclienttransformer.vala
+++ b/codegen/valagdbusclienttransformer.vala
@@ -41,12 +41,14 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
return Symbol.lower_case_to_camel_case (symbol.name);
}
- public Expression read_dbus_value (DataType type, string iter, string message, ref string? fd_list,
ref string? fd_index) {
+ public Expression read_dbus_value (DataType type, bool is_raw_variant, string iter, string message,
ref string? fd_list, ref string? fd_index) {
string? type_name = null;
if (type.data_type != null) {
type_name = type.data_type.get_full_name ();
}
- if (type_name == "GLib.UnixInputStream" || type_name == "GLib.UnixOutputStream" || type_name
== "GLib.Socket") {
+ if (is_raw_variant) {
+ return expression (@"$iter.next_value ()");
+ } else if (type_name == "GLib.UnixInputStream" || type_name == "GLib.UnixOutputStream" ||
type_name == "GLib.Socket") {
if (fd_list == null) {
fd_list = b.add_temp_declaration (data_type ("GLib.UnixFDList"), null);
fd_index = b.add_temp_declaration (null, expression ("0"));
@@ -69,7 +71,7 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
}
}
- public void write_dbus_value (DataType type, string builder, string value, ref string? fd_list) {
+ public void write_dbus_value (DataType type, bool is_raw_variant, string builder, string value, ref
string? fd_list) {
string? type_name = null;
if (type is ObjectType) {
type_name = type.data_type.get_full_name ();
@@ -77,7 +79,9 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
if (type_name == "GLib.Cancellable" || type_name == "GLib.BusName") {
return;
}
- if (type_name == "GLib.UnixInputStream" || type_name == "GLib.UnixOutputStream" || type_name
== "GLib.Socket") {
+ if (is_raw_variant) {
+ statements (@"$builder.add_value ($value);");
+ } else if (type_name == "GLib.UnixInputStream" || type_name == "GLib.UnixOutputStream" ||
type_name == "GLib.Socket") {
if (fd_list == null) {
fd_list = b.add_temp_declaration (null, expression ("new GLib.UnixFDList
()"));
}
@@ -106,7 +110,7 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
if (param.variable_type is ObjectType &&
param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
cancellable = param.name;
}
- write_dbus_value (param.variable_type, builder, param.name, ref fd_list);
+ write_dbus_value (param.variable_type, get_dbus_signature (param) != null,
builder, param.name, ref fd_list);
} else if (param.direction == ParameterDirection.OUT) {
has_result = true;
}
@@ -136,11 +140,11 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
statements (@"$iter = $reply.get_body ().iterator ();");
foreach (var param in m.get_parameters ()) {
if (param.direction == ParameterDirection.OUT) {
- b.add_assignment (expression (param.name), read_dbus_value
(param.variable_type, iter, reply, ref fd_list, ref fd_index));
+ b.add_assignment (expression (param.name), read_dbus_value
(param.variable_type, get_dbus_signature (param) != null, iter, reply, ref fd_list, ref fd_index));
}
}
if (m.has_result) {
- b.add_return (read_dbus_value (m.return_type, iter, reply, ref fd_list, ref
fd_index));
+ b.add_return (read_dbus_value (m.return_type, get_dbus_signature (m) != null,
iter, reply, ref fd_list, ref fd_index));
}
}
}
@@ -194,7 +198,9 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
var call = new MethodCall (expression (sig.name), sig.source_reference);
foreach (var param in sig.get_parameters ()) {
var temp = b.add_temp_declaration (copy_type (param.variable_type, true));
- if (is_gvariant_type (param.variable_type)) {
+ if (get_dbus_signature (param) != null) {
+ statements (@"$temp = $iter.next_value ();");
+ } else if (is_gvariant_type (param.variable_type)) {
statements (@"$temp = $iter.next_value ().get_variant ();");
} else {
statements (@"$temp = ($(param.variable_type)) ($iter.next_value ());");
diff --git a/codegen/valagdbusservertransformer.vala b/codegen/valagdbusservertransformer.vala
index a3c5ac217..19d7cb73f 100644
--- a/codegen/valagdbusservertransformer.vala
+++ b/codegen/valagdbusservertransformer.vala
@@ -67,6 +67,7 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
b.open_try ();
var out_args = new string[0];
+ var out_params = new Parameter[0];
var out_types = new DataType[0];
string fd_list = null;
string fd_index = null;
@@ -87,7 +88,7 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
if (param.direction == ParameterDirection.IN) {
var arg = b.add_temp_declaration (copy_type (param.variable_type, true));
- b.add_assignment (expression (arg), read_dbus_value (param.variable_type,
iter, "invocation.get_message ()", ref fd_list, ref fd_index));
+ b.add_assignment (expression (arg), read_dbus_value (param.variable_type,
get_dbus_signature (param) != null, iter, "invocation.get_message ()", ref fd_list, ref fd_index));
call.add_argument (expression (arg));
} else if (param.direction == ParameterDirection.OUT) {
if (m.coroutine) {
@@ -96,6 +97,7 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
}
var arg = b.add_temp_declaration (copy_type (param.variable_type, true));
out_args += arg;
+ out_params += param;
out_types += param.variable_type.copy ();
finish_call.add_argument (new UnaryExpression (UnaryOperator.OUT, expression
(arg), m.source_reference));
if (m.coroutine) {
@@ -130,10 +132,10 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
var reply = b.add_temp_declaration (null, expression ("new GLib.DBusMessage.method_reply
(invocation.get_message ())"));
var builder = b.add_temp_declaration (null, expression ("new GLib.VariantBuilder
(GLib.VariantType.TUPLE)"));
for (int i = 0; i < out_args.length; i++) {
- write_dbus_value (out_types[i], builder, out_args[i], ref fd_list);
+ write_dbus_value (out_types[i], get_dbus_signature (out_params[i]) != null, builder,
out_args[i], ref fd_list);
}
if (result != null) {
- write_dbus_value (m.return_type.copy (), builder, result, ref fd_list);
+ write_dbus_value (m.return_type.copy (), get_dbus_signature (m) != null, builder,
result, ref fd_list);
}
statements (@"$reply.set_body ($builder.end ());");
if (fd_list != null) {
@@ -297,7 +299,9 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
var builder = b.add_temp_declaration (null, expression ("new GLib.VariantBuilder
(GLib.VariantType.TUPLE)"));
foreach (var param in sig.get_parameters ()) {
- if (is_gvariant_type (param.variable_type)) {
+ if (get_dbus_signature (param) != null) {
+ statements (@"$builder.add_value ($(param.name));");
+ } else if (is_gvariant_type (param.variable_type)) {
statements (@"$builder.add (\"v\", $(param.name));");
} else {
statements (@"$builder.add_value ($(param.name));");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]