[vala/wip/attributes: 81/119] Drop get_real_cname



commit 404a925516dc5cb5d2cddd87bb9e693056679e62
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Jun 30 10:24:13 2011 +0200

    Drop get_real_cname

 codegen/valaccodebasemodule.vala         |   49 ++++++++++++++++++++++++++++-
 codegen/valaccodememberaccessmodule.vala |    2 +-
 codegen/valaccodemethodcallmodule.vala   |    4 +-
 codegen/valaccodemethodmodule.vala       |    8 ++--
 codegen/valadovabasemodule.vala          |    6 +++-
 codegen/valadovamemberaccessmodule.vala  |    2 +-
 codegen/valadovamethodcallmodule.vala    |    2 +-
 codegen/valadovaobjectmodule.vala        |   10 +++---
 codegen/valagasyncmodule.vala            |   12 ++++----
 codegen/valagtypemodule.vala             |   10 +++---
 vala/valacreationmethod.vala             |   29 -----------------
 vala/valamethod.vala                     |   15 ---------
 12 files changed, 77 insertions(+), 72 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 05143c7..49a3eb7 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4083,7 +4083,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			if (!m.has_new_function) {
 				// use construct function directly
-				creation_call = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+				creation_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 				creation_call.add_argument (new CCodeIdentifier (get_ccode_type_id (cl)));
 			} else {
 				creation_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_name (m)));
@@ -5802,6 +5802,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return node.get_attribute_bool ("CCode", "simple_generics");
 	}
 
+	public static string get_ccode_real_name (Method m) {
+		return get_ccode_attribute(m).real_name;
+	}
+
 	public static string get_ccode_vfunc_name (Method m) {
 		return get_ccode_attribute(m).vfunc_name;
 	}
@@ -6399,6 +6403,15 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 	}
 
+	public string real_name {
+		get {
+			if (_real_name == null) {
+				_real_name = get_default_real_name ();
+			}
+			return _real_name;
+		}
+	}
+
 	public string vfunc_name {
 		get {
 			if (_vfunc_name == null) {
@@ -6512,6 +6525,9 @@ public class Vala.CCodeAttribute : AttributeCache {
 			}
 			_vfunc_name = attr.get_string ("vfunc_name");
 			_finish_name = attr.get_string ("finish_name");
+			if (sym is CreationMethod) {
+				_real_name = attr.get_string ("construct_function");
+			}
 		}
 	}
 
@@ -6542,7 +6558,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 			} else if (sym is Method) {
 				var m = (Method) sym;
 				if (m.is_async_callback) {
-					return "%s_co".printf (((Method) m.parent_symbol).get_real_cname ());
+					return "%s_co".printf (get_ccode_real_name (m.parent_symbol));
 				}
 				if (sym.name == "main" && sym.parent_symbol.name == null) {
 					// avoid conflict with generated main function
@@ -7117,4 +7133,33 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 		return result + "_finish";
 	}
+
+	private string get_default_real_name () {
+		var m = (Method) sym;
+		if (m is CreationMethod) {
+			var parent = m.parent_symbol as Class;
+
+			if (parent == null || parent.is_compact) {
+				return name;
+			}
+
+			string infix = "construct";
+
+			if (CodeContext.get ().profile == Profile.DOVA) {
+				infix = "init";
+			}
+
+			if (m.name == ".new") {
+				return "%s%s".printf (CCodeBaseModule.get_ccode_lower_case_prefix (parent), infix);
+			} else {
+				return "%s%s_%s".printf (CCodeBaseModule.get_ccode_lower_case_prefix (parent), infix, m.name);
+			}
+		} else {
+			if (m.base_method != null || m.base_interface_method != null) {
+				return "%sreal_%s".printf (CCodeBaseModule.get_ccode_lower_case_prefix (m.parent_symbol), m.name);
+			} else {
+				return name;
+			}
+		}
+	}
 }
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 9b88c20..fa4a2e3 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -87,7 +87,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 			} else if (m.base_interface_method != null) {
 				set_cvalue (expr, new CCodeIdentifier (get_ccode_name (m.base_interface_method)));
 			} else if (m is CreationMethod) {
-				set_cvalue (expr, new CCodeIdentifier (m.get_real_cname ()));
+				set_cvalue (expr, new CCodeIdentifier (get_ccode_real_name (m)));
 			} else {
 				set_cvalue (expr, new CCodeIdentifier (get_ccode_name (m)));
 			}
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 6da60ea..9d1de0f 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -60,13 +60,13 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			var cl = (Class) ((ObjectType) itype).type_symbol;
 			m = cl.default_construction_method;
 			generate_method_declaration (m, cfile);
