]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add support for saving out the internal api as a vapi
authorRob Taylor <rob.taylor@codethink.co.uk>
Tue, 7 Apr 2009 15:17:50 +0000 (16:17 +0100)
committerRob Taylor <rob.taylor@codethink.co.uk>
Tue, 7 Apr 2009 15:17:50 +0000 (16:17 +0100)
compiler/valacompiler.vala
vala/valacodewriter.vala

index 0506388bace5916216c82fc4ba9eb62cd22c8ac0..50153e0bae28118f40811a8d5fab08097aadf245 100644 (file)
@@ -42,6 +42,7 @@ class Vala.Compiler {
        static bool ccode_only;
        static string header_filename;
        static string internal_header_filename;
+       static string internal_vapi_filename;
        static bool compile_only;
        static string output;
        static bool debug;
@@ -75,6 +76,7 @@ class Vala.Compiler {
                { "ccode", 'C', 0, OptionArg.NONE, ref ccode_only, "Output C code", null },
                { "header", 'H', 0, OptionArg.FILENAME, ref header_filename, "Output C header file", "FILE" },
                { "internal-header", 'h', 0, OptionArg.FILENAME, ref internal_header_filename, "Output internal C header file", "FILE" },
+               { "internal-vapi", 0, 0, OptionArg.FILENAME, ref target_glib, "Output vapi with internal api", "FILE" },
                { "compile", 'c', 0, OptionArg.NONE, ref compile_only, "Compile but do not link", null },
                { "output", 'o', 0, OptionArg.FILENAME, ref output, "Place output in file FILE", "FILE" },
                { "debug", 'g', 0, OptionArg.NONE, ref debug, "Produce debug information", null },
@@ -336,6 +338,19 @@ class Vala.Compiler {
 
                        library = null;
                }
+               if (internal_vapi_filename != null) {
+                       var interface_writer = new CodeWriter (false, true);
+                       string vapi_filename = "%s.vapi".printf (internal_vapi_filename);
+
+                       // put .vapi file in current directory unless -d has been explicitly specified
+                       if (directory != null && !Path.is_absolute (vapi_filename)) {
+                               vapi_filename = "%s%c%s".printf (context.directory, Path.DIR_SEPARATOR, vapi_filename);
+                       }
+
+                       interface_writer.write_file (context, vapi_filename);
+
+                       internal_vapi_filename = null;
+               }
 
                if (!ccode_only) {
                        var ccompiler = new CCodeCompiler ();
index d44a77d86e2750da2cdcc6e36c91071326bae54c..4ceebe18eba01e8dc04b1d600e468a0976e83ab8 100644 (file)
@@ -39,9 +39,11 @@ public class Vala.CodeWriter : CodeVisitor {
        Scope current_scope;
 
        bool dump_tree;
+       bool emit_internal;
 
-       public CodeWriter (bool dump_tree = false) {
+       public CodeWriter (bool dump_tree = false, bool emit_internal = false) {
                this.dump_tree = dump_tree;
+               this.emit_internal = emit_internal;
        }
 
        /**
@@ -1644,10 +1646,19 @@ public class Vala.CodeWriter : CodeVisitor {
        }
 
        private bool check_accessibility (Symbol sym) {
-               if (dump_tree ||
-                   sym.access == SymbolAccessibility.PUBLIC ||
-                   sym.access == SymbolAccessibility.PROTECTED) {
+               if (dump_tree) {
                        return true;
+               } else {
+                   if (!emit_internal &&
+                       ( sym.access == SymbolAccessibility.PUBLIC ||
+                         sym.access == SymbolAccessibility.PROTECTED)) {
+                       return true;
+                   } else if (emit_internal &&
+                       ( sym.access == SymbolAccessibility.INTERNAL ||
+                         sym.access == SymbolAccessibility.PUBLIC ||
+                         sym.access == SymbolAccessibility.PROTECTED)) {
+                       return true;
+                   }
                }
 
                return false;