[vala/wip/dbusgen: 60/60] WIP dbusgen: Add namespace options



commit 4048454071e9e877b0967a69781967908e46dc0f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Sep 20 10:57:10 2018 +0200

    WIP dbusgen: Add namespace options

 dbusgen/valadbusgen.vala               | 14 ++++++++++++--
 dbusgen/valadbusnamespacestrategy.vala |  1 +
 dbusgen/valadbusparser.vala            |  2 +-
 dbusgen/valadbusvariantmodule.vala     |  2 ++
 4 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/dbusgen/valadbusgen.vala b/dbusgen/valadbusgen.vala
index 034556537..4bb726de2 100644
--- a/dbusgen/valadbusgen.vala
+++ b/dbusgen/valadbusgen.vala
@@ -29,7 +29,7 @@ public class Vala.DBusGen {
        public class ConcatenationStrategy : NamespaceStrategy {
 
                public override string? get_namespace (string ns) {
-                       return null;
+                       return root_name;
                }
 
                public override string get_name (string ns) {
@@ -59,6 +59,11 @@ public class Vala.DBusGen {
        static string[] packages;
        static bool nostdpkg;
        static int dbus_timeout = 120000;
+       static string root_namespace;
+       [CCode (array_length = false, array_null_terminated = true)]
+       static string[] rename_namespaces;
+       [CCode (array_length = false, array_null_terminated = true)]
+       static string[] strip_namespaces;
 
        CodeContext context;
 
@@ -68,6 +73,9 @@ public class Vala.DBusGen {
                { "pkg", 0, 0, OptionArg.STRING_ARRAY, ref packages, "Include binding for PACKAGE", 
"PACKAGE..." },
                { "directory", 'd', 0, OptionArg.FILENAME, ref directory, "Output directory", "DIRECTORY" },
                { "disable-warnings", 0, 0, OptionArg.NONE, ref disable_warnings, "Disable warnings", null },
+               { "namespace", 'n', 0, OptionArg.STRING, ref root_namespace, "Name of the parent namespace", 
null },
+               { "rename-namespace", 0, 0, OptionArg.STRING_ARRAY, ref rename_namespaces, "Namespace to 
rename to", "SOURCE_NS:TARGET_NS..." },
+               { "strip-namespace", 0, 0, OptionArg.STRING_ARRAY, ref strip_namespaces, "Namespace to 
strip", "NAMESPACE..." },
                { "dbus-timeout", 0, 0, OptionArg.INT, ref dbus_timeout, "DBus timeout", null },
                { "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null },
                { "quiet", 'q', 0, OptionArg.NONE, ref quiet_mode, "Do not print messages to the console", 
null },
@@ -162,7 +170,9 @@ public class Vala.DBusGen {
 
                var parser = new DBusParser ();
                parser.dbus_timeout = dbus_timeout;
-               parser.namespace_strategy = new ConcatenationStrategy ();
+               parser.namespace_strategy = new ConcatenationStrategy () {
+                       root_name = root_namespace
+               };
                parser.parse (context);
 
                if (context.report.get_errors () > 0) {
diff --git a/dbusgen/valadbusnamespacestrategy.vala b/dbusgen/valadbusnamespacestrategy.vala
index 3c95f1b6e..fc85d9ec9 100644
--- a/dbusgen/valadbusnamespacestrategy.vala
+++ b/dbusgen/valadbusnamespacestrategy.vala
@@ -21,6 +21,7 @@
  */
 
 public abstract class Vala.NamespaceStrategy {
+       public string root_name { get; set; }
 
        public abstract string? get_namespace (string ns);
 
diff --git a/dbusgen/valadbusparser.vala b/dbusgen/valadbusparser.vala
index a6775daa0..56cc75033 100644
--- a/dbusgen/valadbusparser.vala
+++ b/dbusgen/valadbusparser.vala
@@ -127,7 +127,7 @@ public class Vala.DBusParser : CodeVisitor {
                }
 
                string? ns_name = namespace_strategy.get_namespace (name);
-               if (ns_name != null) {
+               if (ns_name != null && current_ns.name != ns_name) {
                        var ns = new Namespace (ns_name, get_current_src ());
                        current_ns.add_namespace (ns);
                        current_ns = ns;
diff --git a/dbusgen/valadbusvariantmodule.vala b/dbusgen/valadbusvariantmodule.vala
index fdb57f7c2..c9931c59a 100644
--- a/dbusgen/valadbusvariantmodule.vala
+++ b/dbusgen/valadbusvariantmodule.vala
@@ -183,6 +183,8 @@ public class Vala.DBusVariantModule {
                        return string_array_type.copy ();
                } else if (type.equal (VariantType.OBJECT_PATH_ARRAY)) {
                        return string_array_type.copy ();
+               } else if (type.equal (VariantType.TUPLE)) {
+                       
                }
 
                Report.warning (null, "Unresolved type: %s".printf ((string) type.peek_string ()));


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