]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add --enable-gobject-tracing option
authorJürg Billeter <j@bitron.ch>
Thu, 31 May 2012 08:01:49 +0000 (10:01 +0200)
committerJürg Billeter <j@bitron.ch>
Thu, 31 May 2012 08:07:23 +0000 (10:07 +0200)
Inserts g_object_set_data (object, "vala-creation-function", METHOD)
after object creation.

codegen/valaccodebasemodule.vala
compiler/valacompiler.vala
vala/valacodecontext.vala

index 6ba654fb0db017447794cedc133f7b16db7fcb0f..6c95b1cb22717644a866248f1c3b57398a89c57d 100644 (file)
@@ -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;
index 058b5016fb88b3ee3a016cf418732ad090dbd376..df51ad638d7322f8a7016da2add2b1cf3d2c7dea 100644 (file)
@@ -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;
index b0a3fd812b9d96f74ed4cbee186b59c5fec8ba96..faa431b67869bcf944ce58bf4418e851f23e170b 100644 (file)
@@ -51,6 +51,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.
         */