3 // valac VapiParser.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
10 public class VapiParser : Vala.CodeVisitor {
12 static Gee.HashMap<string,Gir> cache = null;
16 Vala.CodeContext context;
20 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.new_empty(element.name);
39 cache.set(element.name, g);
42 foreach(var c in element.get_classes()) {
46 element.accept_children(this); // catch sub namespaces..
51 public void add_class(GirObject parent, Vala.Class cls)
54 var c = new GirObject("Class", parent.name + "." + cls.name);
55 parent.classes.set(cls.name, c);
57 c.parent = cls.base_class == null ? "" : cls.base_class.get_full_name() ; // extends...
60 foreach(var p in cls.get_properties()) {
61 this.add_property(c, p);
64 foreach(var p in cls.get_signal()) {
65 this.add_signal(c, p);
69 public void add_property(GirObject parent, Vala.Property prop)
71 var c = new GirObject("Prop",prop.name);
74 c.propertyof = parent.name;
75 c.type = prop.property_type.data_type == null ? "" : prop.property_type.data_type.get_full_name();
76 parent.props.set(prop.name,c);
79 public void add_signal(GirObject parent, Vala.Signal sig)
81 var c = new GirObject("Signal",sig.name);
84 c.type = sig.return_type.data_type == null ? "" : sig.return_type.data_type.get_full_name();
85 parent.signals.set(sig.name,c);
87 var params = sig.get_parameters() ;
88 if (params.size < 1) {
91 var cc = new GirObject("Paramset",n);
97 foreach(var p in sig.get_parameters()) {
98 this.add_param(cc, p);
102 public void add_param(GirObject parent, Vala.Parameter pam)
107 public void create_valac_tree( )
110 context = new Vala.CodeContext ();
111 Vala.CodeContext.push (context);
113 context.experimental = false;
114 context.experimental_non_null = false;
126 for (int i = 2; i <= ver; i += 2) {
127 context.add_define ("VALA_0_%d".printf (i));
131 //var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
132 // what's the current version of vala???
135 //vapidirs += Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
139 // or context.get_vapi_path("glib-2.0"); // should return path..
140 //context.vapi_directories = vapidirs;
141 context.report.enable_warnings = true;
142 context.metadata_directories = { };
143 context.gir_directories = {};
144 context.thread = true;
147 //this.report = new ValaSourceReport(this.file);
148 //context.report = this.report;
151 context.basedir = "/tmp"; //Posix.realpath (".");
153 context.directory = context.basedir;
156 // add default packages:
157 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
158 context.profile = Vala.Profile.GOBJECT;
160 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
161 context.root.add_using_directive (ns_ref);
163 // default.. packages..
164 context.add_external_package ("glib-2.0");
165 context.add_external_package ("gobject-2.0");
166 context.add_external_package ("gdk-3.0");
167 context.add_external_package ("atk");
168 context.add_external_package ("gdk-x11-3.0");
169 context.add_external_package ("x11");
171 // user defined ones..
172 //context.add_package ("Gtk");
174 var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, "/usr/share/vala-0.26/vapi/gtk+-3.0.vapi");
175 context.add_source_file (vfile);
177 //context.add_external_package ("libvala-0.24");
181 //add_documented_files (context, settings.source_files);
183 Vala.Parser parser = new Vala.Parser ();
184 parser.parse (context);
185 //gir_parser.parse (context);
186 if (context.report.get_errors () > 0) {
187 print("parse got errors");
190 Vala.CodeContext.pop ();
198 if (context.report.get_errors () > 0) {
199 print("check got errors");
201 Vala.CodeContext.pop ();
207 Vala.CodeContext.pop ();
209 context.accept(this);
211 // dump the tree for Gtk?
214 print("%s\n", cache.get("Gtk").asJSONString());
225 int main (string[] args) {
227 var a = new Palete.VapiParser( );
228 a.create_valac_tree();