[vala] Move DataType.get_cdeclarator_suffix to the codegen



commit 114013c4b47739e54699dee8826137994cecd27f
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Aug 3 22:22:22 2011 +0200

    Move DataType.get_cdeclarator_suffix to the codegen

 codegen/valaccodebasemodule.vala   |   24 ++++++++++++++++++------
 codegen/valaccodestructmodule.vala |    2 +-
 codegen/valadovabasemodule.vala    |   10 +++++++---
 codegen/valadovaobjectmodule.vala  |    2 +-
 codegen/valadovastructmodule.vala  |    2 +-
 codegen/valagtypemodule.vala       |    4 ++--
 vala/valaarraytype.vala            |   10 ----------
 vala/valadatatype.vala             |    4 ----
 8 files changed, 30 insertions(+), 28 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5ed6f85..78a01ce 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -904,7 +904,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		}
 
 		var cdecl = new CCodeDeclaration (field_ctype);
-		cdecl.add_declarator (new CCodeVariableDeclarator (get_ccode_name (f), null, f.variable_type.get_cdeclarator_suffix ()));
+		cdecl.add_declarator (new CCodeVariableDeclarator (get_ccode_name (f), null, get_ccode_declarator_suffix (f.variable_type)));
 		if (f.is_private_symbol ()) {
 			cdecl.modifiers = CCodeModifiers.STATIC;
 		} else {
@@ -1083,7 +1083,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			lhs = new CCodeIdentifier (get_ccode_name (f));
 
-			var var_decl = new CCodeVariableDeclarator (get_ccode_name (f), null, f.variable_type.get_cdeclarator_suffix ());
+			var var_decl = new CCodeVariableDeclarator (get_ccode_name (f), null, get_ccode_declarator_suffix (f.variable_type));
 			var_decl.initializer = default_value_for_type (f.variable_type, true);
 
 			if (class_init_context != null) {
@@ -1769,7 +1769,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				if (local.captured) {
 					generate_type_declaration (local.variable_type, cfile);
 
-					data.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
+					data.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + get_ccode_declarator_suffix (local.variable_type));
 
 					if (local.variable_type is ArrayType) {
 						var array_type = (ArrayType) local.variable_type;
@@ -2092,9 +2092,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 		if (!local.captured) {
 			if (current_method != null && current_method.coroutine) {
-				closure_struct.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
+				closure_struct.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + get_ccode_declarator_suffix (local.variable_type));
 			} else {
-				var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), null, local.variable_type.get_cdeclarator_suffix ());
+				var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), null, get_ccode_declarator_suffix (local.variable_type));
 
 				// try to initialize uninitialized variables
 				// initialization not necessary for variables stored in closure
@@ -3119,7 +3119,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				}
 			}
 		} else {
-			var cvar = new CCodeVariableDeclarator (local.name, null, local.variable_type.get_cdeclarator_suffix ());
+			var cvar = new CCodeVariableDeclarator (local.name, null, get_ccode_declarator_suffix (local.variable_type));
 			if (init) {
 				cvar.initializer = default_value_for_type (local.variable_type, true);
 				cvar.init0 = true;
@@ -5814,6 +5814,18 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return prop.get_attribute_bool ("CCode", "notify", true);
 	}
 
+	public static string get_ccode_declarator_suffix (DataType type) {
+		var array_type = type as ArrayType;
+		if (array_type != null) {
+			if (array_type.fixed_length) {
+				return "[%d]".printf (array_type.length);
+			} else if (array_type.inline_allocated) {
+				return "[]";
+			}
+		}
+		return "";
+	}
+
 	public CCodeConstant get_signal_canonical_constant (Signal sig, string? detail = null) {
 		var str = new StringBuilder ("\"");
 
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 4d2aaa1..b21829b 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -64,7 +64,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 			if (f.binding == MemberBinding.INSTANCE)  {
 				generate_type_declaration (f.variable_type, decl_space);
 
-				instance_struct.add_field (field_ctype, get_ccode_name (f) + f.variable_type.get_cdeclarator_suffix (), f.deprecated ? " G_GNUC_DEPRECATED" : null);
+				instance_struct.add_field (field_ctype, get_ccode_name (f) + get_ccode_declarator_suffix (f.variable_type), f.deprecated ? " G_GNUC_DEPRECATED" : null);
 				if (f.variable_type is ArrayType && get_ccode_array_length (f)) {
 					// create fields to store array dimensions
 					var array_type = (ArrayType) f.variable_type;
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 87bff4a..adc0c31 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -676,7 +676,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 				if (local.captured) {
 					generate_type_declaration (local.variable_type, cfile);
 
-					data.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
+					data.add_field (get_ccode_name (local.variable_type), get_variable_cname (local.name) + get_ccode_declarator_suffix (local.variable_type));
 				}
 			}
 			// free in reverse order
@@ -868,7 +868,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 				ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id ((Block) local.parent_symbol))), get_variable_cname (local.name)), rhs);
 			}
 		} else {
-			var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), rhs, local.variable_type.get_cdeclarator_suffix ());
+			var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), rhs, get_ccode_declarator_suffix (local.variable_type));
 
 			var cdecl = new CCodeDeclaration (get_ccode_name (local.variable_type));
 			cdecl.add_declarator (cvar);
