[vala: 5/5] Move writing of G_GNUC_DEPRECATED down to CCodeDeclarator implementations



commit 4e3103bfd1928b080df77b68e6015fae609ad351
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Jan 3 18:55:18 2017 +0100

    Move writing of G_GNUC_DEPRECATED down to CCodeDeclarator implementations
    
    Doing so in CCodeDeclaration is error-prone. CCodeVariableDeclarator still
    requires special handling which isn't done here.

 ccode/valaccodedeclaration.vala        |    4 ---
 ccode/valaccodefunctiondeclarator.vala |    4 +++
 codegen/valaccodemethodmodule.vala     |    8 +++++++
 codegen/valagtypemodule.vala           |    4 +++
 tests/annotations/deprecated.vala      |   37 ++++++++++++++++++++++++++++++++
 5 files changed, 53 insertions(+), 4 deletions(-)
---
diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala
index 4d0fa74..4cbd862 100644
--- a/ccode/valaccodedeclaration.vala
+++ b/ccode/valaccodedeclaration.vala
@@ -96,10 +96,6 @@ public class Vala.CCodeDeclaration : CCodeStatement {
                                decl.write (writer);
                        }
 
-                       if (CCodeModifiers.DEPRECATED in modifiers) {
-                               writer.write_string (" G_GNUC_DEPRECATED");
-                       }
-
                        writer.write_string (";");
                        writer.write_newline ();
                        return;
diff --git a/ccode/valaccodefunctiondeclarator.vala b/ccode/valaccodefunctiondeclarator.vala
index b195f5a..30f0c63 100644
--- a/ccode/valaccodefunctiondeclarator.vala
+++ b/ccode/valaccodefunctiondeclarator.vala
@@ -77,6 +77,10 @@ public class Vala.CCodeFunctionDeclarator : CCodeDeclarator {
                
                writer.write_string (")");
 
+               if (CCodeModifiers.DEPRECATED in modifiers) {
+                       writer.write_string (" G_GNUC_DEPRECATED");
+               }
+
                if (CCodeModifiers.PRINTF in modifiers) {
                        format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
                        writer.write_string (" G_GNUC_PRINTF(%d,%d)".printf (format_arg_index, args_index + 
1));
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 35de6de..1f47af9 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -1072,6 +1072,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                } else if (m.scanf_format) {
                        func.modifiers |= CCodeModifiers.SCANF;
                }
+
+               if (m.version.deprecated) {
+                       func.modifiers |= CCodeModifiers.DEPRECATED;
+               }
        }
 
        public void generate_vfunc (Method m, DataType return_type, Map<int,CCodeParameter> cparam_map, 
Map<int,CCodeExpression> carg_map, string suffix = "", int direction = 3) {
@@ -1147,6 +1151,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        vfunc.modifiers |= CCodeModifiers.SCANF;
                }
 
+               if (m.version.deprecated) {
+                       vfunc.modifiers |= CCodeModifiers.DEPRECATED;
+               }
+
                cfile.add_function (vfunc);
 
                pop_context ();
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 654383f..7e5639f 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -393,6 +393,10 @@ public class Vala.GTypeModule : GErrorModule {
                        vdeclarator.modifiers |= CCodeModifiers.SCANF;
                }
 
+               if (m.version.deprecated) {
+                       vdeclarator.modifiers |= CCodeModifiers.DEPRECATED;
+               }
+
                generate_cparameters (m, decl_space, cparam_map, new CCodeFunction ("fake"), vdeclarator);
 
                var vdecl = new CCodeDeclaration (get_ccode_name (creturn_type));
diff --git a/tests/annotations/deprecated.vala b/tests/annotations/deprecated.vala
index 0968b15..f633dac 100644
--- a/tests/annotations/deprecated.vala
+++ b/tests/annotations/deprecated.vala
@@ -1,4 +1,11 @@
 [Version (deprecated = true)]
+int bar = 42;
+
+[Version (deprecated = true)]
+void baz () {
+}
+
+[Version (deprecated = true)]
 delegate void FooDelegate ();
 
 [Version (deprecated = true)]
@@ -17,9 +24,39 @@ void test_struct_field () {
 [Version (deprecated = true)]
 class FooClass : Object {
        [Version (deprecated = true)]
+       public static int manam = 42;
+       [Version (deprecated = true)]
        public int bar { get; set; default = 42; }
        [Version (deprecated = true)]
        public int baz;
+       [Version (deprecated = true)]
+       public int foo () {
+               return 42;
+       }
+       [Version (deprecated = true)]
+       public virtual int foov () {
+               return 42;
+       }
+}
+
+[Version (deprecated = true)]
+abstract class AFoo : Object {
+       [Version (deprecated = true)]
+       public int foo () {
+               return 42;
+       }
+       [Version (deprecated = true)]
+       public abstract int fooa ();
+}
+
+[Version (deprecated = true)]
+interface IFoo : Object {
+       [Version (deprecated = true)]
+       public int foo () {
+               return 42;
+       }
+       [Version (deprecated = true)]
+       public abstract void fooa ();
 }
 
 void test_class_property () {


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