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