From: Florian Brosch Date: Tue, 15 Oct 2013 23:38:09 +0000 (+0200) Subject: Add "finish_instance" CCode attribute X-Git-Tag: 0.35.7~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8f2fe6234c07b259e4af1f98c1cfcbddce66487;p=thirdparty%2Fvala.git Add "finish_instance" CCode attribute https://bugzilla.gnome.org/show_bug.cgi?id=710103 --- diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala index 25579001a..ec41f82b1 100644 --- a/codegen/valaccodeattribute.vala +++ b/codegen/valaccodeattribute.vala @@ -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; diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 4be48a044..84d5982b9 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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; } diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index c047a5277..6202f319b 100644 --- a/codegen/valaccodemethodcallmodule.vala +++ b/codegen/valaccodemethodcallmodule.vala @@ -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")); diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index f28fe86d0..700c7afdc 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -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) { diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 5ed041a4f..b1220948d 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -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") { diff --git a/vala/valausedattr.vala b/vala/valausedattr.vala index 63b710432..314495000 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", "",