3d63c2f3e319149c04447f6441543734d5b6fc08
[roobuilder] / src / Palete / VapiParser.vala
1
2
3  // valac -g  --pkg libvala-0.26  --pkg gee-1.0 --pkg json-glib-1.0  --pkg gtk+-3.0   VapiParser.vala Gir.vala GirObject.vala -o /tmp/vdoc
4
5 namespace Palete {
6          
7          public errordomain VapiParserError {
8                 PARSE_FAILED 
9         }
10          
11  
12         public class VapiParser : Vala.CodeVisitor {
13                 
14                 Vala.CodeContext context;
15                  
16                 Project.Gtk project;
17                 
18                 public VapiParser(Project.Gtk project) {
19                         base();
20                         this.project = project;
21                         // should not really happen..
22                         if (project.gir_cache == null) {
23                                 project.gir_cache =       new Gee.HashMap<string,Gir>();
24                         }
25                 }
26                  
27                 
28                 public override void visit_namespace (Vala.Namespace element) 
29                 {
30                         if (element == null) {
31                                 
32                                 return;
33                         }
34                          
35                         
36                         //print("parsing namespace %s\n", element.name);
37                         if (element.name == null) {
38                                 element.accept_children(this); // catch sub namespaces..
39                                 return;
40                         }
41                         this.add_namespace(null, element);
42                 }
43                 public void add_namespace(GirObject? parent, Vala.Namespace element)
44                 {
45                         
46                         
47                         var g = new GirObject("Package",element.name) ;
48                         if (parent == null) {
49                                 this.project.gir_cache.set(element.name,   g);
50                         } else {
51                                 // we add it as a class of the package.. even though its a namespace..
52                                 parent.classes.set(element.name, g);
53                         }
54                         
55                         
56                         foreach(var c in element.get_classes()) {
57                                 this.add_class(g, c);
58                         }
59                         foreach(var c in element.get_enums()) {
60                                 this.add_enum(g, c);
61                         }
62                         foreach(var c in element.get_interfaces()) {
63                                 this.add_interface(g, c);
64                         }
65                         foreach(var c in element.get_namespaces()) {
66                                 this.add_namespace(g, c);
67                         }
68                         foreach(var c in element.get_methods()) {
69                                 this.add_method(g, c);
70                         }
71                         
72                         foreach(var c in element.get_structs()) {
73                                 this.add_struct(g, c);
74                         }
75                         foreach(var c in element.get_delegates()) {
76                                 this.add_delegate(g, c);
77                         }
78                         element.accept_children(this); // catch sub namespaces..
79                         
80                         
81                 }
82                 
83                 
84                 public void add_enum(GirObject parent, Vala.Enum cls)
85                 {
86                 
87                         var c = new GirObject("Enum",   cls.name);
88                         parent.consts.set(cls.name, c);
89                         c.ns = parent.name;
90                         
91                         c.gparent = parent;
92                         
93                         foreach(var e in cls.get_values()) {
94                                 var em = new GirObject("EnumMember",e.name);
95                                 em.gparent = c;
96                                 em.ns = c.ns;
97                                 
98 #if VALA_0_56
99                                 em.type  = e.type_reference == null ||  e.type_reference.type_symbol == null ? "" : e.type_reference.type_symbol.get_full_name();                       
100 #elif VALA_0_36
101                                 em.type  = e.type_reference == null ||  e.type_reference.data_type == null ? "" : e.type_reference.data_type.get_full_name();
102 #endif                          
103                                 
104                                 
105                                 // unlikely to get value..
106                                 //c.value = element->get_prop("value");
107                                 c.consts.set(e.name,em);
108                         }
109                         
110                          
111                 }
112                 
113                 public void add_interface(GirObject parent, Vala.Interface cls)
114                 {
115                 
116                         var c = new GirObject("Interface", parent.name + "." + cls.name);
117                         parent.classes.set(cls.name, c);
118                         c.ns = parent.name;
119                         //c.parent = cls.base_class == null ? "" : cls.base_class.get_full_name() ;  // extends...
120                         c.gparent = parent;
121                         
122                         foreach(var p in cls.get_properties()) {
123                                 this.add_property(c, p);
124                         }
125                         // methods...
126                         foreach(var p in cls.get_signals()) {
127                                 this.add_signal(c, p);
128                         }
129                         
130                         foreach(var p in cls.get_methods()) {
131                                 // skip static methods..
132                                 if (p.binding != Vala.MemberBinding.INSTANCE &&
133                                         !(p is Vala.CreationMethod)
134                                 ) {
135                                         continue;
136                                 }
137                                 
138                                 this.add_method(c, p);
139                         }
140                         
141                         //if (cls.base_class != null) {
142                         //      c.inherits.add(cls.base_class.get_full_name());
143                         //}
144                         //foreach(var p in cls.get_base_types()) {
145                         //      if (p.data_type != null) {
146                         //              c.implements.add(p.data_type.get_full_name());
147                         //      }
148                         //}
149                           
150                         
151                         
152                          
153                 }
154                 //https://learnxinyminutes.com/docs/vala/ -- see for ctor on structs.
155                 
156                 public void add_struct(GirObject parent, Vala.Struct cls)
157                 {
158                 
159                         var c = new GirObject("Struct", parent.name + "." + cls.name);
160                         parent.classes.set(cls.name, c);
161                           
162                         foreach(var p in cls.get_fields()) {
163                                 this.add_field(c, p);
164                         }
165                         // methods...
166                          
167                           
168                         
169                         if (cls.version.deprecated) { 
170                                 GLib.debug("class %s is deprecated", c.name);
171                                 c.is_deprecated = true;
172                         }
173                         
174                 }
175                 
176                 
177                 
178                 public void add_class(GirObject parent, Vala.Class cls)
179                 {
180                 
181                         var c = new GirObject("Class", parent.name + "." + cls.name);
182                         parent.classes.set(cls.name, c);
183                         c.ns = parent.name;
184                         c.parent = cls.base_class == null ? "" : cls.base_class.get_full_name() ;  // extends...
185                         c.gparent = parent;
186                         c.is_abstract = cls.is_abstract;
187                         foreach(var p in cls.get_properties()) {
188                                 this.add_property(c, p);
189                         }
190                         // methods...
191                         foreach(var p in cls.get_signals()) {
192                                 this.add_signal(c, p);
193                         }
194                         
195                         foreach(var p in cls.get_methods()) {
196                                 // skip static methods..
197                                 if (p.binding != Vala.MemberBinding.INSTANCE &&
198                                         !(p is Vala.CreationMethod)
199                                 ) {
200                                         continue;
201                                 }
202                                 
203                                 this.add_method(c, p);
204                         }
205                         
206                         if (cls.base_class != null) {
207                                 c.inherits.add(cls.base_class.get_full_name());
208                         }
209                         foreach(var p in cls.get_base_types()) {
210 #if VALA_0_56
211                                 if (p.type_symbol != null) {
212                                         c.implements.add(p.type_symbol.get_full_name());
213                                 }
214 #elif VALA_0_36
215                                 if (p.data_type != null) {
216                                         c.implements.add(p.data_type.get_full_name());
217                                 }
218
219 #endif                          
220                                  
221                         }
222                         
223                         if (cls.version.deprecated) { 
224                                 GLib.debug("class %s is deprecated", c.name);
225                                 c.is_deprecated = true;
226                         }
227                         
228                 }
229                 
230                 public GirObject? fqn_to_cls(string fqn)
231                 {
232                         var ar = fqn.split(".");
233                         var pkg = this.project.gir_cache.get(ar[0]);
234                         var cls = pkg != null ? pkg.classes.get(ar[1]) : null;
235                         return cls;
236                 }
237                 
238                 public void augment_inherits_for(GirObject cls, Gee.ArrayList<string> to_check, bool is_top)
239                 {
240                         foreach (var chk_cls in to_check) {
241                                 if (!cls.inherits.contains(chk_cls)) { 
242                                         cls.inherits.add(chk_cls);
243                                         
244                                 } else {
245                                         if (!is_top) {
246                                                 continue;
247                                         }
248                                 }
249                                 
250                                 
251                                 var subcls = this.fqn_to_cls(chk_cls);
252                                 if (subcls == null) {
253                                         continue;
254                                 }
255                                 this.augment_inherits_for(cls, subcls.inherits, false);
256                                 this.augment_implements_for(cls, subcls.implements);
257                         }
258                 
259                 }
260                 public void augment_implements_for(GirObject cls, Gee.ArrayList<string> to_check)
261                 {
262                         foreach (var chk_cls in to_check) {
263                                 if (cls.implements.contains(chk_cls)) { 
264                                         continue;
265                                 }
266                                 cls.implements.add(chk_cls);
267                                 
268                                 var subcls = this.fqn_to_cls(chk_cls);
269                                 if (subcls == null) {
270                                         continue;
271                                 }
272                                 this.augment_implements_for(cls, subcls.implements);
273
274                         }
275                 
276                 }
277                 
278                 // this might miss out interfaces of child classes?
279                 public void augment_all_inheritence()
280                 {
281                         // this works out all the children...
282                         foreach(var pkgname in this.project.gir_cache.keys) {
283                         
284                                 var pkg = this.project.gir_cache.get(pkgname);
285                                 foreach (var clsname in pkg.classes.keys) {
286                                         var cls = pkg.classes.get(clsname);
287                                         this.augment_inherits_for(cls, cls.inherits, true);
288                                         this.augment_implements_for(cls, cls.implements);
289                                 }
290                         }
291                         // now do the implementations
292                         foreach(var pkgname in this.project.gir_cache.keys) {
293                         
294                                 var pkg = this.project.gir_cache.get(pkgname);
295                                 foreach (var clsname in pkg.classes.keys) {
296                                         var cls = pkg.classes.get(clsname);
297                                         foreach(var parentname in cls.inherits) {
298                                                 var parent =  this.fqn_to_cls(parentname);
299                                                 if (parent == null) { 
300                                                         continue;
301                                                 }
302                                                 if (parent.implementations.contains(cls.fqn())) {
303                                                         continue;
304                                                 }
305                                                 parent.implementations.add(cls.fqn());
306                                         
307                                         }
308                                         foreach(var parentname in cls.implements) {
309                                                 var parent =  this.fqn_to_cls(parentname);
310                                                 if (parent == null) { 
311                                                         continue;
312                                                 }
313                                                 if (parent.implementations.contains(cls.fqn())) {
314                                                         continue;
315                                                 }
316                                                 parent.implementations.add(cls.fqn());
317                                         
318                                         }
319                                 }
320                         }
321                         
322                                 
323                 }
324                  
325                 
326                 public void add_property(GirObject parent, Vala.Property prop)
327                 {
328                         var c = new GirObject("Prop",prop.name);
329                         c.gparent = parent;
330                         c.ns = parent.ns;
331                         c.propertyof = parent.name;
332 #if VALA_0_56
333                         c.type  = prop.property_type.type_symbol == null ? "" : prop.property_type.type_symbol.get_full_name();
334 #elif VALA_0_36
335                         c.type  = prop.property_type.data_type == null ? "" : prop.property_type.data_type.get_full_name();             
336 #endif
337                         c.is_readable = prop.get_accessor != null ?  prop.get_accessor.readable : false;
338                         c.is_writable = prop.set_accessor != null ?  prop.set_accessor.writable ||  prop.set_accessor.construction : false;
339                         //if (prop.name == "child") {
340                         //      GLib.debug("prop child : w%s r%s", c.is_writable ? "YES" : "n" , c.is_readable ? "YES" : "n");
341                         //}
342                         if (prop.version.deprecated) { 
343                                 GLib.debug("class %s is deprecated", c.name);
344                                 c.is_deprecated = true;
345                         }
346                         parent.props.set(prop.name,c);
347
348                         
349                 }
350                 
351                 
352                 public void add_field(GirObject parent, Vala.Field prop)
353                 {
354                         var c = new GirObject("Field",prop.name);
355                         c.gparent = parent;
356                         c.ns = parent.ns;
357                         c.propertyof = parent.name;
358 #if VALA_0_56
359                         c.type  = prop.variable_type.type_symbol == null ? "" : prop.variable_type.type_symbol.get_full_name();
360 #elif VALA_0_36
361                         c.type  = prop.variable_type.data_type == null ? "" : prop.variable_type.data_type.get_full_name();             
362 #endif
363                          
364                         if (prop.version.deprecated) { 
365                                 GLib.debug("class %s is deprecated", c.name);
366                                 c.is_deprecated = true;
367                         }
368                         parent.props.set(prop.name,c);
369
370                         
371                 }
372                 public void add_delegate(GirObject parent, Vala.Delegate sig)
373                 {
374                 
375                         var c = new GirObject("Delegate",   sig.name);
376                         c.gparent = parent;
377                         c.ns = parent.ns;
378                         c.propertyof = parent.name;
379 #if VALA_0_56
380                         var dt  = sig.return_type.type_symbol  ;
381 #elif VALA_0_36
382                         var dt  = sig.return_type.data_type;
383 #endif                  
384                         if (sig.version.deprecated) { 
385                                 GLib.debug("class %s is deprecated", c.name);
386                                 c.is_deprecated = true;
387                         } 
388                         
389                         var retval = "";
390                         
391                         if (dt != null) {
392                                 //print("creating return type on signal %s\n", sig.name);
393                                 var cc = new GirObject("Return", "return-value");
394                                 cc.gparent = c;
395                                 cc.ns = c.ns;
396                                 cc.type  =  dt.get_full_name();
397                                 c.return_value = cc;
398                                 c.type = dt.get_full_name(); // type is really return type in this scenario.
399                                  retval = "\treturn " + cc.type +";";
400                         }
401                         parent.delegates.set(sig.name,c);
402                         
403                         var params =  sig.get_parameters() ;
404                         if (params.size < 1) {
405                         
406                                 c.sig = "( ) => {\n\n"+ retval + "\n}\n";
407                         
408                                 return;
409                         }
410                         var cc = new GirObject("Paramset",sig.name); // what's the name on this?
411                         cc.gparent = c;
412                         cc.ns = c.ns;
413                         c.paramset = cc;
414                         
415                         var args = "";                  
416                         foreach(var p in params) {
417                                 this.add_param(cc, p);
418                                 args += args.length > 0 ? ", " : "";
419                                 args += p.name;
420                         }
421                         // add c.sig -> this is the empty 
422                         c.sig = "(" + args + ") => {\n\n"+ retval + "\n}\n";
423                         
424                         
425                          
426                 }
427                 
428                 
429                 
430                 
431                 public void add_signal(GirObject parent, Vala.Signal sig)
432                 {
433                         var c = new GirObject("Signal",sig.name);
434                         c.gparent = parent;
435                         c.ns = parent.ns;
436                         c.propertyof = parent.name;
437 #if VALA_0_56
438                         var dt  = sig.return_type.type_symbol  ;
439 #elif VALA_0_36
440                         var dt  = sig.return_type.data_type;
441 #endif                  
442                         if (sig.version.deprecated) { 
443                                 GLib.debug("class %s is deprecated", c.name);
444                                 c.is_deprecated = true;
445                         } 
446                         
447                         var retval = "";
448                         
449                         if (dt != null) {
450                                 //print("creating return type on signal %s\n", sig.name);
451                                 var cc = new GirObject("Return", "return-value");
452                                 cc.gparent = c;
453                                 cc.ns = c.ns;
454                                 cc.type  =  dt.get_full_name();
455                                 c.return_value = cc;
456                                 c.type = dt.get_full_name(); // type is really return type in this scenario.
457                                  retval = "\treturn " + cc.type +";";
458                         }
459                         parent.signals.set(sig.name,c);
460                         
461                         var params =  sig.get_parameters() ;
462                         if (params.size < 1) {
463                         
464                                 c.sig = "( ) => {\n\n"+ retval + "\n}\n";
465                         
466                                 return;
467                         }
468                         var cc = new GirObject("Paramset",sig.name); // what's the name on this?
469                         cc.gparent = c;
470                         cc.ns = c.ns;
471                         c.paramset = cc;
472                         
473                         var args = "";                  
474                         foreach(var p in params) {
475                                 this.add_param(cc, p);
476                                 args += args.length > 0 ? ", " : "";
477                                 args += p.name;
478                         }
479                         // add c.sig -> this is the empty 
480                         c.sig = "(" + args + ") => {\n\n"+ retval + "\n}\n";
481                         
482                         
483                         
484                 }       
485                 
486                 public void add_method(GirObject parent, Vala.Method met)
487                 {
488                         var n = met.name == null ? "" : met.name;
489                         var ty  = "Method";
490                         if (met is Vala.CreationMethod) {
491                                 ty = "Ctor";
492                                 if(n == "" || n == ".new") {
493                                         n = "new";
494                                 }
495                                 
496                         }
497                         //print("add_method :  %s\n", n);
498                         
499                         var c = new GirObject(ty,n);
500                         c.gparent = parent;
501                         c.ns = parent.ns;
502 #if VALA_0_56                                           
503                         if (met.return_type.type_symbol != null) {
504 #elif VALA_0_36
505                         if (met.return_type.data_type != null) {
506 #endif  
507                         
508                         
509                                 //print("creating return type on method %s\n", met.name);
510                                 var cc = new GirObject("Return", "return-value");
511                                 cc.gparent = c;
512                                 cc.ns = c.ns;
513
514 #if VALA_0_56                   
515                                 cc.type  =  met.return_type.type_symbol.get_full_name();
516 #elif VALA_0_36
517                                 cc.type  =  met.return_type.data_type.get_full_name();
518 #endif  
519                                 
520                                 
521                                 
522                                 c.return_value = cc;
523                         }
524                         if (met is Vala.CreationMethod) {
525                                 parent.ctors.set(c.name,c);
526                         } else {
527                                 parent.methods.set(met.name,c);
528                         }
529                         
530                         var params =  met.get_parameters() ;
531                         if (params.size < 1) {
532                                 return;
533                         }
534                         var cc = new GirObject("Paramset",met.name); // what's the name on this?
535                         cc.gparent = c;
536                         cc.ns = c.ns;
537                         c.paramset = cc;
538                         c.sig = "(";
539                         
540                         foreach(var p in params) {
541                                 if (p.name == null && !p.ellipsis) {
542                                         continue;
543                                 }
544                                 var pp = this.add_param(cc, p);
545                                 c.sig += (c.sig == "(" ? "" : ",");
546                                 c.sig += " " + (pp.direction == "in" ? "" : pp.direction) + " " + pp.type + " " + pp.name;
547                         }
548                         c.sig += (c.sig == "(" ? ")" : " )");
549                         
550                 }
551                 
552                 public GirObject add_param(GirObject parent, Vala.Parameter pam)
553                 {
554                         
555                         var n = pam.name;
556                         if (pam.ellipsis) {
557                                 n = "___";
558                         }
559                         var c = new GirObject("Param",n);
560                         c.gparent = parent;
561                         c.ns = parent.ns;
562                         c.direction = "??";
563                         switch (pam.direction) {
564                                 case Vala.ParameterDirection.IN:
565                                         c.direction = "in";
566                                         break;
567                                 case Vala.ParameterDirection.OUT:
568                                         c.direction = "out";
569                                         break;
570                                 case Vala.ParameterDirection.REF:
571                                         c.direction = "ref";
572                                         break;
573                         }
574                         
575                         parent.params.add(c);
576                         
577                         if (!pam.ellipsis) {
578 #if VALA_0_56                   
579                                 c.type = pam.variable_type.type_symbol == null ? "" : pam.variable_type.type_symbol.get_full_name();
580 #elif VALA_0_36
581                                 c.type = pam.variable_type.data_type == null ? "" : pam.variable_type.data_type.get_full_name();
582 #endif                          
583                         }
584                         Gir.checkParamOverride(c); 
585                         return c;
586                         
587                 }
588                 
589 #if VALA_0_56
590                 int vala_version=56;
591 #elif VALA_0_36
592                 int vala_version=36;
593 #endif          
594                 public Gee.ArrayList<string> fillDeps(Gee.ArrayList<string> in_ar)
595                 {
596                         var ret = new Gee.ArrayList<string>();
597                         foreach(var k in in_ar) {
598                                 if (!ret.contains(k)) {                 
599                                         ret.add(k);
600                                 }
601                                 var deps = this.loadDeps(k);
602                                 // hopefully dont need to recurse through these..
603                                 for(var i =0;i< deps.length;i++) {
604                                         if (!ret.contains(deps[i])) {
605                                                 ret.add(deps[i]);
606                                         }
607                                 }
608                                 
609                         
610                         }
611
612
613                         return ret;
614                 }
615                 
616                 public string[] loadDeps(string n) 
617                 {
618                         // only try two? = we are ignoreing our configDirectory?
619                         string[] ret  = {};
620                         var fn =  "/usr/share/vala-0.%d/vapi/%s.deps".printf(this.vala_version, n);
621                         if (!FileUtils.test (fn, FileTest.EXISTS)) {
622                                 fn = "";
623                         }
624                         if (fn == "") { 
625                                 fn =  "/usr/share/vala/vapi/%s.deps".printf( n);
626                                 if (!FileUtils.test (fn, FileTest.EXISTS)) {
627                                         return ret;
628                                 }
629                         }
630                         string  ostr;
631                         try {
632                                 FileUtils.get_contents(fn, out ostr);
633                         } catch (GLib.Error e) {
634                                 GLib.debug("failed loading deps %s", e.message);
635                                 return {};
636                         }
637                         return ostr.split("\n");
638                         
639                         
640                 }
641                 
642                 
643                 
644                 public void create_valac_tree( )
645                 {
646                         // init context:
647                         context = new Vala.CodeContext ();
648                         Vala.CodeContext.push (context);
649                 
650                         context.experimental = false;
651                         context.experimental_non_null = false;
652  
653                         
654                         //for (int i = 2; i <= ver; i += 2) {
655                         //      context.add_define ("VALA_0_%d".printf (i));
656                         //}
657                         
658                          
659                         //var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
660                         // what's the current version of vala???
661                         
662                         
663                         //vapidirs +=  Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
664                          
665                         var vapidirs = context.vapi_directories;
666                         
667                         vapidirs += (BuilderApplication.configDirectory() + "/resources/vapi");
668                         vapidirs += "/usr/share/vala-0.%d/vapi".printf(this.vala_version);
669                         vapidirs += "/usr/share/vala/vapi";
670                         context.vapi_directories = vapidirs;
671                         
672                         // or context.get_vapi_path("glib-2.0"); // should return path..
673                         //context.vapi_directories = vapidirs;
674                         context.report.enable_warnings = true;
675                         context.metadata_directories = { };
676                         context.gir_directories = {};
677                         //context.thread = true; 
678                         
679                         
680                         //this.report = new ValaSourceReport(this.file);
681                         //context.report = this.report;
682                         
683                         
684                         context.basedir = "/tmp"; //Posix.realpath (".");
685                 
686                         context.directory = context.basedir;
687                 
688
689                         // add default packages:
690                         //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
691 #if VALA_0_56
692                         context.set_target_profile (Vala.Profile.GOBJECT);
693 #elif VALA_0_36
694                         context.profile = Vala.Profile.GOBJECT;
695 #endif
696                          
697                         var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
698                         context.root.add_using_directive (ns_ref);
699                         
700                         
701                         context.add_external_package ("glib-2.0"); 
702                         context.add_external_package ("gobject-2.0");
703                         // user defined ones..
704                         
705  
706                                                 
707                         var pkgs = this.fillDeps(this.project.packages);
708                         
709                 
710                 for (var i = 0; i < pkgs.size; i++) {
711                 
712                         var pkg = pkgs.get(i);
713                         // do not add libvala versions except the one that matches the one we are compiled against..
714                         if (Regex.match_simple("^libvala", pkg) && pkg != ("libvala-0." + vala_version.to_string())) {
715                                 continue;
716                         }
717                                 //valac += " --pkg " + dcg.packages.get(i);
718                                  if (!this.has_vapi(context.vapi_directories, pkg)) {
719                                  
720                                         continue;
721                                 }
722                                 GLib.debug("ADD vapi '%s'",pkgs.get(i));
723                                 context.add_external_package (pkgs.get(i));
724                         }                       
725                         
726                         
727                         
728                          
729                         // core packages we are interested in for the builder..
730                         // some of these may fail... - we probalby need a better way to handle this..
731                         /*
732                         context.add_external_package ("gtk+-3.0");
733                         context.add_external_package ("libsoup-2.4");
734                         if (!context.add_external_package ("webkit2gtk-4.0")) {
735                                 context.add_external_package ("webkit2gtk-3.0");
736                         }
737                         // these are supposed to be in the 'deps' file, but it's not getting read..
738                         context.add_external_package ("cogl-1.0");
739                         context.add_external_package ("json-glib-1.0");
740                         context.add_external_package ("clutter-gtk-1.0");
741
742
743                     
744                         context.add_external_package ("gdl-3.0");
745                         context.add_external_package ("gtksourceview-3.0");
746                         context.add_external_package ("vte-2.90"); //??? -- hopefullly that works..
747                         */
748                         //add_documented_files (context, settings.source_files);
749                 
750                         Vala.Parser parser = new Vala.Parser ();
751                         parser.parse (context);
752                         //gir_parser.parse (context);
753                         if (context.report.get_errors () > 0) {
754                                 
755                                 //throw new VapiParserError.PARSE_FAILED("failed parse VAPIS, so we can not write file correctly");
756                                 
757                                 print("parse got errors");
758                                  
759                                 
760                                 Vala.CodeContext.pop ();
761                                 return ;
762                         }
763
764
765                         
766                         // check context:
767                         context.check ();
768                         if (context.report.get_errors () > 0) {
769                                 GLib.error("failed check VAPIS, so we can not write file correctly");
770                                 // throw new VapiParserError.PARSE_FAILED("failed check VAPIS, so we can not write file correctly");
771                                 //Vala.CodeContext.pop ();
772                                  
773                                 //return;
774                                 
775                         }
776                          
777                         
778                          
779                         context.accept(this);
780                         
781                         context = null;
782                         // dump the tree for Gtk?
783                         
784                         Vala.CodeContext.pop ();
785                         
786                         
787                         this.augment_all_inheritence();
788                         
789                         
790                         
791                         print("ALL OK?\n");
792                  
793                 }
794         //
795                 // startpoint:
796                 //
797          public bool has_vapi(string[] dirs,  string vapi) 
798                 {
799                         for(var i =0 ; i < dirs.length; i++) {
800                                 GLib.debug("check VAPI - %s", dirs[i] + "/" + vapi + ".vapi");
801                                 if (!FileUtils.test( dirs[i] + "/" + vapi + ".vapi", FileTest.EXISTS)) {
802                                         continue;
803                                 }   
804                                 return true;
805                         }
806                         return false;
807                         
808                 }
809         }
810 }
811  /*
812 int main (string[] args) {
813         
814         var g = Palete.Gir.factoryFqn("Gtk.SourceView");
815         print("%s\n", g.asJSONString());
816         
817         return 0;
818 }
819  
820
821 */