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
7 public errordomain VapiParserError {
12 public class VapiParser : Vala.CodeVisitor {
14 Vala.CodeContext context;
18 // should not really happen..
19 if (Gir.cache == null) {
20 Gir.cache = new Gee.HashMap<string,Gir>();
26 public override void visit_namespace (Vala.Namespace element)
28 if (element == null) {
32 //print("parsing namespace %s\n", element.name);
33 if (element.name == null) {
34 element.accept_children(this); // catch sub namespaces..
38 var g = new Gir(element.name);
39 Gir.cache.set(element.name, g);
42 foreach(var c in element.get_classes()) {
45 foreach(var c in element.get_enums()) {
48 foreach(var c in element.get_interfaces()) {
49 this.add_interface(g, c);
51 foreach(var c in element.get_namespaces()) {
52 this.add_namespace(g, c);
54 element.accept_children(this); // catch sub namespaces..
60 public void add_enum(GirObject parent, Vala.Enum cls)
63 var c = new GirObject("Enum", cls.name);
64 parent.consts.set(cls.name, c);
69 foreach(var e in cls.get_values()) {
70 var em = new GirObject("EnumMember",e.name);
73 em.type = e.type_reference == null || e.type_reference.data_type == null ? "" : e.type_reference.data_type.get_full_name();
74 // unlikely to get value..
75 //c.value = element->get_prop("value");
76 c.consts.set(e.name,em);
84 public void add_interface(GirObject parent, Vala.Interface cls)
87 var c = new GirObject("Interface", parent.name + "." + cls.name);
88 parent.classes.set(cls.name, c);
90 //c.parent = cls.base_class == null ? "" : cls.base_class.get_full_name() ; // extends...
93 foreach(var p in cls.get_properties()) {
94 this.add_property(c, p);
97 foreach(var p in cls.get_signals()) {
98 this.add_signal(c, p);
101 foreach(var p in cls.get_methods()) {
102 // skip static methods..
103 if (p.binding != Vala.MemberBinding.INSTANCE &&
104 !(p is Vala.CreationMethod)
109 this.add_method(c, p);
112 //if (cls.base_class != null) {
113 // c.inherits.add(cls.base_class.get_full_name());
115 //foreach(var p in cls.get_base_types()) {
116 // if (p.data_type != null) {
117 // c.implements.add(p.data_type.get_full_name());
126 public void add_class(GirObject parent, Vala.Class cls)
129 var c = new GirObject("Class", parent.name + "." + cls.name);
130 parent.classes.set(cls.name, c);
132 c.parent = cls.base_class == null ? "" : cls.base_class.get_full_name() ; // extends...
135 foreach(var p in cls.get_properties()) {
136 this.add_property(c, p);
139 foreach(var p in cls.get_signals()) {
140 this.add_signal(c, p);
143 foreach(var p in cls.get_methods()) {
144 // skip static methods..
145 if (p.binding != Vala.MemberBinding.INSTANCE &&
146 !(p is Vala.CreationMethod)
151 this.add_method(c, p);
154 if (cls.base_class != null) {
155 c.inherits.add(cls.base_class.get_full_name());
157 foreach(var p in cls.get_base_types()) {
158 if (p.data_type != null) {
159 c.implements.add(p.data_type.get_full_name());
167 public void add_property(GirObject parent, Vala.Property prop)
169 var c = new GirObject("Prop",prop.name);
172 c.propertyof = parent.name;
173 c.type = prop.property_type.data_type == null ? "" : prop.property_type.data_type.get_full_name();
174 parent.props.set(prop.name,c);
177 public void add_signal(GirObject parent, Vala.Signal sig)
179 var c = new GirObject("Signal",sig.name);
183 if (sig.return_type.data_type != null) {
184 //print("creating return type on signal %s\n", sig.name);
185 var cc = new GirObject("Return", "return-value");
188 cc.type = sig.return_type.data_type.get_full_name();
191 parent.signals.set(sig.name,c);
193 var params = sig.get_parameters() ;
194 if (params.size < 1) {
197 var cc = new GirObject("Paramset",sig.name); // what's the name on this?
203 foreach(var p in params) {
204 this.add_param(cc, p);
209 public void add_method(GirObject parent, Vala.Method met)
211 var n = met.name == null ? "" : met.name;
213 if (met is Vala.CreationMethod) {
215 if(n == "" || n == ".new") {
220 //print("add_method : %s\n", n);
222 var c = new GirObject(ty,n);
226 if (met.return_type.data_type != null) {
227 //print("creating return type on method %s\n", met.name);
228 var cc = new GirObject("Return", "return-value");
231 cc.type = met.return_type.data_type.get_full_name();
234 if (met is Vala.CreationMethod) {
235 parent.ctors.set(c.name,c);
237 parent.methods.set(met.name,c);
240 var params = met.get_parameters() ;
241 if (params.size < 1) {
244 var cc = new GirObject("Paramset",met.name); // what's the name on this?
250 foreach(var p in params) {
251 if (p.name == null && !p.ellipsis) {
254 this.add_param(cc, p);
259 public void add_param(GirObject parent, Vala.Parameter pam)
266 var c = new GirObject("Param",n);
269 parent.params.add(c);
272 c.type = pam.variable_type.data_type == null ? "" : pam.variable_type.data_type.get_full_name();
274 Gir.checkParamOverride(c);
278 public void create_valac_tree( )
281 context = new Vala.CodeContext ();
282 Vala.CodeContext.push (context);
284 context.experimental = false;
285 context.experimental_non_null = false;
297 for (int i = 2; i <= ver; i += 2) {
298 context.add_define ("VALA_0_%d".printf (i));
302 //var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
303 // what's the current version of vala???
306 //vapidirs += Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
308 var vapidirs = context.vapi_directories;
310 vapidirs += (BuilderApplication.configDirectory() + "/resources/vapi");
311 context.vapi_directories = vapidirs;
312 // or context.get_vapi_path("glib-2.0"); // should return path..
313 //context.vapi_directories = vapidirs;
314 context.report.enable_warnings = true;
315 context.metadata_directories = { };
316 context.gir_directories = {};
317 context.thread = true;
320 //this.report = new ValaSourceReport(this.file);
321 //context.report = this.report;
324 context.basedir = "/tmp"; //Posix.realpath (".");
326 context.directory = context.basedir;
329 // add default packages:
330 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
331 context.profile = Vala.Profile.GOBJECT;
333 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
334 context.root.add_using_directive (ns_ref);
336 context.add_external_package ("glib-2.0");
337 context.add_external_package ("gobject-2.0");
339 // core packages we are interested in for the builder..
340 // some of these may fail... - we probalby need a better way to handle this..
342 context.add_external_package ("gtk+-3.0");
343 context.add_external_package ("libsoup-2.4");
344 if (!context.add_external_package ("webkit2gtk-4.0")) {
345 context.add_external_package ("webkit2gtk-3.0");
347 context.add_external_package ("clutter-gtk-1.0");
348 context.add_external_package ("gdl-3.0");
349 context.add_external_package ("gtksourceview-3.0");
350 context.add_external_package ("vte-2.90"); //??? -- hopefullly that works..
351 //add_documented_files (context, settings.source_files);
353 Vala.Parser parser = new Vala.Parser ();
354 parser.parse (context);
355 //gir_parser.parse (context);
356 if (context.report.get_errors () > 0) {
358 throw new VapiParserError.PARSE_FAILED("failed parse VAPIS, so we can not write file correctly");
360 print("parse got errors");
363 Vala.CodeContext.pop ();
371 if (context.report.get_errors () > 0) {
372 print("check got errors");
373 throw new VapiParserError.PARSE_FAILED("failed check VAPIS, so we can not write file correctly");
374 Vala.CodeContext.pop ();
382 context.accept(this);
385 // dump the tree for Gtk?
387 Vala.CodeContext.pop ();
399 int main (string[] args) {
401 var g = Palete.Gir.factoryFqn("Gtk.SourceView");
402 print("%s\n", g.asJSONString());