[vala/staging] Fix C code order problems



commit e4ad934347e0309f75532b416a4706dc8160f980
Author: Simon Werbeck <simon werbeck gmail com>
Date:   Tue Aug 5 09:37:11 2014 +0200

    Fix C code order problems
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727667

 ccode/valaccodemacroreplacement.vala |    3 +++
 codegen/valaccodebasemodule.vala     |    6 ++++++
 tests/basic-types/arrays.vala        |    4 +++-
 3 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/ccode/valaccodemacroreplacement.vala b/ccode/valaccodemacroreplacement.vala
index d865387..ae8c306 100644
--- a/ccode/valaccodemacroreplacement.vala
+++ b/ccode/valaccodemacroreplacement.vala
@@ -52,6 +52,9 @@ public class Vala.CCodeMacroReplacement : CCodeNode {
        }
 
        public override void write (CCodeWriter writer) {
+       }
+
+       public override void write_declaration (CCodeWriter writer) {
                writer.write_indent ();
                writer.write_string ("#define ");
                writer.write_string (name);
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 3e4da40..e7f992a 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1436,6 +1436,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                } else if (type is ArrayType) {
                        var array_type = (ArrayType) type;
                        generate_type_declaration (array_type.element_type, decl_space);
+                       if (array_type.length != null) {
+                               var oldcfile = cfile;
+                               cfile = decl_space;
+                               array_type.length.emit (this);
+                               cfile = oldcfile;
+                       }
                } else if (type is ErrorType) {
                        var error_type = (ErrorType) type;
                        if (error_type.error_domain != null) {
diff --git a/tests/basic-types/arrays.vala b/tests/basic-types/arrays.vala
index 7685304..fde0708 100644
--- a/tests/basic-types/arrays.vala
+++ b/tests/basic-types/arrays.vala
@@ -4,6 +4,9 @@ int[] foo;
 [CCode (array_length = false)]
 int[] bar;
 
+static int fixed_length[FOO];
+const int FOO = 2;
+
 void test_integer_array () {
        // declaration and initialization
        int[] a = { 42 };
@@ -84,7 +87,6 @@ void test_array_pass () {
        assert (b[0] == 42);
 }
 
-const int FOO = 2;
 void test_static_array () {
        int a[2];
        assert (a.length == 2);


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