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