[vala/emit-let: 1/2] codegen: Drop unnecessary comma expressions in silent casts



commit 94e77fa26a9fc69603c23a353c05da49a1d9ed66
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Feb 15 15:36:20 2011 +0100

    codegen: Drop unnecessary comma expressions in silent casts
    
    Assume temporary variables owned value depending on the relative
    expression. Use one more temporary variable to avoid side-effects.

 codegen/valaccodebasemodule.vala |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0052ece..c006617 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4707,21 +4707,20 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		if (context.profile == Profile.GOBJECT && (iface != null || (cl != null && !cl.is_compact))) {
 			// checked cast for strict subtypes of GTypeInstance
 			if (expr.is_silent_cast) {
-				var ccomma = new CCodeCommaExpression ();
-				var temp_decl = get_temp_variable (expr.inner.value_type, true, expr, false);
-
+				var temp_decl = get_temp_variable (expr.inner.value_type, expr.inner.value_type.value_owned, expr, false);
 				emit_temp_var (temp_decl);
-
 				var ctemp = get_variable_cexpression (temp_decl.name);
-				var cinit = new CCodeAssignment (ctemp, get_cvalue (expr.inner));
+				var temp_result = get_temp_variable (expr.type_reference, expr.type_reference.value_owned, expr, false);
+				emit_temp_var (temp_result);
+				var cresult = get_variable_cexpression (temp_result.name);
+
+				ccode.add_assignment (ctemp, get_cvalue (expr.inner));
 				var ccheck = create_type_check (ctemp, expr.type_reference);
 				var ccast = new CCodeCastExpression (ctemp, expr.type_reference.get_cname ());
 				var cnull = new CCodeConstant ("NULL");
-
-				ccomma.append_expression (cinit);
-				ccomma.append_expression (new CCodeConditionalExpression (ccheck, ccast, cnull));
+				ccode.add_assignment (cresult, new CCodeConditionalExpression (ccheck, ccast, cnull));
 	
-				set_cvalue (expr, ccomma);
+				set_cvalue (expr, cresult);
 			} else {
 				set_cvalue (expr, generate_instance_cast (get_cvalue (expr.inner), expr.type_reference.data_type));
 			}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]