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