vala r2336 - in trunk: . compiler gobject vala



Author: juergbi
Date: Tue Jan 13 18:41:04 2009
New Revision: 2336
URL: http://svn.gnome.org/viewvc/vala?rev=2336&view=rev

Log:
2009-01-13  JÃrg Billeter  <j bitron ch>

	* vala/valacodecontext.vala:
	* gobject/valaccodebasemodule.vala:
	* compiler/valacompiler.vala:

	Add -H command-line option to generate C header file for public
	API, stub implementation


Modified:
   trunk/ChangeLog
   trunk/compiler/valacompiler.vala
   trunk/gobject/valaccodebasemodule.vala
   trunk/vala/valacodecontext.vala

Modified: trunk/compiler/valacompiler.vala
==============================================================================
--- trunk/compiler/valacompiler.vala	(original)
+++ trunk/compiler/valacompiler.vala	Tue Jan 13 18:41:04 2009
@@ -40,6 +40,7 @@
 	static string target_glib;
 
 	static bool ccode_only;
+	static string header_filename;
 	static bool compile_only;
 	static string output;
 	static bool debug;
@@ -68,6 +69,7 @@
 		{ "directory", 'd', 0, OptionArg.FILENAME, ref directory, "Output directory", "DIRECTORY" },
 		{ "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null },
 		{ "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" },
 		{ "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 },
@@ -166,6 +168,7 @@
 
 		context.ccode_only = ccode_only;
 		context.compile_only = compile_only;
+		context.header_filename = header_filename;
 		context.output = output;
 		if (basedir != null) {
 			context.basedir = realpath (basedir);

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Tue Jan 13 18:41:04 2009
@@ -631,6 +631,26 @@
 				file.accept (codegen);
 			}
 		}
+
+		// generate C header file for public API
+		if (context.header_filename != null) {
+			var writer = new CCodeWriter (context.header_filename);
+			if (!writer.open ()) {
+				Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
+				return;
+			}
+			writer.write_newline ();
+			var once = new CCodeOnceSection (get_define_for_filename (writer.filename));
+			once.append (new CCodeNewline ());
+			once.append (new CCodeIdentifier ("G_BEGIN_DECLS"));
+			once.append (new CCodeNewline ());
+			once.append (new CCodeNewline ());
+			once.append (new CCodeIdentifier ("G_END_DECLS"));
+			once.append (new CCodeNewline ());
+			once.append (new CCodeNewline ());
+			once.write (writer);
+			writer.close ();
+		}
 	}
 
 	public override void visit_enum (Enum en) {

Modified: trunk/vala/valacodecontext.vala
==============================================================================
--- trunk/vala/valacodecontext.vala	(original)
+++ trunk/vala/valacodecontext.vala	Tue Jan 13 18:41:04 2009
@@ -76,6 +76,11 @@
 	public bool ccode_only { get; set; }
 
 	/**
+	 * Output C header file.
+	 */
+	public string header_filename { get; set; }
+
+	/**
 	 * Compile but do not link.
 	 */
 	public bool compile_only { get; set; }



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