2 // valac TreeBuilder.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
6 public class ValaSourceReport : Vala.Report {
11 Gee.HashMap<int,string> line_errors;
13 public ValaSourceReport()
15 this.line_errors = new Gee.HashMap<int,string> ();
18 public override void err (Vala.SourceReference? source, string message) {
22 //stderr.printf ("My error: %s\n", message);
24 if (source.file != "~~~~~testfile.vala") {
28 if (line_errors.has_key(source.begin.line)) {
29 pre = line_errors.get(source.begin.line) + "\n";
32 line_errors.set(source.begin.line, pre + message);
38 public class ValaSource : Vala.CodeVisitor {
40 public Vala.CodeContext check (JsRender.Gtk file) {
45 var context = new Vala.CodeContext ();
46 Vala.CodeContext.push (context);
48 context.experimental = false;
49 context.experimental_non_null = false;
50 context.vapi_directories = { "/usr/share/vala-0.24/vapi" };
51 context.report.enable_warnings = true;
52 context.metadata_directories = { };
53 context.gir_directories = {};
54 context.report = new ValaSourceReport();
56 context.basedir = Posix.realpath (".");
58 context.directory = context.basedir;
61 // add default packages:
62 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
63 context.profile = Vala.Profile.GOBJECT;
64 // context.add_define ("GOBJECT");
66 //add_depencies (context, settings.packages);
67 //if (reporter.errors > 0) {
71 var source_file = new Vala.SourceFile (
73 Vala.SourceFileType.SOURCE,
77 //context.add_source_file (testcode);
80 // source_file = new Vala.SourceFile (context,
81 // Vala.SourceFileType.SOURCE,
82 // "/home/alan/gitlive/app.Builder.js/tests/TreeBuilder.vala");
84 //if (source_package == null) {
85 //source_package = register_package (new Package (settings.pkg_name, false, null));
88 //register_source_file (source_package, source_file);
90 context.add_external_package ("glib-2.0");
91 context.add_external_package ("gobject-2.0");
92 context.add_external_package ("libvala-0.24");
93 //context.add_external_package ("posix");
94 //if (context.profile == Vala.Profile.GOBJECT) {
95 // import the GLib namespace by default (namespace of backend-specific standard library)
96 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
97 source_file.add_using_directive (ns_ref);
98 context.root.add_using_directive (ns_ref);
101 context.add_source_file (source_file);
104 //add_documented_files (context, settings.source_files);
106 Vala.Parser parser = new Vala.Parser ();
107 parser.parse (context);
108 //gir_parser.parse (context);
109 if (context.report.get_errors () > 0) {
118 if (context.report.get_errors () > 0) {
119 print("check got errors");
131 int main (string[] args) {
133 var a = new TreeBuilder();
134 a.create_valac_tree();