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                 public override void visit_namespace (Vala.Namespace element) {
17                         element.accept_children (this);
18                 }
19                 public override void visit_type_parameter (Vala.TypeParameter element) {
20                         print("got param %s", element.name);
21                         
22                          
23                 }
24                 public override void visit_class (Vala.Class element) {
25                         print("got class %s", element.name);
26                         element.accept_children (this);
27                 }
28                 
29                 public void create_valac_tree( )
30                 {
31                         // init context:
32                         context = new Vala.CodeContext ();
33                         Vala.CodeContext.push (context);
34                 
35                         context.experimental = false;
36                         context.experimental_non_null = false;
37                         
38 #if VALA_0_28
39                         var ver=28;
40 #elif VALA_0_26 
41                         var ver=26;
42 #elif VALA_0_24
43                         var ver=24;
44 #elif VALA_0_22 
45                         var ver=22;
46 #endif
47                         
48                         for (int i = 2; i <= ver; i += 2) {
49                                 context.add_define ("VALA_0_%d".printf (i));
50                         }
51                         
52                          
53                         //var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
54                         // what's the current version of vala???
55                         
56                         
57                         //vapidirs +=  Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
58                          
59                                 
60                         
61                         // or context.get_vapi_path("glib-2.0"); // should return path..
62                         //context.vapi_directories = vapidirs;
63                         context.report.enable_warnings = true;
64                         context.metadata_directories = { };
65                         context.gir_directories = {};
66                         context.thread = true;
67                         
68                         
69                         //this.report = new ValaSourceReport(this.file);
70                         //context.report = this.report;
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                         // default.. packages..
86                         context.add_external_package ("glib-2.0"); 
87                         context.add_external_package ("gobject-2.0");
88                         context.add_external_package ("gdk-3.0");
89                         context.add_external_package ("atk");
90                         context.add_external_package ("gdk-x11-3.0");
91                         context.add_external_package ("x11");
92                         
93                         // user defined ones..
94                         //context.add_package ("Gtk");
95                   
96                         var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, "/usr/share/vala-0.26/vapi/gtk+-3.0.vapi");
97                         context.add_source_file (vfile);
98                          
99                         //context.add_external_package ("libvala-0.24");
100                         
101                          
102                 
103                         //add_documented_files (context, settings.source_files);
104                 
105                         Vala.Parser parser = new Vala.Parser ();
106                         parser.parse (context);
107                         //gir_parser.parse (context);
108                         if (context.report.get_errors () > 0) {
109                                 print("parse got errors");
110                                  
111                                 
112                                 Vala.CodeContext.pop ();
113                                 return ;
114                         }
115
116
117                         
118                         // check context:
119                         context.check ();
120                         if (context.report.get_errors () > 0) {
121                                 print("check got errors");
122                                  
123                                 Vala.CodeContext.pop ();
124                                  
125                                 return;
126                                 
127                         }
128                          
129                         Vala.CodeContext.pop ();
130                          
131                          
132                         print("ALL OK?\n");
133                  
134                 }
135         //
136                 // startpoint:
137                 //
138          
139         }
140 }
141  
142 int main (string[] args) {
143
144         var a = new Palete.VapiParser( );
145         a.create_valac_tree();
146         return 0;
147 }
148  
149
150