[vala/wip/effectfree: 38/38] codegen: Use GLibValue.lvalue when taking the address of an expression
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/effectfree: 38/38] codegen: Use GLibValue.lvalue when taking the address of an expression
- Date: Sun, 19 Jun 2011 08:19:57 +0000 (UTC)
commit 2f3b647d4e7bfd37ad5dff856660bb5b3908675d
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Jun 19 09:11:59 2011 +0200
codegen: Use GLibValue.lvalue when taking the address of an expression
codegen/valaccodebasemodule.vala | 39 ++++++++++--------------------
codegen/valaccodememberaccessmodule.vala | 16 +++---------
codegen/valaccodemethodcallmodule.vala | 21 ++++-----------
3 files changed, 23 insertions(+), 53 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 055e0c1..e4c884f 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5120,20 +5120,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
} else if (boxing) {
// value needs to be boxed
- var unary = result.cvalue as CCodeUnaryExpression;
- if (unary != null && unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
- // *expr => expr
- result.cvalue = unary.inner;
- } else if (result.cvalue is CCodeIdentifier || result.cvalue is CCodeMemberAccess) {
- result.cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, result.cvalue);
- } else {
- var decl = get_temp_variable (type, type.value_owned, type, false);
- emit_temp_var (decl);
-
- ccode.add_assignment (get_variable_cexpression (decl.name), result.cvalue);
- result.cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (decl.name));
+ if (!result.lvalue) {
+ result = (GLibValue) store_temp_value (result, node);
requires_temp_value = false;
}
+ result.cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, result.cvalue);
+ result.lvalue = false;
} else if (unboxing) {
// unbox value
@@ -5251,20 +5243,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (prop.parent_symbol is Struct) {
// we need to pass struct instance by reference
- var unary = cinstance as CCodeUnaryExpression;
- if (unary != null && unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
- // *expr => expr
- cinstance = unary.inner;
- } else if (cinstance is CCodeIdentifier || cinstance is CCodeMemberAccess) {
- cinstance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cinstance);
- } else {
- // if instance is e.g. a function call, we can't take the address of the expression
- // (tmp = expr, &tmp)
-
- var temp_value = create_temp_value (instance.target_type, false, instance);
- store_value (temp_value, instance.target_value);
- cinstance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue_ (temp_value));
+ var instance_value = instance.target_value;
+ if (!get_lvalue (instance_value)) {
+ instance_value = store_temp_value (instance_value, instance);
}
+ cinstance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue_ (instance_value));
}
ccall.add_argument (cinstance);
@@ -5710,12 +5693,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return glib_value.array_length_cvalues;
}
+ public bool get_lvalue (TargetValue value) {
+ var glib_value = (GLibValue) value;
+ return glib_value.lvalue;
+ }
+
public bool get_non_null (TargetValue value) {
var glib_value = (GLibValue) value;
return glib_value.non_null;
}
-
public string? get_ctype (TargetValue value) {
var glib_value = (GLibValue) value;
return glib_value.ctype;
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index c97a3df..0ee29d9 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -211,19 +211,11 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (prop.binding == MemberBinding.INSTANCE) {
if (prop.parent_symbol is Struct) {
// we need to pass struct instance by reference
- var unary = pub_inst as CCodeUnaryExpression;
- if (unary != null && unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
- // *expr => expr
- pub_inst = unary.inner;
- } else if (pub_inst is CCodeIdentifier || pub_inst is CCodeMemberAccess) {
- pub_inst = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, pub_inst);
- } else {
- // if instance is e.g. a function call, we can't take the address of the expression
- var temp_var = get_temp_variable (expr.inner.target_type, true, null, false);
- emit_temp_var (temp_var);
- ccode.add_assignment (get_variable_cexpression (temp_var.name), pub_inst);
- pub_inst = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (temp_var.name));
+ var instance = expr.inner.target_value;
+ if (!get_lvalue (instance)) {
+ instance = store_temp_value (instance, expr);
}
+ pub_inst = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue_ (instance));
}
ccall.add_argument (pub_inst);
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 4f8ce16..ffa645d 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -178,29 +178,20 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
in_arg_map.set (get_param_pos (m.cinstance_parameter_position), instance);
out_arg_map.set (get_param_pos (m.cinstance_parameter_position), instance);
} else if (m != null && m.binding == MemberBinding.INSTANCE && !(m is CreationMethod)) {
- instance = get_cvalue (ma.inner);
-
+ var instance_value = ma.inner.target_value;
if ((ma.member_name == "begin" || ma.member_name == "end") && ma.inner.symbol_reference == ma.symbol_reference) {
var inner_ma = (MemberAccess) ma.inner;
- instance = get_cvalue (inner_ma.inner);
+ instance_value = inner_ma.inner.target_value;
}
+ instance = get_cvalue_ (instance_value);
var st = m.parent_symbol as Struct;
if (st != null && !st.is_simple_type ()) {
// we need to pass struct instance by reference
- var unary = instance as CCodeUnaryExpression;
- if (unary != null && unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
- // *expr => expr
- instance = unary.inner;
- } else if (instance is CCodeIdentifier || instance is CCodeMemberAccess) {
- instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance);
- } else {
- // if instance is e.g. a function call, we can't take the address of the expression
- var temp_var = get_temp_variable (ma.inner.target_type, true, null, false);
- emit_temp_var (temp_var);
- ccode.add_assignment (get_variable_cexpression (temp_var.name), instance);
- instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (temp_var.name));
+ if (!get_lvalue (instance_value)) {
+ instance_value = store_temp_value (instance_value, expr);
}
+ instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue_ (instance_value));
}
in_arg_map.set (get_param_pos (m.cinstance_parameter_position), instance);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]