sync
[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                 Vala.CodeContext context;
42                 
43                 public ValaSource(JsRender.JsRender file) {
44                         base();
45                         // init context:
46
47                         context = new Vala.CodeContext ();
48                         Vala.CodeContext.push (context);
49                 
50                         context.experimental = false;
51                         context.experimental_non_null = false;
52                         context.vapi_directories = { "/usr/share/vala-0.24/vapi" };
53                         context.report.enable_warnings = true;
54                         context.metadata_directories = { };
55                         context.gir_directories = {};
56                         context.report = new ValaSourceReport();
57                 
58                         context.basedir = Posix.realpath (".");
59                 
60                         context.directory = context.basedir;
61                 
62
63                         // add default packages:
64                         //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
65                                 context.profile = Vala.Profile.GOBJECT;
66                         //      context.add_define ("GOBJECT");
67                         //}
68                         //add_depencies (context, settings.packages);
69                         //if (reporter.errors > 0) {
70                         //      return context;
71                         //}
72
73                         var source_file = new Vala.SourceFile (
74                                 context, 
75                                 Vala.SourceFileType.SOURCE, 
76                                 "~~~~~testfile.vala",
77                                NodeToVala.mungeFile(file)
78                         );
79                         //context.add_source_file (testcode);
80
81                 
82                         // source_file = new Vala.SourceFile (context, 
83                         //               Vala.SourceFileType.SOURCE, 
84                         //              "/home/alan/gitlive/app.Builder.js/tests/TreeBuilder.vala");
85
86                         //if (source_package == null) {
87                         //source_package = register_package (new Package (settings.pkg_name, false, null));
88                         //}
89
90                         //register_source_file (source_package, source_file);
91
92                         context.add_external_package ("glib-2.0");
93                         context.add_external_package ("gobject-2.0");
94                         context.add_external_package ("libvala-0.24");
95                         //context.add_external_package ("posix");
96                         //if (context.profile == Vala.Profile.GOBJECT) {
97                                 // import the GLib namespace by default (namespace of backend-specific standard library)
98                                 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
99                                 source_file.add_using_directive (ns_ref);
100                                 context.root.add_using_directive (ns_ref);
101                         //}
102
103                         context.add_source_file (source_file);
104
105                 
106                         //add_documented_files (context, settings.source_files);
107                 
108                         Vala.Parser parser = new Vala.Parser ();
109                         parser.parse (context);
110                         //gir_parser.parse (context);
111                         if (context.report.get_errors () > 0) {
112                                 print("parse got errors");
113                                 Vala.CodeContext.pop (context);
114                                 return;
115                         }
116
117
118
119                         // check context:
120                         context.check ();
121                         if (context.report.get_errors () > 0) {
122                                 print("check got errors");
123                                 Vala.CodeContext.pop (context);
124                                 return;
125                         }
126                         Vala.CodeContext.pop (context);
127                         print("ALL OK?\n");
128                         return;
129                 }
130         //
131                 // startpoint:
132                 //
133          
134         }
135 }
136
137 int main (string[] args) {
138
139         var a = new ValaSource(file);
140         a.create_valac_tree();
141         return 0;
142 }
143
144