]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Include "glib.h" for deprecated symbols (GOBJECT)
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 16 Mar 2021 11:41:24 +0000 (12:41 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 18 Mar 2021 09:14:08 +0000 (10:14 +0100)
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
codegen/valaccodedelegatemodule.vala
codegen/valaccodemethodmodule.vala
codegen/valaccodestructmodule.vala
tests/Makefile.am
tests/annotations/deprecated-delegate-minimal.vala [new file with mode: 0644]
tests/annotations/deprecated-enum-minimal.vala [new file with mode: 0644]
tests/annotations/deprecated-method-minimal.vala [new file with mode: 0644]
tests/annotations/deprecated-property-minimal.vala [new file with mode: 0644]
tests/annotations/deprecated-struct-minimal.vala [new file with mode: 0644]

index 4ad56c7a3a035ab22148814ea3b450a019c5803c..94d16e3b12e22be125f519a8926404e4b96cfd68 100644 (file)
@@ -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;
                }
 
index dd3e0fcf6cd5227645565a5f690b499f078dfad7..b0770a5a03543c1d5b9843ffd563466330a86323 100644 (file)
@@ -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);
        }
index 025c0535185bd6b2b8dd433e5c2edbb6ee46922c..e6841275562754e3fc971bbdac4d0a4538181e7e 100644 (file)
@@ -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;
                }
 
index 2eab9e0e125ac50f11167c846544ed59f92404f5..edd3923045f96d49991efe38e6dade2fc0535797 100644 (file)
@@ -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)  {
index 3028a638e480f69c0240e543813634fe6afece7a..202f0920d5c58089810ebb2f9cc36089406daec7 100644 (file)
@@ -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 (file)
index 0000000..3e34e86
--- /dev/null
@@ -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 (file)
index 0000000..91f0be7
--- /dev/null
@@ -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 (file)
index 0000000..99aba27
--- /dev/null
@@ -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 (file)
index 0000000..a52e773
--- /dev/null
@@ -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 (file)
index 0000000..6b1c344
--- /dev/null
@@ -0,0 +1,9 @@
+[Version (deprecated = true)]
+[CCode (has_type_id = false)]
+[SimpleType]
+struct Foo {
+       public void* bar;
+}
+
+void main () {
+}