resources/RooUsage.txt
[app.Builder.js] / src / Palete / VapiParser.vala
index a0fcd5f..0812d60 100644 (file)
@@ -4,7 +4,9 @@
 
 namespace Palete {
         
-        
+        public errordomain VapiParserError {
+               PARSE_FAILED 
+       }
         
 
        public class VapiParser : Vala.CodeVisitor {
@@ -27,14 +29,26 @@ namespace Palete {
                                
                                return;
                        }
-                       print("parsing namespace %s\n", element.name);
+                       
+                       
+                       //print("parsing namespace %s\n", element.name);
                        if (element.name == null) {
                                element.accept_children(this); // catch sub namespaces..
                                return;
                        }
+                       this.add_namespace(null, element);
+               }
+               public void add_namespace(GirObject? parent, Vala.Namespace element)
+               {
                        
-                       var g = new Gir(element.name);
-                       cache.set(element.name, g);
+                       
+                       var g = new GirObject("Package",element.name) ;
+                       if (parent == null) {
+                               Gir.cache.set(element.name, (Gir)g);
+                       } else {
+                               // we add it as a class of the package.. even though its a namespace..
+                               parent.classes.set(element.name, g);
+                       }
                        
                        
                        foreach(var c in element.get_classes()) {
@@ -43,13 +57,20 @@ namespace Palete {
                        foreach(var c in element.get_enums()) {
                                this.add_enum(g, c);
                        }
-                       
-                       
+                       foreach(var c in element.get_interfaces()) {
+                               this.add_interface(g, c);
+                       }
+                       foreach(var c in element.get_namespaces()) {
+                               this.add_namespace(g, c);
+                       }
+                       foreach(var c in element.get_methods()) {
+                               this.add_method(g, c);
+                       }
                        element.accept_children(this); // catch sub namespaces..
                        
                        
                }
-               
+                
                
                public void add_enum(GirObject parent, Vala.Enum cls)
                {
@@ -75,6 +96,47 @@ namespace Palete {
                         
                }
                
+               public void add_interface(GirObject parent, Vala.Interface cls)
+               {
+               
+                       var c = new GirObject("Interface", parent.name + "." + cls.name);
+                       parent.classes.set(cls.name, c);
+                       c.ns = parent.name;
+                       //c.parent = cls.base_class == null ? "" : cls.base_class.get_full_name() ;  // extends...
+                       c.gparent = parent;
+                       
+                       foreach(var p in cls.get_properties()) {
+                               this.add_property(c, p);
+                       }
+                       // methods...
+                       foreach(var p in cls.get_signals()) {
+                               this.add_signal(c, p);
+                       }
+                       
+                       foreach(var p in cls.get_methods()) {
+                               // skip static methods..
+                               if (p.binding != Vala.MemberBinding.INSTANCE &&
+                                       !(p is Vala.CreationMethod)
+                               ) {
+                                       continue;
+                               }
+                               
+                               this.add_method(c, p);
+                       }
+                       
+                       //if (cls.base_class != null) {
+                       //      c.inherits.add(cls.base_class.get_full_name());
+                       //}
+                       //foreach(var p in cls.get_base_types()) {
+                       //      if (p.data_type != null) {
+                       //              c.implements.add(p.data_type.get_full_name());
+                       //      }
+                       //}
+                         
+                       
+                       
+                        
+               }
                
                public void add_class(GirObject parent, Vala.Class cls)
                {
@@ -123,6 +185,7 @@ namespace Palete {
                        c.gparent = parent;
                        c.ns = parent.ns;
                        c.propertyof = parent.name;
+                       
                        c.type  = prop.property_type.data_type == null ? "" : prop.property_type.data_type.get_full_name();
                        parent.props.set(prop.name,c);
                        
@@ -161,12 +224,16 @@ namespace Palete {
                
                public void add_method(GirObject parent, Vala.Method met)
                {
-                       var n = met.name == null ? parent.name : "";
+                       var n = met.name == null ? "" : met.name;
                        var ty  = "Method";
-                       if (met is Vala.CreationMethod && n == "") {
-                               n = ".new";
+                       if (met is Vala.CreationMethod) {
                                ty = "Ctor";
+                               if(n == "" || n == ".new") {
+                                       n = "new";
+                               }
+                               
                        }
+                       //print("add_method :  %s\n", n);
                        
                        var c = new GirObject(ty,n);
                        c.gparent = parent;
@@ -194,25 +261,50 @@ namespace Palete {
                        cc.gparent = c;
                        cc.ns = c.ns;
                        c.paramset = cc;
-                       
+                       c.sig = "(";
                        
                        foreach(var p in params) {
-                               if (p.name == null) {
+                               if (p.name == null && !p.ellipsis) {
                                        continue;
                                }
-                               this.add_param(cc, p);
+                               var pp = this.add_param(cc, p);
+                               c.sig += (c.sig == "(" ? "" : ",");
+                               c.sig += " " + (pp.direction == "in" ? "" : pp.direction) + " " + pp.type + " " + pp.name;
                        }
+                       c.sig += (c.sig == "(" ? ")" : " )");
                        
                }
                
-               public void add_param(GirObject parent, Vala.Parameter pam)
+               public GirObject add_param(GirObject parent, Vala.Parameter pam)
                {
-                       var c = new GirObject("Param",pam.name);
+                       
+                       var n = pam.name;
+                       if (pam.ellipsis) {
+                               n = "___";
+                       }
+                       var c = new GirObject("Param",n);
                        c.gparent = parent;
                        c.ns = parent.ns;
+                       c.direction = "??";
+                       switch (pam.direction) {
+                               case Vala.ParameterDirection.IN:
+                                       c.direction = "in";
+                                       break;
+                               case Vala.ParameterDirection.OUT:
+                                       c.direction = "out";
+                                       break;
+                               case Vala.ParameterDirection.REF:
+                                       c.direction = "ref";
+                                       break;
+                       }
+                       
                        parent.params.add(c);
-                       c.type = pam.variable_type.data_type == null ? "" : pam.variable_type.data_type.get_full_name();
-                       // this.checkParamOverride(c);   - this is an old kludge for Gir files..
+                       
+                       if (!pam.ellipsis) {
+                               c.type = pam.variable_type.data_type == null ? "" : pam.variable_type.data_type.get_full_name();
+                       }
+                       Gir.checkParamOverride(c); 
+                       return c;
                        
                }
                
@@ -224,8 +316,11 @@ namespace Palete {
                
                        context.experimental = false;
                        context.experimental_non_null = false;
-                       
-#if VALA_0_28
+#if VALA_0_32
+                       var ver=32;                     
+#elif VALA_0_30
+                       var ver=30;                     
+#elif VALA_0_28
                        var ver=28;
 #elif VALA_0_26        
                        var ver=26;
@@ -246,8 +341,10 @@ namespace Palete {
                        
                        //vapidirs +=  Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
                         
-                               
+                       var vapidirs = context.vapi_directories;
                        
+                       vapidirs += (BuilderApplication.configDirectory() + "/resources/vapi");
+                       context.vapi_directories = vapidirs;
                        // or context.get_vapi_path("glib-2.0"); // should return path..
                        //context.vapi_directories = vapidirs;
                        context.report.enable_warnings = true;
@@ -271,31 +368,37 @@ namespace Palete {
                         
                        var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
                        context.root.add_using_directive (ns_ref);
-                       // default.. packages..
+                       
                        context.add_external_package ("glib-2.0"); 
                        context.add_external_package ("gobject-2.0");
-                       context.add_external_package ("gdk-3.0");
-                       context.add_external_package ("atk");
-                       context.add_external_package ("gdk-x11-3.0");
-                       context.add_external_package ("x11");
-                       context.add_external_package ("gtk+-3.0");
-                       // user defined ones..
-                       //context.add_package ("Gtk");
-                 
-                       //var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, "/usr/share/vala-0.26/vapi/gtk+-3.0.vapi");
-                       //context.add_source_file (vfile);
-                        
-                       //context.add_external_package ("libvala-0.24");
                        
-                        
-               
+                       // core packages we are interested in for the builder..
+                       // some of these may fail... - we probalby need a better way to handle this..
+                       
+                       context.add_external_package ("gtk+-3.0");
+                       context.add_external_package ("libsoup-2.4");
+                       if (!context.add_external_package ("webkit2gtk-4.0")) {
+                               context.add_external_package ("webkit2gtk-3.0");
+                       }
+                       // these are supposed to be in the 'deps' file, but it's not getting read..
+                       context.add_external_package ("cogl-1.0");
+                       context.add_external_package ("json-glib-1.0");
+                       context.add_external_package ("clutter-gtk-1.0");
+
+
+                   
+                       context.add_external_package ("gdl-3.0");
+                       context.add_external_package ("gtksourceview-3.0");
+                       context.add_external_package ("vte-2.90"); //??? -- hopefullly that works..
                        //add_documented_files (context, settings.source_files);
                
                        Vala.Parser parser = new Vala.Parser ();
                        parser.parse (context);
                        //gir_parser.parse (context);
                        if (context.report.get_errors () > 0) {
+                               
+                               throw new VapiParserError.PARSE_FAILED("failed parse VAPIS, so we can not write file correctly");
+                               
                                print("parse got errors");
                                 
                                
@@ -309,20 +412,21 @@ namespace Palete {
                        context.check ();
                        if (context.report.get_errors () > 0) {
                                print("check got errors");
-                                
+                                throw new VapiParserError.PARSE_FAILED("failed check VAPIS, so we can not write file correctly");
                                Vala.CodeContext.pop ();
                                 
                                return;
                                
                        }
                         
-                       Vala.CodeContext.pop ();
+                       
                         
                        context.accept(this);
                        
+                       context = null;
                        // dump the tree for Gtk?
                        
-                       
+                       Vala.CodeContext.pop ();
                        
                        print("ALL OK?\n");
                 
@@ -333,14 +437,14 @@ namespace Palete {
         
        }
 }
+ /*
 int main (string[] args) {
        
-       var g = Palete.Gir.factory("Gtk");
+       var g = Palete.Gir.factoryFqn("Gtk.SourceView");
        print("%s\n", g.asJSONString());
        
        return 0;
 }
  
 
-
+*/