From: Rico Tzschichholz Date: Thu, 6 Oct 2016 11:50:10 +0000 (+0200) Subject: girparser: Use type_id information from gir if not already overridden X-Git-Tag: 0.35.1~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e7eaf402e88f508dcad21f0206e07bc2c662bf8;p=thirdparty%2Fvala.git girparser: Use type_id information from gir if not already overridden --- diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 96ac8b37b..2e6fa4d92 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -1847,6 +1847,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) { @@ -2257,18 +2270,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; @@ -2673,15 +2683,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; @@ -2741,7 +2748,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) { @@ -2751,6 +2757,9 @@ public class Vala.GirParser : CodeVisitor { } else { cl = (Class) current.symbol; } + + set_type_id_ccode (cl); + cl.access = SymbolAccessibility.PUBLIC; cl.external = true; @@ -2821,16 +2830,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; @@ -3240,16 +3246,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; @@ -3297,7 +3301,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) {