From: Rico Tzschichholz Date: Tue, 16 Mar 2021 11:41:24 +0000 (+0100) Subject: codegen: Include "glib.h" for deprecated symbols (GOBJECT) X-Git-Tag: 0.52.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a1922d32df236daa2dfdf3cbb834c9c70fcfbf8;p=thirdparty%2Fvala.git 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 --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 308aa034e..627039703 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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; } 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 fc99a58aa..d29014180 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -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; } diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala index 5dfc8e8cb..5042698cd 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 4d0568818..3276d3039 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 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 () { +}