From cb0917599711f81aa261df17f294ec75f63b6e24 Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Tue, 22 Jan 2008 17:27:31 +0000 Subject: [PATCH] support length field for array constants 2008-01-22 Juerg Billeter * gobject/valaccodegenerator.vala: support length field for array constants * tests/arrays.vala: test length field of array constants svn path=/trunk/; revision=886 --- ChangeLog | 7 +++++++ gobject/valaccodegenerator.vala | 5 +++++ tests/arrays.vala | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index 78df10b..f566910 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-01-22 Jürg Billeter + * gobject/valaccodegenerator.vala: support length field for array + constants + + * tests/arrays.vala: test length field of array constants + +2008-01-22 Jürg Billeter + * tests/Makefile.am, tests/arrays.exp, tests/arrays.vala: add element access tests to array tests diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index 97dbd16..2fb255d 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -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; } } diff --git a/tests/arrays.vala b/tests/arrays.vala index 5ca3c5b..c031b65 100644 --- a/tests/arrays.vala +++ b/tests/arrays.vala @@ -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 () { -- 2.7.4