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()
16 this.line_errors = new Gee.HashMap<int,string> ();
19 public override void err (Vala.SourceReference? source, string message) {
23 //stderr.printf ("My error: %s\n", message);
25 if (source.file != "~~~~~testfile.vala") {
29 if (line_errors.has_key(source.begin.line)) {
30 pre = line_errors.get(source.begin.line) + "\n";
33 line_errors.set(source.begin.line, pre + message);
39 public class ValaSource : Vala.CodeVisitor {
41 public Vala.CodeContext check (JsRender.Gtk file) {
46 var context = new Vala.CodeContext ();
47 Vala.CodeContext.push (context);
49 context.experimental = false;
50 context.experimental_non_null = false;
51 context.vapi_directories = { "/usr/share/vala-0.24/vapi" };
52 context.report.enable_warnings = true;
53 context.metadata_directories = { };
54 context.gir_directories = {};
55 context.report = new ValaSourceReport();
57 context.basedir = Posix.realpath (".");
59 context.directory = context.basedir;
62 // add default packages:
63 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
64 context.profile = Vala.Profile.GOBJECT;
65 // context.add_define ("GOBJECT");
67 //add_depencies (context, settings.packages);
68 //if (reporter.errors > 0) {
72 var source_file = new Vala.SourceFile (
74 Vala.SourceFileType.SOURCE,
78 //context.add_source_file (testcode);
81 // source_file = new Vala.SourceFile (context,
82 // Vala.SourceFileType.SOURCE,
83 // "/home/alan/gitlive/app.Builder.js/tests/TreeBuilder.vala");
85 //if (source_package == null) {
86 //source_package = register_package (new Package (settings.pkg_name, false, null));
89 //register_source_file (source_package, source_file);
91 context.add_external_package ("glib-2.0");
92 context.add_external_package ("gobject-2.0");
93 context.add_external_package ("libvala-0.24");
94 //context.add_external_package ("posix");
95 //if (context.profile == Vala.Profile.GOBJECT) {
96 // import the GLib namespace by default (namespace of backend-specific standard library)
97 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
98 source_file.add_using_directive (ns_ref);
99 context.root.add_using_directive (ns_ref);
102 context.add_source_file (source_file);
105 //add_documented_files (context, settings.source_files);
107 Vala.Parser parser = new Vala.Parser ();
108 parser.parse (context);
109 //gir_parser.parse (context);
110 if (context.report.get_errors () > 0) {
119 if (context.report.get_errors () > 0) {
120 print("check got errors");
132 int main (string[] args) {
134 var a = new TreeBuilder();
135 a.create_valac_tree();