From: Rico Tzschichholz Date: Tue, 10 Apr 2018 16:16:37 +0000 (+0200) Subject: vala: Support anonymous definitions of delegates in bindings X-Git-Tag: 0.41.90~184 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fkeep-around%2Fe9214a7c1a433f679de43861946d24e98af80d82;p=thirdparty%2Fvala.git vala: Support anonymous definitions of delegates in bindings If a library header does not include a defintion for a delegate then bindings can use the CCode annotation "has_typedef = false" which will force creation of typedef in generated source-file. [CCode (has_typedef = false)] public delegate void Func (); https://bugzilla.gnome.org/show_bug.cgi?id=794920 --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 096426254..3055e45c9 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -616,6 +616,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { if (sym.source_reference != null) { sym.source_reference.file.used = true; } + if (sym.anonymous) { + return !decl_space.is_header && CodeContext.get ().use_header; + } if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) { // add feature test macros foreach (unowned string feature_test_macro in get_ccode_feature_test_macros (sym).split (",")) { diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 127a118a7..51bc7a05f 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -3396,6 +3396,12 @@ public class Vala.Parser : CodeVisitor { if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) { d.external = true; } + if (!d.get_attribute_bool ("CCode", "has_typedef", true)) { + if (!d.external) { + Report.error (get_last_src (), "Delegates without definition must be external"); + } + d.anonymous = true; + } foreach (TypeParameter type_param in type_param_list) { d.add_type_parameter (type_param); } diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala index ed1ad8318..131969afb 100644 --- a/vala/valasymbol.vala +++ b/vala/valasymbol.vala @@ -72,6 +72,11 @@ public abstract class Vala.Symbol : CodeNode { */ public bool used { get; set; } + /** + * Specifies whether this symbol is anonymous and has no public defintion. + */ + public bool anonymous { get; set; } + /** * Specifies the accessibility of this symbol. Public accessibility * doesn't limit access. Default accessibility limits access to this diff --git a/vala/valausedattr.vala b/vala/valausedattr.vala index 4947b33a9..999cfc867 100644 --- a/vala/valausedattr.vala +++ b/vala/valausedattr.vala @@ -33,7 +33,7 @@ public class Vala.UsedAttr : CodeVisitor { "CCode", "type_signature", "default_value", "set_value_function", "type_id", "cprefix", "cheader_filename", "marshaller_type_name", "get_value_function", "cname", "destroy_function", "lvalue_access", "has_type_id", "instance_pos", "const_cname", "take_value_function", "copy_function", "free_function", - "param_spec_function", "has_target", "type_cname", "ref_function", "ref_function_void", "unref_function", "type", + "param_spec_function", "has_target", "has_typedef", "type_cname", "ref_function", "ref_function_void", "unref_function", "type", "has_construct_function", "returns_floating_reference", "gir_namespace", "gir_version", "construct_function", "lower_case_cprefix", "simple_generics", "sentinel", "scope", "has_destroy_function", "ordering", "type_check_function", "has_copy_function", "lower_case_csuffix", "ref_sink_function", "dup_function", "finish_function", "generic_type_pos",