]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't use temp vars when accessing types that forbid lvalue access
authorLuca Bruno <lucabru@src.gnome.org>
Fri, 15 Jul 2011 16:05:56 +0000 (18:05 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Fri, 15 Jul 2011 16:53:25 +0000 (18:53 +0200)
Add support for specifying whether a type allows lvalue access or not by
using the lvalue_access argument of the CCode attribute.

codegen/valaccodebasemodule.vala
codegen/valaccodememberaccessmodule.vala

index 8e6d7fbdcc9825210a2a055ca883708e6923ff15..5460b5e475b5d9de9d41d8d2fa06a9e3ab1f394e 100644 (file)
@@ -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) {
        }
 
index 95a43899af8103e29273749094fa03280c72026c..ace7d343c31fa6d52285a72fce62bff419e0597d 100644 (file)
@@ -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);
                }