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 Vala.CodeContext context;
43 public ValaSource(JsRender.JsRender file) {
47 context = new Vala.CodeContext ();
48 Vala.CodeContext.push (context);
50 context.experimental = false;
51 context.experimental_non_null = false;
52 context.vapi_directories = { "/usr/share/vala-0.24/vapi" };
53 context.report.enable_warnings = true;
54 context.metadata_directories = { };
55 context.gir_directories = {};
56 context.report = new ValaSourceReport();
58 context.basedir = Posix.realpath (".");
60 context.directory = context.basedir;
63 // add default packages:
64 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
65 context.profile = Vala.Profile.GOBJECT;
66 // context.add_define ("GOBJECT");
68 //add_depencies (context, settings.packages);
69 //if (reporter.errors > 0) {
73 var source_file = new Vala.SourceFile (
75 Vala.SourceFileType.SOURCE,
77 NodeToVala.mungeFile(file)
79 //context.add_source_file (testcode);
82 // source_file = new Vala.SourceFile (context,
83 // Vala.SourceFileType.SOURCE,
84 // "/home/alan/gitlive/app.Builder.js/tests/TreeBuilder.vala");
86 //if (source_package == null) {
87 //source_package = register_package (new Package (settings.pkg_name, false, null));
90 //register_source_file (source_package, source_file);
92 context.add_external_package ("glib-2.0");
93 context.add_external_package ("gobject-2.0");
94 context.add_external_package ("libvala-0.24");
95 //context.add_external_package ("posix");
96 //if (context.profile == Vala.Profile.GOBJECT) {
97 // import the GLib namespace by default (namespace of backend-specific standard library)
98 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
99 source_file.add_using_directive (ns_ref);
100 context.root.add_using_directive (ns_ref);
103 context.add_source_file (source_file);
106 //add_documented_files (context, settings.source_files);
108 Vala.Parser parser = new Vala.Parser ();
109 parser.parse (context);
110 //gir_parser.parse (context);
111 if (context.report.get_errors () > 0) {
112 print("parse got errors");
113 Vala.CodeContext.pop (context);
121 if (context.report.get_errors () > 0) {
122 print("check got errors");
123 Vala.CodeContext.pop (context);
126 Vala.CodeContext.pop (context);
137 int main (string[] args) {
139 var a = new ValaSource(file);
140 a.create_valac_tree();