From: Jürg Billeter Date: Sun, 14 Jun 2009 17:06:42 +0000 (+0200) Subject: Generate C89 compatible code for string switch statements X-Git-Tag: 0.7.4~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30c45d0744aeb29f420b98053bd7062fab37bcfe;p=thirdparty%2Fvala.git Generate C89 compatible code for string switch statements Based on patch by Ali Sabil. --- diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala index 7a0223bab..22a37bcb9 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 4b0387de6..42333d7ae 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);