[vala/wip/dbusgen] added support for dbus extensions



commit 3629bbd775b395b87ec39348e9eca6b199c2022b
Author: Chris Daley <chebizarro gmail com>
Date:   Fri Nov 24 17:36:16 2017 -0800

    added support for dbus extensions

 dbusgen/Makefile.am               |    1 +
 dbusgen/valadbusgen.vala          |   18 ++++++++-----
 dbusgen/valadbusgenextension.vala |   30 +++++++++++++++++++++
 dbusgen/valadbusparser.vala       |   51 ++++++++-----------------------------
 4 files changed, 53 insertions(+), 47 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 67bd977..c98e6e9 100644
--- a/dbusgen/valadbusgen.vala
+++ b/dbusgen/valadbusgen.vala
@@ -137,14 +137,18 @@ public class Vala.DBusGen {
                                        source_file.explicit = true;
                                        context.add_source_file (source_file);
                                } else if (FileUtils.test (source, FileTest.IS_DIR)) {
-                                       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);
+                                       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 {
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 62895ec..1af9465 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; }
@@ -353,48 +355,18 @@ public class Vala.DBusParser : CodeVisitor {
 
        private void parse_extension () {
 
-               Report.warning (get_current_src (), "Element %s is unrecognized".printf (reader.name));
-
-               skip_element ();
-
-               return;
-
-               stdout.printf ("%s\n", reader.name);
-               stdout.flush ();
-               next ();
-               next ();
-               return;
+               string prefix = reader.name.split (":")[0];
+               DBusExtension? ext = extensions.get (prefix);
                
-               while (current_token == MarkupTokenType.START_ELEMENT) {
-                       switch (reader.name) {
-                               case "interface":
-                                       parse_interface ();
-                                       break;
-                               case "annotation":
-                                       parse_annotation ();
-                                       break;
-                               case "method":
-                                       parse_method ();
-                                       break;
-                               case "arg":
-                                       parse_arg ();
-                                       break;
-                               case "signal":
-                                       parse_signal ();
-                                       break;
-                               case "property":
-                                       parse_property ();
-                                       break;
-                               case "doc:doc":
-                                       parse_doc ();
-                                       break;
-                               default:
-                                       parse_extension ();
-                                       break;
-                       }
+               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 () {
@@ -407,7 +379,6 @@ public class Vala.DBusParser : CodeVisitor {
                        next ();
                        
                        if (current_token == MarkupTokenType.TEXT) {
-                               SourceReference source = get_current_src ();
                                foreach (string line in reader.content.split ("\n")) {
                                        comment += " * %s \n".printf (line.strip ());
                                }


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