[vala/wip/dbusgen: 313/329] added support for dbus extensions
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/dbusgen: 313/329] added support for dbus extensions
- Date: Fri, 3 Jun 2022 17:49:57 +0000 (UTC)
commit 256ef92c8cdee187675c84f1029bc8e0a06ba2c1
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 | 26 ++++++++++++++++++++++----
dbusgen/valadbusgenextension.vala | 30 ++++++++++++++++++++++++++++++
dbusgen/valadbusparser.vala | 26 +++++++++++++++++++++-----
4 files changed, 74 insertions(+), 9 deletions(-)
---
diff --git a/dbusgen/Makefile.am b/dbusgen/Makefile.am
index 70a37511e..e511ace5c 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 33205bb47..f0ceb2bc1 100644
--- a/dbusgen/valadbusgen.vala
+++ b/dbusgen/valadbusgen.vala
@@ -100,6 +100,8 @@ public class Vala.DBusGen {
context.set_target_profile (Profile.GOBJECT);
context.vapi_comments = true;
+ context.add_external_package ("gio-2.0");
+
if (packages != null) {
foreach (string package in packages) {
context.add_external_package (package);
@@ -119,10 +121,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]