[vala/wip/printer: 2/2] WIP Printer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/printer: 2/2] WIP Printer
- Date: Thu, 9 Apr 2020 18:35:59 +0000 (UTC)
commit 291e3984cacadd73922bb019f7c3441a2d771bba
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Apr 9 20:35:23 2020 +0200
WIP Printer
configure.ac | 1 +
vala/Makefile.am | 4 ++
vala/tests/Makefile.am | 51 +++++++++++++++++++++++++
vala/tests/testprinter.vala | 90 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 146 insertions(+)
---
diff --git a/configure.ac b/configure.ac
index d9f6eb06e..6a6e3edc7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -220,6 +220,7 @@ AC_CONFIG_FILES([Makefile
gee/Makefile
ccode/Makefile
vala/Makefile
+ vala/tests/Makefile
codegen/Makefile
compiler/Makefile
vapi/Makefile
diff --git a/vala/Makefile.am b/vala/Makefile.am
index 78e4c9390..27d313b14 100644
--- a/vala/Makefile.am
+++ b/vala/Makefile.am
@@ -2,6 +2,10 @@ include $(top_srcdir)/Makefile.common
NULL =
+SUBDIRS = \
+ tests \
+ $(NULL)
+
AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\"vala\" \
$(COVERAGE_CFLAGS) \
diff --git a/vala/tests/Makefile.am b/vala/tests/Makefile.am
new file mode 100644
index 000000000..efb498ecd
--- /dev/null
+++ b/vala/tests/Makefile.am
@@ -0,0 +1,51 @@
+include $(top_srcdir)/Makefile.common
+
+NULL =
+
+AM_CPPFLAGS = \
+ -DG_LOG_DOMAIN=\"printer\" \
+ $(COVERAGE_CFLAGS) \
+ -I$(top_srcdir)/gee \
+ -I$(top_srcdir)/vala \
+ $(GLIB_CFLAGS) \
+ -DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
+ $(NULL)
+
+BUILT_SOURCES = printer.vala.stamp
+
+noinst_PROGRAMS = \
+ printer \
+ $(NULL)
+
+printer_VALASOURCES = \
+ testprinter.vala \
+ $(NULL)
+
+printer_SOURCES = \
+ printer.vala.stamp \
+ $(printer_VALASOURCES:.vala=.c) \
+ $(NULL)
+
+printer.vala.stamp: $(printer_VALASOURCES)
+ $(VALA_V)$(VALAC) \
+ $(COVERAGE_VALAFLAGS) \
+ $(VALAFLAGS) \
+ -C \
+ --vapidir $(top_srcdir)/vapi --pkg gobject-2.0 \
+ --vapidir $(top_srcdir)/gee --pkg gee \
+ --vapidir $(top_srcdir)/vala --pkg vala \
+ --pkg config \
+ $^
+ @touch $@
+
+printer_LDADD = \
+ $(COVERAGE_LIBS) \
+ $(GLIB_LIBS) \
+ $(top_builddir)/vala/libvala@PACKAGE_SUFFIX@.la \
+ $(NULL)
+
+EXTRA_DIST = $(printer_VALASOURCES) printer.vala.stamp
+
+MAINTAINERCLEANFILES = \
+ $(printer_VALASOURCES:.vala=.c) \
+ $(NULL)
diff --git a/vala/tests/testprinter.vala b/vala/tests/testprinter.vala
new file mode 100644
index 000000000..b0ded3cba
--- /dev/null
+++ b/vala/tests/testprinter.vala
@@ -0,0 +1,90 @@
+/* testprinter.vala
+ *
+ * Copyright (C) 2020 Rico Tzschichholz
+ *
+ * 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:
+ * Rico Tzschichholz <ricotz ubuntu com>
+ */
+
+class Sink : Vala.Report {
+ public override void note (Vala.SourceReference? source, string message) {
+ }
+
+ public override void depr (Vala.SourceReference? source, string message) {
+ }
+
+ public override void warn (Vala.SourceReference? source, string message) {
+ }
+
+ public override void err (Vala.SourceReference? source, string message) {
+ }
+}
+
+[CCode (array_length = false, array_null_terminated = true)]
+static string[] filenames;
+
+const OptionEntry[] options = {
+ { OPTION_REMAINING, 0, 0, OptionArg.FILENAME_ARRAY, ref filenames, "Input source file", "FILE" },
+ { null }
+};
+
+int main (string[] args) {
+ try {
+ var opt_context = new OptionContext ();
+ opt_context.add_main_entries (options, null);
+ opt_context.parse (ref args);
+ } catch (OptionError e) {
+ return 1;
+ }
+
+ if (filenames.length != 1) {
+ return 1;
+ }
+
+ string filename = filenames[0];
+
+ var context = new Vala.CodeContext ();
+ context.set_target_profile (Vala.Profile.GOBJECT);
+ context.keep_going = true;
+ context.report = new Sink ();
+
+ Vala.CodeContext.push (context);
+
+ context.add_source_filename (filename);
+
+ var vala_parser = new Vala.Parser ();
+ vala_parser.parse (context);
+ //context.check ();
+
+ unowned Vala.SourceReference src = context.get_source_file (filename).first;
+ while (true) {
+ {
+ stdout.printf ("%s | %s | %s\n", src.begin.to_string (), src.end.to_string (),
src.node.type_name);
+ }
+ if (src.next == null) {
+ if (src != context.get_source_file (filename).last) {
+ return 1;
+ }
+ break;
+ }
+ src = src.next;
+ }
+
+ Vala.CodeContext.pop ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]