From: Luca Bruno Date: Fri, 15 Jul 2011 16:05:56 +0000 (+0200) Subject: codegen: Don't use temp vars when accessing types that forbid lvalue access X-Git-Tag: 0.13.2~151 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e429e144d505e6629c94847eb212753fa079443;p=thirdparty%2Fvala.git codegen: Don't use temp vars when accessing types that forbid lvalue access Add support for specifying whether a type allows lvalue access or not by using the lvalue_access argument of the CCode attribute. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 8e6d7fbdc..5460b5e47 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -5460,6 +5460,20 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return get_cvalue (node); } + public bool is_lvalue_access_allowed (DataType type) { + var array_type = type as ArrayType; + if (array_type != null && array_type.inline_allocated) { + return false; + } + if (type.data_type != null) { + var a = type.data_type.get_attribute ("CCode"); + if (a != null && a.has_argument ("lvalue_access")) { + return a.get_bool ("lvalue_access"); + } + } + return true; + } + public override void visit_class (Class cl) { } diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala index 95a43899a..ace7d343c 100644 --- a/codegen/valaccodememberaccessmodule.vala +++ b/codegen/valaccodememberaccessmodule.vala @@ -689,7 +689,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { } result.value_type.value_owned = false; - if (!(variable is Parameter && variable.name == "this") && !(array_type != null && array_type.inline_allocated)) { + if (!(variable is Parameter && variable.name == "this") && is_lvalue_access_allowed (result.value_type)) { result = (GLibValue) store_temp_value (result, variable); }