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