[vala/staging] vala: Support anonymous definitions of delegates in bindings



commit 9104366f110dc582a980938571ee549589900959
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Apr 10 18:16:37 2018 +0200

    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

 codegen/valaccodebasemodule.vala |    3 +++
 vala/valaparser.vala             |    6 ++++++
 vala/valasymbol.vala             |    5 +++++
 vala/valausedattr.vala           |    2 +-
 4 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0964262..3055e45 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 127a118..51bc7a0 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 ed1ad83..131969a 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -73,6 +73,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
         * program or library. Private accessibility limits access to instances
diff --git a/vala/valausedattr.vala b/vala/valausedattr.vala
index 4947b33..999cfc8 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",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]