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