]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Add lvalue field to GLibValue
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 19 Jun 2011 06:55:10 +0000 (08:55 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Wed, 6 Jul 2011 20:34:21 +0000 (22:34 +0200)
codegen/valaccodearraymodule.vala
codegen/valaccodebasemodule.vala
codegen/valaccodecontrolflowmodule.vala
codegen/valaccodememberaccessmodule.vala
codegen/valaccodemethodmodule.vala
codegen/valaccodestructmodule.vala
codegen/valagasyncmodule.vala
codegen/valagerrormodule.vala
codegen/valagobjectmodule.vala

index d143b20d62a9088ab29befef0c47e46d46134020..5946f586d09f8be77753993d774993ff8d04406c 100644 (file)
@@ -505,7 +505,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                                           new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("length")),
                                           new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
 
-                       ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i"))), array_type)));
+                       ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), true), array_type)));
                        ccode.close ();
 
                        ccode.add_return (new CCodeIdentifier ("result"));
@@ -559,7 +559,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                                           new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
 
 
-                       ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i"))), array_type)));
+                       ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new CCodeIdentifier ("i")), get_cvalue_ (copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), true), array_type)));
                } else {
                        cfile.add_include ("string.h");
 
index 5ac3f1875d2b88f61e7965d0dc7d2b6e96f36c45..9c7ea1d83e0f4a1222d21830165fdd5a763b9aca 100644 (file)
@@ -1596,7 +1596,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        if (is_virtual) {
                                ccode.add_declaration (this_type.get_cname (), new CCodeVariableDeclarator ("self"));
-                               ccode.add_assignment (new CCodeIdentifier ("self"), get_cvalue_ (transform_value (new GLibValue (base_type, new CCodeIdentifier ("base")), this_type, acc)));
+                               ccode.add_assignment (new CCodeIdentifier ("self"), get_cvalue_ (transform_value (new GLibValue (base_type, new CCodeIdentifier ("base"), true), this_type, acc)));
                        }
 
                        acc.body.emit (this);
@@ -1858,7 +1858,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        } else {
                                if (in_constructor || (current_method != null && current_method.binding == MemberBinding.INSTANCE) ||
                                           (current_property_accessor != null && current_property_accessor.prop.binding == MemberBinding.INSTANCE)) {
-                                       var this_value = new GLibValue (get_data_type_for_symbol (current_type_symbol), new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "self"));
+                                       var this_value = new GLibValue (get_data_type_for_symbol (current_type_symbol), new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "self"), true);
                                        ccode.add_expression (destroy_value (this_value));
                                }
                        }
@@ -2155,8 +2155,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                if (deleg_type != null) {
                        if (!deleg_type.delegate_symbol.has_target) {
                                value.delegate_target_cvalue = new CCodeConstant ("NULL");
+                               ((GLibValue) value).lvalue = false;
                        } else if (!deleg_type.value_owned) {
                                value.delegate_target_destroy_notify_cvalue = new CCodeConstant ("NULL");
+                               ((GLibValue) value).lvalue = false;
                        }
                }
                return value;
@@ -2699,7 +2701,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                                push_function (function);
 
-                               ccode.add_expression (destroy_value (new GLibValue (type, new CCodeIdentifier ("var")), true));
+                               ccode.add_expression (destroy_value (new GLibValue (type, new CCodeIdentifier ("var"), true), true));
 
                                pop_function ();
 
@@ -2946,7 +2948,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        string free0_func = "_%s0".printf (freeid.name);
 
                        if (add_wrapper (free0_func)) {
-                               var macro = destroy_value (new GLibValue (type, new CCodeIdentifier ("var")), true);
+                               var macro = destroy_value (new GLibValue (type, new CCodeIdentifier ("var"), true), true);
                                cfile.add_type_declaration (new CCodeMacroReplacement.with_expression ("%s(var)".printf (free0_func), macro));
                        }
 
