[vala/wip/girparser2: 23/24] girparser: Use type_id information from gir if not already overridden



commit 09f05b376eefe3ea9461566b3809000f0be3b6de
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Oct 6 13:50:10 2016 +0200

    girparser: Use type_id information from gir if not already overridden

 vala/valagirparser.vala |   59 ++++++++++++++++++++++++++--------------------
 1 files changed, 33 insertions(+), 26 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 2a0e18d..37f34bc 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1840,6 +1840,19 @@ public class Vala.GirParser : CodeVisitor {
                }
        }
 
+       void set_type_id_ccode (Symbol sym) {
+               if (sym.has_attribute_argument ("CCode", "has_type_id")
+                   || sym.has_attribute_argument ("CCode", "type_id"))
+                   return;
+
+               var type_id = element_get_type_id ();
+               if (type_id == null) {
+                       sym.set_attribute_bool ("CCode", "has_type_id", false);
+               } else {
+                       sym.set_attribute_string ("CCode", "type_id", type_id);
+               }
+       }
+
        void parse_repository () {
                start_element ("repository");
                if (reader.get_attribute ("version") != GIR_VERSION) {
@@ -2250,18 +2263,15 @@ public class Vala.GirParser : CodeVisitor {
                                        en.set_attribute ("Flags", true);
                                }
                                sym = en;
-
-                               var type_id = element_get_type_id ();
-                               if (type_id == null) {
-                                       en.set_attribute_bool ("CCode", "has_type_id", false);
-                               } else {
-                                       en.set_attribute_string ("CCode", "type_id", type_id);
-                               }
                        }
                        current.symbol = sym;
                } else {
                        sym = current.symbol;
                }
+
+               if (!error_domain)
+                       set_type_id_ccode (sym);
+
                sym.external = true;
                sym.access = SymbolAccessibility.PUBLIC;
 
@@ -2666,15 +2676,12 @@ public class Vala.GirParser : CodeVisitor {
                if (current.new_symbol) {
                        st = new Struct (element_get_name (), current.source_reference);
                        current.symbol = st;
-                       var type_id = element_get_type_id ();
-                       if (type_id == null) {
-                               st.set_attribute_bool ("CCode", "has_type_id", false);
-                       } else {
-                               st.set_attribute_string ("CCode", "type_id", type_id);
-                       }
                } else {
                        st = (Struct) current.symbol;
                }
+
+               set_type_id_ccode (st);
+
                st.external = true;
                st.access = SymbolAccessibility.PUBLIC;
 
@@ -2734,7 +2741,6 @@ public class Vala.GirParser : CodeVisitor {
                var parent = reader.get_attribute ("parent");
                if (current.new_symbol) {
                        cl = new Class (current.name, current.source_reference);
-                       cl.set_attribute_string ("CCode", "type_id", element_get_type_id ());
                        cl.is_abstract = metadata.get_bool (ArgumentType.ABSTRACT, reader.get_attribute 
("abstract") == "1");
 
                        if (parent != null) {
@@ -2744,6 +2750,9 @@ public class Vala.GirParser : CodeVisitor {
                } else {
                        cl = (Class) current.symbol;
                }
+
+               set_type_id_ccode (cl);
+
                cl.access = SymbolAccessibility.PUBLIC;
                cl.external = true;
 
@@ -2814,16 +2823,13 @@ public class Vala.GirParser : CodeVisitor {
                Interface iface;
                if (current.new_symbol) {
                        iface = new Interface (current.name, current.source_reference);
-                       var typeid = element_get_type_id ();
-                       if (typeid != null) {
-                               iface.set_attribute_string ("CCode", "type_id", typeid);
-                       }
-
                        current.symbol = iface;
                } else {
                        iface = (Interface) current.symbol;
                }
 
+               set_type_id_ccode (iface);
+
                iface.access = SymbolAccessibility.PUBLIC;
                iface.external = true;
 
@@ -3229,16 +3235,14 @@ public class Vala.GirParser : CodeVisitor {
                if (current.new_symbol) {
                        cl = new Class (current.name, current.source_reference);
                        cl.is_compact = true;
-                       var typeid = element_get_type_id ();
-                       if (typeid != null) {
-                               require_copy_free = true;
-                               cl.set_attribute_string ("CCode", "type_id", typeid);
-                       }
-
                        current.symbol = cl;
                } else {
                        cl = (Class) current.symbol;
                }
+
+               set_type_id_ccode (cl);
+               require_copy_free = cl.has_attribute_argument ("CCode", "type_id");
+
                cl.access = SymbolAccessibility.PUBLIC;
                cl.external = true;
 
@@ -3286,7 +3290,10 @@ public class Vala.GirParser : CodeVisitor {
 
                // Add ccode-attributes for ref/unref methodes if available
                // otherwise fallback to default g_boxed_copy/free
-               if (ref_method != null && unref_method != null) {
+               if (cl.has_attribute_argument ("CCode", "ref_function") || cl.has_attribute_argument 
("CCode", "unref_function")
+                   || cl.has_attribute_argument ("CCode", "copy_function") || cl.has_attribute_argument 
("CCode", "free_function")) {
+                       //do nothing
+               } else if (ref_method != null && unref_method != null) {
                        cl.set_attribute_string ("CCode", "ref_function", ref_method.get_cname ());
                        cl.set_attribute_string ("CCode", "unref_function", unref_method.get_cname ());
                } else if (require_copy_free) {


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