[vala] Improve assertion messages
- From: JÃrg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Improve assertion messages
- Date: Sat, 2 Jun 2012 16:19:45 +0000 (UTC)
commit 4051a8a36cd40ec4a78c1eb963c10080557b54da
Author: JÃrg Billeter <j bitron ch>
Date: Sat Jun 2 18:17:43 2012 +0200
Improve assertion messages
Fixes bug 658825.
codegen/valaccodebasemodule.vala | 5 +++++
codegen/valaccodemethodcallmodule.vala | 8 ++++++++
vala/valamethodcall.vala | 5 +++++
3 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 57ac8a5..c158eaf 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -321,6 +321,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public string module_init_param_name;
public bool gvaluecollector_h_needed;
+ public bool requires_assert;
public bool requires_array_free;
public bool requires_array_move;
public bool requires_array_length;
@@ -664,6 +665,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
next_regex_id = 0;
gvaluecollector_h_needed = false;
+ requires_assert = false;
requires_array_free = false;
requires_array_move = false;
requires_array_length = false;
@@ -692,6 +694,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return;
}
+ 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);")));
+ }
if (requires_array_free) {
append_vala_array_free ();
}
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 296efc1..8be973e 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -677,6 +677,14 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
ccode.add_label ("_state_%d".printf (state));
}
+ if (expr.is_assert) {
+ string message = ((string) expr.source_reference.begin.pos).substring (0, (int) (expr.source_reference.end.pos - expr.source_reference.begin.pos));
+ ccall.call = new CCodeIdentifier ("_vala_assert");
+ ccall.add_argument (new CCodeConstant ("\"%s\"".printf (message.replace ("\n", " ").escape (""))));
+ requires_assert = true;
+
+ }
+
if (return_result_via_out_param) {
ccode.add_expression (ccall_expr);
ccall_expr = out_param_ref;
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index f0e9585..33b820f 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -203,6 +203,11 @@ public class Vala.MethodCall : Expression {
if (ma.symbol_reference != null && ma.symbol_reference.get_attribute ("Assert") != null) {
this.is_assert = true;
+
+ var args = get_argument_list ();
+ if (args.size == 1) {
+ this.source_reference = args[0].source_reference;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]