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                                 
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                         context.add_external_package ("atk");
79                         // user defined ones..
80                         //context.add_package ("Gtk");
81                   
82                         var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, "/usr/share/vala-0.26/vapi/gtk+-3.0.vapi");
83                         context.add_source_file (vfile);
84                          
85                         //context.add_external_package ("libvala-0.24");
86                         
87                          
88                 
89                         //add_documented_files (context, settings.source_files);
90                 
91                         Vala.Parser parser = new Vala.Parser ();
92                         parser.parse (context);
93                         //gir_parser.parse (context);
94                         if (context.report.get_errors () > 0) {
95                                 print("parse got errors");
96                                  
97                                 
98                                 Vala.CodeContext.pop ();
99                                 return ;
100                         }
101
102
103                         
104                         // check context:
105                         context.check ();
106                         if (context.report.get_errors () > 0) {
107                                 print("check got errors");
108                                  
109                                 Vala.CodeContext.pop ();
110                                  
111                                 return;
112                                 
113                         }
114                          
115                         Vala.CodeContext.pop ();
116                          
117                          
118                         print("ALL OK?\n");
119                  
120                 }
121         //
122                 // startpoint:
123                 //
124          
125         }
126 }
127  
128 int main (string[] args) {
129
130         var a = new Palete.VapiParser( );
131         a.create_valac_tree();
132         return 0;
133 }
134  
135
136