[vala] Generate C89 compatible code for string switch statements



commit 30c45d0744aeb29f420b98053bd7062fab37bcfe
Author: Jürg Billeter <j bitron ch>
Date:   Sun Jun 14 19:06:42 2009 +0200

    Generate C89 compatible code for string switch statements
    
    Based on patch by Ali Sabil.

 ccode/valaccodedeclaration.vala  |   40 ++++++++++++++++++-------------------
 codegen/valaccodebasemodule.vala |    2 +-
 2 files changed, 20 insertions(+), 22 deletions(-)
---
diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala
index 7a0223b..22a37bc 100644
--- a/ccode/valaccodedeclaration.vala
+++ b/ccode/valaccodedeclaration.vala
@@ -53,6 +53,24 @@ public class Vala.CCodeDeclaration : CCodeStatement {
 	}
 	
 	public override void write (CCodeWriter writer) {
+		if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.EXTERN)) == 0) {
+			foreach (CCodeDeclarator decl in declarators) {
+				decl.write_initialization (writer);
+			}
+		}
+	}
+
+	private bool has_initializer () {
+		foreach (CCodeDeclarator decl in declarators) {
+			var var_decl = decl as CCodeVariableDeclarator;
+			if (var_decl != null && var_decl.initializer == null) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	public override void write_declaration (CCodeWriter writer) {
 		if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.EXTERN)) != 0) {
 			// combined declaration and initialization for static and extern variables
 			writer.write_indent (line);
@@ -67,7 +85,7 @@ public class Vala.CCodeDeclaration : CCodeStatement {
 			}
 			writer.write_string (type_name);
 			writer.write_string (" ");
-		
+
 			bool first = true;
 			foreach (CCodeDeclarator decl in declarators) {
 				if (!first) {
@@ -80,26 +98,6 @@ public class Vala.CCodeDeclaration : CCodeStatement {
 
 			writer.write_string (";");
 			writer.write_newline ();
-		} else {
-			foreach (CCodeDeclarator decl in declarators) {
-				decl.write_initialization (writer);
-			}
-		}
-	}
-
-	private bool has_initializer () {
-		foreach (CCodeDeclarator decl in declarators) {
-			var var_decl = decl as CCodeVariableDeclarator;
-			if (var_decl != null && var_decl.initializer == null) {
-				return false;
-			}
-		}
-		return true;
-	}
-
-	public override void write_declaration (CCodeWriter writer) {
-		if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.EXTERN)) != 0) {
-			// no separate declaration for static variables
 			return;
 		}
 
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4b0387d..42333d7 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -580,7 +580,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 		writer.write_newline ();
 		source_declarations.type_member_declaration.write (writer);
 		writer.write_newline ();
-		source_declarations.constant_declaration.write (writer);
+		source_declarations.constant_declaration.write_combined (writer);
 		writer.write_newline ();
 		source_signal_marshaller_declaration.write_declaration (writer);
 		source_signal_marshaller_declaration.write (writer);



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