resources/RooUsage.txt
[app.Builder.js] / tests / TestCompiler.vala
1
2 // valac TestCompiler.vala --pkg libvala-0.26 --pkg posix -o /tmp/TestCompiler
3
4 namespace Palete {
5          
6         
7          
8
9         public class TestCompiler : Vala.CodeVisitor {
10
11                 Vala.CodeContext context;
12                 string file;
13                 
14                 public TestCompiler(string file) {
15                         base();
16                         this.file = file;
17                         
18
19                 }
20                 public void dumpCode(string str) {
21                         var ls = str.split("\n");
22                         for (var i=0;i < ls.length; i++) {
23                                 print("%d : %s\n", i+1, ls[i]);
24                         }
25                 }
26                 
27                  
28                 
29                 
30                 public void checkString( )
31                 {
32                         // init context:
33                         var valac = "valac " ;
34                         
35                         context = new Vala.CodeContext ();
36                         Vala.CodeContext.push (context);
37                 
38                         context.experimental = false;
39                         context.experimental_non_null = false;
40                         
41 #if VALA_0_28
42                         var ver=28;
43 #elif VALA_0_26 
44                         var ver=26;
45 #elif VALA_0_24
46                         var ver=24;
47 #elif VALA_0_22 
48                         var ver=22;
49 #endif
50                         
51                         for (int i = 2; i <= ver; i += 2) {
52                                 context.add_define ("VALA_0_%d".printf (i));
53                         }
54                         
55                         
56                         
57                         
58                         
59                         
60                          
61                                 
62                         
63                         // or context.get_vapi_path("glib-2.0"); // should return path..
64                         //context.vapi_directories = vapidirs;
65                         context.report.enable_warnings = true;
66                         context.metadata_directories = { };
67                         context.gir_directories = {};
68                         context.thread = true;
69                         
70                         
71                         
72                         
73                         context.basedir = "/tmp"; //Posix.realpath (".");
74                 
75                         context.directory = context.basedir;
76                 
77
78                         // add default packages:
79                         //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
80                         context.profile = Vala.Profile.GOBJECT;
81                          
82                         var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
83                         context.root.add_using_directive (ns_ref);
84
85                         var source_file = new Vala.SourceFile (
86                                 context, 
87                                 Vala.SourceFileType.SOURCE, 
88                                         this.file
89                         );
90                         source_file.add_using_directive (ns_ref);
91                         context.add_source_file (source_file);
92                         
93                 // add all the files (except the current one) - this.file.path
94                  
95                         // default.. packages..
96                         context.add_external_package ("glib-2.0"); 
97                         context.add_external_package ("gobject-2.0");
98                         context.add_external_package ("gtk+-3.0");
99                         if (!context.add_external_package ("webkit2gtk-4.0")) {
100                                 context.add_external_package ("webkit2gtk-3.0");
101                         }
102                         context.add_external_package ("clutter-gtk-1.0");
103                         context.add_external_package ("gdl-3.0");
104                         context.add_external_package ("gtksourceview-3.0");
105                         context.add_external_package ("libvala-0.26");
106                         // user defined ones..
107                          
108                 
109                          //Vala.Config.PACKAGE_SUFFIX.substring (1)
110                         
111                         // add the modules...
112                         
113                         
114                         
115                         //context.add_external_package ("libvala-0.24");
116                         
117                  
118                 
119                         //add_documented_files (context, settings.source_files);
120                 
121                         Vala.Parser parser = new Vala.Parser ();
122                         parser.parse (context);
123                         //gir_parser.parse (context);
124                         if (context.report.get_errors () > 0) {
125                                 print("parse got errors");
126                                  
127                                 Vala.CodeContext.pop ();
128                                  
129                                 return;
130                         }
131
132
133                         
134                         // check context:
135                         context.check ();
136                         if (context.report.get_errors () > 0) {
137                                  Vala.CodeContext.pop ();
138                                  
139                                 return ;
140                                 
141                         }
142                         
143                         //context.codegen = new Vala.GDBusServerModule ();
144                         
145                          
146                         context.output = "/tmp/testbuild";
147                         valac += " -o " +context.output;
148                         //context.codegen.emit (context);
149                         /*
150                         var ccompiler = new Vala.CCodeCompiler ();
151                         var cc_command = Environment.get_variable ("CC");
152                         var pkg_config_command = Environment.get_variable ("PKG_CONFIG");
153 #if VALA_0_28
154                         ccompiler.compile (context, cc_command, new string[] { }, pkg_config_command);
155 #else
156                         ccompiler.compile (context, cc_command, new string[] { });
157 #endif
158                         */
159  
160                         
161                         
162                         context.resolver.resolve(new Vala.CodeContext());
163                         context.analyzer.context = null;
164                         context.flow_analyzer.analyze(new Vala.CodeContext());
165                         //context.analyzer = null; << private
166                         Vala.CodeContext.pop ();
167                           
168                         print("%s\n", valac);
169                         print("ALL OK?\n");
170                         return ;
171                 }
172         //
173                 // startpoint:
174                 //
175          
176         }
177 }
178  
179 int main (string[] args) {
180
181         for (var i = 0;i < 1000;i++) {
182                 var a = new Palete.TestCompiler("/home/alan/gitlive/app.Builder.js/tests/TestCompiler.vala");
183                 a.checkString();
184         }
185         return 0;
186 }
187  
188
189