src/Palete/VapiParser.vala
[app.Builder.js] / src / Palete / VapiParser.vala
1
2
3 // valac VapiParser.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
4
5 namespace Palete {
6          
7          
8          
9
10         public class VapiParser : Vala.CodeVisitor {
11                 Vala.CodeContext context;
12                 public VapiParser() {
13                         base();
14                         
15                 }
16                  
17                 
18                 public void create_valac_tree( )
19                 {
20                         // init context:
21                         context = new Vala.CodeContext ();
22                         Vala.CodeContext.push (context);
23                 
24                         context.experimental = false;
25                         context.experimental_non_null = false;
26                         
27 #if VALA_0_28
28                         var ver=28;
29 #elif VALA_0_26 
30                         var ver=26;
31 #elif VALA_0_24
32                         var ver=24;
33 #elif VALA_0_22 
34                         var ver=22;
35 #endif
36                         
37                         for (int i = 2; i <= ver; i += 2) {
38                                 context.add_define ("VALA_0_%d".printf (i));
39                         }
40                         
41                          
42                         //var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
43                         // what's the current version of vala???
44                         
45                         
46                         //vapidirs +=  Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
47                         
48                         //for(var i =0 ; i < vapidirs.length; i++) {
49                         //      valac += " --vapidir=" + vapidirs[i];
50                         //}
51                                 
52                         
53                         // or context.get_vapi_path("glib-2.0"); // should return path..
54                         //context.vapi_directories = vapidirs;
55                         context.report.enable_warnings = true;
56                         context.metadata_directories = { };
57                         context.gir_directories = {};
58                         context.thread = true;
59                         
60                         
61                         //this.report = new ValaSourceReport(this.file);
62                         //context.report = this.report;
63                         
64                         
65                         context.basedir = "/tmp"; //Posix.realpath (".");
66                 
67                         context.directory = context.basedir;
68                 
69
70                         // add default packages:
71                         //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
72                         context.profile = Vala.Profile.GOBJECT;
73                          
74                         var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
75                         context.root.add_using_directive (ns_ref);
76  
77                         // default.. packages..
78                         context.add_external_package ("glib-2.0"); 
79                         context.add_external_package ("gobject-2.0");
80                         // user defined ones..
81                         context.add_package ("Gtk");
82                   
83                         var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, "/usr/share/vala-0.26/vapi/gtk+-3.0.vapi");
84                         context.add_source_file (vfile);
85                          
86                         //context.add_external_package ("libvala-0.24");
87                         
88                          
89                 
90                         //add_documented_files (context, settings.source_files);
91                 
92                         Vala.Parser parser = new Vala.Parser ();
93                         parser.parse (context);
94                         //gir_parser.parse (context);
95                         if (context.report.get_errors () > 0) {
96                                 print("parse got errors");
97                                  
98                                 
99                                 Vala.CodeContext.pop ();
100                                 return ;
101                         }
102
103
104                         
105                         // check context:
106                         context.check ();
107                         if (context.report.get_errors () > 0) {
108                                 print("check got errors");
109                                  
110                                 Vala.CodeContext.pop ();
111                                  
112                                 return;
113                                 
114                         }
115                          
116                         Vala.CodeContext.pop ();
117                          
118                         print("%s\n", valac);
119                         print("ALL OK?\n");
120                  
121                 }
122         //
123                 // startpoint:
124                 //
125          
126         }
127 }
128  
129 int main (string[] args) {
130
131         var a = new VapiParser(file);
132         a.create_valac_tree();
133         return 0;
134 }
135  
136
137