-			ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+			ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 		} else if (itype is StructValueType) {
 			// constructor
 			var st = (Struct) ((StructValueType) itype).type_symbol;
 			m = st.default_construction_method;
 			generate_method_declaration (m, cfile);
-			ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+			ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 		} else if (itype is DelegateType) {
 			deleg = ((DelegateType) itype).delegate_symbol;
 		}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index f469368..3f3d4e3 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -182,7 +182,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 
 		if (m is CreationMethod && cl != null) {
 			// _construct function
-			function = new CCodeFunction (m.get_real_cname ());
+			function = new CCodeFunction (get_ccode_real_name (m));
 
 			if (m.is_private_symbol ()) {
 				function.modifiers |= CCodeModifiers.STATIC;
@@ -301,7 +301,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 		}
 
 		CCodeFunction function;
-		function = new CCodeFunction (m.get_real_cname ());
+		function = new CCodeFunction (get_ccode_real_name (m));
 
 		if (m.is_inline) {
 			function.modifiers |= CCodeModifiers.INLINE;
@@ -324,7 +324,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 				}
 			} else {
 				if (m.body != null) {
-					function = new CCodeFunction (m.get_real_cname () + "_co", "gboolean");
+					function = new CCodeFunction (get_ccode_real_name (m) + "_co", "gboolean");
 
 					// data struct to hold parameters, local variables, and the return value
 					function.add_parameter (new CCodeParameter ("_data_", Symbol.lower_case_to_camel_case (get_ccode_const_name (m)) + "Data*"));
@@ -1010,7 +1010,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 
 			push_function (vfunc);
 
-			var vcall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+			var vcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 			vcall.add_argument (new CCodeIdentifier (get_ccode_type_id (current_class)));
 
 			generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall);
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 8f0e3fb..aa6c30c 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -1587,7 +1587,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 
 			if (!m.has_new_function) {
 				// use construct function directly
-				creation_call = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+				creation_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 				creation_call.add_argument (new CCodeIdentifier (CCodeBaseModule.get_ccode_type_id (cl)));
 			} else {
 				creation_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_name (m)));
@@ -2318,6 +2318,10 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 		return CCodeBaseModule.get_ccode_default_value (node);
 	}
 
+	public string get_ccode_real_name (CodeNode node) {
+		return CCodeBaseModule.get_ccode_real_name (node);
+	}
+
 	public DataType? get_this_type () {
 		if (current_method != null && current_method.binding == MemberBinding.INSTANCE) {
 			return current_method.this_parameter.variable_type;
diff --git a/codegen/valadovamemberaccessmodule.vala b/codegen/valadovamemberaccessmodule.vala
index deb5d05..8315b3e 100644
--- a/codegen/valadovamemberaccessmodule.vala
+++ b/codegen/valadovamemberaccessmodule.vala
@@ -86,7 +86,7 @@ public abstract class Vala.DovaMemberAccessModule : DovaControlFlowModule {
 			} else if (m.base_interface_method != null) {
 				set_cvalue (expr, new CCodeIdentifier (get_ccode_name (m.base_interface_method)));
 			} else if (m is CreationMethod) {
-				set_cvalue (expr, new CCodeIdentifier (m.get_real_cname ()));
+				set_cvalue (expr, new CCodeIdentifier (get_ccode_real_name (m)));
 			} else {
 				set_cvalue (expr, new CCodeIdentifier (get_ccode_name (m)));
 			}
diff --git a/codegen/valadovamethodcallmodule.vala b/codegen/valadovamethodcallmodule.vala
index 7106bc2..e2a7b91 100644
--- a/codegen/valadovamethodcallmodule.vala
+++ b/codegen/valadovamethodcallmodule.vala
@@ -42,7 +42,7 @@ public class Vala.DovaMethodCallModule : DovaAssignmentModule {
 			var cl = (Class) ((ObjectType) itype).type_symbol;
 			m = cl.default_construction_method;
 			generate_method_declaration (m, cfile);
-			ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+			ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 		} else if (itype is DelegateType) {
 			deleg = ((DelegateType) itype).delegate_symbol;
 			ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_invoke".printf (deleg.get_lower_case_cname ())));
diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala
index 5e308ba..4b9334d 100644
--- a/codegen/valadovaobjectmodule.vala
+++ b/codegen/valadovaobjectmodule.vala
@@ -859,12 +859,12 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			if (m.is_virtual || m.overrides) {
 				var override_call = new CCodeFunctionCall (new CCodeIdentifier ("%soverride_%s".printf (m.base_method.parent_symbol.get_lower_case_cprefix (), m.name)));
 				override_call.add_argument (new CCodeIdentifier ("type"));
-				override_call.add_argument (new CCodeIdentifier (m.get_real_cname ()));
+				override_call.add_argument (new CCodeIdentifier (get_ccode_real_name (m)));
 				type_init_block.add_statement (new CCodeExpressionStatement (override_call));
 			} else if (m.base_interface_method != null) {
 				var override_call = new CCodeFunctionCall (new CCodeIdentifier ("%soverride_%s".printf (m.base_interface_method.parent_symbol.get_lower_case_cprefix (), m.name)));
 				override_call.add_argument (new CCodeIdentifier ("type"));
-				override_call.add_argument (new CCodeIdentifier (m.get_real_cname ()));
+				override_call.add_argument (new CCodeIdentifier (get_ccode_real_name (m)));
 				type_init_block.add_statement (new CCodeExpressionStatement (override_call));
 			}
 		}
@@ -1381,7 +1381,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			generate_class_declaration ((Class) m.parent_symbol, decl_space);
 
 			// _init function
-			function = new CCodeFunction (m.get_real_cname ());
+			function = new CCodeFunction (get_ccode_real_name (m));
 
 			if (m.is_internal_symbol ()) {
 				function.modifiers |= CCodeModifiers.STATIC;
@@ -1419,7 +1419,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			generate_method_declaration (m, header_file);
 		}
 
-		var function = new CCodeFunction (m.get_real_cname ());
+		var function = new CCodeFunction (get_ccode_real_name (m));
 
 		generate_cparameters (m, cfile, function);
 
@@ -1786,7 +1786,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 				vblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (priv_call, f.name), calloc_call)));
 			}
 
