From: Jürg Billeter Date: Sun, 21 Mar 2010 10:01:29 +0000 (+0100) Subject: Fix fixed-length array fields X-Git-Tag: 0.8.0~114 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=82d63600d49c5be6b390a1b8f358d863563c589f;p=thirdparty%2Fvala.git Fix fixed-length array fields Fixes bug 603293. --- diff --git a/ccode/valaccodestruct.vala b/ccode/valaccodestruct.vala index ceef03e12..7aa5c407c 100644 --- a/ccode/valaccodestruct.vala +++ b/ccode/valaccodestruct.vala @@ -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); } diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index edb496bc6..0ded9029b 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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; diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 62c1b1d29..7f6de7ed5 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -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;