2 // valac TreeBuilder.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
9 public class TestCompiler : Vala.CodeVisitor {
11 Vala.CodeContext context;
14 public TestCompiler(string file) {
20 public void dumpCode(string str) {
21 var ls = str.split("\n");
22 for (var i=0;i < ls.length; i++) {
23 print("%d : %s\n", i+1, ls[i]);
30 public Gee.HashMap<int,string> checkString( )
33 var valac = "valac " ;
35 context = new Vala.CodeContext ();
36 Vala.CodeContext.push (context);
38 context.experimental = false;
39 context.experimental_non_null = false;
51 for (int i = 2; i <= ver; i += 2) {
52 context.add_define ("VALA_0_%d".printf (i));
63 // or context.get_vapi_path("glib-2.0"); // should return path..
64 //context.vapi_directories = vapidirs;
65 context.report.enable_warnings = true;
66 context.metadata_directories = { };
67 context.gir_directories = {};
68 context.thread = true;
71 this.report = new ValaSourceReport(this.file);
72 context.report = this.report;
75 context.basedir = "/tmp"; //Posix.realpath (".");
77 context.directory = context.basedir;
80 // add default packages:
81 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
82 context.profile = Vala.Profile.GOBJECT;
84 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
85 context.root.add_using_directive (ns_ref);
87 var source_file = new Vala.SourceFile (
89 Vala.SourceFileType.SOURCE,
92 source_file.add_using_directive (ns_ref);
93 context.add_source_file (source_file);
95 // add all the files (except the current one) - this.file.path
97 // default.. packages..
98 context.add_external_package ("glib-2.0");
99 context.add_external_package ("gobject-2.0");
100 context.add_external_package ("gtk+-3.0");
101 if (!context.add_external_package ("webkit2gtk-4.0")) {
102 context.add_external_package ("webkit2gtk-3.0");
104 context.add_external_package ("clutter-gtk-1.0");
105 context.add_external_package ("gdl-3.0");
106 context.add_external_package ("gtksourceview-3.0");
107 context.add_external_package ("libvala-0.26");
108 // user defined ones..
110 var dcg = pr.compilegroups.get("_default_");
111 for (var i = 0; i < dcg.packages.size; i++) {
112 valac += " --pkg " + dcg.packages.get(i);
113 context.add_external_package (dcg.packages.get(i));
116 //Vala.Config.PACKAGE_SUFFIX.substring (1)
118 // add the modules...
122 //context.add_external_package ("libvala-0.24");
124 this.report.compile_notice("START", "", 0, "");
127 //add_documented_files (context, settings.source_files);
129 Vala.Parser parser = new Vala.Parser ();
130 parser.parse (context);
131 //gir_parser.parse (context);
132 if (context.report.get_errors () > 0) {
133 print("parse got errors");
134 ((ValaSourceReport)context.report).dump();
136 Vala.CodeContext.pop ();
137 this.report.compile_notice("END", "", 0, "");
138 return this.report.line_errors;
145 if (context.report.get_errors () > 0) {
146 print("check got errors");
147 ((ValaSourceReport)context.report).dump();
148 Vala.CodeContext.pop ();
149 this.report.compile_notice("END", "", 0, "");
150 return this.report.line_errors;
154 //context.codegen = new Vala.GDBusServerModule ();
157 context.output = "/tmp/testbuild";
158 valac += " -o " +context.output;
159 //context.codegen.emit (context);
161 var ccompiler = new Vala.CCodeCompiler ();
162 var cc_command = Environment.get_variable ("CC");
163 var pkg_config_command = Environment.get_variable ("PKG_CONFIG");
165 ccompiler.compile (context, cc_command, new string[] { }, pkg_config_command);
167 ccompiler.compile (context, cc_command, new string[] { });
171 Vala.CodeContext.pop ();
172 //(new Vala.CodeNode()).get_error_types().clear();
173 //(new Vala.NullType()).get_type_arguments().clear();
174 (new Vala.NullType(null)).get_type_arguments().clear();
176 this.report.compile_notice("END", "", 0, "");
177 print("%s\n", valac);
179 return this.report.line_errors;
188 int main (string[] args) {
190 var a = new ValaSource(file);
191 a.create_valac_tree();