vala r2390 - in trunk: . gobject vala



Author: juergbi
Date: Sun Jan 18 16:59:18 2009
New Revision: 2390
URL: http://svn.gnome.org/viewvc/vala?rev=2390&view=rev

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

	* vala/valacodecontext.vala:
	* gobject/valaccodebasemodule.vala:
	* gobject/valaccodecompiler.vala:

	Do not generate legacy header files when using -H


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodebasemodule.vala
   trunk/gobject/valaccodecompiler.vala
   trunk/vala/valacodecontext.vala

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Sun Jan 18 16:59:18 2009
@@ -308,39 +308,63 @@
 
 		header_begin.append (new CCodeIncludeDirective ("glib.h"));
 		header_begin.append (new CCodeIncludeDirective ("glib-object.h"));
-		if (context.basedir != null || context.library != null) {
-			source_include_directives.append (new CCodeIncludeDirective (source_file.get_cinclude_filename ()));
-		} else {
-			source_include_directives.append (new CCodeIncludeDirective (source_file.get_cinclude_filename (), true));
+
+		if (context.legacy_headers) {
+			if (context.basedir != null || context.library != null) {
+				source_include_directives.append (new CCodeIncludeDirective (source_file.get_cinclude_filename ()));
+			} else {
+				source_include_directives.append (new CCodeIncludeDirective (source_file.get_cinclude_filename (), true));
+			}
 		}
 		
 		Gee.List<string> used_includes = new ArrayList<string> (str_equal);
 		used_includes.add ("glib.h");
 		used_includes.add ("glib-object.h");
-		used_includes.add (source_file.get_cinclude_filename ());
+
+		if (context.legacy_headers) {
+			used_includes.add (source_file.get_cinclude_filename ());
 		
-		foreach (string filename in source_file.get_header_external_includes ()) {
-			if (!used_includes.contains (filename)) {
-				header_begin.append (new CCodeIncludeDirective (filename));
-				used_includes.add (filename);
-			}
-		}
-		foreach (string filename in source_file.get_header_internal_includes ()) {
-			if (!used_includes.contains (filename)) {
-				header_begin.append (get_internal_include (filename));
-				used_includes.add (filename);
-			}
-		}
-		foreach (string filename in source_file.get_source_external_includes ()) {
-			if (!used_includes.contains (filename)) {
-				source_include_directives.append (new CCodeIncludeDirective (filename));
-				used_includes.add (filename);
-			}
-		}
-		foreach (string filename in source_file.get_source_internal_includes ()) {
-			if (!used_includes.contains (filename)) {
-				source_include_directives.append (get_internal_include (filename));
-				used_includes.add (filename);
+			foreach (string filename in source_file.get_header_external_includes ()) {
+				if (!used_includes.contains (filename)) {
+					header_begin.append (new CCodeIncludeDirective (filename));
+					used_includes.add (filename);
+				}
+			}
+			foreach (string filename in source_file.get_header_internal_includes ()) {
+				if (!used_includes.contains (filename)) {
+					header_begin.append (get_internal_include (filename));
+					used_includes.add (filename);
+				}
+			}
+			foreach (string filename in source_file.get_source_external_includes ()) {
+				if (!used_includes.contains (filename)) {
+					source_include_directives.append (new CCodeIncludeDirective (filename));
+					used_includes.add (filename);
+				}
+			}
+			foreach (string filename in source_file.get_source_internal_includes ()) {
+				if (!used_includes.contains (filename)) {
+					source_include_directives.append (get_internal_include (filename));
+					used_includes.add (filename);
+				}
+			}
+			if (source_file.is_cycle_head) {
+				foreach (SourceFile cycle_file in source_file.cycle.files) {
+					foreach (CodeNode node in cycle_file.get_nodes ()) {
+						if (node is Struct) {
+							var st = (Struct) node;
+							header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
+						} else if (node is Class) {
+							var cl = (Class) node;
+							header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (cl.get_cname ()), new CCodeVariableDeclarator (cl.get_cname ())));
+							header_type_declaration.append (new CCodeTypeDefinition ("struct _%sClass".printf (cl.get_cname ()), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
+						} else if (node is Interface) {
+							var iface = (Interface) node;
+							header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
+							header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_type_cname ()), new CCodeVariableDeclarator (iface.get_type_cname ())));
+						}
+					}
+				}
 			}
 		}
 		foreach (Symbol symbol in source_file.get_source_symbol_dependencies ()) {
@@ -348,24 +372,6 @@
 				symbol.accept (codegen);
 			}
 		}
