[vala/wip/dbusgen: 12/15] added support for dbus extensions



commit 0bc10467a0934d5587d8b6f53aa37bf130f8c0d7
Author: Chris Daley <chebizarro gmail com>
Date:   Fri Nov 24 17:19:22 2017 -0800

    added support for dbus extensions

 dbusgen/Makefile.am               |    1 +
 dbusgen/valadbusgen.vala          |   25 +++++++++++++++++++++----
 dbusgen/valadbusgenextension.vala |   30 ++++++++++++++++++++++++++++++
 dbusgen/valadbusparser.vala       |   28 +++++++++++++++++++++++-----
 4 files changed, 75 insertions(+), 9 deletions(-)
---
diff --git a/dbusgen/Makefile.am b/dbusgen/Makefile.am
index d5175eb..584396a 100644
--- a/dbusgen/Makefile.am
+++ b/dbusgen/Makefile.am
@@ -19,6 +19,7 @@ valadbusgen_VALASOURCES = \
        valadbusparser.vala \
        valadbusvariantmodule.vala \
        valadbusnamespacestrategy.vala \
+       valadbusgenextension.vala \
        $(NULL)
 
 valadbusgen_SOURCES = \
diff --git a/dbusgen/valadbusgen.vala b/dbusgen/valadbusgen.vala
index 93cf463..c98e6e9 100644
--- a/dbusgen/valadbusgen.vala
+++ b/dbusgen/valadbusgen.vala
@@ -110,6 +110,7 @@ public class Vala.DBusGen {
 
                context.add_external_package ("glib-2.0");
                context.add_external_package ("gobject-2.0");
+               context.add_external_package ("gio-2.0");
 
                if (packages != null) {
                        foreach (string package in packages) {
@@ -130,10 +131,26 @@ public class Vala.DBusGen {
                }
 
                foreach (string source in sources) {
-                       if (FileUtils.test (source, FileTest.EXISTS) && source.has_suffix (".xml")) {
-                               var source_file = new SourceFile (context, SourceFileType.SOURCE, source);
-                               source_file.explicit = true;
-                               context.add_source_file (source_file);
+                       if (FileUtils.test (source, FileTest.EXISTS)) {
+                               if (source.has_suffix (".xml")) {
+                                       var source_file = new SourceFile (context, SourceFileType.SOURCE, 
source);
+                                       source_file.explicit = true;
+                                       context.add_source_file (source_file);
+                               } else if (FileUtils.test (source, FileTest.IS_DIR)) {
+                                       try {
+                                               GLib.Dir dir = GLib.Dir.open(source);
+                                               string name;
+                                               while ((name = dir.read_name()) != null) {
+                                                       if (name.has_suffix(".xml")) {
+                                                               var source_file = new SourceFile (context, 
SourceFileType.SOURCE, Path.build_filename(source, name));
+                                                               source_file.explicit = true;
+                                                               context.add_source_file (source_file);
+                                                       }
+                                               }
+                                       } catch (FileError e) {
+                                               Report.error (null, e.message);
+                                       }
+                               }
                        } else {
                                Report.error (null, "%s not found".printf (source));
                        }
diff --git a/dbusgen/valadbusgenextension.vala b/dbusgen/valadbusgenextension.vala
new file mode 100644
index 0000000..afd7e85
--- /dev/null
+++ b/dbusgen/valadbusgenextension.vala
@@ -0,0 +1,30 @@
+/* valadbusnamespacestrategy.vala
+ *
+ * Copyright (C) 2017 Chris Daley
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Chris Daley <chebizarro gmail com>
+ */
+
+public abstract class Vala.DBusExtension {
+
+       public string prefix { get; set; }
+
+       public abstract void parse_node (string decl, CodeNode node, SourceReference reference);
+       
+       public abstract void parse_attribute (CodeNode node, SourceReference reference);
+}
diff --git a/dbusgen/valadbusparser.vala b/dbusgen/valadbusparser.vala
index 4848d77..8b0268e 100644
--- a/dbusgen/valadbusparser.vala
+++ b/dbusgen/valadbusparser.vala
@@ -47,6 +47,8 @@ public class Vala.DBusParser : CodeVisitor {
        private SourceLocation begin;
        private SourceLocation end;
 
+       private HashMap<string, DBusExtension> extensions = new HashMap<string, DBusExtension> ();
+
        public int dbus_timeout { get; set; }
 
        public NamespaceStrategy namespace_strategy { get; set; }
@@ -200,7 +202,7 @@ public class Vala.DBusParser : CodeVisitor {
                                break;
                        case "org.freedesktop.DBus.GLib.Async":
                                if (current_node is Method) {
-                                       ((Method) current_method).is_async_callback = true;
+                                       ((Method) current_method).coroutine = true;
                                }
                                break;
                        case "org.freedesktop.DBus.GLib.NoReply":
@@ -243,6 +245,7 @@ public class Vala.DBusParser : CodeVisitor {
                current_param_index = 0U;
 
                while (current_token == MarkupTokenType.START_ELEMENT) {
+                                               
                        switch (reader.name) {
                                case "annotation":
                                        parse_annotation ();
@@ -342,6 +345,8 @@ public class Vala.DBusParser : CodeVisitor {
                                parse_annotation ();
                        } else if (reader.name == "doc:doc") {
                                parse_doc ();
+                       } else {
+                               parse_extension ();
                        }
                }
 
@@ -349,7 +354,19 @@ public class Vala.DBusParser : CodeVisitor {
        }
 
        private void parse_extension () {
-               next ();
+
+               string prefix = reader.name.split (":")[0];
+               DBusExtension? ext = extensions.get (prefix);
+               
+               if (ext != null) {
+                       ext.parse_node (reader.name, current_node, get_current_src ());
+                       next ();
+               } else {
+                       Report.warning (get_current_src (), "Element %s is unrecognized".printf 
(reader.name));
+                       skip_element ();
+               }
+
+               return;
        }
 
        private void parse_doc () {
@@ -362,8 +379,9 @@ public class Vala.DBusParser : CodeVisitor {
                        next ();
                        
                        if (current_token == MarkupTokenType.TEXT) {
-                               SourceReference source = get_current_src ();
-                               comment += source.file.get_source_line (source.begin.line).strip ();
+                               foreach (string line in reader.content.split ("\n")) {
+                                       comment += " * %s \n".printf (line.strip ());
+                               }
                        }
                        
                        if (current_token == MarkupTokenType.END_ELEMENT && reader.name == "doc:doc") {
@@ -372,7 +390,7 @@ public class Vala.DBusParser : CodeVisitor {
                }
 
                if (comment.length > 0) {
-                       comment = "*\n * %s\n*".printf (comment);
+                       comment = "*\n%s*".printf (comment);
                        Comment doc = new Comment (comment, start_loc);
                        Symbol node = current_node as Symbol;
                        if (node != null) {


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