]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix deprecation of class/struct fields
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 2 Nov 2016 14:36:33 +0000 (15:36 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 3 Nov 2016 19:47:31 +0000 (20:47 +0100)
Respect the "deprecated" attributes given to class and struct fields, while
actually adding G_GNUC_DEPRECATED to their declaration.

ccode/valaccodedeclaration.vala
ccode/valaccodestruct.vala
ccode/valaccodevariabledeclarator.vala
codegen/valaccodebasemodule.vala
codegen/valaccodestructmodule.vala
codegen/valagtypemodule.vala
tests/Makefile.am
tests/annotations/deprecated.vala [new file with mode: 0644]
vala/valamethodcall.vala

index 24bda724d43c23d1c3bb033fa7b257e3b50b9835..634165a69df8611aa5fc79845e721d39b716436b 100644 (file)
@@ -114,6 +114,9 @@ public class Vala.CCodeDeclaration : CCodeStatement {
                if ((modifiers & CCodeModifiers.REGISTER) == CCodeModifiers.REGISTER) {
                        writer.write_string ("register ");
                }
+               if ((modifiers & CCodeModifiers.VOLATILE) != 0) {
+                       writer.write_string ("volatile ");
+               }
                writer.write_string (type_name);
                writer.write_string (" ");
        
@@ -127,6 +130,10 @@ public class Vala.CCodeDeclaration : CCodeStatement {
                        decl.write_declaration (writer);
                }
 
+               if (CCodeModifiers.DEPRECATED in modifiers) {
+                       writer.write_string (" G_GNUC_DEPRECATED");
+               }
+
                writer.write_string (";");
                writer.write_newline ();
        }
index 96836ed5dd4b7786ab5ec5526cb83ab379256411..1eadd025ce2df7f14fb46b7b5286cdf55d66df3e 100644 (file)
@@ -59,9 +59,10 @@ public class Vala.CCodeStruct : CCodeNode {
         * @param type_name field type
         * @param name      member name
         */
-       public void add_field (string type_name, string name, CCodeDeclaratorSuffix? declarator_suffix = null) {
+       public void add_field (string type_name, string name, CCodeModifiers modifiers = 0, CCodeDeclaratorSuffix? declarator_suffix = null) {
                var decl = new CCodeDeclaration (type_name);
                decl.add_declarator (new CCodeVariableDeclarator (name, null, declarator_suffix));
+               decl.modifiers = modifiers;
                add_declaration (decl);
        }
        
index c8dd87495af26383cdd15cc95e55d6e15a8ddf90..43372bf6d8615032f32ccaaa2b21057bbc2d3572 100644 (file)
@@ -101,9 +101,8 @@ public class Vala.CCodeVariableDeclarator : CCodeDeclarator {
 }
 
 public class Vala.CCodeDeclaratorSuffix {
-       public bool array;
-       public CCodeExpression? array_length;
-       public bool deprecated;
+       bool array;
+       CCodeExpression? array_length;
 
        public CCodeDeclaratorSuffix.with_array (CCodeExpression? array_length = null) {
                this.array_length = array_length;
@@ -118,9 +117,5 @@ public class Vala.CCodeDeclaratorSuffix {
                        }
                        writer.write_string ("]");
                }
-
-               if (deprecated) {
-                       writer.write_string (" G_GNUC_DEPRECATED");
-               }
        }
 }
index d37563794e05e503b1651ca00f74fef3f0cc10d6..cdab6f1c82efaa59ca9cee189c267d7084e2bbc5 100644 (file)
@@ -990,12 +990,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                generate_type_declaration (f.variable_type, decl_space);
 
-               string field_ctype = get_ccode_name (f.variable_type);
-               if (f.is_volatile) {
-                       field_ctype = "volatile " + field_ctype;
-               }
-
-               var cdecl = new CCodeDeclaration (field_ctype);
+               var cdecl = new CCodeDeclaration (get_ccode_name (f.variable_type));
                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;
@@ -1005,6 +1000,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                if (f.version.deprecated) {
                        cdecl.modifiers |= CCodeModifiers.DEPRECATED;
                }
+               if (f.is_volatile) {
+                       cdecl.modifiers |= CCodeModifiers.VOLATILE;
+               }
                decl_space.add_type_member_declaration (cdecl);
 
                if (f.get_lock_used ()) {
@@ -1085,11 +1083,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                CCodeExpression lhs = null;
 
-               string field_ctype = get_ccode_name (f.variable_type);
-               if (f.is_volatile) {
-                       field_ctype = "volatile " + field_ctype;
-               }
-
                if (f.binding == MemberBinding.INSTANCE)  {
                        if (is_gtypeinstance && f.access == SymbolAccessibility.PRIVATE) {
                                lhs = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), get_ccode_name (f));
@@ -1215,13 +1208,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        }
                                }
 
-                               var var_def = new CCodeDeclaration (field_ctype);
+                               var var_def = new CCodeDeclaration (get_ccode_name (f.variable_type));
                                var_def.add_declarator (var_decl);
                                if (!f.is_private_symbol ()) {
                                        var_def.modifiers = CCodeModifiers.EXTERN;
                                } else {
                                        var_def.modifiers = CCodeModifiers.STATIC;
                                }
+                               if (f.version.deprecated) {
+                                       var_def.modifiers |= CCodeModifiers.DEPRECATED;
+                               }
+                               if (f.is_volatile) {
+                                       var_def.modifiers |= CCodeModifiers.VOLATILE;
+                               }
                                cfile.add_type_member_declaration (var_def);
 
                                /* add array length fields where necessary */
@@ -1937,7 +1936,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_local_cname (local), get_ccode_declarator_suffix (local.variable_type));
+                                       data.add_field (get_ccode_name (local.variable_type), get_local_cname (local), 0, get_ccode_declarator_suffix (local.variable_type));
 
                                        if (local.variable_type is ArrayType) {
                                                var array_type = (ArrayType) local.variable_type;
@@ -2354,7 +2353,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                }
                                emit_context.closure_variable_count_map.set (local.name, count + 1);
 
