[vala/wip/attributes: 18/119] codegen: Add get_ccode_get_marshaller_type_name



commit 477d4c13c19946dc774814c11264775293a76654
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jun 28 14:02:09 2011 +0200

    codegen: Add get_ccode_get_marshaller_type_name

 codegen/valaccodebasemodule.vala |   91 ++++++++++++++++++++++++++++++++++++++
 codegen/valagsignalmodule.vala   |   39 ++--------------
 2 files changed, 96 insertions(+), 34 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e504e3c..ad964e1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5657,6 +5657,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(node).type_id;
 	}
 
+	public static string get_ccode_marshaller_type_name (CodeNode node) {
+		return get_ccode_attribute(sym).marshaller_type_name;
+	}
+
 	public override void visit_class (Class cl) {
 	}
 
@@ -6146,6 +6150,15 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 	}
 
+	public string marshaller_type_name {
+		get {
+			if (_marshaller_type_name == null) {
+				_marshaller_type_name = get_default_marshaller_type_name ();
+			}
+			return _marshaller_type_name;
+		}
+	}
+
 	private string _name;
 	private string _const_name;
 	private string _type_name;
@@ -6160,6 +6173,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 	private string _copy_function;
 	private string _free_function;
 	private string _type_id;
+	private string _marshaller_type_name;
 
 	public CCodeAttribute (CodeNode node) {
 		this.node = node;
@@ -6192,6 +6206,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 			_copy_function = attr.get_string ("copy_function");
 			_free_function = attr.get_string ("free_function");
 			_type_id = attr.get_string ("type_id");
+			_marshaller_type_name = attr.get_string ("marshaller_type_name");
 		}
 	}
 
@@ -6504,4 +6519,80 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 		return "";
 	}
+
+	private string get_default_marshaller_type_name () {
+		if (sym != null) {
+			if (sym is Class) {
+				var cl = (Class) sym;
+				if (cl.base_class != null) {
+					return CCodeBaseModule.get_ccode_marshaller_type_name ();
+				} else if (!cl.is_compact) {
+					return cl.get_uppwer_case_cname ();
+				} else if (type_id == "G_TYPE_POINTER") {
+					return "POINTER";
+				} else {
+					return "BOXED";
+				}
+			} else if (sym is Enum) {
+				var en = (Enum) sym;
+				if (en.has_type_id) {
+					if (en.is_flags) {
+						return "FLAGS";
+					} else {
+						return "ENUM";
+					}
+				} else {
+					if (en.is_flags) {
+						return "UINT";
+					} else {
+						return "INT";
+					}
+				}
+			} else if (sym is Interface) {
+				foreach (var prereq in ((Interface) sym).get_prerequisites ()) {
+					var type_name = CCodeBaseModule.get_ccode_marshaller_type_name (prereq.data_type);
+					if (type_name != "") {
+						return type_name;
+					}
+				}
+				return "POINTER";
+			} else if (sym is Struct) {
+				var st = (Struct) sym;
+				var base_st = st.base_struct;
+				if (base_st != null) {
+					return CCodeBaseModule.get_ccode_marshaller_type_name (base_st);
+				}
+				if (st.is_simple_type ()) {
+					Report.error (st.source_reference, "The type `%s` doesn't declare a marshaller type name".printf (st.get_full_name ()));
+				} else if (st.has_type_id) {
+					return "BOXED";
+				} else {
+					return "POINTER";
+				}
+			} else if (sym is Parameter) {
+				var param = (Parameter) sym;
+				if (param.direction != ParameterDirection.IN) {
+					return "POINTER";
+				} else {
+					return CCodeBaseModule.get_ccode_marshaller_type_name (param.variable_type);
+				}
+			} else {
+				return "POINTER";
+			}
+		} else if (node is PointerType || ((DataType) node).type_parameter != null) {
+			return "POINTER";
+		} else if (node is ErrorType) {
+			return "POINTER";
+		} else if (node is ArrayType) {
+			if (((ArrayType) t).element_type.data_type == string_type.data_type) {
+				return "BOXED,INT";
+			} else {
+				return "POINTER,INT";
+			}
+		} else if (node is VoidType) {
+			return "VOID";
+		} else {
+			return CCodeBaseModule.get_ccode_marshaller_type_name (((DataType) node).dat_type);
+		}
+	}
 }
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index 95dee3c..fead94b 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -24,35 +24,6 @@
 
 
 public class Vala.GSignalModule : GObjectModule {
-	private string get_marshaller_type_name (DataType t) {
-		if (t is PointerType || t.type_parameter != null) {
-			return ("POINTER");
-		} else if (t is ErrorType) {
-			return ("POINTER");
-		} else if (t is ArrayType) {
-			if (((ArrayType) t).element_type.data_type == string_type.data_type) {
-				return ("BOXED,INT");
-			} else {
-				return ("POINTER,INT");
-			}
-		} else if (t is VoidType) {
-			return ("VOID");
-		} else if (t.data_type is Enum) {
-			var en = (Enum) t.data_type;
-			return en.get_marshaller_type_name ();
-		} else {
-			return t.data_type.get_marshaller_type_name ();
-		}
-	}
-	
-	private string get_marshaller_type_name_for_parameter (Parameter param) {
-		if (param.direction != ParameterDirection.IN) {
-			return ("POINTER");
-		} else {
-			return get_marshaller_type_name (param.variable_type);
-		}
-	}
-	
 	string get_marshaller_function (List<Parameter> params, DataType return_type, string? prefix = null) {
 		var signature = get_marshaller_signature (params, return_type);
 		string ret;
@@ -65,13 +36,13 @@ public class Vala.GSignalModule : GObjectModule {
 			}
 		}
 		
-		ret = "%s_%s_".printf (prefix, get_marshaller_type_name (return_type));
+		ret = "%s_%s_".printf (prefix, get_ccode_marshaller_type_name (return_type));
 		
 		if (params == null || params.size == 0) {
 			ret = ret + "_VOID";
 		} else {
 			foreach (Parameter p in params) {
-				ret = "%s_%s".printf (ret, get_marshaller_type_name_for_parameter (p).replace (",", "_"));
+				ret = "%s_%s".printf (ret, get_ccode_marshaller_type_name (p).replace (",", "_"));
 			}
 		}
 		
@@ -116,17 +87,17 @@ public class Vala.GSignalModule : GObjectModule {
 	private string get_marshaller_signature (List<Parameter> params, DataType return_type) {
 		string signature;
 		
-		signature = "%s:".printf (get_marshaller_type_name (return_type));
+		signature = "%s:".printf (get_ccode_marshaller_type_name (return_type));
 		if (params == null || params.size == 0) {
 			signature = signature + "VOID";
 		} else {
 			bool first = true;
 			foreach (Parameter p in params) {
 				if (first) {
-					signature = signature + get_marshaller_type_name_for_parameter (p);
+					signature = signature + get_ccode_marshaller_type_name (p);
 					first = false;
 				} else {
-					signature = "%s,%s".printf (signature, get_marshaller_type_name_for_parameter (p));
+					signature = "%s,%s".printf (signature, get_ccode_marshaller_type_name (p));
 				}
 			}
 		}



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