[vala/wip/effectfree: 37/38] codegen: Add lvalue field to GLibValue
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/effectfree: 37/38] codegen: Add lvalue field to GLibValue
- Date: Mon, 27 Jun 2011 11:50:05 +0000 (UTC)
commit e4437048c8328daf5a353a1fee683efe0c7fbe25
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Jun 19 08:55:10 2011 +0200
codegen: Add lvalue field to GLibValue
codegen/valaccodearraymodule.vala | 4 ++--
codegen/valaccodebasemodule.vala | 20 ++++++++++++--------
codegen/valaccodecontrolflowmodule.vala | 2 +-
codegen/valaccodememberaccessmodule.vala | 9 +++++++++
codegen/valaccodemethodmodule.vala | 2 +-
codegen/valaccodestructmodule.vala | 2 +-
codegen/valagasyncmodule.vala | 6 +++---
codegen/valagerrormodule.vala | 2 +-
codegen/valagobjectmodule.vala | 10 +++++-----
9 files changed, 35 insertions(+), 22 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index d143b20..5946f58 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -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");
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 056bb08..055e0c1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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 ();
@@ -2943,7 +2945,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));
}
@@ -4279,7 +4281,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;
@@ -5523,7 +5525,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));
@@ -5732,6 +5734,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;
@@ -5743,9 +5746,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) {
@@ -5756,7 +5760,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.non_null = non_null;
result.ctype = ctype;
diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala
index 17ded58..d467398 100644
--- a/codegen/valaccodecontrolflowmodule.vala
+++ b/codegen/valaccodecontrolflowmodule.vala
@@ -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);
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 8eb6c0e..c97a3df 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -328,6 +328,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;
@@ -386,6 +387,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 ());
@@ -506,6 +508,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
var result = new GLibValue (value_type);
+ 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 ());
@@ -654,6 +657,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"));
@@ -661,21 +665,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) {
@@ -684,6 +692,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;
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index e2f0985..92c3544 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -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);
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index a1abbbf..39aa95a 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -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));
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index fdbd2aa..ddf8b37 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -179,7 +179,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);
}
@@ -236,7 +236,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);
@@ -436,7 +436,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)) {
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index 7331280..e8ba641 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -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"));
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index 63419b1..7979aa7 100644
--- a/codegen/valagobjectmodule.vala
+++ b/codegen/valagobjectmodule.vala
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]