- // valac -g --pkg libvala-0.26 --pkg libxml-2.0 --pkg gee-1.0 --pkg json-glib-1.0 --pkg gobject-introspection-1.0 --pkg gtk+-3.0 ../Application.vala VapiParser.vala Gir.vala -o /tmp/vdoc
+ // 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
namespace Palete {
-
+ public errordomain VapiParserError {
+ PARSE_FAILED
+ }
public class VapiParser : Vala.CodeVisitor {
-
- public static Gee.HashMap<string,Gir> cache = null;
-
-
- public static GirObject? factory(string ns) {
- if (cache == null) {
- cache = new Gee.HashMap<string,Gir>();
- }
- var ret = cache.get(ns);
- if (ret == null) {
-
- var add = new GirObject("Namespace",ns);
-
-
-
- cache.set(ns, add);
-
- var iter = add.classes.map_iterator();
- while(iter.next()) {
- iter.get_value().overlayParent();
- }
- // loop again and add the ctor properties.
- iter = add.classes.map_iterator();
- while(iter.next()) {
- iter.get_value().overlayCtorProperties();
- }
-
-
- ret = cache.get(ns);
- }
-
-
- return ret;
-
- }
- Vala.CodeContext context;
- public VapiParser() {
+ Vala.CodeContext context;
+
+ public VapiParser() {
base();
- if (cache == null) {
- cache = new Gee.HashMap<string,Gir>();
+ // should not really happen..
+ if (Gir.cache == null) {
+ Gir.cache = new Gee.HashMap<string,Gir>();
}
}
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.new_empty(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()) {
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)
{
}
+ 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)
{
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);
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;
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;
}
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;
//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;
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");
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("%s\n", cache.get("Gtk").asJSONString());
print("ALL OK?\n");
}
}
}
-
+ /*
int main (string[] args) {
-
- var a = new Palete.VapiParser( );
- a.create_valac_tree();
+
+ var g = Palete.Gir.factoryFqn("Gtk.SourceView");
+ print("%s\n", g.asJSONString());
+
return 0;
}
-
+*/