[vala/wip/dbusgen: 146/152] dbusgen: Add DBus signature attribute if type is not supported yet



commit 13abed071218beb59e5ced5fdc0414b9e8641dc3
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Sep 19 19:13:18 2018 +0200

    dbusgen: Add DBus signature attribute if type is not supported yet

 dbusgen/valadbusparser.vala        | 18 ++++++++++++++++++
 dbusgen/valadbusvariantmodule.vala | 24 +++++++++++++++++-------
 2 files changed, 35 insertions(+), 7 deletions(-)
---
diff --git a/dbusgen/valadbusparser.vala b/dbusgen/valadbusparser.vala
index b6dd359f1..6d38d99ad 100644
--- a/dbusgen/valadbusparser.vala
+++ b/dbusgen/valadbusparser.vala
@@ -349,7 +349,12 @@ public class Vala.DBusParser : CodeVisitor {
                        return;
                }
 
+               var needs_signature = false;
                var data_type = dbus_module.get_dbus_type (type);
+               if (data_type == null) {
+                       data_type = dbus_module.gvariant_type.copy ();
+                       needs_signature = true;
+               }
 
                PropertyAccessor get_access = null;
                PropertyAccessor set_access = null;
@@ -371,6 +376,10 @@ public class Vala.DBusParser : CodeVisitor {
                current_property.access = SymbolAccessibility.PUBLIC;
                current_iface.add_property (current_property);
 
+               if (needs_signature) {
+                       current_node.set_attribute_string ("DBus", "signature", type);
+               }
+
                next ();
 
                while (current_token == MarkupTokenType.START_ELEMENT) {
@@ -398,12 +407,21 @@ public class Vala.DBusParser : CodeVisitor {
                        return;
                }
 
+               var needs_signature = false;
                var data_type = dbus_module.get_dbus_type (type);
+               if (data_type == null) {
+                       data_type = dbus_module.gvariant_type.copy ();
+                       needs_signature = true;
+               }
                data_type.value_owned = false;
 
                current_node = current_param = new Parameter (name, data_type, get_current_src ());
                current_method.add_parameter (current_param);
 
+               if (needs_signature) {
+                       current_node.set_attribute_string ("DBus", "signature", type);
+               }
+
                if (current_method is Method) {
                        string? direction = reader.get_attribute ("direction");
                        if (direction == "out") {
diff --git a/dbusgen/valadbusvariantmodule.vala b/dbusgen/valadbusvariantmodule.vala
index df69a2c15..fdb57f7c2 100644
--- a/dbusgen/valadbusvariantmodule.vala
+++ b/dbusgen/valadbusvariantmodule.vala
@@ -120,7 +120,7 @@ public class Vala.DBusVariantModule {
                }
        }
 
-       private DataType get_variant_type (VariantType type) {
+       private DataType? get_variant_type (VariantType type) {
                if (type.is_basic ()) {
                        if (type.equal (VariantType.BOOLEAN)) {
                                return bool_type.copy ();
@@ -155,16 +155,26 @@ public class Vala.DBusVariantModule {
                return get_complex_type (type);
        }
 
-       private DataType get_complex_type (VariantType type) {
+       private DataType? get_complex_type (VariantType type) {
                if (type.is_array ()) {
                        var element = type.element ();
                        if (element.equal (VariantType.DICTIONARY) || element.is_dict_entry ()) {
                                var res = dictionary_type.copy ();
-                               res.add_type_argument (get_variant_type (element.key ()));
-                               res.add_type_argument (get_variant_type (element.value ()));
-                               return res;
+                               var key = get_variant_type (element.key ());
+                               var value = get_variant_type (element.value ());
+                               if (key != null && value != null) {
+                                       res.add_type_argument (key);
+                                       res.add_type_argument (value);
+                                       return res;
+                               }
+                       } else {
+                               var element_type = get_variant_type (element);
+                               if (element != null && !(element_type is ArrayType)) {
+                                       var array = new ArrayType (element_type, 1, null);
+                                       array.value_owned = true;
+                                       return array;
+                               }
                        }
-                       return new ArrayType (get_variant_type (element), 1, null);
                } else if (type.equal (VariantType.BYTESTRING)) {
                        return string_type.copy (); //new ArrayType (uchar_type.copy (), 1, null);
                } else if (type.equal (VariantType.BYTESTRING_ARRAY)) {
@@ -177,7 +187,7 @@ public class Vala.DBusVariantModule {
 
                Report.warning (null, "Unresolved type: %s".printf ((string) type.peek_string ()));
 
-               return gvariant_type.copy ();
+               return null;
 
                if (type.equal (VariantType.DICT_ENTRY) || type.is_dict_entry ()) {
                        return dictionary_type.copy ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]