3 // valac VapiParser.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
10 public class VapiParser : Vala.CodeVisitor {
12 Vala.CodeContext context;
19 public void checkString(string contents)
22 context = new Vala.CodeContext ();
23 Vala.CodeContext.push (context);
25 context.experimental = false;
26 context.experimental_non_null = false;
38 for (int i = 2; i <= ver; i += 2) {
39 context.add_define ("VALA_0_%d".printf (i));
43 //var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
44 // what's the current version of vala???
47 //vapidirs += Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
49 //for(var i =0 ; i < vapidirs.length; i++) {
50 // valac += " --vapidir=" + vapidirs[i];
54 // or context.get_vapi_path("glib-2.0"); // should return path..
55 //context.vapi_directories = vapidirs;
56 context.report.enable_warnings = true;
57 context.metadata_directories = { };
58 context.gir_directories = {};
59 context.thread = true;
62 this.report = new ValaSourceReport(this.file);
63 context.report = this.report;
66 context.basedir = "/tmp"; //Posix.realpath (".");
68 context.directory = context.basedir;
71 // add default packages:
72 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
73 context.profile = Vala.Profile.GOBJECT;
75 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
76 context.root.add_using_directive (ns_ref);
78 var source_file = new Vala.SourceFile (
80 Vala.SourceFileType.SOURCE,
84 source_file.add_using_directive (ns_ref);
85 context.add_source_file (source_file);
87 // add all the files (except the current one) - this.file.path
88 var pr = ((Project.Gtk)this.file.project);
89 if (this.file.build_module.length > 0) {
90 var cg = pr.compilegroups.get(this.file.build_module);
91 for (var i = 0; i < cg.sources.size; i++) {
92 var path = pr.resolve_path(
93 pr.resolve_path_combine_path(pr.firstPath(),cg.sources.get(i)));
95 if (!FileUtils.test(path, FileTest.EXISTS)) {
99 if (path == this.file.path.replace(".bjs", ".vala")) {
103 if (FileUtils.test(path, FileTest.IS_DIR)) {
106 //print("Add source file %s\n", path);
110 if (Regex.match_simple("\\.c$", path)) {
111 context.add_c_source_file(path);
116 var xsf = new Vala.SourceFile (
118 Vala.SourceFileType.SOURCE,
121 xsf.add_using_directive (ns_ref);
122 context.add_source_file(xsf);
126 // default.. packages..
127 context.add_external_package ("glib-2.0");
128 context.add_external_package ("gobject-2.0");
129 // user defined ones..
131 var dcg = pr.compilegroups.get("_default_");
132 for (var i = 0; i < dcg.packages.size; i++) {
133 valac += " --pkg " + dcg.packages.get(i);
134 context.add_external_package (dcg.packages.get(i));
137 //Vala.Config.PACKAGE_SUFFIX.substring (1)
139 // add the modules...
143 //context.add_external_package ("libvala-0.24");
145 this.report.compile_notice("START", "", 0, "");
148 //add_documented_files (context, settings.source_files);
150 Vala.Parser parser = new Vala.Parser ();
151 parser.parse (context);
152 //gir_parser.parse (context);
153 if (context.report.get_errors () > 0) {
154 print("parse got errors");
155 ((ValaSourceReport)context.report).dump();
157 Vala.CodeContext.pop ();
158 this.report.compile_notice("END", "", 0, "");
159 return this.report.line_errors;
166 if (context.report.get_errors () > 0) {
167 print("check got errors");
168 ((ValaSourceReport)context.report).dump();
169 Vala.CodeContext.pop ();
170 this.report.compile_notice("END", "", 0, "");
171 return this.report.line_errors;
175 context.codegen = new Vala.GDBusServerModule ();
178 context.output = "/tmp/testbuild";
179 valac += " -o " +context.output;
180 context.codegen.emit (context);
182 var ccompiler = new Vala.CCodeCompiler ();
183 var cc_command = Environment.get_variable ("CC");
184 var pkg_config_command = Environment.get_variable ("PKG_CONFIG");
186 ccompiler.compile (context, cc_command, new string[] { }, pkg_config_command);
188 ccompiler.compile (context, cc_command, new string[] { });
192 Vala.CodeContext.pop ();
193 this.report.compile_notice("END", "", 0, "");
194 print("%s\n", valac);
196 return this.report.line_errors;
205 int main (string[] args) {
207 var a = new ValaSource(file);
208 a.create_valac_tree();