[vala/0.50] codegen: Include "glib.h" for deprecated symbols (GOBJECT)



commit b420931212f3019424e9d6065d627a3a0e96ee0f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Mar 16 12:41:24 2021 +0100

    codegen: Include "glib.h" for deprecated symbols (GOBJECT)
    
    It is required for G_GNUC_DEPRECATED in declarations of
    enums, delegates, methods, property accessors and structs.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1155

 codegen/valaccodebasemodule.vala                   | 10 +++++++++-
 codegen/valaccodedelegatemodule.vala               |  8 +++++++-
 codegen/valaccodemethodmodule.vala                 |  3 +++
 codegen/valaccodestructmodule.vala                 |  8 +++++++-
 tests/Makefile.am                                  |  5 +++++
 tests/annotations/deprecated-delegate-minimal.vala |  6 ++++++
 tests/annotations/deprecated-enum-minimal.vala     |  8 ++++++++
 tests/annotations/deprecated-method-minimal.vala   |  6 ++++++
 tests/annotations/deprecated-property-minimal.vala | 13 +++++++++++++
 tests/annotations/deprecated-struct-minimal.vala   |  9 +++++++++
 10 files changed, 73 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4ad56c7a3..94d16e3b1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -828,7 +828,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                var cenum = new CCodeEnum (get_ccode_name (en));
 
-               cenum.modifiers |= (en.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
+               if (en.version.deprecated) {
+                       if (context.profile == Profile.GOBJECT) {
+                               decl_space.add_include ("glib.h");
+                       }
+                       cenum.modifiers |= CCodeModifiers.DEPRECATED;
+               }
 
                var current_cfile = cfile;
                cfile = decl_space;
@@ -1649,6 +1654,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                }
 
                if (prop.version.deprecated) {
+                       if (context.profile == Profile.GOBJECT) {
+                               decl_space.add_include ("glib.h");
+                       }
                        function.modifiers |= CCodeModifiers.DEPRECATED;
                }
 
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index dd3e0fcf6..b0770a5a0 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -111,7 +111,13 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                }
 
                var ctypedef = new CCodeTypeDefinition (get_ccode_name (creturn_type), cfundecl);
-               ctypedef.modifiers |= (d.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
+
+               if (d.version.deprecated) {
+                       if (context.profile == Profile.GOBJECT) {
+                               decl_space.add_include ("glib.h");
+                       }
+                       ctypedef.modifiers |= CCodeModifiers.DEPRECATED;
+               }
 
                decl_space.add_type_declaration (ctypedef);
        }
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 025c05351..e68412755 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -178,6 +178,9 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                }
 
                if (m.version.deprecated) {
+                       if (context.profile == Profile.GOBJECT) {
+                               decl_space.add_include ("glib.h");
+                       }
                        function.modifiers |= CCodeModifiers.DEPRECATED;
                }
 
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 2eab9e0e1..edd392304 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -77,7 +77,13 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                }
 
                var instance_struct = new CCodeStruct ("_%s".printf (get_ccode_name (st)));
-               instance_struct.modifiers |= (st.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
+
+               if (st.version.deprecated) {
+                       if (context.profile == Profile.GOBJECT) {
+                               decl_space.add_include ("glib.h");
+                       }
+                       instance_struct.modifiers |= CCodeModifiers.DEPRECATED;
+               }
 
                foreach (Field f in st.get_fields ()) {
                        if (f.binding == MemberBinding.INSTANCE)  {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3028a638e..202f0920d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -747,6 +747,11 @@ TESTS = \
        gtktemplate/gtkchild-without-gtktemplate.test \
        gtktemplate/gtktemplate-gtkwidget-subclass.test \
        annotations/deprecated.vala \
+       annotations/deprecated-delegate-minimal.vala \
+       annotations/deprecated-enum-minimal.vala \
+       annotations/deprecated-method-minimal.vala \
+       annotations/deprecated-property-minimal.vala \
+       annotations/deprecated-struct-minimal.vala \
        annotations/description.vala \
        annotations/noaccessormethod.test \
        scanner/comment-not-closed.test \
diff --git a/tests/annotations/deprecated-delegate-minimal.vala 
b/tests/annotations/deprecated-delegate-minimal.vala
new file mode 100644
index 000000000..3e34e8657
--- /dev/null
+++ b/tests/annotations/deprecated-delegate-minimal.vala
@@ -0,0 +1,6 @@
+[Version (deprecated = true)]
+[CCode (has_target = false)]
+delegate void Foo ();
+
+void main () {
+}
diff --git a/tests/annotations/deprecated-enum-minimal.vala b/tests/annotations/deprecated-enum-minimal.vala
new file mode 100644
index 000000000..91f0be73e
--- /dev/null
+++ b/tests/annotations/deprecated-enum-minimal.vala
@@ -0,0 +1,8 @@
+[Version (deprecated = true)]
+[CCode (has_type_id = false)]
+enum Foo {
+       BAR
+}
+
+void main () {
+}
diff --git a/tests/annotations/deprecated-method-minimal.vala 
b/tests/annotations/deprecated-method-minimal.vala
new file mode 100644
index 000000000..99aba27e8
--- /dev/null
+++ b/tests/annotations/deprecated-method-minimal.vala
@@ -0,0 +1,6 @@
+[Version (deprecated = true)]
+void foo () {
+}
+
+void main () {
+}
diff --git a/tests/annotations/deprecated-property-minimal.vala 
b/tests/annotations/deprecated-property-minimal.vala
new file mode 100644
index 000000000..a52e7733f
--- /dev/null
+++ b/tests/annotations/deprecated-property-minimal.vala
@@ -0,0 +1,13 @@
+[CCode (has_type_id = false)]
+[SimpleType]
+struct Foo {
+       void* _bar;
+       [Version (deprecated = true)]
+       public void* bar {
+               get { return _bar; }
+               set { _bar = value; }
+       }
+}
+
+void main () {
+}
diff --git a/tests/annotations/deprecated-struct-minimal.vala 
b/tests/annotations/deprecated-struct-minimal.vala
new file mode 100644
index 000000000..6b1c34493
--- /dev/null
+++ b/tests/annotations/deprecated-struct-minimal.vala
@@ -0,0 +1,9 @@
+[Version (deprecated = true)]
+[CCode (has_type_id = false)]
+[SimpleType]
+struct Foo {
+       public void* bar;
+}
+
+void main () {
+}


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