]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add "finish_instance" CCode attribute
authorFlorian Brosch <flo.brosch@gmail.com>
Tue, 15 Oct 2013 23:38:09 +0000 (01:38 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 6 Mar 2017 13:21:08 +0000 (14:21 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=710103

codegen/valaccodeattribute.vala
codegen/valaccodebasemodule.vala
codegen/valaccodemethodcallmodule.vala
codegen/valaccodemethodmodule.vala
vala/valagirparser.vala
vala/valausedattr.vala

index 25579001aa753226756a118e554b0f001c43136d..ec41f82b119ac3ab2a8f9dedf1bce1bbc282e465 100644 (file)
@@ -455,6 +455,21 @@ public class Vala.CCodeAttribute : AttributeCache {
                }
        }
 
+       public bool finish_instance {
+               get {
+                       if (_finish_instance == null) {
+                               Method m = node as Method;
+                               bool is_creation_method = m is CreationMethod;
+                               if (ccode == null || m == null || m.is_abstract || m.is_virtual) {
+                                       _finish_instance = !is_creation_method;
+                               } else {
+                                       _finish_instance = ccode.get_bool ("finish_instance", !is_creation_method);
+                               }
+                       }
+                       return _finish_instance;
+               }
+       }
+
        public string delegate_target_name {
                get {
                        if (_delegate_target_name == null) {
@@ -536,6 +551,7 @@ public class Vala.CCodeAttribute : AttributeCache {
        private string _finish_name;
        private string _finish_vfunc_name;
        private string _finish_real_name;
+       private bool? _finish_instance;
        private string _real_name;
        private string _delegate_target_name;
        private string _ctype;
index 4be48a044a5d001f1efb6ce868b7d7bdebe64276..84d5982b9197db90969ed41a7def8268827afb22 100644 (file)
@@ -4738,6 +4738,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                }
                        }
 
+                       if (m != null && m.parent_symbol is Class) {
+                               if (get_ccode_finish_instance (m)) {
+                                       var tmp = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), "_source_object_");
+                                       out_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), tmp);
+                               }
+                       }
+
                        // append C arguments in the right order
 
                        int last_pos;
@@ -6227,6 +6234,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                return get_ccode_free_function (sym) == "g_boxed_free";
        }
 
+       public static bool get_ccode_finish_instance (CodeNode node) {
+               return get_ccode_attribute (node).finish_instance;
+       }
+
        public static string get_ccode_type_id (CodeNode node) {
                return get_ccode_attribute(node).type_id;
        }
index c047a52771902e23c21f65e9193431eeca0cf027..6202f319b74f7f05ed356e8be5a7067332b44618 100644 (file)
@@ -226,8 +226,15 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue_ (instance_value));
                        }
 
-                       in_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
-                       out_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
+                       if (expr.is_yield_expression) {
+                               in_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
+                               if (get_ccode_finish_instance (m)) {
+                                       out_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
+                               }
+                       } else if (ma.member_name != "end" || get_ccode_finish_instance (m)) {
+                               out_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
+                               in_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
+                       }
                } else if (m != null && m.binding == MemberBinding.CLASS) {
                        var cl = (Class) m.parent_symbol;
                        var cast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_upper_case_name (cl, null) + "_CLASS"));
index f28fe86d06d5e422c197d35fd003af7ddeaed0cb..700c7afdcc40ad21b4bbb5d3a402dce310a1ba55 100644 (file)
@@ -952,7 +952,8 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        if (!cl.is_compact && vcall == null && (direction & 1) == 1) {
                                cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), new CCodeParameter ("object_type", "GType"));
                        }
-               } else if (m.binding == MemberBinding.INSTANCE || (m.parent_symbol is Struct && m is CreationMethod)) {
+               } else if ((m.binding == MemberBinding.INSTANCE || (m.parent_symbol is Struct && m is CreationMethod))
+                   && (direction != 2 || get_ccode_finish_instance (m))) {
                        TypeSymbol parent_type = find_parent_type (m);
                        DataType this_type;
                        if (parent_type is Class) {
index 5ed041a4faf6ae554f0610ae384097a08d0e017c..b1220948d26fdb5be90a6bc62f34ef2ab421ad73 100644 (file)
@@ -75,6 +75,7 @@ public class Vala.GirParser : CodeVisitor {
                DESTROYS_INSTANCE,
                BASE_TYPE,
                FINISH_NAME,
+               FINISH_INSTANCE,
                SYMBOL_TYPE,
                INSTANCE_IDX,
                EXPERIMENTAL,
@@ -3148,6 +3149,9 @@ public class Vala.GirParser : CodeVisitor {
                if (metadata.has_argument (ArgumentType.FINISH_NAME)) {
                        s.set_attribute_string ("CCode", "finish_name", metadata.get_string (ArgumentType.FINISH_NAME));
                }
+               if (metadata.has_argument (ArgumentType.FINISH_INSTANCE)) {
+                       s.set_attribute_bool ("CCode", "finish_instance", metadata.get_bool (ArgumentType.FINISH_INSTANCE));
+               }
 
                int instance_idx = -2;
                if (element_name == "function" && symbol_type == "method") {
index 63b71043246be3c70e7b4285ebbb0813f382a4fd..314495000b4d3acb1b273ed99e391bff4a849d4c 100644 (file)
@@ -39,7 +39,7 @@ public class Vala.UsedAttr : CodeVisitor {
                "has_copy_function", "lower_case_csuffix", "ref_sink_function", "dup_function", "finish_function", "generic_type_pos",
                "array_length_type", "array_length", "array_length_cname", "array_length_cexpr", "array_null_terminated",
                "vfunc_name", "finish_vfunc_name", "finish_name", "free_function_address_of", "pos", "delegate_target", "delegate_target_cname",
-               "array_length_pos", "delegate_target_pos", "destroy_notify_pos", "ctype", "has_new_function", "notify", "",
+               "array_length_pos", "delegate_target_pos", "destroy_notify_pos", "ctype", "has_new_function", "notify", "finish_instance", "",
 
                "Immutable", "",
                "Compact", "",