[vala/wip/effectfree: 32/39] codegen: Replace temp_ref_vars with temp_ref_values using TargetValue
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/effectfree: 32/39] codegen: Replace temp_ref_vars with temp_ref_values using TargetValue
- Date: Fri, 1 Jul 2011 07:52:25 +0000 (UTC)
commit 6890dd6b454a345e9a81e9a13adc1bd03b1ff074
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jun 14 10:58:58 2011 +0200
codegen: Replace temp_ref_vars with temp_ref_values using TargetValue
codegen/valaccodebasemodule.vala | 73 ++++++++++++++------------------------
codegen/valagasyncmodule.vala | 6 ++--
codegen/valagsignalmodule.vala | 9 ++---
3 files changed, 34 insertions(+), 54 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index b6ba4b4..283796c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -34,7 +34,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public CatchClause current_catch;
public CCodeFunction ccode;
public ArrayList<CCodeFunction> ccode_stack = new ArrayList<CCodeFunction> ();
- public ArrayList<LocalVariable> temp_ref_vars = new ArrayList<LocalVariable> ();
+ public ArrayList<TargetValue> temp_ref_values = new ArrayList<TargetValue> ();
public int next_temp_var_id;
public bool current_method_inner_error;
public bool current_method_return;
@@ -217,7 +217,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public CCodeFunction ccode { get { return emit_context.ccode; } }
/* temporary variables that own their content */
- public ArrayList<LocalVariable> temp_ref_vars { get { return emit_context.temp_ref_vars; } }
+ public ArrayList<TargetValue> temp_ref_values { get { return emit_context.temp_ref_values; } }
/* cache to check whether a certain marshaller has been created yet */
public Set<string> user_marshal_set;
/* (constant) hash table with all predefined marshallers */
@@ -984,11 +984,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
- foreach (LocalVariable local in temp_ref_vars) {
- ccode.add_expression (destroy_local (local));
+ foreach (var value in temp_ref_values) {
+ ccode.add_expression (destroy_value (value));
}
- temp_ref_vars.clear ();
+ temp_ref_values.clear ();
pop_context ();
}
@@ -1022,11 +1022,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_assignment (lhs, rhs);
- foreach (LocalVariable local in temp_ref_vars) {
- ccode.add_expression (destroy_local (local));
+ foreach (var value in temp_ref_values) {
+ ccode.add_expression (destroy_value (value));
}
- temp_ref_vars.clear ();
+ temp_ref_values.clear ();
pop_context ();
}
@@ -3039,7 +3039,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
* we unref temporary variables at the end of a full
* expression
*/
- if (temp_ref_vars.size == 0) {
+ if (temp_ref_values.size == 0) {
/* nothing to do without temporary variables */
return;
}
@@ -3059,15 +3059,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_assignment (get_variable_cexpression (full_expr_var.name), get_cvalue (expr));
}
- foreach (LocalVariable local in temp_ref_vars) {
- ccode.add_expression (destroy_local (local));
+ foreach (var value in temp_ref_values) {
+ ccode.add_expression (destroy_value (value));
}
if (full_expr_var != null) {
set_cvalue (expr, get_variable_cexpression (full_expr_var.name));
}
- temp_ref_vars.clear ();
+ temp_ref_values.clear ();
}
public void emit_temp_var (LocalVariable local) {
@@ -3109,8 +3109,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
/* free temporary objects and handle errors */
- foreach (LocalVariable local in temp_ref_vars) {
- ccode.add_expression (destroy_local (local));
+ foreach (var value in temp_ref_values) {
+ ccode.add_expression (destroy_value (value));
}
if (stmt.tree_can_fail && stmt.expression.tree_can_fail) {
@@ -3118,7 +3118,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
add_simple_check (stmt.expression);
}
- temp_ref_vars.clear ();
+ temp_ref_values.clear ();
}
protected virtual void append_scope_free (Symbol sym, CodeNode? stop_at = null) {
@@ -5044,28 +5044,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// manual memory management for non-void pointers
// treat void* special to not leak memory with void* method parameters
} else if (requires_destroy (type)) {
- var decl = get_temp_variable (type, true, type, false);
- emit_temp_var (decl);
- temp_ref_vars.insert (0, decl);
- ccode.add_assignment (get_variable_cexpression (decl.name), result.cvalue);
- result.cvalue = get_variable_cexpression (decl.name);
-
- if (type is ArrayType) {
- var array_type = (ArrayType) type;
- for (int dim = 1; dim <= array_type.rank; dim++) {
- var len_decl = new LocalVariable (int_type.copy (), get_array_length_cname (decl.name, dim));
- emit_temp_var (len_decl);
- ccode.add_assignment (get_variable_cexpression (len_decl.name), get_array_length_cvalue (value, dim));
- }
- } else if (type is DelegateType) {
- var target_decl = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (decl.name));
- emit_temp_var (target_decl);
- var target_destroy_notify_decl = new LocalVariable (gdestroynotify_type, get_delegate_target_destroy_notify_cname (decl.name));
- emit_temp_var (target_destroy_notify_decl);
- ccode.add_assignment (get_variable_cexpression (target_decl.name), get_delegate_target_cvalue (value));
- ccode.add_assignment (get_variable_cexpression (target_destroy_notify_decl.name), get_delegate_target_destroy_notify_cvalue (value));
-
- }
+ var temp_value = create_temp_value (type, false, node);
+ temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
+ store_value (temp_value, value);
+ result.cvalue = get_cvalue_ (temp_value);
requires_temp_value = false;
}
}
@@ -5077,27 +5059,26 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (gvalue_boxing) {
// implicit conversion to GValue
- var decl = get_temp_variable (target_type, true, target_type);
- emit_temp_var (decl);
+ var temp_value = create_temp_value (target_type, true, node, true);
if (!target_type.value_owned) {
// boxed GValue leaked, destroy it
- temp_ref_vars.insert (0, decl);
+ temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
}
if (target_type.nullable) {
var newcall = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
newcall.add_argument (new CCodeConstant ("GValue"));
newcall.add_argument (new CCodeConstant ("1"));
- var newassignment = new CCodeAssignment (get_variable_cexpression (decl.name), newcall);
+ var newassignment = new CCodeAssignment (get_cvalue_ (temp_value), newcall);
ccode.add_expression (newassignment);
}
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_init"));
if (target_type.nullable) {
- ccall.add_argument (get_variable_cexpression (decl.name));
+ ccall.add_argument (get_cvalue_ (temp_value));
} else {
- ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (decl.name)));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue_ (temp_value)));
}
ccall.add_argument (new CCodeIdentifier (type.get_type_id ()));
ccode.add_expression (ccall);
@@ -5108,9 +5089,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccall = new CCodeFunctionCall (get_value_setter_function (type));
}
if (target_type.nullable) {
- ccall.add_argument (get_variable_cexpression (decl.name));
+ ccall.add_argument (get_cvalue_ (temp_value));
} else {
- ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (decl.name)));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue_ (temp_value)));
}
if (type.is_real_non_null_struct_type ()) {
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, result.cvalue));
@@ -5120,7 +5101,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_expression (ccall);
- result = (GLibValue) get_local_cvalue (decl);
+ result = (GLibValue) temp_value;
requires_temp_value = false;
} else if (gvariant_boxing) {
// implicit conversion to GVariant
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index df8184a..fdbd2aa 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -569,11 +569,11 @@ public class Vala.GAsyncModule : GSignalModule {
/* free temporary objects */
- foreach (LocalVariable local in temp_ref_vars) {
- ccode.add_expression (destroy_local (local));
+ foreach (var value in temp_ref_values) {
+ ccode.add_expression (destroy_value (value));
}
- temp_ref_vars.clear ();
+ temp_ref_values.clear ();
}
public override void return_with_exception (CCodeExpression error_expr)
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index 1bde964..6e06f72 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -149,17 +149,16 @@ public class Vala.GSignalModule : GObjectModule {
return sig.get_canonical_cconstant (((StringLiteral) detail_expr).eval ());
}
- var detail_decl = get_temp_variable (detail_expr.value_type, true, node);
- emit_temp_var (detail_decl);
- temp_ref_vars.insert (0, detail_decl);
+ var detail_value = create_temp_value (detail_expr.value_type, false, node, true);
+ temp_ref_values.insert (0, detail_value);
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_strconcat"));
ccall.add_argument (sig.get_canonical_cconstant (""));
ccall.add_argument (get_cvalue (detail_expr));
ccall.add_argument (new CCodeConstant ("NULL"));
- ccode.add_assignment (get_variable_cexpression (detail_decl.name), ccall);
- return get_variable_cexpression (detail_decl.name);
+ ccode.add_assignment (get_cvalue_ (detail_value), ccall);
+ return get_cvalue_ (detail_value);
}
public override void visit_signal (Signal sig) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]