/*
public static int main (string[] args) {
- var g = new Palete.Gir("Gtk");
+ var g = Palete.Gir.factory("Gtk");
+ var test = g.classes.get("ToolButton");
+
+
var generator = new Json.Generator ();
var n = new Json.Node(Json.NodeType.OBJECT);
- n.set_object(g.toJSON());
+ n.set_object(test.toJSON());
generator.set_root(n);
generator.indent = 4;
generator.pretty = true;
print(generator.to_data(null));
return 0;
}
-*/
+ */
namespace Palete {
-
+ public errordomain GirError {
+ INVALID_TYPE,
+ NEED_IMPLEMENTING,
+ MISSING_FILE,
+ INVALID_VALUE
+ }
public class GirObject: Object {
public string name;
public string ns;
+ public string propertyof;
public string type;
public string nodetype;
public string package;
public bool is_varargs;
public string parent;
public string value;
-
- public Gee.HashMap<string,GirObject> params;
+
+ bool is_overlaid;
+ public GLib.List<GirObject> params;
public GLib.List<string> implements;
+ public GLib.List<string> inherits; // full list of all classes and interfaces...
public Gee.HashMap<string,GirObject> ctors;
public Gee.HashMap<string,GirObject> methods;
public Gee.HashMap<string,string> includes;
public Gee.HashMap<string,GirObject> props;
public Gee.HashMap<string,GirObject> consts;
public Gee.HashMap<string,GirObject> signals;
- public string doc;
+ public string doctxt;
public GirObject(string nodetype, string n)
{
this.nodetype = nodetype;
this.ns = "";
this.parent = "";
this.type = "";
+ this.propertyof = "";
this.is_array = false;
this.is_instance = false;
this.is_varargs = false;
this.implements = new GLib.List<string>();
+ this.inherits = new GLib.List<string>();
this.includes = new Gee.HashMap<string,string>();
- this.params = new Gee.HashMap<string,GirObject>();
+ this.params = new GLib.List<GirObject>();
this.ctors = new Gee.HashMap<string,GirObject>();
this.methods =new Gee.HashMap<string,GirObject>();
this.props = new Gee.HashMap<string,GirObject>();
this.consts = new Gee.HashMap<string,GirObject>();
this.signals = new Gee.HashMap<string,GirObject>();
+ this.is_overlaid = false;
+ this.paramset = null;
}
- public void overlayParent(Gir gir)
+ public void overlayParent()
{
-
- if (this.parent.length < 1) {
+
+ if (this.parent.length < 1 || this.is_overlaid) {
+ this.is_overlaid = true;
return;
}
- print(this.parent);
- Gir pns = gir;
- if (parent.contains(".")) {
- var Gir.factory(parent.split(".")[0]);
+ // print("Overlaying " +this.name + " with " + this.parent + "\n");
+ var pcls = this.clsToObject( this.parent);
+ if (pcls == null) {
+ throw new GirError.INVALID_VALUE("Could not find class : " +
+ this.parent + " of " + this.name + " in " + this.ns);
}
- gir.classes.get(
+ pcls.overlayParent( );
+ this.copyFrom(pcls,false);
+ for(var i=0; i < this.implements.length(); i++) {
+ var clsname = this.implements.nth_data(i);
+ var picls = this.clsToObject(clsname);
+ this.copyFrom(picls,true);
+ }
+ this.is_overlaid = true;
+
+ }
+ public GirObject clsToObject(string in_pn)
+ {
+ var pn = in_pn;
+ var gir = Gir.factory (this.ns);
+ if (in_pn.contains(".")) {
+ gir = Gir.factory(in_pn.split(".")[0]);
+ pn = in_pn.split(".")[1];
+ }
+
+ return gir.classes.get(pn);
+
+ }
+ public string fqn() {
+ return this.ns + this.name;
+ }
+
+ public void copyFrom(GirObject pcls, bool is_interface)
+ {
+
+ this.inherits.append(pcls.fqn());
+ var iter = pcls.methods.map_iterator();
+ while(iter.next()) {
+ if (null != this.methods.get(iter.get_key())) {
+ continue;
+ }
+
+ this.methods.set(iter.get_key(), iter.get_value());
+ }
+
+ iter = pcls.props.map_iterator();
+ while(iter.next()) {
+ if (null != this.props.get(iter.get_key())) {
+ continue;
+ }
+
+ this.props.set(iter.get_key(), iter.get_value());
+ }
+
+ iter = pcls.signals.map_iterator();
+ while(iter.next()) {
+ if (null != this.signals.get(iter.get_key())) {
+ continue;
+ }
+
+ this.signals.set(iter.get_key(), iter.get_value());
+ }
}
public Json.Object toJSON()
var r = new Json.Object();
r.set_string_member("nodetype", this.nodetype);
r.set_string_member("name", this.name);
+ if (this.propertyof.length > 0) {
+ r.set_string_member("of", this.propertyof);
+ }
if (this.type.length > 0) {
r.set_string_member("type", this.type);
}
r.set_array_member("length", this.toJSONArrayString(this.implements));
}
- if (this.params.size > 0) {
- r.set_object_member("params", this.toJSONObject(this.params));
+ if (this.params.length() > 0) {
+ r.set_array_member("params", this.toJSONArrayObject(this.params));
}
if (this.ctors.size > 0) {
r.set_object_member("ctors", this.toJSONObject(this.ctors));
r.set_object_member("consts", this.toJSONObject(this.consts));
}
if (this.signals.size > 0) {
- r.set_object_member("cosignalsnsts", this.toJSONObject(this.signals));
+ r.set_object_member("signals", this.toJSONObject(this.signals));
}
if (this.paramset != null) {
r.set_object_member("params", this.paramset.toJSON());
r.add_string_element(map.nth_data(i));
}
return r;
+ }
+ public Json.Array toJSONArrayObject(GLib.List<GirObject> map)
+ {
+ var r = new Json.Array();
+ for(var i =0;i< map.length();i++) {
+
+ r.add_object_element(map.nth_data(i).toJSON());
+ }
+ return r;
}
}
if (ret != null) {
return ret;
}
- cache.set(ns, new Gir(ns));
+ var add = new Gir(ns);
+ cache.set(ns, add);
+
+ var iter = add.classes.map_iterator();
+ while(iter.next()) {
+
+ iter.get_value().overlayParent();
+ }
+
return cache.get(ns);
}
- public Gir (string ns) Gee.HashMap<string,Gir> = null;
+ public Gir (string ns)
{
var gi = GI.Repository.get_default();
var gir_path = pth.nth_data(0).replace("/lib/girepository-1.0", "/share/gir-1.0");
//console.log(fn);
var file = gir_path + "/" + ns + "-" + ver + ".gir";
- print("ns: " + ns + "\n");
- print("ver: " + ver + "\n");
- print(file);
+ // print("ns: " + ns + "\n");
+ // print("ver: " + ver + "\n");
+ // print(file);
base("Package",ns);
+ this.ns = ns;
//this.nodes = new Gee.Hashmap<string,what>();
var doc = Xml.Parser.parse_file (file);
var root = doc->get_root_element();
this.walk( root, (GirObject) this );
+
delete doc;
}
case "class":
var c = new GirObject("Class", parent.name + "." + n);
parent.classes.set(n, c);
- c.ns = parent.name;
+ c.ns = this.ns;
c.parent = element->get_prop("parent");
if (c.parent == null) {
c.parent = "";
case "interface":
var c = new GirObject("Interface", parent.name + "." + n);
parent.classes.set(n, c);
+ c.ns = this.ns;
c.ns = parent.name;
c.parent = element->get_prop("parent");
if (c.parent == null) {
case "doc":
- parent.doc = element->get_content();
+ parent.doctxt = element->get_content();
return;
case "implements":
case "constructor":
var c = new GirObject("Ctor",n);
+ c.ns = this.ns;
parent.ctors.set(n,c);
parent = c;
break;
case "return-value":
var c = new GirObject("Return", "return-value");
+ c.ns = this.ns;
parent.return_value = c;
parent = c;
break;
break;
*/
case "signal": // Glib:signal
- var c = new GirObject("Signal",n);
- parent.signals.set(n,c);
+ var c = new GirObject("Signal",n.replace("-", "_"));
+ c.ns = this.ns;
+ parent.signals.set(n.replace("-", "_"),c);
parent = c;
break;
case "type":
parent.type = n;
- return; // no children?
+
+ return; // no children?
//break;
case "method":
var c = new GirObject("Method",n);
+ c.ns = this.ns;
+ c.propertyof = parent.name;
parent.methods.set(n,c);
parent = c;
break;
case "parameters":
var c = new GirObject("Paramset",n);
+ c.ns = this.ns;
parent.paramset = c;
parent = c;
break;
case "instance-parameter":
var c = new GirObject("Param",n);
+ c.ns = this.ns;
c.is_instance = true;
- parent.params.set(n,c);
+ parent.params.append(c);
parent = c;
break;
case "parameter":
var c = new GirObject("Param",n);
- parent.params.set(n,c);
+ c.ns = this.ns;
+ parent.params.append(c);
parent = c;
break;
case "property":
case "field":
- var c = new GirObject("Prop",n);
- parent.props.set(n,c);
+ var c = new GirObject("Prop",n.replace("-", "_"));
+ c.ns = this.ns;
+ c.propertyof = parent.name;
+ parent.props.set(n.replace("-", "_"),c);
parent = c;
break;
case "function":
var c = new GirObject("Function",n);
+ c.ns = this.ns;
parent.methods.set(n,c);
parent = c;
break;
case "constant":
var c = new GirObject("Const",n);
c.value = element->get_prop("value");
+ c.ns = this.ns;
parent.consts.set(n,c);
parent = c;
return;
case "enumeration":
var c = new GirObject("Enum",n);
+ c.ns = this.ns;
parent.consts.set(n,c);
+
parent = c;
break;
case "member":
var c = new GirObject("EnumMember",n);
+ c.ns = this.ns;
c.value = element->get_prop("value");
parent.consts.set(n,c);
return;
case "prerequisite": // ignore?
return;
default:
- print("UNHANDLED" + element->name +"\n");
+ print("UNHANDLED Gir file element: " + element->name +"\n");
return;
}
/*
}
}
-
+ public string doc(string what)
+ {
+ var ar = what.split(".");
+ var cls = this.classes.get(ar[1]);
+ if (ar.length == 2) {
+ return cls.doctxt != null ? cls.doctxt : "";
+ }
+ // return the property.. by default..
+ var pr = cls.props.get(ar[2]);
+ return pr.doctxt != null ? pr.doctxt : "";
+
+ }
}