-		if (source_file.is_cycle_head) {
-			foreach (SourceFile cycle_file in source_file.cycle.files) {
-				foreach (CodeNode node in cycle_file.get_nodes ()) {
-					if (node is Struct) {
-						var st = (Struct) node;
-						header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
-					} else if (node is Class) {
-						var cl = (Class) node;
-						header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (cl.get_cname ()), new CCodeVariableDeclarator (cl.get_cname ())));
-						header_type_declaration.append (new CCodeTypeDefinition ("struct _%sClass".printf (cl.get_cname ()), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
-					} else if (node is Interface) {
-						var iface = (Interface) node;
-						header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
-						header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_type_cname ()), new CCodeVariableDeclarator (iface.get_type_cname ())));
-					}
-				}
-			}
-		}
 
 		source_file.accept_children (codegen);
 
@@ -456,37 +462,39 @@
 			comment = new CCodeComment (source_file.comment);
 		}
 
-		var writer = new CCodeWriter (source_file.get_cheader_filename ());
-		if (!writer.open ()) {
-			Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
-			return;
-		}
-		if (comment != null) {
-			comment.write (writer);
+		if (context.legacy_headers) {
+			var writer = new CCodeWriter (source_file.get_cheader_filename ());
+			if (!writer.open ()) {
+				Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
+				return;
+			}
+			if (comment != null) {
+				comment.write (writer);
+			}
+			writer.write_newline ();
+			var once = new CCodeOnceSection (header_define);
+			once.append (new CCodeNewline ());
+			once.append (header_begin);
+			once.append (new CCodeNewline ());
+			once.append (new CCodeIdentifier ("G_BEGIN_DECLS"));
+			once.append (new CCodeNewline ());
+			once.append (new CCodeNewline ());
+			once.append (header_type_declaration);
+			once.append (new CCodeNewline ());
+			once.append (header_type_definition);
+			once.append (new CCodeNewline ());
+			once.append (header_type_member_declaration);
+			once.append (new CCodeNewline ());
+			once.append (header_constant_declaration);
+			once.append (new CCodeNewline ());
+			once.append (new CCodeIdentifier ("G_END_DECLS"));
+			once.append (new CCodeNewline ());
+			once.append (new CCodeNewline ());
+			once.write (writer);
+			writer.close ();
 		}
-		writer.write_newline ();
-		var once = new CCodeOnceSection (header_define);
-		once.append (new CCodeNewline ());
-		once.append (header_begin);
-		once.append (new CCodeNewline ());
-		once.append (new CCodeIdentifier ("G_BEGIN_DECLS"));
-		once.append (new CCodeNewline ());
-		once.append (new CCodeNewline ());
-		once.append (header_type_declaration);
-		once.append (new CCodeNewline ());
-		once.append (header_type_definition);
-		once.append (new CCodeNewline ());
-		once.append (header_type_member_declaration);
-		once.append (new CCodeNewline ());
-		once.append (header_constant_declaration);
-		once.append (new CCodeNewline ());
-		once.append (new CCodeIdentifier ("G_END_DECLS"));
-		once.append (new CCodeNewline ());
-		once.append (new CCodeNewline ());
-		once.write (writer);
-		writer.close ();
 		
-		writer = new CCodeWriter (source_file.get_csource_filename ());
+		var writer = new CCodeWriter (source_file.get_csource_filename ());
 		if (!writer.open ()) {
 			Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
 			return;
@@ -556,8 +564,10 @@
 
 	public override void emit (CodeContext context) {
 		this.context = context;
-	
-		context.find_header_cycles ();
+
+		if (context.legacy_headers) {
+			context.find_header_cycles ();
+		}
 
 		root_symbol = context.root;
 

Modified: trunk/gobject/valaccodecompiler.vala
==============================================================================
--- trunk/gobject/valaccodecompiler.vala	(original)
+++ trunk/gobject/valaccodecompiler.vala	Sun Jan 18 16:59:18 2009
@@ -95,7 +95,7 @@
 		}
 
 		/* make sure include files can be found if -d is used */
-		if (context.directory != null && context.directory != "") {
+		if (context.legacy_headers && context.directory != null && context.directory != "") {
 			cmdline += " -I" + Shell.quote (context.directory);
 		}
 
@@ -130,10 +130,12 @@
 		/* remove generated C source and header files */
 		foreach (SourceFile file in source_files) {
 			if (!file.external_package) {
-				if (!context.save_csources)
+				if (!context.save_csources) {
 					FileUtils.unlink (file.get_csource_filename ());
-				if (!context.save_cheaders)
+				}
+				if (context.legacy_headers && !context.save_cheaders) {
 					FileUtils.unlink (file.get_cheader_filename ());
+				}
 			}
 		}
 	}

Modified: trunk/vala/valacodecontext.vala
==============================================================================
--- trunk/vala/valacodecontext.vala	(original)
+++ trunk/vala/valacodecontext.vala	Sun Jan 18 16:59:18 2009
@@ -101,6 +101,13 @@
 	public string directory { get; set; }
 
 	/**
+	 * Generate a C header file per Vala source file.
+	 */
+	public bool legacy_headers {
+		get { return header_filename == null; }
+	}
+
+	/**
 	 * Produce debug information.
 	 */
 	public bool debug { get; set; }



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