vala r1867 - in trunk: . gobject



Author: juergbi
Date: Tue Oct 21 21:33:15 2008
New Revision: 1867
URL: http://svn.gnome.org/viewvc/vala?rev=1867&view=rev

Log:
2008-10-21  JÃrg Billeter  <j bitron ch>

	* gobject/valaccodeassignmentbinding.vala:
	* gobject/valaccodegenerator.vala:
	* gobject/valaccodememberaccessbinding.vala:

	Generate C code nodes only when needed for assignments to avoid
	unnecessary temporary variables


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodeassignmentbinding.vala
   trunk/gobject/valaccodegenerator.vala
   trunk/gobject/valaccodememberaccessbinding.vala

Modified: trunk/gobject/valaccodeassignmentbinding.vala
==============================================================================
--- trunk/gobject/valaccodeassignmentbinding.vala	(original)
+++ trunk/gobject/valaccodeassignmentbinding.vala	Tue Oct 21 21:33:15 2008
@@ -74,7 +74,7 @@
 				} else if (assignment.operator == AssignmentOperator.SHIFT_RIGHT) {
 					cop = CCodeBinaryOperator.SHIFT_RIGHT;
 				}
-				cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) assignment.left.ccodenode, new CCodeParenthesizedExpression (cexpr));
+				cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) codegen.get_ccodenode (assignment.left), new CCodeParenthesizedExpression (cexpr));
 			}
 			
 			var ccall = codegen.get_property_set_call (prop, ma, cexpr);
@@ -83,7 +83,7 @@
 			if (!(assignment.parent_node is ExpressionStatement)) {
 				var ccomma = new CCodeCommaExpression ();
 				ccomma.append_expression (ccall); // update property
-				ccomma.append_expression ((CCodeExpression) ma.ccodenode); // current property value
+				ccomma.append_expression ((CCodeExpression) codegen.get_ccodenode (ma)); // current property value
 				
 				codenode = ccomma;
 			} else {
@@ -142,7 +142,7 @@
 			ma = (MemberAccess) assignment.left;
 		}
 		if (ma.inner != null) {
-			ccall.add_argument ((CCodeExpression) ma.inner.ccodenode);
+			ccall.add_argument ((CCodeExpression) codegen.get_ccodenode (ma.inner));
 		} else {
 			ccall.add_argument (new CCodeIdentifier ("self"));
 		}
@@ -241,8 +241,8 @@
 		Iterator<Expression> indices_it = indices.iterator ();
 		indices_it.next ();
 
-		var ccontainer = (CCodeExpression) expr.container.ccodenode;
-		var cindex = (CCodeExpression) indices_it.get ().ccodenode;
+		var ccontainer = (CCodeExpression) codegen.get_ccodenode (expr.container);
+		var cindex = (CCodeExpression) codegen.get_ccodenode (indices_it.get ());
 
 		if (container_type != null && codegen.list_type != null && codegen.map_type != null &&
 		    (container_type.is_subtype_of (codegen.list_type) || container_type.is_subtype_of (codegen.map_type))) {
@@ -297,7 +297,7 @@
 			ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), rhs));
 			if (unref_old) {
 				/* unref old value */
-				ccomma.append_expression (codegen.get_unref_expression ((CCodeExpression) assignment.left.ccodenode, assignment.left.value_type, assignment.left));
+				ccomma.append_expression (codegen.get_unref_expression ((CCodeExpression) codegen.get_ccodenode (assignment.left), assignment.left.value_type, assignment.left));
 			}
 			
 			if (array) {
@@ -342,12 +342,12 @@
 			cop = CCodeAssignmentOperator.SHIFT_RIGHT;
 		}
 	
-		codenode = new CCodeAssignment ((CCodeExpression) assignment.left.ccodenode, rhs, cop);
+		codenode = new CCodeAssignment ((CCodeExpression) codegen.get_ccodenode (assignment.left), rhs, cop);
 
