[vala/wip/attributes: 33/119] codegen: Add get_ccode_type



commit e65be19b4d9a02c6e5e5d31f32b417b0c8efd8b5
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jun 28 19:36:50 2011 +0200

    codegen: Add get_ccode_type

 codegen/valaccodebasemodule.vala         |   20 ++++++++++++--------
 codegen/valaccodememberaccessmodule.vala |    4 ++--
 codegen/valaccodemethodcallmodule.vala   |    6 +++---
 codegen/valaccodemethodmodule.vala       |   10 +++-------
 4 files changed, 20 insertions(+), 20 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 7726c30..8f2e1ce 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2130,7 +2130,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 					var cexpr = get_cvalue (expr);
 
-					string ctype = field.get_ctype ();
+					string ctype = get_ccode_type (field);
 					if (ctype != null) {
 						cexpr = new CCodeCastExpression (cexpr, ctype);
 					}
@@ -4170,8 +4170,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 						cexpr = handle_struct_argument (param, arg, cexpr);
 
-						if (param.ctype != null) {
-							cexpr = new CCodeCastExpression (cexpr, param.ctype);
+						if (get_ccode_type (param) != null) {
+							cexpr = new CCodeCastExpression (cexpr, get_ccode_type (param));
 						}
 					} else {
 						cexpr = handle_struct_argument (null, arg, cexpr);
@@ -4250,7 +4250,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			// cast the return value of the creation method back to the intended type if
 			// it requested a special C return type
-			if (get_custom_creturn_type (m) != null) {
+			if (get_ccode_type (m) != null) {
 				creation_expr = new CCodeCastExpression (creation_expr, get_ccode_name (expr.type_reference));
 			}
 		} else if (expr.symbol_reference is ErrorCode) {
@@ -5755,6 +5755,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(param).pos;
 	}
 
+	public static string? get_ccode_type (CodeNode node) {
+		var a = node.get_attribute ("CCode");
+		if (a != null) {
+			return a.get_string ("type");
+		}
+		return null;
+	}
+
 	public override void visit_class (Class cl) {
 	}
 
@@ -5856,10 +5864,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		ccode.add_return (default_value_for_type (return_type, false));
 	}
 
-	public virtual string? get_custom_creturn_type (Method m) {
-		return null;
-	}
-
 	public virtual void generate_dynamic_method_wrapper (DynamicMethod method) {
 	}
 
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 6df007e..92f91d2 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -402,7 +402,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		if (param.has_array_length_cexpr) {
 			result.array_length_cexpr = new CCodeConstant (param.get_array_length_cexpr ());
 		}
-		result.ctype = param.ctype;
+		result.ctype = get_ccode_type (param);
 
 		var array_type = result.value_type as ArrayType;
 		var delegate_type = result.value_type as DelegateType;
@@ -522,7 +522,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		if (field.has_array_length_cexpr) {
 			result.array_length_cexpr = new CCodeConstant (field.get_array_length_cexpr ());
 		}
-		result.ctype = field.get_ctype ();
+		result.ctype = get_ccode_type (field);
 
 		var array_type = result.value_type as ArrayType;
 		var delegate_type = result.value_type as DelegateType;
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 9cc3573..6095862 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -351,7 +351,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 								CCodeExpression delegate_target_destroy_notify;
 								var delegate_target = get_delegate_target_cexpression (arg, out delegate_target_destroy_notify);
 								assert (delegate_target != null);
-								if (param.ctype == "GClosure*") {
+								if (get_ccode_type (param) == "GClosure*") {
 									// one single GClosure parameter
 									var closure_new = new CCodeFunctionCall (new CCodeIdentifier ("g_cclosure_new"));
 									closure_new.add_argument (new CCodeCastExpression (cexpr, "GCallback"));
@@ -426,8 +426,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 						}
 					}
 
-					if (param.ctype != null) {
-						cexpr = new CCodeCastExpression (cexpr, param.ctype);
+					if (get_ccode_type (param) != null) {
+						cexpr = new CCodeCastExpression (cexpr, get_ccode_type (param));
 					}
 				} else {
 					cexpr = handle_struct_argument (null, arg, cexpr);
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index c24418d..24bfe5d 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -31,12 +31,8 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 		return (method.get_attribute ("NoWrapper") == null);
 	}
 
-	public override string? get_custom_creturn_type (Method m) {
-		return m.custom_return_type_cname;
-	}
-
 	string get_creturn_type (Method m, string default_value) {
-		string type = get_custom_creturn_type (m);
+		string type = get_ccode_type (m);
 		if (type == null) {
 			return default_value;
 		}
@@ -620,8 +616,8 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 
 					if (current_type_symbol is Class) {
 						CCodeExpression cresult = new CCodeIdentifier ("self");
-						if (get_custom_creturn_type (m) != null) {
-							cresult = new CCodeCastExpression (cresult, get_custom_creturn_type (m));
+						if (get_ccode_type (m) != null) {
+							cresult = new CCodeCastExpression (cresult, get_ccode_type (m));
 						}
 
 						ccode.add_return (cresult);



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