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