]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
WIP Printer
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 9 Apr 2020 18:35:23 +0000 (20:35 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 9 Apr 2020 18:35:23 +0000 (20:35 +0200)
configure.ac
vala/Makefile.am
vala/tests/Makefile.am [new file with mode: 0644]
vala/tests/testprinter.vala [new file with mode: 0644]

index d9f6eb06e10ad29a9f811e280a79c64fec481bf2..6a6e3edc76e866a59a0fb15ce366d08a66786979 100644 (file)
@@ -220,6 +220,7 @@ AC_CONFIG_FILES([Makefile
            gee/Makefile
            ccode/Makefile
            vala/Makefile
+           vala/tests/Makefile
            codegen/Makefile
            compiler/Makefile
            vapi/Makefile
index 78e4c93909e7b23f166b9174ff780bffca153c51..27d313b144bd62df43edae67def60a90e6462dc6 100644 (file)
@@ -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 (file)
index 0000000..efb498e
--- /dev/null
@@ -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 (file)
index 0000000..b0ded3c
--- /dev/null
@@ -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;
+}