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