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) {
27 print("parsing namespace %s\n", element.name);
29 var g = new Gir.new_empty(element.name);
30 cache.set(element.name, g);
33 foreach(var c in element.get_classes()) {
42 public void add_class(GirObject parent, Vala.Class cls)
45 var c = new GirObject("Class", parent.name + "." + cls.name);
46 parent.classes.set(cls.name, c);
48 c.parent = cls.base_class.get_full_name() ; // extends...
51 foreach(var p in element.get_properties()) {
52 this.add_property(c, p);
58 public void add_property(GirObject parent, Vala.Property prop)
60 var c = new GirObject("Prop",prop.name);
63 c.propertyof = parent.name;
64 c.type = prop.property_type.data_type..get_full_name();
65 parent.props.set(prop.name,c);
70 public void create_valac_tree( )
73 context = new Vala.CodeContext ();
74 Vala.CodeContext.push (context);
76 context.experimental = false;
77 context.experimental_non_null = false;
89 for (int i = 2; i <= ver; i += 2) {
90 context.add_define ("VALA_0_%d".printf (i));
94 //var vapidirs = ((Project.Gtk)this.file.project).vapidirs();
95 // what's the current version of vala???
98 //vapidirs += Path.get_dirname (context.get_vapi_path("glib-2.0")) ;
102 // or context.get_vapi_path("glib-2.0"); // should return path..
103 //context.vapi_directories = vapidirs;
104 context.report.enable_warnings = true;
105 context.metadata_directories = { };
106 context.gir_directories = {};
107 context.thread = true;
110 //this.report = new ValaSourceReport(this.file);
111 //context.report = this.report;
114 context.basedir = "/tmp"; //Posix.realpath (".");
116 context.directory = context.basedir;
119 // add default packages:
120 //if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) {
121 context.profile = Vala.Profile.GOBJECT;
123 var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
124 context.root.add_using_directive (ns_ref);
126 // default.. packages..
127 context.add_external_package ("glib-2.0");
128 context.add_external_package ("gobject-2.0");
129 context.add_external_package ("gdk-3.0");
130 context.add_external_package ("atk");
131 context.add_external_package ("gdk-x11-3.0");
132 context.add_external_package ("x11");
134 // user defined ones..
135 //context.add_package ("Gtk");
137 var vfile = new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, "/usr/share/vala-0.26/vapi/gtk+-3.0.vapi");
138 context.add_source_file (vfile);
140 //context.add_external_package ("libvala-0.24");
144 //add_documented_files (context, settings.source_files);
146 Vala.Parser parser = new Vala.Parser ();
147 parser.parse (context);
148 //gir_parser.parse (context);
149 if (context.report.get_errors () > 0) {
150 print("parse got errors");
153 Vala.CodeContext.pop ();
161 if (context.report.get_errors () > 0) {
162 print("check got errors");
164 Vala.CodeContext.pop ();
170 Vala.CodeContext.pop ();
172 context.accept(this);
174 // dump the tree for Gtk?
188 int main (string[] args) {
190 var a = new Palete.VapiParser( );
191 a.create_valac_tree();