@@ -1151,7 +1151,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 	public void emit_temp_var (LocalVariable local) {
 		var cdecl = new CCodeDeclaration (get_ccode_name (local.variable_type));
 
-		var vardecl = new CCodeVariableDeclarator (local.name, null, local.variable_type.get_cdeclarator_suffix ());
+		var vardecl = new CCodeVariableDeclarator (local.name, null, get_ccode_declarator_suffix (local.variable_type));
 		cdecl.add_declarator (vardecl);
 
 		var st = local.variable_type.data_type as Struct;
@@ -2350,6 +2350,10 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 		return CCodeBaseModule.get_ccode_sentinel (m);
 	}
 
+	public string get_ccode_declarator_suffix (DataType type) {
+		return CCodeBaseModule.get_ccode_declarator_suffix (type);
+	}
+
 	public DataType? get_this_type () {
 		if (current_method != null && current_method.binding == MemberBinding.INSTANCE) {
 			return current_method.this_parameter.variable_type;
diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala
index b0ec8de..d0436b0 100644
--- a/codegen/valadovaobjectmodule.vala
+++ b/codegen/valadovaobjectmodule.vala
@@ -153,7 +153,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 					field_ctype = "volatile " + field_ctype;
 				}
 
-				instance_priv_struct.add_field (field_ctype, get_ccode_name (f) + f.variable_type.get_cdeclarator_suffix ());
+				instance_priv_struct.add_field (field_ctype, get_ccode_name (f) + get_ccode_declarator_suffix (f.variable_type));
 			}
 		}
 
diff --git a/codegen/valadovastructmodule.vala b/codegen/valadovastructmodule.vala
index 642519d..ba3d49d 100644
--- a/codegen/valadovastructmodule.vala
+++ b/codegen/valadovastructmodule.vala
@@ -60,7 +60,7 @@ public abstract class Vala.DovaStructModule : DovaBaseModule {
 			if (f.binding == MemberBinding.INSTANCE)  {
 				generate_type_declaration (f.variable_type, decl_space);
 
-				instance_struct.add_field (field_ctype, get_ccode_name (f) + f.variable_type.get_cdeclarator_suffix ());
+				instance_struct.add_field (field_ctype, get_ccode_name (f) + get_ccode_declarator_suffix (f.variable_type));
 			}
 		}
 
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 7c0219a..198c0cb 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -312,7 +312,7 @@ public class Vala.GTypeModule : GErrorModule {
 				if (f.binding == MemberBinding.INSTANCE) {
 					generate_type_declaration (f.variable_type, decl_space);
 
-					instance_struct.add_field (field_ctype, get_ccode_name (f), f.variable_type.get_cdeclarator_suffix ());
+					instance_struct.add_field (field_ctype, get_ccode_name (f), get_ccode_declarator_suffix (f.variable_type));
 					if (f.variable_type is ArrayType && get_ccode_array_length (f)) {
 						// create fields to store array dimensions
 						var array_type = (ArrayType) f.variable_type;
@@ -419,7 +419,7 @@ public class Vala.GTypeModule : GErrorModule {
 				if (f.access == SymbolAccessibility.PRIVATE)  {
 					generate_type_declaration (f.variable_type, decl_space);
 
-					instance_priv_struct.add_field (field_ctype, get_ccode_name (f), f.variable_type.get_cdeclarator_suffix ());
+					instance_priv_struct.add_field (field_ctype, get_ccode_name (f), get_ccode_declarator_suffix (f.variable_type));
 					if (f.variable_type is ArrayType && get_ccode_array_length (f)) {
 						// create fields to store array dimensions
 						var array_type = (ArrayType) f.variable_type;
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index 4bba50e..040df21 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -148,16 +148,6 @@ public class Vala.ArrayType : ReferenceType {
 		return result;
 	}
 
-	public override string get_cdeclarator_suffix () {
-		if (fixed_length) {
-			return "[%d]".printf (length);
-		} else if (inline_allocated) {
-			return "[]";
-		} else {
-			return "";
-		}
-	}
-
 	public override bool is_array () {
 		return true;
 	}
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 0b2847c..c4384bf 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -117,10 +117,6 @@ public abstract class Vala.DataType : CodeNode {
 		}
 	}
 
-	public virtual string get_cdeclarator_suffix () {
-		return "";
-	}
-
 	public override string to_string () {
 		return to_qualified_string (null);
 	}



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