[vala] Fix methods returning nullable structs



commit a85486029c8040f293e38a0ebc13c74b86d67689
Author: Jürg Billeter <j bitron ch>
Date:   Thu Sep 17 15:00:50 2009 +0200

    Fix methods returning nullable structs

 codegen/valaccodebasemodule.vala       |   12 ++++++------
 codegen/valaccodemethodcallmodule.vala |    2 +-
 codegen/valaccodemethodmodule.vala     |    8 ++++----
 codegen/valagtypemodule.vala           |    6 +++---
 vala/valadatatype.vala                 |    4 ++++
 5 files changed, 18 insertions(+), 14 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index f0c40d8..e907155 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1256,13 +1256,13 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 		var prop = (Property) acc.prop;
 
-		bool returns_real_struct = acc.readable && prop.property_type.is_real_struct_type ();
+		bool returns_real_struct = acc.readable && prop.property_type.is_real_non_null_struct_type ();
 
 
 		CCodeFormalParameter cvalueparam;
 		if (returns_real_struct) {
 			cvalueparam = new CCodeFormalParameter ("result", acc.value_type.get_cname () + "*");
-		} else if (!acc.readable && prop.property_type.is_real_struct_type ()) {
+		} else if (!acc.readable && prop.property_type.is_real_non_null_struct_type ()) {
 			cvalueparam = new CCodeFormalParameter ("value", acc.value_type.get_cname () + "*");
 		} else {
 			cvalueparam = new CCodeFormalParameter ("value", acc.value_type.get_cname ());
@@ -1320,7 +1320,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 		var prop = (Property) acc.prop;
 
-		bool returns_real_struct = acc.readable && prop.property_type.is_real_struct_type ();
+		bool returns_real_struct = acc.readable && prop.property_type.is_real_non_null_struct_type ();
 
 		acc.accept_children (codegen);
 
@@ -1358,7 +1358,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 		CCodeFormalParameter cvalueparam;
 		if (returns_real_struct) {
 			cvalueparam = new CCodeFormalParameter ("result", acc.value_type.get_cname () + "*");
-		} else if (!acc.readable && prop.property_type.is_real_struct_type ()) {
+		} else if (!acc.readable && prop.property_type.is_real_non_null_struct_type ()) {
 			cvalueparam = new CCodeFormalParameter ("value", acc.value_type.get_cname () + "*");
 		} else {
 			cvalueparam = new CCodeFormalParameter ("value", acc.value_type.get_cname ());
@@ -2815,7 +2815,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 			// assign method result to `result'
 			CCodeExpression result_lhs = get_result_cexpression ();
-			if (current_return_type.is_real_struct_type () && (current_method == null || !current_method.coroutine)) {
+			if (current_return_type.is_real_non_null_struct_type () && (current_method == null || !current_method.coroutine)) {
 				result_lhs = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, result_lhs);
 			}
 			cfrag.append (new CCodeExpressionStatement (new CCodeAssignment (result_lhs, (CCodeExpression) stmt.return_expression.ccodenode)));
@@ -2832,7 +2832,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 			if (current_method == null || !current_method.coroutine) {
 				// structs are returned via out parameter
-				if (current_return_type.is_real_struct_type()) {
+				if (current_return_type.is_real_non_null_struct_type()) {
 					cfrag.append (new CCodeReturnStatement ());
 				} else {
 					cfrag.append (new CCodeReturnStatement (new CCodeIdentifier ("result")));
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index f0e118d..c47c4bc 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -568,7 +568,7 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 		}
 
 		// structs are returned via out parameter
-		bool return_result_via_out_param = itype.get_return_type ().is_real_struct_type ();
+		bool return_result_via_out_param = itype.get_return_type ().is_real_non_null_struct_type ();
 
 		// pass address for the return value of non-void signals without emitter functions
 		if (itype is SignalType && !(itype.get_return_type () is VoidType)) {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index a270c21..0a846b6 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -75,7 +75,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 				// in Vala they have no return type
 				creturn_type = new ObjectType (cl);
 			}
-		} else if (m.return_type.is_real_struct_type ()) {
+		} else if (m.return_type.is_real_non_null_struct_type ()) {
 			// structs are returned via out parameter
 			creturn_type = new VoidType ();
 		}
@@ -83,7 +83,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 
 		generate_type_declaration (m.return_type, decl_space);
 
-		if (m.return_type.is_real_struct_type ()) {
+		if (m.return_type.is_real_non_null_struct_type ()) {
 			// structs are returned via out parameter
 			var cparam = new CCodeFormalParameter ("result", m.return_type.get_cname () + "*");
 			cparam_map.set (get_param_pos (-3), cparam);
@@ -233,7 +233,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 		}
 
 		var creturn_type = m.return_type;
-		if (m.return_type.is_real_struct_type ()) {
+		if (m.return_type.is_real_non_null_struct_type ()) {
 			// structs are returned via out parameter
 			creturn_type = new VoidType ();
 		}
@@ -497,7 +497,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 					}
 				}
 
-				if (!(m.return_type is VoidType) && !m.return_type.is_real_struct_type () && !m.coroutine) {
+				if (!(m.return_type is VoidType) && !m.return_type.is_real_non_null_struct_type () && !m.coroutine) {
 					// do not declare result variable if exit block is known to be unreachable
 					if (m.exit_block == null || m.exit_block.get_predecessors ().size > 0) {
 						var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 6af51c2..417d29a 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -229,7 +229,7 @@ internal class Vala.GTypeModule : GErrorModule {
 				var vdeclarator = new CCodeFunctionDeclarator ("get_%s".printf (prop.name));
 				vdeclarator.add_parameter (cselfparam);
 				string creturn_type;
-				if (prop.property_type.is_real_struct_type ()) {
+				if (prop.property_type.is_real_non_null_struct_type ()) {
 					var cvalueparam = new CCodeFormalParameter ("result", prop.property_type.get_cname () + "*");
 					vdeclarator.add_parameter (cvalueparam);
 					creturn_type = "void";
@@ -250,7 +250,7 @@ internal class Vala.GTypeModule : GErrorModule {
 			}
 			if (prop.set_accessor != null) {
 				CCodeFormalParameter cvalueparam;
-				if (prop.property_type.is_real_struct_type ()) {
+				if (prop.property_type.is_real_non_null_struct_type ()) {
 					cvalueparam = new CCodeFormalParameter ("value", prop.property_type.get_cname () + "*");
 				} else {
 					cvalueparam = new CCodeFormalParameter ("value", prop.property_type.get_cname ());
@@ -1720,7 +1720,7 @@ internal class Vala.GTypeModule : GErrorModule {
 
 			var t = (ObjectTypeSymbol) prop.parent_symbol;
 
-			bool returns_real_struct = prop.property_type.is_real_struct_type ();
+			bool returns_real_struct = prop.property_type.is_real_non_null_struct_type ();
 
 			var this_type = new ObjectType (t);
 			var cselfparam = new CCodeFormalParameter ("self", this_type.get_cname ());
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index b0497d8..fc4791b 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -450,6 +450,10 @@ public abstract class Vala.DataType : CodeNode {
 		return false;
 	}
 
+	public bool is_real_non_null_struct_type () {
+		return is_real_struct_type () && !nullable;
+	}
+
 	public virtual string? get_type_id () {
 		if (data_type != null) {
 			return data_type.get_type_id ();



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