51581412bba302be0bd9d5d9ae7c39f099ff7a52
[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 (
52                         context, 
53                         Vala.SourceFileType.SOURCE, 
54                        "stdin.vala",
55                         "void atest() { 
56                             var a= 100;
57                             a++;
58                         }"
59                     );
60                 //context.add_source_file (testcode);
61
62                 
63                 // source_file = new Vala.SourceFile (context, 
64                 //               Vala.SourceFileType.SOURCE, 
65                 //              "/home/alan/gitlive/app.Builder.js/tests/TreeBuilder.vala");
66
67                 //if (source_package == null) {
68                 //source_package = register_package (new Package (settings.pkg_name, false, null));
69                 //}
70
71                 //register_source_file (source_package, source_file);
72
73                 context.add_external_package ("glib-2.0");
74                 context.add_external_package ("gobject-2.0");
75                 context.add_external_package ("libvala-0.24");
76                 //context.add_external_package ("posix");
77                 //if (context.profile == Vala.Profile.GOBJECT) {
78                         // import the GLib namespace by default (namespace of backend-specific standard library)
79                         var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
80                         source_file.add_using_directive (ns_ref);
81                         context.root.add_using_directive (ns_ref);
82                 //}
83
84                 context.add_source_file (source_file);
85
86                 
87                 //add_documented_files (context, settings.source_files);
88                 
89                 Vala.Parser parser = new Vala.Parser ();
90                 parser.parse (context);
91                 //gir_parser.parse (context);
92                 if (context.report.get_errors () > 0) {
93                         print("got errors");
94                         return context;
95                 }
96
97
98
99                 // check context:
100                 context.check ();
101                 if (context.report.get_errors () > 0) {
102                         print("check got errors");
103                         return context;
104                 }
105                 print("ALL OK?\n");
106                 return context;
107         }
108 //
109         // startpoint:
110         //
111  
112 }
113
114 int main (string[] args) {
115
116         var a = new TreeBuilder();
117         a.create_valac_tree();
118         return 0;
119 }
120
121