[vala/wip/dbusgen: 138/152] added support for dbus extensions
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/dbusgen: 138/152] added support for dbus extensions
- Date: Mon, 4 Feb 2019 09:12:47 +0000 (UTC)
commit 97d1339b8163f0e2db5e0404cdf39f2eb3ca8f18
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 | 26 +++++++++++++++++++++-----
4 files changed, 73 insertions(+), 9 deletions(-)
---
diff --git a/dbusgen/Makefile.am b/dbusgen/Makefile.am
index d5175eb80..584396a40 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 ad81d9027..327543afd 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.from_commandline = 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.from_commandline = 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 000000000..3d1268fbb
--- /dev/null
+++ b/dbusgen/valadbusgenextension.vala
@@ -0,0 +1,30 @@
+/* valadbusgenextension.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 9a1890dba..0def2b17b 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":
@@ -342,6 +344,8 @@ public class Vala.DBusParser : CodeVisitor {
parse_annotation ();
} else if (reader.name == "doc:doc") {
parse_doc ();
+ } else {
+ parse_extension ();
}
}
@@ -349,7 +353,18 @@ 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 +377,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 +388,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]