]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Support anonymous definitions of delegates in bindings e9214a7c1a433f679de43861946d24e98af80d82
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 10 Apr 2018 16:16:37 +0000 (18:16 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 14 Apr 2018 08:26:06 +0000 (10:26 +0200)
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

codegen/valaccodebasemodule.vala
vala/valaparser.vala
vala/valasymbol.vala
vala/valausedattr.vala

index 096426254806012b86ac64ab2ca0e3762a9d7d55..3055e45c944f9439ca6f6e7bf556cee6df9829da 100644 (file)
@@ -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 (",")) {
index 127a118a7a46d9af1f33d41a05f4735d6e5c9acc..51bc7a05f072bc7a1f0f589fff61a14cfd9d587a 100644 (file)
@@ -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);
                }
index ed1ad8318b927a8d1cb1aac90e38d5c32182a821..131969afbbc076765f40ca848611759c5b3fdeb9 100644 (file)
@@ -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
index 4947b33a9415faee614855569627f599e2d8177d..999cfc8675583151814b11573db3eba2d4ac76c9 100644 (file)
@@ -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",