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