]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move DataType.get_cdeclarator_suffix to the codegen
authorLuca Bruno <lucabru@src.gnome.org>
Wed, 3 Aug 2011 20:22:22 +0000 (22:22 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Thu, 4 Aug 2011 07:49:44 +0000 (09:49 +0200)
codegen/valaccodebasemodule.vala
codegen/valaccodestructmodule.vala
codegen/valadovabasemodule.vala
codegen/valadovaobjectmodule.vala
codegen/valadovastructmodule.vala
codegen/valagtypemodule.vala
vala/valaarraytype.vala
vala/valadatatype.vala

index 5ed6f855b704177112929c457c873d43a9554670..78a01ce483f9524a1bb7facad29e455b552a5e69 100644 (file)
@@ -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 ("\"");
 
index 4d2aaa17ca4dd55b867daadf0134a43b11a40de3..b21829b5480dfb14c7198ae0d88c11aff5c9b91a 100644 (file)
@@ -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;
index 87bff4a6a50f10f5fc99cb384bff79aaeca3c728..adc0c31a83ef7fcb8e9c5c90cee19c21a99ca56c 100644 (file)
@@ -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;
index b0ec8de10c665fab539a363dfa682e6696b6c222..d0436b01c0697b05f8055825e8ba7f6464ed9545 100644 (file)
@@ -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));
                        }
                }
 
index 642519d17a314133b38b1ae447237eaf12da95d6..ba3d49dedc19b89fa7ca8a58473b46267cd549d1 100644 (file)
@@ -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));
                        }
                }
 
index 7c0219a0319e700fba30a789d6ec491e24f8335b..198c0cb6f3a1bcdf80c4d8d420d13d1ef633b25c 100644 (file)
@@ -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;
index 4bba50ec351bd1206e34206063b871b0abfc37bc..040df21c25b80e5ae6a08f10b26be0ae63a306ef 100644 (file)
@@ -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;
        }
index 0b2847cf1f31629d6aeb9cbead3646572d4cd81a..c4384bf9a786514fcac17599a72222e4d43f3eba 100644 (file)
@@ -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);
        }