This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH partial gcj support for disabling assertion


The attached patch provides a compiler hook for disable or
enabling assertion.  It does add any new flags or fine-grained
control, yet:  assertions are enabled if generating class files
or not optimizing, and disabled if optimizing and generying native
code.  I think this is a reasonable default; new options can be
use to override the default - I may add those later.

Note that when assertions are disabled, we still build a tree
that includes the assertion and the asertion value, so the
compiler can check for errors.  But because the assertion
is rewritten to 'false && ASSERTION" it will get optimized out.
(It least it does this when optimizing; we should verify this
when we add a flag to disable assertion even when not optimizing.)

Tested in Fedora Core (with Mauve and Jacks); no regressions.
I'll check this into mainline in a few days if I don't hear objections.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/
2004-03-03  Per Bothner  <per@bothner.com>

	* parse.y (enable_assertions):  New function.
	(build_assertion):  Short-circuit if enable_assertions is false.

Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.472
diff -u -p -r1.472 parse.y
--- parse.y	28 Feb 2004 00:34:25 -0000	1.472
+++ parse.y	2 Mar 2004 18:22:50 -0000
@@ -215,6 +215,7 @@ static tree build_string_concatenation (
 static tree patch_string_cst (tree);
 static tree patch_string (tree);
 static tree encapsulate_with_try_catch (int, tree, tree, tree);
+static bool enable_assertions (tree);
 static tree build_assertion (int, tree, tree);
 static tree build_try_statement (int, tree, tree);
 static tree build_try_finally_statement (int, tree, tree);
@@ -15290,6 +15291,19 @@ patch_switch_statement (tree node)
 
 /* Assertions.  */
 
+/* Return true if we should generate code to check assertions within KLASS. */
+
+static bool
+enable_assertions (tree klass)
+{
+  /* Check if command-line specifies whether we should check asserrtions. */
+  /* FIXME ... */
+
+  /* The default is to enable assertions if generating class files,
+     or not optimizing. */
+  return flag_emit_class_files || optimize == 0;
+}
+
 /* Build an assertion expression for `assert CONDITION : VALUE'; VALUE
    might be NULL_TREE.  */
 static tree
@@ -15297,6 +15311,16 @@ build_assertion (int location, tree cond
 {
   tree node;
   tree klass = GET_CPC ();
+
+  if (! enable_assertions (klass))
+    {
+      condition = build (TRUTH_ANDIF_EXPR, NULL_TREE,
+			 boolean_false_node, condition);
+      if (value == NULL_TREE)
+	value = empty_stmt_node;
+      return build_if_else_statement (location, condition,
+				      value, NULL_TREE);
+    }
 
   if (! CLASS_USES_ASSERTIONS (klass))
     {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]