2 // valac TreeBuilder.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
6 * This just deals with spawning the compiler and getting the results.
8 * each window should have one of these...
10 * x = new ValaSource();
11 * x.connect.compiled(... do something with results... );
19 public errordomain ValaSourceError {
23 //public delegate void ValaSourceResult(Json.Object res);
27 public class ValaSource : Object {
30 public signal void compiled(Json.Object res);
33 JsRender.JsRender file;
34 public int line_offset = 0;
41 public void dumpCode(string str)
43 var ls = str.split("\n");
44 for (var i=0;i < ls.length; i++) {
45 print("%d : %s\n", i+1, ls[i]);
49 //public Gee.HashMap<int,string> checkFile()
51 // return this.checkString(JsRender.NodeToVala.mungeFile(this.file));
54 public void checkFileWithNodePropChange(
56 JsRender.JsRender file,
65 if (this.compiler != null) {
69 Gee.HashMap<int,string> ret = new Gee.HashMap<int,string> ();
70 var hash = ptype == "listener" ? node.listeners : node.props;
72 // untill we get a smarter renderer..
73 // we have some scenarios where changing the value does not work
74 if (prop == "* xns" || prop == "xtype") {
75 this.compiled(new Json.Object());
80 var old = hash.get(prop);
81 var newval = "/*--VALACHECK-START--*/ " + val ;
83 hash.set(prop, newval);
84 var tmpstring = JsRender.NodeToVala.mungeFile(file);
86 //print("%s\n", tmpstring);
87 var bits = tmpstring.split("/*--VALACHECK-START--*/");
89 if (bits.length > 0) {
90 offset = bits[0].split("\n").length +1;
93 this.line_offset = offset;
95 //this.dumpCode(tmpstring);
96 //print("offset %d\n", offset);
97 this.checkStringSpawn(tmpstring );
106 public void checkStringSpawn(
113 FileIOStream iostream;
114 var tmpfile = File.new_tmp ("test-XXXXXX.vala", out iostream);
117 OutputStream ostream = iostream.output_stream;
118 DataOutputStream dostream = new DataOutputStream (ostream);
119 dostream.put_string (contents);
123 var regex = new Regex("\\.bjs$");
125 valafn = regex.replace(this.file.path,this.file.path.length , 0 , ".vala");
126 } catch (GLib.RegexError e) {
127 var ret = new Json.Object();
128 ret.set_boolean_member("success", false);
129 ret.set_string_member("message", e.message);
135 args += BuilderApplication._self;
137 args += this.file.project.fn;
139 args += this.file.build_module;
140 args += "--add-file";
141 args += tmpfile.get_path();
142 args += "--skip-file";
147 this.compiler = new Spawn("/tmp", args);
148 this.compiler.complete.connect(spawnResult);
152 } catch (GLib.SpawnError e) {
153 var ret = new Json.Object();
154 ret.set_boolean_member("success", false);
155 ret.set_string_member("message", e.message);
157 this.compiler = null;
162 public void checkFileSpawn(JsRender.JsRender file )
165 if (this.compiler != null) {
170 this.line_offset = 0;
173 args += BuilderApplication._self;
175 args += this.file.project.fn;
177 args += this.file.build_module;
181 this.compiler = new Spawn("/tmp", args);
182 this.compiler.complete.connect(spawnResult);
186 } catch (GLib.SpawnError e) {
187 var ret = new Json.Object();
188 ret.set_boolean_member("success", false);
189 ret.set_string_member("message", e.message);
191 this.compiler = null;
199 public void spawnResult(int res, string output, string stderr)
204 GLib.debug("GOT output %s", output);
206 var pa = new Json.Parser();
207 pa.load_from_data(output);
208 var node = pa.get_root();
210 if (node.get_node_type () != Json.NodeType.OBJECT) {
211 var ret = new Json.Object();
212 ret.set_boolean_member("success", false);
213 ret.set_string_member("message", "Compiler returned Unexpected element type %s", node.type_name ());
215 this.compiler = null;
217 var ret = node.get_object ();
218 ret.set_int_member("line_offset", this.line_offset);
224 var ret = new Json.Object();
225 ret.set_boolean_member("success", false);
226 ret.set_string_member("message", e.message);
229 this.compiler = null;
240 int main (string[] args) {
242 var a = new ValaSource(file);
243 a.create_valac_tree();