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
10 public class VapiParser : Vala.CodeVisitor {
12 Vala.CodeContext context;
16 // should not really happen..
17 if (Gir.cache == null) {
18 Gir.cache = new Gee.HashMap<string,Gir>();
24 public override void visit_namespace (Vala.Namespace element)
26 if (element == null) {
30 print("parsing namespace %s\n", element.name);
31 if (element.name == null) {
32 element.accept_children(this); // catch sub namespaces..
36 var g = new Gir(element.name);
37 Gir.cache.set(element.name, g);
40 foreach(var c in element.get_classes()) {
43 foreach(var c in element.get_enums()) {
48 element.accept_children(this); // catch sub namespaces..
54 public void add_enum(GirObject parent, Vala.Enum cls)
57 var c = new GirObject("Enum", cls.name);
58 parent.consts.set(cls.name, c);
63 foreach(var e in cls.get_values()) {
64 var em = new GirObject("EnumMember",e.name);
67 em.type = e.type_reference == null || e.type_reference.data_type == null ? "" : e.type_reference.data_type.get_full_name();
68 // unlikely to get value..
69 //c.value = element->get_prop("value");
70 c.consts.set(e.name,em);
79 public void add_class(GirObject parent, Vala.Class cls)
82 var c = new GirObject("Class", parent.name + "." + cls.name);
83 parent.classes.set(cls.name, c);
85 c.parent = cls.base_class == null ? "" : cls.base_class.get_full_name() ; // extends...
88 foreach(var p in cls.get_properties()) {
89 this.add_property(c, p);
92 foreach(var p in cls.get_signals()) {
93 this.add_signal(c, p);
96 foreach(var p in cls.get_methods()) {
97 // skip static methods..
98 if (p.binding != Vala.MemberBinding.INSTANCE &&
99 !(p is Vala.CreationMethod)
104 this.add_method(c, p);
107 if (cls.base_class != null) {
108 c.inherits.add(cls.base_class.get_full_name());
110 foreach(var p in cls.get_base_types()) {
111 if (p.data_type != null) {
112 c.implements.add(p.data_type.get_full_name());
120 public void add_property(GirObject parent, Vala.Property prop)
122 var c = new GirObject("Prop",prop.name);
125 c.propertyof = parent.name;
126 c.type = prop.property_type.data_type == null ? "" : prop.property_type.data_type.get_full_name();
127 parent.props.set(prop.name,c);
130 public void add_signal(GirObject parent, Vala.Signal sig)
132 var c = new GirObject("Signal",sig.name);
136 if (sig.return_type.data_type != null) {
137 //print("creating return type on signal %s\n", sig.name);
138 var cc = new GirObject("Return", "return-value");
141 cc.type = sig.return_type.data_type.get_full_name();
144 parent.signals.set(sig.name,c);
146 var params = sig.get_parameters() ;
147 if (params.size < 1) {
150 var cc = new GirObject("Paramset",sig.name); // what's the name on this?
156 foreach(var p in params) {
157 this.add_param(cc, p);
162 public void add_method(GirObject parent, Vala.Method met)
164 var n = met.name == null ? parent.name : "";
166 if (met is Vala.CreationMethod && n == "") {
171 var c = new GirObject(ty,n);
175 if (met.return_type.data_type != null) {
176 //print("creating return type on method %s\n", met.name);
177 var cc = new GirObject("Return", "return-value");
180 cc.type = met.return_type.data_type.get_full_name();
183 if (met is Vala.CreationMethod) {
184 parent.ctors.set(c.name,c);
186 parent.methods.set(met.name,c);
189 var params = met.get_parameters() ;
190 if (params.size < 1) {
193 var cc = new GirObject("Paramset",met.name); // what's the name on this?
199 foreach(var p in params) {
200 if (p.name == null) {
203 this.add_param(cc, p);
208 public void add_param(GirObject parent, Vala.Parameter pam)
210 var c = new GirObject("Param",pam.name);
213 parent.params.add(c);
214 c.type = pam.variable_type.data_type == null ? "" : pam.variable_type.data_type.get_full_name();
215 // this.checkParamOverride(c); - this is an old kludge for Gir files..
219 public void create_valac_tree( )
222 context = new Vala.CodeContext ();
223 Vala.CodeContext.push (context);
225 context.experimental = false;
226 context.experimental_non_null = false;
238 for (int i = 2; i <= ver; i += 2) {
239 context.add_define ("VALA_0_%d".printf (i));
243 //var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
244 // what's the current version of vala???
247 //vapidirs += Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
251 // or context.get_vapi_path("glib-2.0"); // should return path..
252 //context.vapi_directories = vapidirs;
253 context.report.enable_warnings = true;
254 context.metadata_directories = { };
255 context.gir_directories = {};
256 context.thread = true;
259 //this.report = new ValaSourceReport(this.file);
260 //context.report = this.report;
263 context.basedir = "/tmp"; //Posix.realpath (".");
265 context.directory = context.basedir;
268 // add default packages:
269 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
270 context.profile = Vala.Profile.GOBJECT;
272 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
273 context.root.add_using_directive (ns_ref);
275 context.add_external_package ("glib-2.0");
276 context.add_external_package ("gobject-2.0");
278 // core packages we are interested in for the builder..
279 // some of these may fail... - we probalby need a better way to handle this..
281 context.add_external_package ("gtk+-3.0");
282 if (!context.add_external_package ("webkit2gtk-4.0")) {
283 context.add_external_package ("webkit2gtk-3.0");
285 context.add_external_package ("clutter-gtk-1.0");
286 context.add_external_package ("gdl-3.0");
287 context.add_external_package ("gtksourceview-3.0");
288 context.add_external_package ("vte-2.90"); //??? -- hopefullly that works..
289 //add_documented_files (context, settings.source_files);
291 Vala.Parser parser = new Vala.Parser ();
292 parser.parse (context);
293 //gir_parser.parse (context);
294 if (context.report.get_errors () > 0) {
295 print("parse got errors");
298 Vala.CodeContext.pop ();
306 if (context.report.get_errors () > 0) {
307 print("check got errors");
309 Vala.CodeContext.pop ();
315 Vala.CodeContext.pop ();
317 context.accept(this);
319 // dump the tree for Gtk?
333 int main (string[] args) {
335 var g = Palete.Gir.factory("Gdk");
336 print("%s\n", g.asJSONString());