[vala] Add --enable-gobject-tracing option



commit 295d51f0f41425cfc6148e89341bf6ee56a33997
Author: JÃrg Billeter <j bitron ch>
Date:   Thu May 31 10:01:49 2012 +0200

    Add --enable-gobject-tracing option
    
    Inserts g_object_set_data (object, "vala-creation-function", METHOD)
    after object creation.

 codegen/valaccodebasemodule.vala |   29 +++++++++++++++++++++++++++++
 compiler/valacompiler.vala       |    3 +++
 vala/valacodecontext.vala        |    5 +++++
 3 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 6ba654f..6c95b1c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4559,6 +4559,35 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			var temp_value = create_temp_value (expr.value_type, false, expr);
 			ccode.add_assignment (get_cvalue_ (temp_value), creation_expr);
 			expr.target_value = temp_value;
+
+			if (context.gobject_tracing) {
+				// GObject creation tracing enabled
+
+				var cl = expr.type_reference.data_type as Class;
+				if (cl != null && cl.is_subtype_of (gobject_type)) {
+					// creating GObject
+
+					// instance can be NULL in error cases
+					ccode.open_if (get_cvalue_ (expr.target_value));
+
+					var set_data_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_set_data"));
+					set_data_call.add_argument (new CCodeCastExpression (get_cvalue_ (expr.target_value), "GObject *"));
+					set_data_call.add_argument (new CCodeConstant ("\"vala-creation-function\""));
+
+					string func_name = "";
+					if (current_method != null) {
+						func_name = current_method.get_full_name ();
+					} else if (current_property_accessor != null) {
+						func_name = current_property_accessor.get_full_name ();
+					}
+
+					set_data_call.add_argument (new CCodeConstant ("\"%s\"".printf (func_name)));
+
+					ccode.add_expression (set_data_call);
+
+					ccode.close ();
+				}
+			}
 		}
 
 		((GLibValue) expr.target_value).lvalue = true;
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 058b501..df51ad6 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -62,6 +62,7 @@ class Vala.Compiler {
 	static bool deprecated;
 	static bool experimental;
 	static bool experimental_non_null;
+	static bool gobject_tracing;
 	static bool disable_warnings;
 	static string cc_command;
 	[CCode (array_length = false, array_null_terminated = true)]
@@ -121,6 +122,7 @@ class Vala.Compiler {
 		{ "disable-warnings", 0, 0, OptionArg.NONE, ref disable_warnings, "Disable warnings", null },
 		{ "fatal-warnings", 0, 0, OptionArg.NONE, ref fatal_warnings, "Treat warnings as fatal", null },
 		{ "enable-experimental-non-null", 0, 0, OptionArg.NONE, ref experimental_non_null, "Enable experimental enhancements for non-null types", null },
+		{ "enable-gobject-tracing", 0, 0, OptionArg.NONE, ref gobject_tracing, "Enable GObject creation tracing", null },
 		{ "cc", 0, 0, OptionArg.STRING, ref cc_command, "Use COMMAND as C compiler command", "COMMAND" },
 		{ "Xcc", 'X', 0, OptionArg.STRING_ARRAY, ref cc_options, "Pass OPTION to the C compiler", "OPTION..." },
 		{ "dump-tree", 0, 0, OptionArg.FILENAME, ref dump_tree, "Write code tree to FILE", "FILE" },
@@ -171,6 +173,7 @@ class Vala.Compiler {
 		context.deprecated = deprecated;
 		context.experimental = experimental;
 		context.experimental_non_null = experimental_non_null;
+		context.gobject_tracing = gobject_tracing;
 		context.report.enable_warnings = !disable_warnings;
 		context.report.set_verbose_errors (!quiet_mode);
 		context.verbose_mode = verbose_mode;
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index b0a3fd8..faa431b 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -52,6 +52,11 @@ public class Vala.CodeContext {
 	public bool experimental_non_null { get; set; }
 
 	/**
+	 * Enable GObject creation tracing.
+	 */
+	public bool gobject_tracing { get; set; }
+
+	/**
 	 * Output C code, don't compile to object code.
 	 */
 	public bool ccode_only { get; set; }



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