[vala] Improve pre/postcondition messages
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Improve pre/postcondition messages
- Date: Fri, 5 Dec 2014 16:56:53 +0000 (UTC)
commit 4aad168412bb90c8bd5f24f64106d6d4b224b705
Author: Simon Werbeck <simon werbeck gmail com>
Date: Tue Nov 25 02:31:19 2014 +0100
Improve pre/postcondition messages
codegen/valaccodebasemodule.vala | 8 +++++++-
codegen/valaccodemethodmodule.vala | 12 ++++++++----
2 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index f1b6f82..1bee9e5 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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);
}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 0a933ac..dc70a58 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]