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