-                               closure_struct.add_field (get_ccode_name (local.variable_type), get_local_cname (local), get_ccode_declarator_suffix (local.variable_type));
+                               closure_struct.add_field (get_ccode_name (local.variable_type), get_local_cname (local), 0, get_ccode_declarator_suffix (local.variable_type));
                        } else {
                                var cvar = new CCodeVariableDeclarator (get_local_cname (local), null, get_ccode_declarator_suffix (local.variable_type));
 
index 3f226d55b0ff81b465a86aa851ea5320678d77e5..6b6682b0e004136fb0216c0a5fa2f81237c81903 100644 (file)
@@ -67,20 +67,10 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                instance_struct.deprecated = st.version.deprecated;
 
                foreach (Field f in st.get_fields ()) {
-                       string field_ctype = get_ccode_name (f.variable_type);
-                       if (f.is_volatile) {
-                               field_ctype = "volatile " + field_ctype;
-                       }
-
                        if (f.binding == MemberBinding.INSTANCE)  {
                                generate_type_declaration (f.variable_type, decl_space);
-
-                               var suffix = get_ccode_declarator_suffix (f.variable_type);
-                               if (suffix != null) {
-                                       suffix.deprecated = f.version.deprecated;
-                               }
-
-                               instance_struct.add_field (field_ctype, get_ccode_name (f), suffix);
+                               CCodeModifiers modifiers = (f.is_volatile ? CCodeModifiers.VOLATILE : 0) | (f.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
+                               instance_struct.add_field (get_ccode_name (f.variable_type), get_ccode_name (f), modifiers, 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 ed251858cf9bf60251eabcc347c5a1362fa77028..2407446f7dc24ace87b05a5e3d4adaba52b8bc3a 100644 (file)
@@ -322,16 +322,12 @@ public class Vala.GTypeModule : GErrorModule {
                }
 
                foreach (Field f in cl.get_fields ()) {
-                       string field_ctype = get_ccode_name (f.variable_type);
-                       if (f.is_volatile) {
-                               field_ctype = "volatile %s".printf (field_ctype);
-                       }
-
                        if (f.access != SymbolAccessibility.PRIVATE) {
+                               CCodeModifiers modifiers = (f.is_volatile ? CCodeModifiers.VOLATILE : 0) | (f.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
                                if (f.binding == MemberBinding.INSTANCE) {
                                        generate_type_declaration (f.variable_type, decl_space);
 
-                                       instance_struct.add_field (field_ctype, get_ccode_name (f), get_ccode_declarator_suffix (f.variable_type));
+                                       instance_struct.add_field (get_ccode_name (f.variable_type), get_ccode_name (f), modifiers, 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;
@@ -364,7 +360,7 @@ public class Vala.GTypeModule : GErrorModule {
                                                }
                                        }
                                } else if (f.binding == MemberBinding.CLASS) {
-                                       type_struct.add_field (field_ctype, get_ccode_name (f));
+                                       type_struct.add_field (get_ccode_name (f.variable_type), get_ccode_name (f), modifiers);
                                }
                        }
                }
@@ -429,16 +425,12 @@ public class Vala.GTypeModule : GErrorModule {
                }
 
                foreach (Field f in cl.get_fields ()) {
-                       string field_ctype = get_ccode_name (f.variable_type);
-                       if (f.is_volatile) {
-                               field_ctype = "volatile %s".printf (field_ctype);
-                       }
-
+                       CCodeModifiers modifiers = (f.is_volatile ? CCodeModifiers.VOLATILE : 0) | (f.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
                        if (f.binding == MemberBinding.INSTANCE) {
                                if (f.access == SymbolAccessibility.PRIVATE)  {
                                        generate_type_declaration (f.variable_type, decl_space);
 
-                                       instance_priv_struct.add_field (field_ctype, get_ccode_name (f), get_ccode_declarator_suffix (f.variable_type));
+                                       instance_priv_struct.add_field (get_ccode_name (f.variable_type), get_ccode_name (f), modifiers, 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;
@@ -478,7 +470,7 @@ public class Vala.GTypeModule : GErrorModule {
                                }
                        } else if (f.binding == MemberBinding.CLASS) {
                                if (f.access == SymbolAccessibility.PRIVATE) {
-                                       type_priv_struct.add_field (field_ctype, get_ccode_name (f));
+                                       type_priv_struct.add_field (get_ccode_name (f.variable_type), get_ccode_name (f), modifiers);
                                }
 
                                if (f.get_lock_used ()) {
index f5e99a2b6e511ac8a824bb21f4f79e37abafcd12..2a2ea073ca606a5202e6d0f689f3cf9f2203e2e5 100644 (file)
@@ -238,6 +238,7 @@ TESTS = \
        gir/bug651773.test \
        gir/bug667751.test \
        gir/bug742012.test \
+       annotations/deprecated.vala \
        $(NULL)
 
 check-TESTS: $(TESTS)
diff --git a/tests/annotations/deprecated.vala b/tests/annotations/deprecated.vala
new file mode 100644 (file)
index 0000000..c9f4a1a
--- /dev/null
@@ -0,0 +1,32 @@
+[Version (deprecated = true)]
+struct FooStruct {
+       [Version (deprecated = true)]
+       public int bar;
+}
+
+void test_struct_field () {
+       FooStruct foo = { 42 };
+       var i = foo.bar;
+       foo.bar = i;
+       assert (foo.bar == 42);
+}
+
+[Version (deprecated = true)]
+class FooClass : Object {
+       [Version (deprecated = true)]
+       public int bar { get; set; default = 42; }
+       [Version (deprecated = true)]
+       public int baz;
+}
+
+void test_class_property () {
+       var foo = new FooClass ();
+       var i = foo.bar;
+       foo.bar = i;
+       assert (foo.bar == 42);
+}
+
+void main () {
+       test_class_property ();
+       test_struct_field ();
+}
index d3889eb1accac1357832d23d99c9a984a5e9aefb..e604afe34cb8ea3347a6d2226899ee6840446353 100644 (file)
@@ -46,7 +46,7 @@ public class Vala.MethodCall : Expression {
         */
        public bool is_constructv_chainup { get; private set; }
 
-       public Expression _call;
+       private Expression _call;
        
        private List<Expression> argument_list = new ArrayList<Expression> ();