960415f3c99748b2e3c197970f7a34727ebfafec
[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                                 
49                         
50                         // or context.get_vapi_path("glib-2.0"); // should return path..
51                         //context.vapi_directories = vapidirs;
52                         context.report.enable_warnings = true;
53                         context.metadata_directories = { };
54                         context.gir_directories = {};
55                         context.thread = true;
56                         
57                         
58                         //this.report = new ValaSourceReport(this.file);
59                         //context.report = this.report;
60                         
61                         
62                         context.basedir = "/tmp"; //Posix.realpath (".");
63                 
64                         context.directory = context.basedir;
65                 
66
67                         // add default packages:
68                         //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
69                         context.profile = Vala.Profile.GOBJECT;
70                          
71                         var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
72                         context.root.add_using_directive (ns_ref);
73  
74                         // default.. packages..
75                         context.add_external_package ("glib-2.0"); 
76                         context.add_external_package ("gobject-2.0");
77                         context.add_external_package ("gdk-3.0");
78                         // user defined ones..
79                         //context.add_package ("Gtk");
80                   
81                         var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, "/usr/share/vala-0.26/vapi/gtk+-3.0.vapi");
82                         context.add_source_file (vfile);
83                          
84                         //context.add_external_package ("libvala-0.24");
85                         
86                          
87                 
88                         //add_documented_files (context, settings.source_files);
89                 
90                         Vala.Parser parser = new Vala.Parser ();
91                         parser.parse (context);
92                         //gir_parser.parse (context);
93                         if (context.report.get_errors () > 0) {
94                                 print("parse got errors");
95                                  
96                                 
97                                 Vala.CodeContext.pop ();
98                                 return ;
99                         }
100
101
102                         
103                         // check context:
104                         context.check ();
105                         if (context.report.get_errors () > 0) {
106                                 print("check got errors");
107                                  
108                                 Vala.CodeContext.pop ();
109                                  
110                                 return;
111                                 
112                         }
113                          
114                         Vala.CodeContext.pop ();
115                          
116                          
117                         print("ALL OK?\n");
118                  
119                 }
120         //
121                 // startpoint:
122                 //
123          
124         }
125 }
126  
127 int main (string[] args) {
128
129         var a = new Palete.VapiParser( );
130         a.create_valac_tree();
131         return 0;
132 }
133  
134
135