[vala/wip/transform: 34/87] Drop unnecessary code
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 34/87] Drop unnecessary code
- Date: Thu, 25 Oct 2018 07:00:01 +0000 (UTC)
commit 8cac050e12079d6f3f22c93aba134bde56926ba4
Author: Luca Bruno <lucabru src gnome org>
Date: Wed Jan 4 15:19:23 2012 +0100
Drop unnecessary code
codegen/valagdbusmodule.vala | 368 -----------------------
codegen/valagdbusservermodule.vala | 20 --
codegen/valagvariantmodule.vala | 588 -------------------------------------
3 files changed, 976 deletions(-)
---
diff --git a/codegen/valagdbusmodule.vala b/codegen/valagdbusmodule.vala
index 8acb28259..93d87c866 100644
--- a/codegen/valagdbusmodule.vala
+++ b/codegen/valagdbusmodule.vala
@@ -121,372 +121,4 @@ public class Vala.GDBusModule : GVariantModule {
pop_function ();
cfile.add_function (cquark_fun);
}
-
- bool is_file_descriptor (DataType type) {
- if (type is ObjectType) {
- if (type.data_type.get_full_name () == "GLib.UnixInputStream" ||
- type.data_type.get_full_name () == "GLib.UnixOutputStream" ||
- type.data_type.get_full_name () == "GLib.Socket" ||
- type.data_type.get_full_name () == "GLib.FileDescriptorBased") {
- return true;
- }
- }
-
- return false;
- }
-
- public bool dbus_method_uses_file_descriptor (Method method) {
- foreach (Parameter param in method.get_parameters ()) {
- if (is_file_descriptor (param.variable_type)) {
- return true;
- }
- }
-
- if (is_file_descriptor (method.return_type)) {
- return true;
- }
-
- return false;
- }
-
- CCodeExpression? get_file_descriptor (DataType type, CCodeExpression expr) {
- if (type is ObjectType) {
- if (type.data_type.get_full_name () == "GLib.UnixInputStream") {
- var result = new CCodeFunctionCall (new CCodeIdentifier
("g_unix_input_stream_get_fd"));
- result.add_argument (expr);
- return result;
- } else if (type.data_type.get_full_name () == "GLib.UnixOutputStream") {
- var result = new CCodeFunctionCall (new CCodeIdentifier
("g_unix_output_stream_get_fd"));
- result.add_argument (expr);
- return result;
- } else if (type.data_type.get_full_name () == "GLib.Socket") {
- var result = new CCodeFunctionCall (new CCodeIdentifier ("g_socket_get_fd"));
- result.add_argument (expr);
- return result;
- } else if (type.data_type.get_full_name () == "GLib.FileDescriptorBased") {
- var result = new CCodeFunctionCall (new CCodeIdentifier
("g_file_descriptor_based_get_fd"));
- result.add_argument (expr);
- return result;
- }
- }
-
- return null;
- }
-
- public void send_dbus_value (DataType type, CCodeExpression builder_expr, CCodeExpression expr,
Symbol? sym) {
- var fd = get_file_descriptor (type, expr);
- if (fd != null) {
- // add file descriptor to the file descriptor list
- var fd_append = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_append"));
- fd_append.add_argument (new CCodeIdentifier ("_fd_list"));
- fd_append.add_argument (fd);
- fd_append.add_argument (new CCodeConstant ("NULL"));
-
- // add index to file descriptor to gvariant
- var builder_add = new CCodeFunctionCall (new CCodeIdentifier
("g_variant_builder_add"));
- builder_add.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF,
builder_expr));
- builder_add.add_argument (new CCodeConstant ("\"h\""));
- builder_add.add_argument (fd_append);
- ccode.add_expression (builder_add);
- } else {
- write_expression (type, builder_expr, expr, sym);
- }
- }
-
- CCodeExpression? create_from_file_descriptor (DataType type, CCodeExpression expr) {
- if (type is ObjectType) {
- if (type.data_type.get_full_name () == "GLib.UnixInputStream") {
- var result = new CCodeFunctionCall (new CCodeIdentifier
("g_unix_input_stream_new"));
- result.add_argument (expr);
- result.add_argument (new CCodeConstant ("TRUE"));
- return new CCodeCastExpression (result, "GUnixInputStream *");
- } else if (type.data_type.get_full_name () == "GLib.UnixOutputStream") {
- var result = new CCodeFunctionCall (new CCodeIdentifier
("g_unix_output_stream_new"));
- result.add_argument (expr);
- result.add_argument (new CCodeConstant ("TRUE"));
- return new CCodeCastExpression (result, "GUnixOutputStream *");
- } else if (type.data_type.get_full_name () == "GLib.Socket") {
- var result = new CCodeFunctionCall (new CCodeIdentifier
("g_socket_new_from_fd"));
- result.add_argument (expr);
- result.add_argument (new CCodeConstant ("NULL"));
- return result;
- }
- }
-
- return null;
- }
-
- public void receive_dbus_value (DataType type, CCodeExpression message_expr, CCodeExpression
iter_expr, CCodeExpression target_expr, Symbol? sym, CCodeExpression? error_expr = null, out bool may_fail =
null) {
- var fd_list = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_get_unix_fd_list"));
- fd_list.add_argument (message_expr);
-
- var fd_var = new CCodeIdentifier ("_fd");
-
- var stream = create_from_file_descriptor (type, fd_var);
- if (stream != null) {
- var fd_list_var = new CCodeIdentifier ("_fd_list");
-
- var fd = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_get"));
- fd.add_argument (fd_list_var);
- fd.add_argument (new CCodeIdentifier ("_fd_index"));
- fd.add_argument (error_expr);
-
- ccode.add_assignment (fd_list_var, fd_list);
- ccode.open_if (fd_list_var);
-
- var get_fd = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_next"));
- get_fd.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF,
iter_expr));
- get_fd.add_argument (new CCodeConstant ("\"h\""));
- get_fd.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier ("_fd_index")));
- ccode.add_expression (get_fd);
-
- ccode.add_assignment (fd_var, fd);
- ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN_OR_EQUAL,
fd_var, new CCodeConstant ("0")));
-
- ccode.add_assignment (target_expr, stream);
- may_fail = true;
-
- ccode.close ();
-
- ccode.add_else ();
- var set_error = new CCodeFunctionCall (new CCodeIdentifier ("g_set_error_literal"));
- set_error.add_argument (error_expr);
- set_error.add_argument (new CCodeIdentifier ("G_IO_ERROR"));
- set_error.add_argument (new CCodeIdentifier ("G_IO_ERROR_FAILED"));
- set_error.add_argument (new CCodeConstant ("\"FD List is NULL\""));
- ccode.add_expression (set_error);
- ccode.close ();
- } else {
- read_expression (type, iter_expr, target_expr, sym, error_expr, out may_fail);
- }
- }
- CCodeExpression get_method_info (ObjectTypeSymbol sym) {
- var infos = new CCodeInitializerList ();
-
- foreach (Method m in sym.get_methods ()) {
- if (m is CreationMethod || m.binding != MemberBinding.INSTANCE
- || m.overrides || m.access != SymbolAccessibility.PUBLIC) {
- continue;
- }
- if (!is_dbus_visible (m)) {
- continue;
- }
-
- var in_args_info = new CCodeInitializerList ();
- var out_args_info = new CCodeInitializerList ();
-
- foreach (Parameter param in m.get_parameters ()) {
- if (param.variable_type is ObjectType &&
param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
- continue;
- }
- if (param.variable_type is ObjectType &&
param.variable_type.data_type.get_full_name () == "GLib.BusName") {
- continue;
- }
-
- var info = new CCodeInitializerList ();
- info.append (new CCodeConstant ("-1"));
- info.append (new CCodeConstant ("\"%s\"".printf (param.name)));
- info.append (new CCodeConstant ("\"%s\"".printf (get_type_signature
(param.variable_type, param))));
-
- var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" +
get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_" + param.name, info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- if (param.direction == ParameterDirection.IN) {
- in_args_info.append (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_arg_info_" + m.name + "_" + param.name)));
- } else {
- out_args_info.append (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_arg_info_" + m.name + "_" + param.name)));
- }
- }
-
- if (!(m.return_type is VoidType)) {
- var info = new CCodeInitializerList ();
- info.append (new CCodeConstant ("-1"));
- info.append (new CCodeConstant ("\"%s\"".printf (dbus_result_name (m))));
- info.append (new CCodeConstant ("\"%s\"".printf (get_type_signature
(m.return_type, m))));
-
- var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" +
get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_result", info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- out_args_info.append (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_arg_info_" + m.name + "_result")));
- }
-
- in_args_info.append (new CCodeConstant ("NULL"));
- out_args_info.append (new CCodeConstant ("NULL"));
-
- var cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix
(sym) + "dbus_arg_info_" + m.name + "_in[]", in_args_info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix
(sym) + "dbus_arg_info_" + m.name + "_out[]", out_args_info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- var info = new CCodeInitializerList ();
- info.append (new CCodeConstant ("-1"));
- info.append (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (m))));
- info.append (new CCodeCastExpression (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_arg_info_" + m.name + "_in")), "GDBusArgInfo **"));
- info.append (new CCodeCastExpression (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_arg_info_" + m.name + "_out")), "GDBusArgInfo **"));
-
- cdecl = new CCodeDeclaration ("const GDBusMethodInfo");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix
(sym) + "dbus_method_info_" + m.name, info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_method_info_" + m.name)));
- }
-
- infos.append (new CCodeConstant ("NULL"));
-
- var cdecl = new CCodeDeclaration ("const GDBusMethodInfo * const");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_method_info[]", infos));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- return new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_method_info");
- }
-
- CCodeExpression get_signal_info (ObjectTypeSymbol sym) {
- var infos = new CCodeInitializerList ();
-
- foreach (Signal sig in sym.get_signals ()) {
- if (sig.access != SymbolAccessibility.PUBLIC) {
- continue;
- }
- if (!is_dbus_visible (sig)) {
- continue;
- }
-
- var args_info = new CCodeInitializerList ();
-
- foreach (Parameter param in sig.get_parameters ()) {
- var info = new CCodeInitializerList ();
- info.append (new CCodeConstant ("-1"));
- info.append (new CCodeConstant ("\"%s\"".printf (param.name)));
- info.append (new CCodeConstant ("\"%s\"".printf (get_type_signature
(param.variable_type, param))));
-
- var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" +
get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + get_ccode_lower_case_name (sig) + "_" + param.name,
info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF,
new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + get_ccode_lower_case_name
(sig) + "_" + param.name)));
- }
-
- args_info.append (new CCodeConstant ("NULL"));
-
- var cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix
(sym) + "dbus_arg_info_" + get_ccode_lower_case_name (sig) + "[]", args_info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- var info = new CCodeInitializerList ();
- info.append (new CCodeConstant ("-1"));
- info.append (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (sig))));
- info.append (new CCodeCastExpression (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_arg_info_" + get_ccode_lower_case_name (sig))), "GDBusArgInfo **"));
-
- cdecl = new CCodeDeclaration ("const GDBusSignalInfo");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix
(sym) + "dbus_signal_info_" + get_ccode_lower_case_name (sig), info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_signal_info_" + get_ccode_lower_case_name
(sig))));
- }
-
- infos.append (new CCodeConstant ("NULL"));
-
- var cdecl = new CCodeDeclaration ("const GDBusSignalInfo * const");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_signal_info[]", infos));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- return new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_signal_info");
- }
-
- CCodeExpression get_property_info (ObjectTypeSymbol sym) {
- var infos = new CCodeInitializerList ();
-
- foreach (Property prop in sym.get_properties ()) {
- if (prop.binding != MemberBinding.INSTANCE
- || prop.overrides || prop.access != SymbolAccessibility.PUBLIC) {
- continue;
- }
- if (!is_dbus_visible (prop)) {
- continue;
- }
-
- var info = new CCodeInitializerList ();
- info.append (new CCodeConstant ("-1"));
- info.append (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (prop))));
- info.append (new CCodeConstant ("\"%s\"".printf (get_type_signature
(prop.property_type, prop))));
- if (prop.get_accessor != null && prop.set_accessor != null) {
- info.append (new CCodeConstant ("G_DBUS_PROPERTY_INFO_FLAGS_READABLE |
G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE"));
- } else if (prop.get_accessor != null) {
- info.append (new CCodeConstant ("G_DBUS_PROPERTY_INFO_FLAGS_READABLE"));
- } else if (prop.set_accessor != null) {
- info.append (new CCodeConstant ("G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE"));
- } else {
- info.append (new CCodeConstant ("G_DBUS_PROPERTY_INFO_FLAGS_NONE"));
- }
-
- var cdecl = new CCodeDeclaration ("const GDBusPropertyInfo");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix
(sym) + "dbus_property_info_" + prop.name, info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_property_info_" + prop.name)));
- }
-
- infos.append (new CCodeConstant ("NULL"));
-
- var cdecl = new CCodeDeclaration ("const GDBusPropertyInfo * const");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_property_info[]", infos));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
-
- return new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_property_info");
- }
-
- void declare_interface_info (ObjectTypeSymbol sym) {
- var info = new CCodeInitializerList ();
- info.append (new CCodeConstant ("-1"));
- info.append (new CCodeConstant ("\"%s\"".printf (get_dbus_name (sym))));
- info.append (new CCodeCastExpression (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, get_method_info (sym)), "GDBusMethodInfo **"));
- info.append (new CCodeCastExpression (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, get_signal_info (sym)), "GDBusSignalInfo **"));
- info.append (new CCodeCastExpression (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, get_property_info (sym)), "GDBusPropertyInfo **"));
-
- var cdecl = new CCodeDeclaration ("const GDBusInterfaceInfo");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_" + get_ccode_lower_case_prefix (sym) +
"dbus_interface_info", info));
- cdecl.modifiers = CCodeModifiers.STATIC;
- cfile.add_constant_declaration (cdecl);
- }
-
- protected CCodeExpression get_interface_info (ObjectTypeSymbol sym) {
- return new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_interface_info");
- }
-
- public override void visit_class (Class cl) {
- base.visit_class (cl);
-
- visit_object_type_symbol (cl);
- }
-
- public override void visit_interface (Interface iface) {
- base.visit_interface (iface);
-
- visit_object_type_symbol (iface);
- }
-
- void visit_object_type_symbol (ObjectTypeSymbol sym) {
- if (get_dbus_name (sym) == null) {
- return;
- }
-
- declare_interface_info(sym);
- }
}
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index c84fd1812..763864935 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -21,26 +21,6 @@
*/
public class Vala.GDBusServerModule : GDBusClientModule {
- public static bool is_dbus_visible (CodeNode node) {
- var dbus_attribute = node.get_attribute ("DBus");
- if (dbus_attribute != null
- && dbus_attribute.has_argument ("visible")
- && !dbus_attribute.get_bool ("visible")) {
- return false;
- }
-
- return true;
- }
-
- public static string dbus_result_name (Method m) {
- var dbus_name = m.get_attribute_string ("DBus", "result");
- if (dbus_name != null && dbus_name != "") {
- return dbus_name;
- }
-
- return "result";
- }
-
string generate_dbus_signal_wrapper (Signal sig, ObjectTypeSymbol sym, string dbus_iface_name) {
return "_dbus_%s_%s".printf (get_ccode_lower_case_name (sym), get_ccode_lower_case_name
(sig));
}
diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala
index 349f9f5cf..b3f1fa86d 100644
--- a/codegen/valagvariantmodule.vala
+++ b/codegen/valagvariantmodule.vala
@@ -53,19 +53,6 @@ public class Vala.GVariantModule : GAsyncModule {
return symbol.get_attribute_string ("DBus", "signature");
}
- bool get_basic_type_info (string? signature, out BasicTypeInfo basic_type) {
- if (signature != null) {
- foreach (BasicTypeInfo info in basic_types) {
- if (info.signature == signature) {
- basic_type = info;
- return true;
- }
- }
- }
- basic_type = BasicTypeInfo ();
- return false;
- }
-
public static string? get_type_signature (DataType datatype, Symbol? symbol = null) {
if (symbol != null) {
string sig = get_dbus_signature (symbol);
@@ -135,579 +122,4 @@ public class Vala.GVariantModule : GAsyncModule {
return null;
}
}
-
- CCodeExpression? get_array_length (CCodeExpression expr, int dim) {
- var id = expr as CCodeIdentifier;
- var ma = expr as CCodeMemberAccess;
- if (id != null) {
- return new CCodeIdentifier ("%s_length%d".printf (id.name, dim));
- } else if (ma != null) {
- if (ma.is_pointer) {
- return new CCodeMemberAccess.pointer (ma.inner, "%s_length%d".printf
(ma.member_name, dim));
- } else {
- return new CCodeMemberAccess (ma.inner, "%s_length%d".printf (ma.member_name,
dim));
- }
- } else {
- // must be NULL-terminated
- var len_call = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
- len_call.add_argument (expr);
- return len_call;
- }
- }
-
- CCodeExpression? generate_enum_value_from_string (EnumValueType type, CCodeExpression? expr,
CCodeExpression? error_expr) {
- var en = type.type_symbol as Enum;
- var from_string_name = "%s_from_string".printf (get_ccode_lower_case_name (en, null));
-
- var from_string_call = new CCodeFunctionCall (new CCodeIdentifier (from_string_name));
- from_string_call.add_argument (expr);
- from_string_call.add_argument (error_expr != null ? error_expr : new CCodeConstant ("NULL"));
-
- return from_string_call;
- }
-
- CCodeExpression deserialize_basic (BasicTypeInfo basic_type, CCodeExpression variant_expr, bool
transfer = false) {
- var get_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_get_" +
basic_type.type_name));
- get_call.add_argument (variant_expr);
-
- if (basic_type.is_string) {
- if (transfer) {
- get_call.call = new CCodeIdentifier ("g_variant_get_string");
- } else {
- get_call.call = new CCodeIdentifier ("g_variant_dup_string");
- }
- get_call.add_argument (new CCodeConstant ("NULL"));
- }
-
- return get_call;
- }
-
- CCodeExpression deserialize_array (ArrayType array_type, CCodeExpression variant_expr,
CCodeExpression? expr) {
- if (array_type.rank == 1 && get_type_signature (array_type) == "ay") {
- return deserialize_buffer_array (array_type, variant_expr, expr);
- }
-
- string temp_name = "_tmp%d_".printf (next_temp_var_id++);
-
- var new_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new"));
- new_call.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
- // add one extra element for NULL-termination
- new_call.add_argument (new CCodeConstant ("5"));
-
- ccode.add_declaration (get_ccode_name (array_type), new CCodeVariableDeclarator (temp_name,
new_call));
- ccode.add_declaration ("int", new CCodeVariableDeclarator (temp_name + "_length", new
CCodeConstant ("0")));
- ccode.add_declaration ("int", new CCodeVariableDeclarator (temp_name + "_size", new
CCodeConstant ("4")));
-
- deserialize_array_dim (array_type, 1, temp_name, variant_expr, expr);
-
- if (array_type.element_type.is_reference_type_or_type_parameter ()) {
- // NULL terminate array
- var length = new CCodeIdentifier (temp_name + "_length");
- var element_access = new CCodeElementAccess (new CCodeIdentifier (temp_name), length);
- ccode.add_assignment (element_access, new CCodeIdentifier ("NULL"));
- }
-
- return new CCodeIdentifier (temp_name);
- }
-
- void deserialize_array_dim (ArrayType array_type, int dim, string temp_name, CCodeExpression
variant_expr, CCodeExpression? expr) {
- string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
- string element_name = "_tmp%d_".printf (next_temp_var_id++);
-
- ccode.add_declaration ("int", new CCodeVariableDeclarator ("%s_length%d".printf (temp_name,
dim), new CCodeConstant ("0")));
- ccode.add_declaration ("GVariantIter", new CCodeVariableDeclarator (subiter_name));
- ccode.add_declaration ("GVariant*", new CCodeVariableDeclarator (element_name));
-
- var iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_init"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (subiter_name)));
- iter_call.add_argument (variant_expr);
- ccode.add_expression (iter_call);
-
- iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_next_value"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (subiter_name)));
-
- var cforcond = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeAssignment
(new CCodeIdentifier (element_name), iter_call), new CCodeConstant ("NULL"));
- var cforiter = new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new
CCodeIdentifier ("%s_length%d".printf (temp_name, dim)));
- ccode.open_for (null, cforcond, cforiter);
-
- if (dim < array_type.rank) {
- deserialize_array_dim (array_type, dim + 1, temp_name, new CCodeIdentifier
(element_name), expr);
- } else {
- var size_check = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new
CCodeIdentifier (temp_name + "_size"), new CCodeIdentifier (temp_name + "_length"));
-
- ccode.open_if (size_check);
-
- // tmp_size = (2 * tmp_size);
- var new_size = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant
("2"), new CCodeIdentifier (temp_name + "_size"));
- ccode.add_assignment (new CCodeIdentifier (temp_name + "_size"), new_size);
-
- var renew_call = new CCodeFunctionCall (new CCodeIdentifier ("g_renew"));
- renew_call.add_argument (new CCodeIdentifier (get_ccode_name
(array_type.element_type)));
- renew_call.add_argument (new CCodeIdentifier (temp_name));
- // add one extra element for NULL-termination
- renew_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new
CCodeIdentifier (temp_name + "_size"), new CCodeConstant ("1")));
- ccode.add_assignment (new CCodeIdentifier (temp_name), renew_call);
-
- ccode.close ();
-
- var element_access = new CCodeElementAccess (new CCodeIdentifier (temp_name), new
CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier (temp_name + "_length")));
- var element_expr = deserialize_expression (array_type.element_type, new
CCodeIdentifier (element_name), null);
- ccode.add_assignment (element_access, element_expr);
- }
-
- var unref = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_unref"));
- unref.add_argument (new CCodeIdentifier (element_name));
- ccode.add_expression (unref);
-
- ccode.close ();
-
- if (expr != null) {
- ccode.add_assignment (get_array_length (expr, dim), new CCodeIdentifier
("%s_length%d".printf (temp_name, dim)));
- }
- }
-
- CCodeExpression deserialize_buffer_array (ArrayType array_type, CCodeExpression variant_expr,
CCodeExpression? expr) {
- string temp_name = "_tmp%d_".printf (next_temp_var_id++);
-
- var get_data_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_get_data"));
- get_data_call.add_argument (variant_expr);
-
- var get_size_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_get_size"));
- get_size_call.add_argument (variant_expr);
- ccode.add_declaration ("gsize", new CCodeVariableDeclarator (temp_name + "_length",
get_size_call));
- var length = new CCodeIdentifier (temp_name + "_length");
-
- var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup"));
- dup_call.add_argument (get_data_call);
- dup_call.add_argument (length);
-
- ccode.add_declaration (get_ccode_name (array_type), new CCodeVariableDeclarator (temp_name,
dup_call));
- if (expr != null) {
- ccode.add_assignment (get_array_length (expr, 1), length);
- }
-
- return new CCodeIdentifier (temp_name);
- }
-
- CCodeExpression? deserialize_struct (Struct st, CCodeExpression variant_expr) {
- string temp_name = "_tmp%d_".printf (next_temp_var_id++);
- string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
-
- ccode.add_declaration (get_ccode_name (st), new CCodeVariableDeclarator (temp_name));
- ccode.add_declaration ("GVariantIter", new CCodeVariableDeclarator (subiter_name));
-
- var iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_init"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (subiter_name)));
- iter_call.add_argument (variant_expr);
- ccode.add_expression (iter_call);
-
- bool field_found = false;;
-
- foreach (Field f in st.get_fields ()) {
- if (f.binding != MemberBinding.INSTANCE) {
- continue;
- }
-
- field_found = true;
-
- read_expression (f.variable_type, new CCodeIdentifier (subiter_name), new
CCodeMemberAccess (new CCodeIdentifier (temp_name), get_ccode_name (f)), f);
- }
-
- if (!field_found) {
- return null;
- }
-
- return new CCodeIdentifier (temp_name);
- }
-
- CCodeExpression? deserialize_hash_table (ObjectType type, CCodeExpression variant_expr) {
- string temp_name = "_tmp%d_".printf (next_temp_var_id++);
- string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
- string key_name = "_tmp%d_".printf (next_temp_var_id++);
- string value_name = "_tmp%d_".printf (next_temp_var_id++);
-
- var type_args = type.get_type_arguments ();
- assert (type_args.size == 2);
- var key_type = type_args.get (0);
- var value_type = type_args.get (1);
-
- ccode.add_declaration ("GHashTable*", new CCodeVariableDeclarator (temp_name));
- ccode.add_declaration ("GVariantIter", new CCodeVariableDeclarator (subiter_name));
- ccode.add_declaration ("GVariant*", new CCodeVariableDeclarator (key_name));
- ccode.add_declaration ("GVariant*", new CCodeVariableDeclarator (value_name));
-
- var hash_table_new = new CCodeFunctionCall (new CCodeIdentifier ("g_hash_table_new_full"));
- if (key_type.data_type.is_subtype_of (string_type.data_type)) {
- hash_table_new.add_argument (new CCodeIdentifier ("g_str_hash"));
- hash_table_new.add_argument (new CCodeIdentifier ("g_str_equal"));
- } else if (key_type.data_type == gvariant_type) {
- hash_table_new.add_argument (new CCodeIdentifier ("g_variant_hash"));
- hash_table_new.add_argument (new CCodeIdentifier ("g_variant_equal"));
- } else {
- hash_table_new.add_argument (new CCodeIdentifier ("g_direct_hash"));
- hash_table_new.add_argument (new CCodeIdentifier ("g_direct_equal"));
- }
-
- if (key_type.data_type.is_subtype_of (string_type.data_type)) {
- hash_table_new.add_argument (new CCodeIdentifier ("g_free"));
- } else if (key_type.data_type == gvariant_type) {
- hash_table_new.add_argument (new CCodeCastExpression (new CCodeIdentifier
("g_variant_unref"), "GDestroyNotify"));
- } else if (key_type.data_type.get_full_name () == "GLib.HashTable") {
- hash_table_new.add_argument (new CCodeCastExpression (new CCodeIdentifier
("g_hash_table_unref"), "GDestroyNotify"));
- } else {
- hash_table_new.add_argument (new CCodeIdentifier ("NULL"));
- }
-
- if (value_type.data_type.is_subtype_of (string_type.data_type)) {
- hash_table_new.add_argument (new CCodeIdentifier ("g_free"));
- } else if (value_type.data_type == gvariant_type) {
- hash_table_new.add_argument (new CCodeCastExpression (new CCodeIdentifier
("g_variant_unref"), "GDestroyNotify"));
- } else if (value_type.data_type.get_full_name () == "GLib.HashTable") {
- hash_table_new.add_argument (new CCodeCastExpression (new CCodeIdentifier
("g_hash_table_unref"), "GDestroyNotify"));
- } else {
- hash_table_new.add_argument (new CCodeIdentifier ("NULL"));
- }
- ccode.add_assignment (new CCodeIdentifier (temp_name), hash_table_new);
-
- var iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_init"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (subiter_name)));
- iter_call.add_argument (variant_expr);
- ccode.add_expression (iter_call);
-
- iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_loop"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (subiter_name)));
- iter_call.add_argument (new CCodeConstant ("\"{?*}\""));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (key_name)));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (value_name)));
-
- ccode.open_while (iter_call);
-
- var key_expr = deserialize_expression (key_type, new CCodeIdentifier (key_name), null);
- var value_expr = deserialize_expression (value_type, new CCodeIdentifier (value_name), null);
- if (key_expr == null || value_expr == null) {
- return null;
- }
-
- var hash_table_insert = new CCodeFunctionCall (new CCodeIdentifier ("g_hash_table_insert"));
- hash_table_insert.add_argument (new CCodeIdentifier (temp_name));
- hash_table_insert.add_argument (convert_to_generic_pointer (key_expr, key_type));
- hash_table_insert.add_argument (convert_to_generic_pointer (value_expr, value_type));
- ccode.add_expression (hash_table_insert);
-
- ccode.close ();
-
- return new CCodeIdentifier (temp_name);
- }
-
- public override CCodeExpression? deserialize_expression (DataType type, CCodeExpression variant_expr,
CCodeExpression? expr, CCodeExpression? error_expr = null, out bool may_fail = null) {
- BasicTypeInfo basic_type;
- CCodeExpression result = null;
- may_fail = false;
- if (is_string_marshalled_enum (type.data_type)) {
- get_basic_type_info ("s", out basic_type);
- result = deserialize_basic (basic_type, variant_expr, true);
- result = generate_enum_value_from_string (type as EnumValueType, result, error_expr);
- may_fail = true;
- } else if (get_basic_type_info (get_type_signature (type), out basic_type)) {
- result = deserialize_basic (basic_type, variant_expr);
- } else if (type is ArrayType) {
- result = deserialize_array ((ArrayType) type, variant_expr, expr);
- } else if (type.data_type is Struct) {
- var st = (Struct) type.data_type;
- result = deserialize_struct (st, variant_expr);
- if (result != null && type.nullable) {
- var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
- csizeof.add_argument (new CCodeIdentifier (get_ccode_name (st)));
- var cdup = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup"));
- cdup.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF,
result));
- cdup.add_argument (csizeof);
- result = cdup;
- }
- } else if (type is ObjectType) {
- if (type.data_type.get_full_name () == "GLib.Variant") {
- var variant_get = new CCodeFunctionCall (new CCodeIdentifier
("g_variant_get_variant"));
- variant_get.add_argument (variant_expr);
- result = variant_get;
- } else if (type.data_type.get_full_name () == "GLib.HashTable") {
- result = deserialize_hash_table ((ObjectType) type, variant_expr);
- }
- }
-
- if (result == null) {
- Report.error (type.source_reference, "GVariant deserialization of type `%s' is not
supported".printf (type.to_string ()));
- }
-
- return result;
- }
-
- public void read_expression (DataType type, CCodeExpression iter_expr, CCodeExpression target_expr,
Symbol? sym, CCodeExpression? error_expr = null, out bool may_fail = null) {
- var iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_next_value"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, iter_expr));
-
- if (sym != null && get_dbus_signature (sym) != null) {
- // raw GVariant
- ccode.add_assignment (target_expr, iter_call);
- may_fail = false;
- return;
- }
-
- string temp_name = "_tmp%d_".printf (next_temp_var_id++);
-
- ccode.add_declaration ("GVariant*", new CCodeVariableDeclarator (temp_name));
-
- var variant_expr = new CCodeIdentifier (temp_name);
-
- ccode.add_assignment (variant_expr, iter_call);
-
- var result = deserialize_expression (type, variant_expr, target_expr, error_expr, out
may_fail);
- if (result == null) {
- // error already reported
- return;
- }
-
- ccode.add_assignment (target_expr, result);
-
- var unref = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_unref"));
- unref.add_argument (variant_expr);
- ccode.add_expression (unref);
- }
-
- CCodeExpression? generate_enum_value_to_string (EnumValueType type, CCodeExpression? expr) {
- var en = type.type_symbol as Enum;
- var to_string_name = "%s_to_string".printf (get_ccode_lower_case_name (en, null));
-
- var to_string_call = new CCodeFunctionCall (new CCodeIdentifier (to_string_name));
- to_string_call.add_argument (expr);
-
- return to_string_call;
- }
-
- CCodeExpression? serialize_basic (BasicTypeInfo basic_type, CCodeExpression expr) {
- var new_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_new_" +
basic_type.type_name));
- new_call.add_argument (expr);
- return new_call;
- }
-
- CCodeExpression? serialize_array (ArrayType array_type, CCodeExpression array_expr) {
- if (array_type.rank == 1 && get_type_signature (array_type) == "ay") {
- return serialize_buffer_array (array_type, array_expr);
- }
-
- string array_iter_name = "_tmp%d_".printf (next_temp_var_id++);
-
- ccode.add_declaration (get_ccode_name (array_type), new CCodeVariableDeclarator
(array_iter_name));
- ccode.add_assignment (new CCodeIdentifier (array_iter_name), array_expr);
-
- return serialize_array_dim (array_type, 1, array_expr, new CCodeIdentifier (array_iter_name));
- }
-
- CCodeExpression? serialize_array_dim (ArrayType array_type, int dim, CCodeExpression array_expr,
CCodeExpression array_iter_expr) {
- string builder_name = "_tmp%d_".printf (next_temp_var_id++);
- string index_name = "_tmp%d_".printf (next_temp_var_id++);
-
- ccode.add_declaration ("GVariantBuilder", new CCodeVariableDeclarator (builder_name));
- ccode.add_declaration ("int", new CCodeVariableDeclarator (index_name));
-
- var gvariant_type = new CCodeFunctionCall (new CCodeIdentifier ("G_VARIANT_TYPE"));
- ArrayType array_type_copy = (ArrayType) array_type.copy ();
- array_type_copy.rank -= dim - 1;
- gvariant_type.add_argument (new CCodeConstant ("\"%s\"".printf (get_type_signature
(array_type_copy))));
-
- var builder_init = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_init"));
- builder_init.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (builder_name)));
- builder_init.add_argument (gvariant_type);
- ccode.add_expression (builder_init);
-
- var cforinit = new CCodeAssignment (new CCodeIdentifier (index_name), new CCodeConstant
("0"));
- var cforcond = new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier
(index_name), get_array_length (array_expr, dim));
- var cforiter = new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new
CCodeIdentifier (index_name));
- ccode.open_for (cforinit, cforcond, cforiter);
-
- CCodeExpression element_variant;
- if (dim < array_type.rank) {
- element_variant = serialize_array_dim (array_type, dim + 1, array_expr,
array_iter_expr);
- } else {
- var element_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION,
array_iter_expr);
- element_variant = serialize_expression (array_type.element_type, element_expr);
- }
-
- var builder_add = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_add_value"));
- builder_add.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (builder_name)));
- builder_add.add_argument (element_variant);
- ccode.add_expression (builder_add);
-
- if (dim == array_type.rank) {
- var array_iter_incr = new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT,
array_iter_expr);
- ccode.add_expression (array_iter_incr);
- }
-
- ccode.close ();
-
- var builder_end = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_end"));
- builder_end.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (builder_name)));
- return builder_end;
- }
-
- CCodeExpression serialize_buffer_array (ArrayType array_type, CCodeExpression array_expr) {
- string buffer_name = "_tmp%d_".printf (next_temp_var_id++);
-
- var gvariant_type = new CCodeFunctionCall (new CCodeIdentifier ("G_VARIANT_TYPE"));
- gvariant_type.add_argument (new CCodeConstant ("\"%s\"".printf (get_type_signature
(array_type))));
-
- var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup"));
- dup_call.add_argument (array_expr);
- dup_call.add_argument (get_array_length (array_expr, 1));
- ccode.add_declaration (get_ccode_name (array_type), new CCodeVariableDeclarator (buffer_name,
dup_call));
-
- var new_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_new_from_data"));
- new_call.add_argument (gvariant_type);
- new_call.add_argument (new CCodeIdentifier (buffer_name));
- new_call.add_argument (get_array_length (array_expr, 1));
- new_call.add_argument (new CCodeConstant ("TRUE"));
- new_call.add_argument (new CCodeIdentifier ("g_free"));
- new_call.add_argument (new CCodeIdentifier (buffer_name));
-
- return new_call;
- }
-
- CCodeExpression? serialize_struct (Struct st, CCodeExpression struct_expr) {
- string builder_name = "_tmp%d_".printf (next_temp_var_id++);
-
- ccode.add_declaration ("GVariantBuilder", new CCodeVariableDeclarator (builder_name));
-
- var iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_init"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (builder_name)));
- iter_call.add_argument (new CCodeIdentifier ("G_VARIANT_TYPE_TUPLE"));
- ccode.add_expression (iter_call);
-
- bool field_found = false;;
-
- foreach (Field f in st.get_fields ()) {
- if (f.binding != MemberBinding.INSTANCE) {
- continue;
- }
-
- field_found = true;
-
- write_expression (f.variable_type, new CCodeIdentifier (builder_name), new
CCodeMemberAccess (struct_expr, get_ccode_name (f)), f);
- }
-
- if (!field_found) {
- return null;
- }
-
- var builder_end = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_end"));
- builder_end.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (builder_name)));
- return builder_end;
- }
-
- CCodeExpression? serialize_hash_table (ObjectType type, CCodeExpression hash_table_expr) {
- string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
- string tableiter_name = "_tmp%d_".printf (next_temp_var_id++);
- string key_name = "_tmp%d_".printf (next_temp_var_id++);
- string value_name = "_tmp%d_".printf (next_temp_var_id++);
-
- var type_args = type.get_type_arguments ();
- assert (type_args.size == 2);
- var key_type = type_args.get (0);
- var value_type = type_args.get (1);
-
- ccode.add_declaration ("GVariantBuilder", new CCodeVariableDeclarator (subiter_name));
- ccode.add_declaration ("GHashTableIter", new CCodeVariableDeclarator (tableiter_name));
- ccode.add_declaration ("gpointer", new CCodeVariableDeclarator (key_name));
- ccode.add_declaration ("gpointer", new CCodeVariableDeclarator (value_name));
-
- var iter_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_hash_table_iter_init"));
- iter_init_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (tableiter_name)));
- iter_init_call.add_argument (hash_table_expr);
- ccode.add_expression (iter_init_call);
-
- var gvariant_type = new CCodeFunctionCall (new CCodeIdentifier ("G_VARIANT_TYPE"));
- gvariant_type.add_argument (new CCodeConstant ("\"%s\"".printf (get_type_signature (type))));
-
- var iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_init"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (subiter_name)));
- iter_call.add_argument (gvariant_type);
- ccode.add_expression (iter_call);
-
- var iter_next_call = new CCodeFunctionCall (new CCodeIdentifier ("g_hash_table_iter_next"));
- iter_next_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (tableiter_name)));
- iter_next_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (key_name)));
- iter_next_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (value_name)));
-
- ccode.open_while (iter_next_call);
-
- ccode.add_declaration (get_ccode_name (key_type), new CCodeVariableDeclarator ("_key"));
- ccode.add_declaration (get_ccode_name (value_type), new CCodeVariableDeclarator ("_value"));
-
- ccode.add_assignment (new CCodeIdentifier ("_key"), convert_from_generic_pointer (new
CCodeIdentifier (key_name), key_type));
- ccode.add_assignment (new CCodeIdentifier ("_value"), convert_from_generic_pointer (new
CCodeIdentifier (value_name), value_type));
-
- var serialized_key = serialize_expression (key_type, new CCodeIdentifier ("_key"));
- var serialized_value = serialize_expression (value_type, new CCodeIdentifier ("_value"));
- if (serialized_key == null || serialized_value == null) {
- return null;
- }
-
- iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_add"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (subiter_name)));
- iter_call.add_argument (new CCodeConstant ("\"{?*}\""));
- iter_call.add_argument (serialized_key);
- iter_call.add_argument (serialized_value);
- ccode.add_expression (iter_call);
-
- ccode.close ();
-
- iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_end"));
- iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new
CCodeIdentifier (subiter_name)));
- return iter_call;
- }
-
- public override CCodeExpression? serialize_expression (DataType type, CCodeExpression expr) {
- BasicTypeInfo basic_type;
- CCodeExpression result = null;
- if (is_string_marshalled_enum (type.data_type)) {
- get_basic_type_info ("s", out basic_type);
- result = generate_enum_value_to_string (type as EnumValueType, expr);
- result = serialize_basic (basic_type, result);
- } else if (get_basic_type_info (get_type_signature (type), out basic_type)) {
- result = serialize_basic (basic_type, expr);
- } else if (type is ArrayType) {
- result = serialize_array ((ArrayType) type, expr);
- } else if (type.data_type is Struct) {
- var st_expr = expr;
- if (type.nullable) {
- st_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION,
st_expr);
- }
- result = serialize_struct ((Struct) type.data_type, st_expr);
- } else if (type is ObjectType) {
- if (type.data_type.get_full_name () == "GLib.Variant") {
- var variant_new = new CCodeFunctionCall (new CCodeIdentifier
("g_variant_new_variant"));
- variant_new.add_argument (expr);
- result = variant_new;
- } else if (type.data_type.get_full_name () == "GLib.HashTable") {
- result = serialize_hash_table ((ObjectType) type, expr);
- }
- }
-
- if (result == null) {
- Report.error (type.source_reference, "GVariant serialization of type `%s' is not
supported".printf (type.to_string ()));
- }
-
- return result;
- }
-
- public void write_expression (DataType type, CCodeExpression builder_expr, CCodeExpression expr,
Symbol? sym) {
- var variant_expr = expr;
- if (sym == null || get_dbus_signature (sym) == null) {
- // perform boxing
- variant_expr = serialize_expression (type, expr);
- }
- if (variant_expr != null) {
- var builder_add = new CCodeFunctionCall (new CCodeIdentifier
("g_variant_builder_add_value"));
- builder_add.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF,
builder_expr));
- builder_add.add_argument (variant_expr);
- ccode.add_expression (builder_add);
- }
- }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]