[vala/0.34] Add "finish_instance" CCode attribute



commit 65a26e1f14bd91fac7913d34037a24580e2ee94d
Author: Florian Brosch <flo brosch gmail com>
Date:   Wed Oct 16 01:38:09 2013 +0200

    Add "finish_instance" CCode attribute
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710103

 codegen/valaccodeattribute.vala        |   16 ++++++++++++++++
 codegen/valaccodebasemodule.vala       |   11 +++++++++++
 codegen/valaccodemethodcallmodule.vala |   11 +++++++++--
 codegen/valaccodemethodmodule.vala     |    3 ++-
 vala/valagirparser.vala                |    4 ++++
 vala/valausedattr.vala                 |    2 +-
 6 files changed, 43 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index ecadd80..81c70f2 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -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;
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c0d10ef..669c950 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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;
        }
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 9808ae5..376e82a 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -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"));
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index a1ab21a..f7fbae7 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -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) {
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index b48dbb3..ba104ee 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -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> ();
diff --git a/vala/valausedattr.vala b/vala/valausedattr.vala
index 698954e..191c124 100644
--- a/vala/valausedattr.vala
+++ b/vala/valausedattr.vala
@@ -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", "",


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