tests/TreeBuilder.vala
[app.Builder.js] / tests / TreeBuilder.vala
1
2 // valac TreeBuilder.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
3
4 namespace Palete {
5         
6         public class ValaSourceReport  : Vala.Report {
7
8
9                 Gee.HashMap<int,string> line_errors;
10                 
11                 public override void err (Vala.SourceReference? source, string message) {
12                         errors++;
13                         if (source == null) {
14                                 return;
15                                 //stderr.printf ("My error: %s\n", message);
16                         }
17                         if (source.file != "~~~~~testfile.vala") {
18                                 return;
19                         }
20                         var pre = "";
21                         if (line_errors.has_key(source.begin.line)) {
22                                 pre = line_errors.get(source.begin.line) + "\n";
23                                 
24                         }
25                         line_errors.set(source.begin.line, pre +  message);
26                 }
27         
28
29         }
30
31         public class ValaSource : Vala.CodeVisitor {
32         
33                 public Vala.CodeContext check (JsRender.Gtk file) {
34                         // init context:
35
36
37                         
38                         var context = new Vala.CodeContext ();
39                         Vala.CodeContext.push (context);
40                 
41                         context.experimental = false;
42                         context.experimental_non_null = false;
43                         context.vapi_directories = { "/usr/share/vala-0.24/vapi" };
44                         context.report.enable_warnings = true;
45                         context.metadata_directories = { };
46                         context.gir_directories = {};
47                         context.report = new ValaSourceReport();
48                 
49                         context.basedir = Posix.realpath (".");
50                 
51                         context.directory = context.basedir;
52                 
53
54                         // add default packages:
55                         //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
56                                 context.profile = Vala.Profile.GOBJECT;
57                         //      context.add_define ("GOBJECT");
58                         //}
59                         //add_depencies (context, settings.packages);
60                         //if (reporter.errors > 0) {
61                         //      return context;
62                         //}
63
64                         var source_file = new Vala.SourceFile (
65                                 context, 
66                                 Vala.SourceFileType.SOURCE, 
67                                 "~~~~~testfile.vala",
68                                file.toSource()
69                         );
70                         //context.add_source_file (testcode);
71
72                 
73                         // source_file = new Vala.SourceFile (context, 
74                         //               Vala.SourceFileType.SOURCE, 
75                         //              "/home/alan/gitlive/app.Builder.js/tests/TreeBuilder.vala");
76
77                         //if (source_package == null) {
78                         //source_package = register_package (new Package (settings.pkg_name, false, null));
79                         //}
80
81                         //register_source_file (source_package, source_file);
82
83                         context.add_external_package ("glib-2.0");
84                         context.add_external_package ("gobject-2.0");
85                         context.add_external_package ("libvala-0.24");
86                         //context.add_external_package ("posix");
87                         //if (context.profile == Vala.Profile.GOBJECT) {
88                                 // import the GLib namespace by default (namespace of backend-specific standard library)
89                                 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
90                                 source_file.add_using_directive (ns_ref);
91                                 context.root.add_using_directive (ns_ref);
92                         //}
93
94                         context.add_source_file (source_file);
95
96                 
97                         //add_documented_files (context, settings.source_files);
98                 
99                         Vala.Parser parser = new Vala.Parser ();
100                         parser.parse (context);
101                         //gir_parser.parse (context);
102                         if (context.report.get_errors () > 0) {
103                                 print("got errors");
104                                 return context;
105                         }
106
107
108
109                         // check context:
110                         context.check ();
111                         if (context.report.get_errors () > 0) {
112                                 print("check got errors");
113                                 return context;
114                         }
115                         print("ALL OK?\n");
116                         return context;
117                 }
118         //
119                 // startpoint:
120                 //
121          
122         }
123
124 int main (string[] args) {
125
126         var a = new TreeBuilder();
127         a.create_valac_tree();
128         return 0;
129 }
130
131