[vala/wip/effectfree: 6/6] codegen: Use temporary variables in member access for possible side effects
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/effectfree: 6/6] codegen: Use temporary variables in member access for possible side effects
- Date: Wed, 15 Jun 2011 11:42:48 +0000 (UTC)
commit e5a72a6c502ae04c57222ace47206d5352eed444
Author: Luca Bruno <lucabru src gnome org>
Date: Wed Jun 15 13:27:21 2011 +0200
codegen: Use temporary variables in member access for possible side effects
codegen/valaccodememberaccessmodule.vala | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 443992f..6b82fa0 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -23,6 +23,14 @@
*/
public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
+ private static unowned CodeNode get_outer_expression_parent (Expression expr) {
+ unowned CodeNode cur = expr.parent_node;
+ while (cur is Expression) {
+ cur = cur.parent_node;
+ }
+ return cur;
+ }
+
public override void visit_member_access (MemberAccess expr) {
CCodeExpression pub_inst = null;
@@ -326,6 +334,17 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
// don't unref variable
local.active = false;
+ } else if (!expr.lvalue && !expr.target_value.value_type.is_real_non_null_struct_type () && !(expr.target_value.value_type is ArrayType && ((ArrayType) expr.target_value.value_type).inline_allocated)) {
+ var node = get_outer_expression_parent (expr);
+ if (node != null) {
+ var defined_variables = new ArrayList<LocalVariable> ();
+ node.get_defined_variables (defined_variables);
+ if (defined_variables.contains (local)) {
+ // statement may have side effects on this variable
+ var temp_value = create_temp_value (expr.target_value.value_type, expr.target_value, expr);
+ expr.target_value = temp_value;
+ }
+ }
}
} else if (expr.symbol_reference is Parameter) {
var param = (Parameter) expr.symbol_reference;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]