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                 context.add_external_package ("glib-2.0");
62                 context.add_external_package ("gobject-2.0");
63                 context.add_external_package ("libvala-0.2");
64                 //if (context.profile == Vala.Profile.GOBJECT) {
65                         // import the GLib namespace by default (namespace of backend-specific standard library)
66                         var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
67                         source_file.add_using_directive (ns_ref);
68                         context.root.add_using_directive (ns_ref);
69                 //}
70
71                 context.add_source_file (source_file);
72
73                 
74                 //add_documented_files (context, settings.source_files);
75                 
76                 Vala.Parser parser = new Vala.Parser ();
77                 parser.parse (context);
78                 //gir_parser.parse (context);
79                 if (context.report.get_errors () > 0) {
80                         print("got errors");
81                         return context;
82                 }
83
84
85
86                 // check context:
87                 context.check ();
88                 if (context.report.get_errors () > 0) {
89                         return context;
90                 }
91                 return context;
92         }
93 //
94         // startpoint:
95         //
96  
97 }
98
99 int main (string[] args) {
100
101         var a = new TreeBuilder();
102         a.create_valac_tree();
103         return 0;
104 }
105
106