X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=tests%2FTestCompiler.vala;h=7c23d11d61279900ba2557040dd2cc2d3fdcfdc6;hb=6f6e6ab99d47d1211e8f308cc7f2e88efc06503f;hp=166a5f288c071e648454ff117ea37ad3a897587d;hpb=5069b428b323144931bce0f5bf4394be7a5182d1;p=app.Builder.js diff --git a/tests/TestCompiler.vala b/tests/TestCompiler.vala index 166a5f288..7c23d11d6 100644 --- a/tests/TestCompiler.vala +++ b/tests/TestCompiler.vala @@ -1,5 +1,5 @@ -// valac TreeBuilder.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder +// valac TestCompiler.vala --pkg libvala-0.26 --pkg posix -o /tmp/TestCompiler namespace Palete { @@ -9,6 +9,8 @@ namespace Palete { public class TestCompiler : Vala.CodeVisitor { Vala.CodeContext context; + string file; + public TestCompiler(string file) { base(); this.file = file; @@ -22,78 +24,10 @@ namespace Palete { } } - public Gee.HashMap checkFile() - { - return this.checkString(JsRender.NodeToVala.mungeFile(this.file)); - } - - public async Gee.HashMap checkFileWithNodePropChange( - JsRender.Node node, - string prop, - string ptype, - string val) - { - Gee.HashMap ret = new Gee.HashMap (); - var hash = ptype == "listener" ? node.listeners : node.props; - - // untill we get a smarter renderer.. - // we have some scenarios where changing the value does not work - if (prop == "* xns" || prop == "xtype") { - return ret; - } - - - var old = hash.get(prop); - var newval = "/*--VALACHECK-START--*/ " + val ; - - hash.set(prop, newval); - var tmpstring = JsRender.NodeToVala.mungeFile(this.file); - hash.set(prop, old); - //print("%s\n", tmpstring); - var bits = tmpstring.split("/*--VALACHECK-START--*/"); - var offset =0; - if (bits.length > 0) { - offset = bits[0].split("\n").length +1; - } - //this.dumpCode(tmpstring); - //print("offset %d\n", offset); - yield this.checkStringThread(tmpstring); - - // modify report - - var iter = this.report.line_errors.map_iterator(); - while (iter.next()) { - // print("%d : %s\n",iter.get_key() - offset, iter.get_value()); - // we have to prefix the error with the fake line number - // so that it's a unique mark.. - ret.set(iter.get_key() - offset, - "%d : %s".printf(iter.get_key() - offset,iter.get_value())); - } - return ret; - - } - - public async Gee.HashMap checkStringThread(string contents) - { - SourceFunc callback = checkStringThread.callback; - var ret = new Gee.HashMap(); - ThreadFunc run = () => { - - // Pass back result and schedule callback - ret = this.checkString(contents); - Idle.add((owned) callback); - return null; - }; - Thread.create(run, false); - - // Wait for background thread to schedule our callback - yield; - return ret; - } + - - public Gee.HashMap checkString(string contents) + public void checkString( ) { // init context: var valac = "valac " ; @@ -123,29 +57,18 @@ namespace Palete { - - var vapidirs = ((Project.Gtk)this.file.project).vapidirs(); - // what's the current version of vala??? - - - vapidirs += Path.get_dirname (context.get_vapi_path("glib-2.0")) ; - - for(var i =0 ; i < vapidirs.length; i++) { - valac += " --vapidir=" + vapidirs[i]; - } + // or context.get_vapi_path("glib-2.0"); // should return path.. - context.vapi_directories = vapidirs; + //context.vapi_directories = vapidirs; context.report.enable_warnings = true; context.metadata_directories = { }; context.gir_directories = {}; context.thread = true; - this.report = new ValaSourceReport(this.file); - context.report = this.report; - + context.basedir = "/tmp"; //Posix.realpath ("."); @@ -162,61 +85,26 @@ namespace Palete { var source_file = new Vala.SourceFile ( context, Vala.SourceFileType.SOURCE, - "~~~~~testfile.vala", - contents + this.file ); source_file.add_using_directive (ns_ref); context.add_source_file (source_file); // add all the files (except the current one) - this.file.path - var pr = ((Project.Gtk)this.file.project); - if (this.file.build_module.length > 0) { - var cg = pr.compilegroups.get(this.file.build_module); - for (var i = 0; i < cg.sources.size; i++) { - var path = pr.resolve_path( - pr.resolve_path_combine_path(pr.firstPath(),cg.sources.get(i))); - - if (!FileUtils.test(path, FileTest.EXISTS)) { - continue; - } - - if (path == this.file.path.replace(".bjs", ".vala")) { - valac += " " + path; - continue; - } - if (FileUtils.test(path, FileTest.IS_DIR)) { - continue; - } - //print("Add source file %s\n", path); - - valac += " " + path; - - if (Regex.match_simple("\\.c$", path)) { - context.add_c_source_file(path); - continue; - } - - - var xsf = new Vala.SourceFile ( - context, - Vala.SourceFileType.SOURCE, - path - ); - xsf.add_using_directive (ns_ref); - context.add_source_file(xsf); - - } - } + // default.. packages.. context.add_external_package ("glib-2.0"); context.add_external_package ("gobject-2.0"); - // user defined ones.. - - var dcg = pr.compilegroups.get("_default_"); - for (var i = 0; i < dcg.packages.size; i++) { - valac += " --pkg " + dcg.packages.get(i); - context.add_external_package (dcg.packages.get(i)); + context.add_external_package ("gtk+-3.0"); + if (!context.add_external_package ("webkit2gtk-4.0")) { + context.add_external_package ("webkit2gtk-3.0"); } + context.add_external_package ("clutter-gtk-1.0"); + context.add_external_package ("gdl-3.0"); + context.add_external_package ("gtksourceview-3.0"); + context.add_external_package ("libvala-0.26"); + // user defined ones.. + //Vala.Config.PACKAGE_SUFFIX.substring (1) @@ -226,8 +114,7 @@ namespace Palete { //context.add_external_package ("libvala-0.24"); - this.report.compile_notice("START", "", 0, ""); - + //add_documented_files (context, settings.source_files); @@ -236,11 +123,10 @@ namespace Palete { //gir_parser.parse (context); if (context.report.get_errors () > 0) { print("parse got errors"); - ((ValaSourceReport)context.report).dump(); - + Vala.CodeContext.pop (); - this.report.compile_notice("END", "", 0, ""); - return this.report.line_errors; + + return; } @@ -248,11 +134,9 @@ namespace Palete { // check context: context.check (); if (context.report.get_errors () > 0) { - print("check got errors"); - ((ValaSourceReport)context.report).dump(); - Vala.CodeContext.pop (); - this.report.compile_notice("END", "", 0, ""); - return this.report.line_errors; + Vala.CodeContext.pop (); + + return ; } @@ -273,15 +157,17 @@ namespace Palete { #endif */ + + + context.resolver.resolve(new Vala.CodeContext()); + context.analyzer.context = null; + context.flow_analyzer.analyze(new Vala.CodeContext()); + //context.analyzer = null; << private Vala.CodeContext.pop (); - //(new Vala.CodeNode()).get_error_types().clear(); - //(new Vala.NullType()).get_type_arguments().clear(); - (new Vala.NullType(null)).get_type_arguments().clear(); - parser = null; - this.report.compile_notice("END", "", 0, ""); + print("%s\n", valac); print("ALL OK?\n"); - return this.report.line_errors; + return ; } // // startpoint: @@ -289,13 +175,15 @@ namespace Palete { } } -/* + int main (string[] args) { - var a = new ValaSource(file); - a.create_valac_tree(); + for (var i = 0;i < 1000;i++) { + var a = new Palete.TestCompiler("/home/alan/gitlive/app.Builder.js/tests/TestCompiler.vala"); + a.checkString(); + } return 0; } -*/ +