[vala: 1/8] Add support for saving out the internal api as a vapi



commit 097b3eb67e29fb68d6f4e06c5b0f311b984a1e63
Author: Rob Taylor <rob taylor codethink co uk>
Date:   Tue Apr 7 16:17:50 2009 +0100

    Add support for saving out the internal api as a vapi
---
 compiler/valacompiler.vala |   15 +++++++++++++++
 vala/valacodewriter.vala   |   19 +++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 0506388..50153e0 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -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 ();
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index d44a77d..4ceebe1 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]