@@ -4294,7 +4296,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                if (init.symbol_reference is Field) {
                                        var f = (Field) init.symbol_reference;
                                        var instance_target_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
-                                       var typed_inst = transform_value (new GLibValue (expr.type_reference, instance), instance_target_type, init);
+                                       var typed_inst = transform_value (new GLibValue (expr.type_reference, instance, true), instance_target_type, init);
                                        store_field (f, typed_inst, init.initializer.target_value);
 
                                        var cl = f.parent_symbol as Class;
@@ -5540,7 +5542,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                push_context (new EmitContext ());
                push_function (function);
 
-               var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"));
+               var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true);
                foreach (Field f in st.get_fields ()) {
                        if (f.binding == MemberBinding.INSTANCE) {
                                var value = load_field (f, load_this_parameter ((TypeSymbol) st));
@@ -5749,6 +5751,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 public class Vala.GLibValue : TargetValue {
        public CCodeExpression cvalue;
+       public bool lvalue;
        public bool non_null;
        public string? ctype;
 
@@ -5760,9 +5763,10 @@ public class Vala.GLibValue : TargetValue {
        public CCodeExpression? delegate_target_cvalue;
        public CCodeExpression? delegate_target_destroy_notify_cvalue;
 
-       public GLibValue (DataType? value_type = null, CCodeExpression? cvalue = null) {
+       public GLibValue (DataType? value_type = null, CCodeExpression? cvalue = null, bool lvalue = false) {
                base (value_type);
                this.cvalue = cvalue;
+               this.lvalue = lvalue;
        }
 
        public void append_array_length_cvalue (CCodeExpression length_cvalue) {
@@ -5773,7 +5777,7 @@ public class Vala.GLibValue : TargetValue {
        }
 
        public GLibValue copy () {
-               var result = new GLibValue (value_type.copy (), cvalue);
+               var result = new GLibValue (value_type.copy (), cvalue, lvalue);
                result.actual_value_type = actual_value_type;
                result.non_null = non_null;
                result.ctype = ctype;
index 17ded5816e176e45f19e88b1bb6407952fb2cb59..d467398ddab86b5177ada367478a52c7b9a10256 100644 (file)
@@ -261,7 +261,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
 
                        var element_type = array_type.element_type.copy ();
                        element_type.value_owned = false;
-                       element_expr = get_cvalue_ (transform_value (new GLibValue (element_type, element_expr), stmt.type_reference, stmt));
+                       element_expr = get_cvalue_ (transform_value (new GLibValue (element_type, element_expr, true), stmt.type_reference, stmt));
 
                        visit_local_variable (stmt.element_variable);
                        ccode.add_assignment (get_variable_cexpression (stmt.variable_name), element_expr);
index 2f92b0fe6f185d8461cde72e68509c1964c694ee..b34290fc68ea60cfa0c803cb3d7e98419be6aba3 100644 (file)
@@ -329,6 +329,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
        /* Returns lvalue access to the given local variable */
        public override TargetValue get_local_cvalue (LocalVariable local) {
                var result = new GLibValue (local.variable_type.copy ());
+               result.lvalue = true;
 
                var array_type = local.variable_type as ArrayType;
                var delegate_type = local.variable_type as DelegateType;
@@ -387,6 +388,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
        /* Returns access values to the given parameter */
        public override TargetValue get_parameter_cvalue (Parameter param) {
                var result = new GLibValue (param.variable_type.copy ());
+               result.lvalue = true;
                result.array_null_terminated = param.array_null_terminated;
                if (param.has_array_length_cexpr) {
                        result.array_length_cexpr = new CCodeConstant (param.get_array_length_cexpr ());
@@ -507,6 +509,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                if (instance != null) {
                        result.actual_value_type = field.variable_type.get_actual_type (instance.value_type, null, field);
                }
+               result.lvalue = true;
                result.array_null_terminated = field.array_null_terminated;
                if (field.has_array_length_cexpr) {
                        result.array_length_cexpr = new CCodeConstant (field.get_array_length_cexpr ());
@@ -655,6 +658,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                        if (array_type.fixed_length) {
                                result.array_length_cvalues = null;
                                result.append_array_length_cvalue (new CCodeConstant (array_type.length.to_string ()));
+                               result.lvalue = false;
                        } else if (variable.array_null_terminated) {
                                requires_array_length = true;
                                var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
@@ -662,21 +666,25 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 
                                result.array_length_cvalues = null;
                                result.append_array_length_cvalue (len_call);
+                               result.lvalue = false;
                        } else if (variable.has_array_length_cexpr) {
                                var length_expr = new CCodeConstant (variable.get_array_length_cexpr ());
 
                                result.array_length_cvalues = null;
                                result.append_array_length_cvalue (length_expr);
+                               result.lvalue = false;
                        } else if (variable.no_array_length) {
                                result.array_length_cvalues = null;
                                for (int dim = 1; dim <= array_type.rank; dim++) {
                                        result.append_array_length_cvalue (new CCodeConstant ("-1"));
                                }
+                               result.lvalue = false;
                        } else if (variable.array_length_type != null) {
                                for (int dim = 1; dim <= array_type.rank; dim++) {
                                        // cast if variable does not use int for array length
                                        result.array_length_cvalues[dim - 1] = new CCodeCastExpression (result.array_length_cvalues[dim - 1], "gint");
                                }
+                               result.lvalue = false;
                        }
                        result.array_size_cvalue = null;
                } else if (delegate_type != null) {
@@ -685,6 +693,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                        }
 
                        result.delegate_target_destroy_notify_cvalue = new CCodeConstant ("NULL");
+                       result.lvalue = false;
                }
                result.value_type.value_owned = false;
 
index edda88deced662db8931d0c43ad2b6ef2e969b3d..607d5f622791de628d0d2fd540c16a6518b29742 100644 (file)
@@ -429,7 +429,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                                        base_expression_type = new ObjectType ((Interface) base_method.parent_symbol);
                                                }
                                                var self_target_type = new ObjectType (cl);
-                                               CCodeExpression cself = get_cvalue_ (transform_value (new GLibValue (base_expression_type, new CCodeIdentifier ("base")), self_target_type, m));
+                                               CCodeExpression cself = get_cvalue_ (transform_value (new GLibValue (base_expression_type, new CCodeIdentifier ("base"), true), self_target_type, m));
 
                                                ccode.add_declaration ("%s *".printf (cl.get_cname ()), new CCodeVariableDeclarator ("self"));
                                                ccode.add_assignment (new CCodeIdentifier ("self"), cself);
index a1abbbf9cc9156e8ea32be78a717243fc8596fd1..39aa95a56f113865842d4b6408a005667f04541f 100644 (file)
@@ -261,7 +261,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 
                push_function (function);
 
-               var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"));
+               var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true);
                foreach (var f in st.get_fields ()) {
                        if (f.binding == MemberBinding.INSTANCE) {
                                var value = load_field (f, load_this_parameter ((TypeSymbol) st));
index 5b33603ce8d58ee0b9508698d72d70b8e5ced9aa..b6c486b37d5446f3d42314acb2bdea360390b21d 100644 (file)
@@ -183,7 +183,7 @@ public class Vala.GAsyncModule : GSignalModule {
                        var type_symbol = m.parent_symbol as ObjectTypeSymbol;
 
                        var self_target_type = new ObjectType (type_symbol);
-                       var cself = get_cvalue_ (transform_value (new GLibValue (base_expression_type, new CCodeIdentifier ("base")), self_target_type, m));
+                       var cself = get_cvalue_ (transform_value (new GLibValue (base_expression_type, new CCodeIdentifier ("base"), true), self_target_type, m));
                        ccode.add_declaration ("%s *".printf (type_symbol.get_cname ()), new CCodeVariableDeclarator ("self"));
                        ccode.add_assignment (new CCodeIdentifier ("self"), cself);
                }
@@ -240,7 +240,7 @@ public class Vala.GAsyncModule : GSignalModule {
                                cself = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, cself);
                        }
                        if (requires_copy (this_type))  {
-                               cself = get_cvalue_ (copy_value (new GLibValue (m.this_parameter.variable_type, cself), m.this_parameter));
+                               cself = get_cvalue_ (copy_value (new GLibValue (m.this_parameter.variable_type, cself, true), m.this_parameter));
                        }
 
                        ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, "self"), cself);
@@ -433,7 +433,7 @@ public class Vala.GAsyncModule : GSignalModule {
                        // structs are returned via out parameter
                        CCodeExpression cexpr = new CCodeMemberAccess.pointer (data_var, "result");
                        if (requires_copy (return_type)) {
-                               cexpr = get_cvalue_ (copy_value (new GLibValue (return_type, cexpr), return_type));
+                               cexpr = get_cvalue_ (copy_value (new GLibValue (return_type, cexpr, true), return_type));
                        }
                        ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("result")), cexpr);
                } else if (!(return_type is VoidType)) {
index 7331280d4d5a607746dbcfb2e2c61fd4bd33b64c..e8ba64162a51842f7efeec082c2d6516d1a5f714 100644 (file)
@@ -104,7 +104,7 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 
                if (current_method is CreationMethod && current_method.parent_symbol is Class) {
                        var cl = (Class) current_method.parent_symbol;
-                       ccode.add_expression (destroy_value (new GLibValue (new ObjectType (cl), new CCodeIdentifier ("self"))));
+                       ccode.add_expression (destroy_value (new GLibValue (new ObjectType (cl), new CCodeIdentifier ("self"), true)));
                        ccode.add_return (new CCodeConstant ("NULL"));
                } else if (is_in_coroutine ()) {
                        ccode.add_return (new CCodeConstant ("FALSE"));
index 63419b1dd30956955cd7be1f146c3f5d653afe7a..7979aa722f8fca82ba9f38dfe56c43fb67a1306d 100644 (file)
@@ -202,13 +202,13 @@ public class Vala.GObjectModule : GTypeModule {
                        if (prop.base_property != null) {
                                var base_type = (Class) prop.base_property.parent_symbol;
                                base_prop = prop.base_property;
-                               cself = get_cvalue_ (transform_value (new GLibValue (new ObjectType (cl), cself), new ObjectType (base_type), prop));
+                               cself = get_cvalue_ (transform_value (new GLibValue (new ObjectType (cl), cself, true), new ObjectType (base_type), prop));
 
                                generate_property_accessor_declaration (prop.base_property.get_accessor, cfile);
                        } else if (prop.base_interface_property != null) {
                                var base_type = (Interface) prop.base_interface_property.parent_symbol;
                                base_prop = prop.base_interface_property;
-                               cself = get_cvalue_ (transform_value (new GLibValue (new ObjectType (cl), cself), new ObjectType (base_type), prop));
+                               cself = get_cvalue_ (transform_value (new GLibValue (new ObjectType (cl), cself, true), new ObjectType (base_type), prop));
 
                                generate_property_accessor_declaration (prop.base_interface_property.get_accessor, cfile);
                        }
@@ -233,7 +233,7 @@ public class Vala.GObjectModule : GTypeModule {
                                ccode.add_expression (csetcall);
 
                                if (requires_destroy (prop.get_accessor.value_type)) {
-                                       ccode.add_expression (destroy_value (new GLibValue (prop.get_accessor.value_type, new CCodeIdentifier ("boxed"))));
+                                       ccode.add_expression (destroy_value (new GLibValue (prop.get_accessor.value_type, new CCodeIdentifier ("boxed"), true)));
                                }
                                ccode.close ();
                        } else {
@@ -301,13 +301,13 @@ public class Vala.GObjectModule : GTypeModule {
                        if (prop.base_property != null) {
                                var base_type = (Class) prop.base_property.parent_symbol;
                                base_prop = prop.base_property;
-                               cself = get_cvalue_ (transform_value (new GLibValue (new ObjectType (cl), cself), new ObjectType (base_type), prop));
+                               cself = get_cvalue_ (transform_value (new GLibValue (new ObjectType (cl), cself, true), new ObjectType (base_type), prop));
 
                                generate_property_accessor_declaration (prop.base_property.set_accessor, cfile);
                        } else if (prop.base_interface_property != null) {
                                var base_type = (Interface) prop.base_interface_property.parent_symbol;
                                base_prop = prop.base_interface_property;
-                               cself = get_cvalue_ (transform_value (new GLibValue (new ObjectType (cl), cself), new ObjectType (base_type), prop));
+                               cself = get_cvalue_ (transform_value (new GLibValue (new ObjectType (cl), cself, true), new ObjectType (base_type), prop));
 
                                generate_property_accessor_declaration (prop.base_interface_property.set_accessor, cfile);
                        }