]> 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>
Fri, 6 Oct 2017 12:28:02 +0000 (14:28 +0200)
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 ecadd80f34c5b3b21f5ee842c7ba0f8410c19722..81c70f222990fb2a8750a4cc543b5aecebc11328 100644 (file)
@@ -459,6 +459,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) {
@@ -540,6 +555,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 c0d10ef82b183bc26e10ba5bb443c382c8dabff7..669c950196e5394bb740acdd830d950d0ac588f5 100644 (file)
@@ -4718,6 +4718,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;
@@ -6197,6 +6204,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 9808ae5a6fbea5067a29ec83c3f992def2b25851..376e82aacac57d75808260a720b658e159211ff5 100644 (file)
@@ -218,8 +218,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 a1ab21a2fbae4f766db09525b27ec1e962037bc6..f7fbae783359a458731bbcfc6c38ad56715051cc 100644 (file)
@@ -928,7 +928,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 b48dbb3890f742b789c5423a9cffb06a059b1364..ba104ee1788b81b783c34485d873171b3414a3d4 100644 (file)
@@ -76,6 +76,7 @@ public class Vala.GirParser : CodeVisitor {
                DESTROYS_INSTANCE,
                BASE_TYPE,
                FINISH_NAME,
+               FINISH_INSTANCE,
                SYMBOL_TYPE,
                INSTANCE_IDX,
                EXPERIMENTAL,
@@ -3166,6 +3167,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));
+               }
 
                var parameters = new ArrayList<ParameterInfo> ();
                current.array_length_parameters = new ArrayList<int> ();
index 698954e642b4aff63cfefb1eb12b1a9e7e4c6a12..191c1248cfa292fdf0d2effc2c794d1f36921915 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", "",