-			var vcall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+			var vcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 			vcall.add_argument (new CCodeIdentifier ("this"));
 			vblock.add_statement (new CCodeExpressionStatement (vcall));
 
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index cc8b9a4..c725b8b 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -90,7 +90,7 @@ public class Vala.GAsyncModule : GSignalModule {
 	CCodeFunction generate_free_function (Method m) {
 		var dataname = Symbol.lower_case_to_camel_case (get_ccode_name (m)) + "Data";
 
-		var freefunc = new CCodeFunction (m.get_real_cname () + "_data_free", "void");
+		var freefunc = new CCodeFunction (get_ccode_real_name (m) + "_data_free", "void");
 		freefunc.modifiers = CCodeModifiers.STATIC;
 		freefunc.add_parameter (new CCodeParameter ("_data", "gpointer"));
 
@@ -151,7 +151,7 @@ public class Vala.GAsyncModule : GSignalModule {
 		push_context (new EmitContext (m));
 
 		var dataname = Symbol.lower_case_to_camel_case (get_ccode_name (m)) + "Data";
-		var asyncfunc = new CCodeFunction (m.get_real_cname (), "void");
+		var asyncfunc = new CCodeFunction (get_ccode_real_name (m), "void");
 		var cparam_map = new HashMap<int,CCodeParameter> (direct_hash, direct_equal);
 
 		cparam_map.set (get_param_pos (-1), new CCodeParameter ("_callback_", "GAsyncReadyCallback"));
@@ -220,14 +220,14 @@ public class Vala.GAsyncModule : GSignalModule {
 
 		create_result.add_argument (new CCodeIdentifier ("_callback_"));
 		create_result.add_argument (new CCodeIdentifier ("_user_data_"));
-		create_result.add_argument (new CCodeIdentifier (m.get_real_cname ()));
+		create_result.add_argument (new CCodeIdentifier (get_ccode_real_name (m)));
 
 		ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, "_async_result"), create_result);
 
 		var set_op_res_call = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_set_op_res_gpointer"));
 		set_op_res_call.add_argument (new CCodeMemberAccess.pointer (data_var, "_async_result"));
 		set_op_res_call.add_argument (data_var);
-		set_op_res_call.add_argument (new CCodeIdentifier (m.get_real_cname () + "_data_free"));
+		set_op_res_call.add_argument (new CCodeIdentifier (get_ccode_real_name (m) + "_data_free"));
 		ccode.add_expression (set_op_res_call);
 
 		if (m.binding == MemberBinding.INSTANCE) {
@@ -269,7 +269,7 @@ public class Vala.GAsyncModule : GSignalModule {
 			}
 		}
 
-		var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname () + "_co"));
+		var ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m) + "_co"));
 		ccall.add_argument (data_var);
 		ccode.add_expression (ccall);
 
@@ -480,7 +480,7 @@ public class Vala.GAsyncModule : GSignalModule {
 		ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), "_source_object_"), new CCodeIdentifier ("source_object"));
 		ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), "_res_"), new CCodeIdentifier ("_res_"));
 
