]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix fixed-length array fields
authorJürg Billeter <j@bitron.ch>
Sun, 21 Mar 2010 10:01:29 +0000 (11:01 +0100)
committerJürg Billeter <j@bitron.ch>
Sun, 21 Mar 2010 10:01:29 +0000 (11:01 +0100)
Fixes bug 603293.

ccode/valaccodestruct.vala
codegen/valaccodebasemodule.vala
codegen/valagtypemodule.vala

index ceef03e12f1da8b18bbea246be46c29dd85cc837..7aa5c407c11916ffbf7d959769274c12d44a6712 100644 (file)
@@ -52,9 +52,9 @@ public class Vala.CCodeStruct : CCodeNode {
         * @param type_name field type
         * @param name      member name
         */
-       public void add_field (string type_name, string name) {
+       public void add_field (string type_name, string name, string? declarator_suffix = null) {
                var decl = new CCodeDeclaration (type_name);
-               decl.add_declarator (new CCodeVariableDeclarator (name));
+               decl.add_declarator (new CCodeVariableDeclarator (name, null, declarator_suffix));
                add_declaration (decl);
        }
        
index edb496bc6df9c981a5293d24ce2ce58e11f68479..0ded9029b54e1f7f418d0f35068b3d21c33ff2c9 100644 (file)
@@ -962,7 +962,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                }
 
                var cdecl = new CCodeDeclaration (field_ctype);
-               cdecl.add_declarator (new CCodeVariableDeclarator (f.get_cname ()));
+               cdecl.add_declarator (new CCodeVariableDeclarator (f.get_cname (), null, f.field_type.get_cdeclarator_suffix ()));
                if (f.is_private_symbol ()) {
                        cdecl.modifiers = CCodeModifiers.STATIC;
                } else {
@@ -987,17 +987,19 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                if (f.field_type is ArrayType && !f.no_array_length) {
                        var array_type = (ArrayType) f.field_type;
 
-                       for (int dim = 1; dim <= array_type.rank; dim++) {
-                               var len_type = int_type.copy ();
+                       if (!array_type.fixed_length) {
+                               for (int dim = 1; dim <= array_type.rank; dim++) {
+                                       var len_type = int_type.copy ();
 
-                               cdecl = new CCodeDeclaration (len_type.get_cname ());
-                               cdecl.add_declarator (new CCodeVariableDeclarator (head.get_array_length_cname (f.get_cname (), dim)));
-                               if (f.is_private_symbol ()) {
-                                       cdecl.modifiers = CCodeModifiers.STATIC;
-                               } else {
-                                       cdecl.modifiers = CCodeModifiers.EXTERN;
+                                       cdecl = new CCodeDeclaration (len_type.get_cname ());
+                                       cdecl.add_declarator (new CCodeVariableDeclarator (head.get_array_length_cname (f.get_cname (), dim)));
+                                       if (f.is_private_symbol ()) {
+                                               cdecl.modifiers = CCodeModifiers.STATIC;
+                                       } else {
+                                               cdecl.modifiers = CCodeModifiers.EXTERN;
+                                       }
+                                       decl_space.add_type_member_declaration (cdecl);
                                }
-                               decl_space.add_type_member_declaration (cdecl);
                        }
                } else if (f.field_type is DelegateType) {
                        var delegate_type = (DelegateType) f.field_type;
@@ -1124,7 +1126,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
                        lhs = new CCodeIdentifier (f.get_cname ());
 
-                       var var_decl = new CCodeVariableDeclarator (f.get_cname ());
+                       var var_decl = new CCodeVariableDeclarator (f.get_cname (), null, f.field_type.get_cdeclarator_suffix ());
                        var_decl.initializer = default_value_for_type (f.field_type, true);
 
                        if (f.initializer != null) {
@@ -1147,26 +1149,28 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                        if (f.field_type is ArrayType && !f.no_array_length) {
                                var array_type = (ArrayType) f.field_type;
 
-                               for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       var len_type = int_type.copy ();
+                               if (!array_type.fixed_length) {
+                                       for (int dim = 1; dim <= array_type.rank; dim++) {
+                                               var len_type = int_type.copy ();
 
-                                       var len_def = new CCodeDeclaration (len_type.get_cname ());
-                                       len_def.add_declarator (new CCodeVariableDeclarator (head.get_array_length_cname (f.get_cname (), dim), new CCodeConstant ("0")));
-                                       if (!f.is_private_symbol ()) {
-                                               len_def.modifiers = CCodeModifiers.EXTERN;
-                                       } else {
-                                               len_def.modifiers = CCodeModifiers.STATIC;
+                                               var len_def = new CCodeDeclaration (len_type.get_cname ());
+                                               len_def.add_declarator (new CCodeVariableDeclarator (head.get_array_length_cname (f.get_cname (), dim), new CCodeConstant ("0")));
+                                               if (!f.is_private_symbol ()) {
+                                                       len_def.modifiers = CCodeModifiers.EXTERN;
+                                               } else {
+                                                       len_def.modifiers = CCodeModifiers.STATIC;
+                                               }
+                                               source_declarations.add_type_member_declaration (len_def);
                                        }
-                                       source_declarations.add_type_member_declaration (len_def);
-                               }
 
-                               if (array_type.rank == 1 && f.is_internal_symbol ()) {
-                                       var len_type = int_type.copy ();
+                                       if (array_type.rank == 1 && f.is_internal_symbol ()) {
+                                               var len_type = int_type.copy ();
 
-                                       var cdecl = new CCodeDeclaration (len_type.get_cname ());
-                                       cdecl.add_declarator (new CCodeVariableDeclarator (head.get_array_size_cname (f.get_cname ()), new CCodeConstant ("0")));
-                                       cdecl.modifiers = CCodeModifiers.STATIC;
-                                       source_declarations.add_type_member_declaration (cdecl);
+                                               var cdecl = new CCodeDeclaration (len_type.get_cname ());
+                                               cdecl.add_declarator (new CCodeVariableDeclarator (head.get_array_size_cname (f.get_cname ()), new CCodeConstant ("0")));
+                                               cdecl.modifiers = CCodeModifiers.STATIC;
+                                               source_declarations.add_type_member_declaration (cdecl);
+                                       }
                                }
                        } else if (f.field_type is DelegateType) {
                                var delegate_type = (DelegateType) f.field_type;
index 62c1b1d29cc360dec97db57a549b6321ed4bd3eb..7f6de7ed50a1cfd858377001270b9a0c9c3e2562 100644 (file)
@@ -288,18 +288,21 @@ internal class Vala.GTypeModule : GErrorModule {
                                if (f.binding == MemberBinding.INSTANCE) {
                                        generate_type_declaration (f.field_type, decl_space);
 
-                                       instance_struct.add_field (field_ctype, f.get_cname ());
+                                       instance_struct.add_field (field_ctype, f.get_cname (), f.field_type.get_cdeclarator_suffix ());
                                        if (f.field_type is ArrayType && !f.no_array_length) {
                                                // create fields to store array dimensions
                                                var array_type = (ArrayType) f.field_type;
-                                               var len_type = int_type.copy ();
 
-                                               for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                       instance_struct.add_field (len_type.get_cname (), head.get_array_length_cname (f.name, dim));
-                                               }
+                                               if (!array_type.fixed_length) {
+                                                       var len_type = int_type.copy ();
 
-                                               if (array_type.rank == 1 && f.is_internal_symbol ()) {
-                                                       instance_struct.add_field (len_type.get_cname (), head.get_array_size_cname (f.name));
+                                                       for (int dim = 1; dim <= array_type.rank; dim++) {
+                                                               instance_struct.add_field (len_type.get_cname (), head.get_array_length_cname (f.name, dim));
+                                                       }
+
+                                                       if (array_type.rank == 1 && f.is_internal_symbol ()) {
+                                                               instance_struct.add_field (len_type.get_cname (), head.get_array_size_cname (f.name));
+                                                       }
                                                }
                                        } else if (f.field_type is DelegateType) {
                                                var delegate_type = (DelegateType) f.field_type;