-		if (unref_old && assignment.left.ccodenode is CCodeElementAccess) {
+		if (unref_old && codegen.get_ccodenode (assignment.left) is CCodeElementAccess) {
 			// ensure that index expression in element access doesn't get evaluated more than once
 			// except when it's a simple expression
-			var cea = (CCodeElementAccess) assignment.left.ccodenode;
+			var cea = (CCodeElementAccess) codegen.get_ccodenode (assignment.left);
 			if (!(cea.index is CCodeConstant || cea.index is CCodeIdentifier)) {
 				var index_temp_decl = codegen.get_temp_variable (codegen.int_type);
 				codegen.temp_vars.insert (0, index_temp_decl);
@@ -364,7 +364,7 @@
 	}
 
 	public override void emit () {
-		assignment.accept_children (codegen);
+		assignment.right.accept (codegen);
 
 		if (assignment.left.error || assignment.right.error) {
 			assignment.error = true;

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Tue Oct 21 21:33:15 2008
@@ -2834,7 +2834,7 @@
 		if (array_expr is ArrayCreationExpression) {
 			Gee.List<Expression> size = ((ArrayCreationExpression) array_expr).get_sizes ();
 			var length_expr = size[dim - 1];
-			return (CCodeExpression) length_expr.ccodenode;
+			return (CCodeExpression) get_ccodenode (length_expr);
 		} else if (array_expr is InvocationExpression) {
 			var invocation_expr = (InvocationExpression) array_expr;
 			Gee.List<CCodeExpression> size = invocation_expr.get_array_sizes ();
@@ -2879,7 +2879,7 @@
 						var length_cname = get_array_length_cname (field.name, dim);
 						var instance_expression_type = get_data_type_for_symbol (base_type);
 						var instance_target_type = get_data_type_for_symbol ((TypeSymbol) field.parent_symbol);
-						CCodeExpression typed_inst = (CCodeExpression) ma.inner.ccodenode;
+						CCodeExpression typed_inst = (CCodeExpression) get_ccodenode (ma.inner);
 
 						CCodeExpression inst;
 						if (field.access == SymbolAccessibility.PRIVATE) {
@@ -2980,7 +2980,7 @@
 				TypeSymbol base_type = null;
 				CCodeExpression target_expr = null;
 
-				var pub_inst = (CCodeExpression) ma.inner.ccodenode;
+				var pub_inst = (CCodeExpression) get_ccodenode (ma.inner);
 
 				if (ma.inner.value_type != null) {
 					base_type = ma.inner.value_type.data_type;
@@ -3017,7 +3017,7 @@
 				if (m.binding == MemberBinding.STATIC) {
 					return new CCodeConstant ("NULL");
 				} else {
-					return (CCodeExpression) ma.inner.ccodenode;
+					return (CCodeExpression) get_ccodenode (ma.inner);
 				}
 			}
 		}
@@ -4105,7 +4105,7 @@
 				vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (current_class.get_lower_case_cname (null))));
 				
 				var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, "set_%s".printf (prop.name)));
-				ccall.add_argument ((CCodeExpression) ma.inner.ccodenode);
+				ccall.add_argument ((CCodeExpression) get_ccodenode (ma.inner));
 				ccall.add_argument (cexpr);
 				return ccall;
 			} else if (prop.base_interface_property != null) {
@@ -4113,7 +4113,7 @@
 				string parent_iface_var = "%s_%s_parent_iface".printf (current_class.get_lower_case_cname (null), base_iface.get_lower_case_cname (null));
 
 				var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), "set_%s".printf (prop.name)));
-				ccall.add_argument ((CCodeExpression) ma.inner.ccodenode);
+				ccall.add_argument ((CCodeExpression) get_ccodenode (ma.inner));
 				ccall.add_argument (cexpr);
 				return ccall;
 			}
@@ -4139,7 +4139,7 @@
 
 		if (prop.binding == MemberBinding.INSTANCE) {
 			/* target instance is first argument */
-			ccall.add_argument ((CCodeExpression) ma.inner.ccodenode);
+			ccall.add_argument ((CCodeExpression) get_ccodenode (ma.inner));
 		}
 
 		if (prop.no_accessor_method) {
@@ -4329,6 +4329,13 @@
 		}
 	}
 
+	public CCodeNode? get_ccodenode (CodeNode node) {
+		if (node.ccodenode == null) {
+			node.accept (this);
+		}
+		return node.ccodenode;
+	}
+
 	public override CodeBinding? create_namespace_binding (Namespace node) {
 		return null;
 	}

Modified: trunk/gobject/valaccodememberaccessbinding.vala
==============================================================================
--- trunk/gobject/valaccodememberaccessbinding.vala	(original)
+++ trunk/gobject/valaccodememberaccessbinding.vala	Tue Oct 21 21:33:15 2008
@@ -135,10 +135,6 @@
 		} else if (expr.symbol_reference is Property) {
 			var prop = (Property) expr.symbol_reference;
 
-			if (prop.get_accessor == null) {
-				return;
-			}
-			
 			if (expr.inner is BaseAccess) {
 				if (prop.base_property != null) {
 					var base_class = (Class) prop.base_property.parent_symbol;



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