-		var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname () + "_co"));
+		var ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m) + "_co"));
 		ccall.add_argument (new CCodeIdentifier ("_data_"));
 		ccode.add_expression (ccall);
 
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index cdf9ff3..dc041ca 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1218,7 +1218,7 @@ public class Vala.GTypeModule : GErrorModule {
 				var ccast = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (get_ccode_upper_case_name (base_type))));
 				ccast.add_argument (new CCodeIdentifier ("klass"));
 
-				ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_vfunc_name (m.base_method)), new CCodeIdentifier (m.get_real_cname ()));
+				ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_vfunc_name (m.base_method)), new CCodeIdentifier (get_ccode_real_name (m)));
 
 				if (m.coroutine) {
 					ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_finish_vfunc_name (m.base_method)), new CCodeIdentifier (get_ccode_finish_real_cname (m)));
@@ -1233,7 +1233,7 @@ public class Vala.GTypeModule : GErrorModule {
 			}
 			var ccast = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (get_ccode_upper_case_name (cl, null))));
 			ccast.add_argument (new CCodeIdentifier ("klass"));
-			ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_vfunc_name (sig.default_handler)), new CCodeIdentifier (sig.default_handler.get_real_cname ()));
+			ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_vfunc_name (sig.default_handler)), new CCodeIdentifier (get_ccode_real_name (sig.default_handler)));
 		}
 
 		/* connect overridden properties */
@@ -1311,7 +1311,7 @@ public class Vala.GTypeModule : GErrorModule {
 			if (m.is_abstract || m.is_virtual) {
 				cfunc = new CCodeIdentifier (get_ccode_name (m));
 			} else {
-				cfunc = new CCodeIdentifier (m.get_real_cname ());
+				cfunc = new CCodeIdentifier (get_ccode_real_name (m));
 			}
 			cfunc = cast_method_pointer (m.base_interface_method, cfunc, iface);
 			ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m.base_interface_method)), cfunc);
@@ -2023,7 +2023,7 @@ public class Vala.GTypeModule : GErrorModule {
 			if (sig.default_handler == null) {
 				continue;
 			}
-			var cname = sig.default_handler.get_real_cname ();
+			var cname = get_ccode_real_name (sig.default_handler);
 			ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (sig.default_handler)), new CCodeIdentifier (cname));
 		}
 
@@ -2038,7 +2038,7 @@ public class Vala.GTypeModule : GErrorModule {
 		// connect default implementations
 		foreach (Method m in iface.get_methods ()) {
 			if (m.is_virtual) {
-				var cname = m.get_real_cname ();
+				var cname = get_ccode_real_name (m);
 				ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), new CCodeIdentifier (cname));
 				if (m.coroutine) {
 					ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_finish_vfunc_name (m)), new CCodeIdentifier (get_ccode_finish_real_cname (m)));
diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala
index 27ce3c6..3315228 100644
--- a/vala/valacreationmethod.vala
+++ b/vala/valacreationmethod.vala
@@ -106,35 +106,6 @@ public class Vala.CreationMethod : Method {
 		}
 	}
 
-	public override string get_real_cname () {
-		var func = get_attribute_string ("CCode", "construct_function");
-		if (func != null) {
-			return func;
-		}
-
-		return get_default_construct_function ();
-	}
-
-	public string get_default_construct_function () {
-		var parent = parent_symbol as Class;
-
-		if (parent == null || parent.is_compact) {
-			return get_cname ();
-		}
-
-		string infix = "construct";
-
-		if (CodeContext.get ().profile == Profile.DOVA) {
-			infix = "init";
-		}
-
-		if (name == ".new") {
-			return "%s%s".printf (parent.get_lower_case_cprefix (), infix);
-		} else {
-			return "%s%s_%s".printf (parent.get_lower_case_cprefix (), infix, name);
-		}
-	}
-
 	public override bool check (CodeContext context) {
 		if (checked) {
 			return !error;
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 7b6856d..556c189 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -345,20 +345,6 @@ public class Vala.Method : Subroutine {
 	}
 
 	/**
-	 * Returns the implementation name of this data type as it is used in C
-	 * code.
-	 *
-	 * @return the name to be used in C code
-	 */
-	public virtual string get_real_cname () {
-		if (base_method != null || base_interface_method != null) {
-			return "%sreal_%s".printf (parent_symbol.get_lower_case_cprefix (), name);
-		} else {
-			return get_cname ();
-		}
-	}
-
-	/**
 	 * Sets the name of this method as it is used in C code.
 	 *
 	 * @param cname the name to be used in C code
@@ -1022,7 +1008,6 @@ public class Vala.Method : Subroutine {
 			callback_method.binding = MemberBinding.INSTANCE;
 			callback_method.owner = scope;
 			callback_method.is_async_callback = true;
-			callback_method.set_cname (get_real_cname () + "_co");
 		}
 		return callback_method;
 	}



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