]> 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>
Tue, 16 Mar 2021 11:41:24 +0000 (12:41 +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 308aa034e6de6bf242ccf984e2dd5f8a9f24de79..62703970326806894a5fadd59fa6e76864887d42 100644 (file)
@@ -878,7 +878,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;
@@ -1699,6 +1704,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 fc99a58aaa0dc87a25118a56177aeb4fd7478ac3..d29014180ee0fc504235a29233c7a7d4ac6038fc 100644 (file)
@@ -174,6 +174,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 5dfc8e8cbeb578399b004ce4378cc826619b5d69..5042698cd82a1b0006030cb821a9fe85d43a6118 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 4d0568818140cc8f90db67d524fb9db606e4a6a8..3276d30398d1bc41ec86ae2e523eb800ffd16953 100644 (file)
@@ -759,6 +759,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 () {
+}