Commit 3f7e03ce authored by Luca Bruno's avatar Luca Bruno

codegen: Add lvalue field to GLibValue

parent d777977f
......@@ -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");
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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));
......
......@@ -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)) {
......
......@@ -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"));
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment