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