vala r963 - in trunk: . gobject vala



Author: juergbi
Date: Mon Feb  4 21:52:51 2008
New Revision: 963
URL: http://svn.gnome.org/viewvc/vala?rev=963&view=rev

Log:
2008-02-04  Juerg Billeter  <j bitron ch>

	* vala/valaclass.vala, vala/valainterface.vala, vala/valastruct.vala,
	  gobject/valaccodegeneratormethod.vala: don't generate result
	  variable when not using postconditions to avoid unnecessary name
	  conflicts with method parameters


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodegeneratormethod.vala
   trunk/vala/valaclass.vala
   trunk/vala/valainterface.vala
   trunk/vala/valastruct.vala

Modified: trunk/gobject/valaccodegeneratormethod.vala
==============================================================================
--- trunk/gobject/valaccodegeneratormethod.vala	(original)
+++ trunk/gobject/valaccodegeneratormethod.vala	Mon Feb  4 21:52:51 2008
@@ -501,8 +501,11 @@
 			CCodeStatement cstmt;
 			if (creturn_type is VoidType) {
 				cstmt = new CCodeExpressionStatement (vcall);
+			} else if (m.get_postconditions ().size == 0) {
+				/* pass method return value */
+				cstmt = new CCodeReturnStatement (vcall);
 			} else {
-				/* store method return value */
+				/* store method return value for postconditions */
 				var cdecl = new CCodeDeclaration (creturn_type.get_cname ());
 				cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("result", vcall));
 				cstmt = cdecl;
@@ -510,14 +513,16 @@
 			cstmt.line = vfunc.line;
 			vblock.add_statement (cstmt);
 
-			foreach (Expression postcondition in m.get_postconditions ()) {
-				vblock.add_statement (create_postcondition_statement (postcondition));
-			}
+			if (m.get_postconditions ().size > 0) {
+				foreach (Expression postcondition in m.get_postconditions ()) {
+					vblock.add_statement (create_postcondition_statement (postcondition));
+				}
 
-			if (!(creturn_type is VoidType)) {
-				var cret_stmt = new CCodeReturnStatement (new CCodeIdentifier ("result"));
-				cret_stmt.line = vfunc.line;
-				vblock.add_statement (cret_stmt);
+				if (!(creturn_type is VoidType)) {
+					var cret_stmt = new CCodeReturnStatement (new CCodeIdentifier ("result"));
+					cret_stmt.line = vfunc.line;
+					vblock.add_statement (cret_stmt);
+				}
 			}
 
 			if (visible) {

Modified: trunk/vala/valaclass.vala
==============================================================================
--- trunk/vala/valaclass.vala	(original)
+++ trunk/vala/valaclass.vala	Mon Feb  4 21:52:51 2008
@@ -190,7 +190,7 @@
 			m.this_parameter = new FormalParameter ("this", new ClassType (this));
 			m.scope.add (m.this_parameter.name, m.this_parameter);
 		}
-		if (!(m.return_type is VoidType)) {
+		if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
 			m.result_var = new VariableDeclarator ("result");
 			m.result_var.type_reference = m.return_type.copy ();
 			m.scope.add (m.result_var.name, m.result_var);

Modified: trunk/vala/valainterface.vala
==============================================================================
--- trunk/vala/valainterface.vala	(original)
+++ trunk/vala/valainterface.vala	Mon Feb  4 21:52:51 2008
@@ -125,7 +125,7 @@
 			m.this_parameter = new FormalParameter ("this", new InterfaceType (this));
 			m.scope.add (m.this_parameter.name, m.this_parameter);
 		}
-		if (!(m.return_type is VoidType)) {
+		if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
 			m.result_var = new VariableDeclarator ("result");
 			m.result_var.type_reference = m.return_type.copy ();
 			m.scope.add (m.result_var.name, m.result_var);

Modified: trunk/vala/valastruct.vala
==============================================================================
--- trunk/vala/valastruct.vala	(original)
+++ trunk/vala/valastruct.vala	Mon Feb  4 21:52:51 2008
@@ -117,7 +117,7 @@
 			m.this_parameter = new FormalParameter ("this", new ValueType (this));
 			m.scope.add (m.this_parameter.name, m.this_parameter);
 		}
-		if (!(m.return_type is VoidType)) {
+		if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
 			m.result_var = new VariableDeclarator ("result");
 			m.result_var.type_reference = m.return_type.copy ();
 			m.scope.add (m.result_var.name, m.result_var);



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