[vala] Fix fixed-length array fields



commit 82d63600d49c5be6b390a1b8f358d863563c589f
Author: Jürg Billeter <j bitron ch>
Date:   Sun Mar 21 11:01:29 2010 +0100

    Fix fixed-length array fields
    
    Fixes bug 603293.

 ccode/valaccodestruct.vala       |    4 +-
 codegen/valaccodebasemodule.vala |   60 ++++++++++++++++++++-----------------
 codegen/valagtypemodule.vala     |   17 ++++++----
 3 files changed, 44 insertions(+), 37 deletions(-)
---
diff --git a/ccode/valaccodestruct.vala b/ccode/valaccodestruct.vala
index ceef03e..7aa5c40 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 edb496b..0ded902 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 62c1b1d..7f6de7e 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;



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