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