support length field for array constants
authorJuerg Billeter <j@bitron.ch>
Tue, 22 Jan 2008 17:27:31 +0000 (17:27 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 22 Jan 2008 17:27:31 +0000 (17:27 +0000)
2008-01-22  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegenerator.vala: support length field for array
  constants

* tests/arrays.vala: test length field of array constants

svn path=/trunk/; revision=886

ChangeLog
gobject/valaccodegenerator.vala
tests/arrays.vala

index 78df10b..f566910 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-01-22  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valaccodegenerator.vala: support length field for array
+         constants
+
+       * tests/arrays.vala: test length field of array constants
+
+2008-01-22  Jürg Billeter  <j@bitron.ch>
+
        * tests/Makefile.am, tests/arrays.exp, tests/arrays.vala: add element
          access tests to array tests
 
index 97dbd16..2fb255d 100644 (file)
@@ -2218,6 +2218,11 @@ public class Vala.CCodeGenerator : CodeGenerator {
                                                return length_expr;
                                        }
                                }
+                       } else if (array_expr.symbol_reference is Constant) {
+                               var constant = (Constant) array_expr.symbol_reference;
+                               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
+                               ccall.add_argument (new CCodeIdentifier (constant.get_cname ()));
+                               return ccall;
                        }
                }
 
index 5ca3c5b..c031b65 100644 (file)
@@ -216,6 +216,12 @@ class Maman.Foo : Object {
                stdout.printf (" 13\n");
        }
 
+       const int[] const_array = { 1, 2, 3 };
+
+       static void test_array_length_of_array_constants () {
+               assert (const_array.length == 3);
+       }
+
        static void main (string[] args) {
                test_integer_array ();
                test_string_array ();
@@ -233,6 +239,8 @@ class Maman.Foo : Object {
                test_array_creation_side_effects ();
 
                test_element_access ();
+
+               test_array_length_of_array_constants ();
        }
        
        public static int inc () {