]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Improve pre/postcondition messages
authorSimon Werbeck <simon.werbeck@gmail.com>
Tue, 25 Nov 2014 01:31:19 +0000 (02:31 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Fri, 5 Dec 2014 16:52:02 +0000 (17:52 +0100)
codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala

index f1b6f8224f881e9895376b5dc6f274a636fbc284..1bee9e52cd6ddc549f5d09a0f60ecd54abbda9d8 100644 (file)
@@ -742,6 +742,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                if (requires_assert) {
                        cfile.add_type_declaration (new CCodeMacroReplacement.with_expression ("_vala_assert(expr, msg)", new CCodeConstant ("if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);")));
+                       cfile.add_type_declaration (new CCodeMacroReplacement.with_expression ("_vala_return_if_fail(expr, msg)", new CCodeConstant ("if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }")));
+                       cfile.add_type_declaration (new CCodeMacroReplacement.with_expression ("_vala_return_val_if_fail(expr, msg, val)", new CCodeConstant ("if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }")));
+                       cfile.add_type_declaration (new CCodeMacroReplacement.with_expression ("_vala_warn_if_fail(expr, msg)", new CCodeConstant ("if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);")));
                }
                if (requires_array_free) {
                        append_vala_array_free ();
@@ -6412,11 +6415,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        }
 
        public void create_postcondition_statement (Expression postcondition) {
-               var cassert = new CCodeFunctionCall (new CCodeIdentifier ("g_warn_if_fail"));
+               var cassert = new CCodeFunctionCall (new CCodeIdentifier ("_vala_warn_if_fail"));
 
                postcondition.emit (this);
 
+               string message = ((string) postcondition.source_reference.begin.pos).substring (0, (int) (postcondition.source_reference.end.pos - postcondition.source_reference.begin.pos));
                cassert.add_argument (get_cvalue (postcondition));
+               cassert.add_argument (new CCodeConstant ("\"%s\"".printf (message.replace ("\n", " ").escape (""))));
+               requires_assert = true;
 
                ccode.add_expression (cassert);
        }
index 0a933ac094b0f3a9bb898374612f876894db81c7..dc70a58c4452df856a2c0e639954e06c4829be7e 100644 (file)
@@ -1121,18 +1121,22 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 
                ccheck.add_argument (get_cvalue (precondition));
 
+               string message = ((string) precondition.source_reference.begin.pos).substring (0, (int) (precondition.source_reference.end.pos - precondition.source_reference.begin.pos));
+               ccheck.add_argument (new CCodeConstant ("\"%s\"".printf (message.replace ("\n", " ").escape (""))));
+               requires_assert = true;
+
                if (method_node is CreationMethod) {
-                       ccheck.call = new CCodeIdentifier ("g_return_val_if_fail");
+                       ccheck.call = new CCodeIdentifier ("_vala_return_val_if_fail");
                        ccheck.add_argument (new CCodeConstant ("NULL"));
                } else if (method_node is Method && ((Method) method_node).coroutine) {
                        // _co function
-                       ccheck.call = new CCodeIdentifier ("g_return_val_if_fail");
+                       ccheck.call = new CCodeIdentifier ("_vala_return_val_if_fail");
                        ccheck.add_argument (new CCodeConstant ("FALSE"));
                } else if (ret_type is VoidType) {
                        /* void function */
-                       ccheck.call = new CCodeIdentifier ("g_return_if_fail");
+                       ccheck.call = new CCodeIdentifier ("_vala_return_if_fail");
                } else {
-                       ccheck.call = new CCodeIdentifier ("g_return_val_if_fail");
+                       ccheck.call = new CCodeIdentifier ("_vala_return_val_if_fail");
 
                        var cdefault = default_value_for_type (ret_type, false);
                        if (cdefault != null) {