]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Move DataType.get_type_signature to D-Bus modules
authorJürg Billeter <j@bitron.ch>
Mon, 8 Feb 2010 07:07:26 +0000 (08:07 +0100)
committerJürg Billeter <j@bitron.ch>
Mon, 8 Feb 2010 07:07:26 +0000 (08:07 +0100)
Fixes bug 607558.

codegen/valadbusclientmodule.vala
codegen/valadbusmodule.vala
vala/valaarraytype.vala
vala/valaclass.vala
vala/valadatatype.vala
vala/valaenum.vala
vala/valastruct.vala
vala/valatypesymbol.vala

index 0f8e765097771a827dcd5f957be90fe7c701b841..f869206342598b0fc99e0ec7d921a17c8c8b1868 100644 (file)
@@ -1,6 +1,6 @@
 /* valadbusclientmodule.vala
  *
- * Copyright (C) 2007-2009  Jürg Billeter
+ * Copyright (C) 2007-2010  Jürg Billeter
 *  Copyright (C) 2008  Philip Van Hoof
  *
  * This library is free software; you can redistribute it and/or
@@ -2276,7 +2276,7 @@ internal class Vala.DBusClientModule : DBusModule {
                iter_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_message_iter_open_container"));
                iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_iter")));
                iter_call.add_argument (new CCodeIdentifier ("DBUS_TYPE_VARIANT"));
-               iter_call.add_argument (new CCodeConstant ("\"%s\"".printf (prop.property_type.get_type_signature ())));
+               iter_call.add_argument (new CCodeConstant ("\"%s\"".printf (get_type_signature (prop.property_type))));
                iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_subiter")));
                prefragment.append (new CCodeExpressionStatement (iter_call));
 
index 2ceca5fbcd3e2707337a45f422bc742484b490bf..8325aa6984fdd44c1377ee81eebaf68a6d7da9ce 100644 (file)
@@ -1,6 +1,6 @@
 /* valadbusmodule.vala
  *
- * Copyright (C) 2008-2009  Jürg Billeter
+ * Copyright (C) 2008-2010  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -98,11 +98,63 @@ internal class Vala.DBusModule : GAsyncModule {
                return false;
        }
 
-       public static string get_type_signature (DataType datatype) {
-               if (is_string_marshalled_enum (datatype.data_type)) {
+       public static string? get_type_signature (DataType datatype) {
+               var array_type = datatype as ArrayType;
+
+               if (array_type != null) {
+                       string element_type_signature = get_type_signature (array_type.element_type);
+
+                       if (element_type_signature == null) {
+                               return null;
+                       }
+
+                       return string.nfill (array_type.rank, 'a') + element_type_signature;
+               } else if (is_string_marshalled_enum (datatype.data_type)) {
                        return "s";
+               } else if (datatype.data_type != null) {
+                       string sig = null;
+
+                       var ccode = datatype.data_type.get_attribute ("CCode");
+                       if (ccode != null) {
+                               sig = ccode.get_string ("type_signature");
+                       }
+
+                       var st = datatype.data_type as Struct;
+                       var en = datatype.data_type as Enum;
+                       if (sig == null && st != null) {
+                               var str = new StringBuilder ();
+                               str.append_c ('(');
+                               foreach (Field f in st.get_fields ()) {
+                                       if (f.binding == MemberBinding.INSTANCE) {
+                                               str.append (get_type_signature (f.field_type));
+                                       }
+                               }
+                               str.append_c (')');
+                               sig = str.str;
+                       } else if (sig == null && en != null) {
+                               if (en.is_flags) {
+                                       return "u";
+                               } else {
+                                       return "i";
+                               }
+                       }
+
+                       var type_args = datatype.get_type_arguments ();
+                       if (sig != null && sig.str ("%s") != null && type_args.size > 0) {
+                               string element_sig = "";
+                               foreach (DataType type_arg in type_args) {
+                                       var s = get_type_signature (type_arg);
+                                       if (s != null) {
+                                               element_sig += s;
+                                       }
+                               }
+
+                               sig = sig.printf (element_sig);
+                       }
+
+                       return sig;
                } else {
-                       return datatype.get_type_signature ();
+                       return null;
                }
        }
 
index da81400b74fa30fca954bca6db52764fb4264f75..2ed20f227baaa63b6a6232d48d56f04c86ae3fa9 100644 (file)
@@ -207,16 +207,6 @@ public class Vala.ArrayType : ReferenceType {
                return true;
        }
 
-       public override string? get_type_signature () {
-               string element_type_signature = element_type.get_type_signature ();
-
-               if (element_type_signature == null) {
-                       return null;
-               }
-
-               return string.nfill (rank, 'a') + element_type_signature;
-       }
-
        public override void accept_children (CodeVisitor visitor) {
                element_type.accept (visitor);
        }
index aee77433dc5e7188c5056826f7d2b8d1cb1eb621..18564b319c84394983c513c20085568484f7af32 100644 (file)
@@ -123,7 +123,6 @@ public class Vala.Class : ObjectTypeSymbol {
        private string marshaller_type_name;
        private string get_value_function;
        private string set_value_function;
-       private string? type_signature;
        private bool _is_compact;
        private bool _is_immutable;
 
@@ -596,10 +595,6 @@ public class Vala.Class : ObjectTypeSymbol {
                return get_lower_case_cname (infix).up ();
        }
 
-       public override string? get_type_signature () {
-               return type_signature;
-       }
-
        public override bool is_reference_type () {
                return true;
        }
@@ -654,9 +649,6 @@ public class Vala.Class : ObjectTypeSymbol {
                                add_cheader_filename (filename);
                        }
                }
-               if (a.has_argument ("type_signature")) {
-                       type_signature = a.get_string ("type_signature");
-               }
                if (a.has_argument ("type_check_function")) {
                        type_check_function = a.get_string ("type_check_function");
                }
index 7e6cb64c425292511117ba12cf27bd58be329d33..bba74622febae972de3a8f56cfaf81ac8c1d067e 100644 (file)
@@ -473,32 +473,6 @@ public abstract class Vala.DataType : CodeNode {
                }
        }
 
-       /**
-        * Returns type signature as used for GVariant and D-Bus.
-        */
-       public virtual string? get_type_signature () {
-               if (data_type != null) {
-                       string sig = data_type.get_type_signature ();
-
-                       var type_args = get_type_arguments ();
-                       if (sig != null && sig.str ("%s") != null && type_args.size > 0) {
-                               string element_sig = "";
-                               foreach (DataType type_arg in type_args) {
-                                       var s = type_arg.get_type_signature ();
-                                       if (s != null) {
-                                               element_sig += s;
-                                       }
-                               }
-
-                               sig = sig.printf (element_sig);
-                       }
-
-                       return sig;
-               } else {
-                       return null;
-               }
-       }
-
        /**
         * Returns whether the value needs to be disposed, i.e. whether
         * allocated memory or other resources need to be released when
index 471a1832d353e32f5a148901d6b1ec7cdf3325ea..7c6391c54770975f4aa73ed6ffda72289771dd80 100644 (file)
@@ -283,14 +283,6 @@ public class Vala.Enum : TypeSymbol {
                return "0";
        }
 
-       public override string? get_type_signature () {
-               if (is_flags) {
-                       return "u";
-               } else {
-                       return "i";
-               }
-       }
-
        public override bool check (SemanticAnalyzer analyzer) {
                if (checked) {
                        return !error;
index 63b8b8542476e0c8d8b7fd41a94e00a4ea7ab6db..6ce33ccc1b026a6aa15383962674202a15fedf59 100644 (file)
@@ -46,7 +46,6 @@ public class Vala.Struct : TypeSymbol {
        private string get_value_function;
        private string set_value_function;
        private string default_value = null;
-       private string? type_signature;
        private string copy_function;
        private string destroy_function;
 
@@ -334,21 +333,6 @@ public class Vala.Struct : TypeSymbol {
                return get_lower_case_cname (infix).up ();
        }
 
-       public override string? get_type_signature () {
-               if (type_signature == null) {
-                       var str = new StringBuilder ();
-                       str.append_c ('(');
-                       foreach (Field f in fields) {
-                               if (f.binding == MemberBinding.INSTANCE) {
-                                       str.append (f.field_type.get_type_signature ());
-                               }
-                       }
-                       str.append_c (')');
-                       return str.str;
-               }
-               return type_signature;
-       }
-
        /**
         * Returns whether this is a boolean type.
         *
@@ -443,9 +427,6 @@ public class Vala.Struct : TypeSymbol {
                if (a.has_argument ("default_value")) {
                        set_default_value (a.get_string ("default_value"));
                }
-               if (a.has_argument ("type_signature")) {
-                       type_signature = a.get_string ("type_signature");
-               }
                if (a.has_argument ("copy_function")) {
                        set_copy_function (a.get_string ("copy_function"));
                }
index b3fd075d942b8545fbaac9c73bc2bb531b93ea50..2614f8af9ebaeeea26b081454ffd6a219b0782b8 100644 (file)
@@ -262,11 +262,4 @@ public abstract class Vala.TypeSymbol : Symbol {
        public virtual int get_type_parameter_index (string name) {
                return -1;
        }
-
-       /**
-        * Returns type signature as used for GVariant and D-Bus
-        */
-       public virtual string? get_type_signature () {
-               return null;
-       }
 }