semantics.c (finish_then_clause): Remove redundant assignment.
authorJason Merrill <jason@redhat.com>
Sat, 17 Aug 2002 01:17:24 +0000 (21:17 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 17 Aug 2002 01:17:24 +0000 (21:17 -0400)
        * semantics.c (finish_then_clause): Remove redundant assignment.
        (finish_if_stmt, begin_switch_stmt, finish_switch_stmt): Move the
        extra binding level outside the if/switch statement.
        (finish_while_cond, finish_for_cond): Rewrite complex condition
        into the loop body.

From-SVN: r56402

gcc/cp/ChangeLog
gcc/cp/semantics.c

index 7d47a099a477bb1a5554dc762168a8af6bd236b7..3c91c431a147f7ca34f34947f5d1136cade5b54b 100644 (file)
@@ -1,3 +1,11 @@
+2002-08-15  Jason Merrill  <jason@redhat.com>
+
+       * semantics.c (finish_then_clause): Remove redundant assignment.
+       (finish_if_stmt, begin_switch_stmt, finish_switch_stmt): Move the
+       extra binding level outside the if/switch statement.
+       (finish_while_cond, finish_for_cond): Rewrite complex condition
+       into the loop body.
+
 2002-08-15  Alexandre Oliva  <aoliva@redhat.com>
 
        * parse.y (sizeof, alignof, typeof): New non-terminals to
index cbe9b45b7a5394e3e3dadc1f1a64b27de9eddaa8..9efc7de8570c87d65da74adb774bd69a171f0f74 100644 (file)
@@ -266,7 +266,6 @@ finish_then_clause (if_stmt)
      tree if_stmt;
 {
   RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
-  last_tree = if_stmt;
   return if_stmt;
 }
 
@@ -292,21 +291,8 @@ finish_else_clause (if_stmt)
 void 
 finish_if_stmt ()
 {
-  do_poplevel ();
   finish_stmt ();
-}
-
-void
-clear_out_block ()
-{
-  /* If COND wasn't a declaration, clear out the
-     block we made for it and start a new one here so the
-     optimization in expand_end_loop will work.  */
-  if (getdecls () == NULL_TREE)
-    {
-      do_poplevel ();
-      do_pushlevel ();
-    }
+  do_poplevel ();
 }
 
 /* Begin a while-statement.  Returns a newly created WHILE_STMT if
@@ -331,8 +317,26 @@ finish_while_stmt_cond (cond, while_stmt)
      tree while_stmt;
 {
   cond = maybe_convert_cond (cond);
-  FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
-  clear_out_block ();
+  if (getdecls () == NULL_TREE)
+    /* It was a simple condition; install it.  */
+    WHILE_COND (while_stmt) = cond;
+  else
+    {
+      /* If there was a declaration in the condition, we can't leave it
+        there; transform
+           while (A x = 42) { }
+        to
+           while (true) { A x = 42; if (!x) break; }  */
+      tree if_stmt;
+      WHILE_COND (while_stmt) = boolean_true_node;
+
+      if_stmt = begin_if_stmt ();
+      cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0);
+      finish_if_stmt_cond (cond, if_stmt);
+      finish_break_stmt ();
+      finish_then_clause (if_stmt);
+      finish_if_stmt ();
+    }
 }
 
 /* Finish a while-statement, which may be given by WHILE_STMT.  */
@@ -448,8 +452,26 @@ finish_for_cond (cond, for_stmt)
      tree for_stmt;
 {
   cond = maybe_convert_cond (cond);
-  FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
-  clear_out_block ();
+  if (getdecls () == NULL_TREE)
+    /* It was a simple condition; install it.  */
+    FOR_COND (for_stmt) = cond;
+  else
+    {
+      /* If there was a declaration in the condition, we can't leave it
+        there; transform
+           for (; A x = 42;) { }
+        to
+           for (;;) { A x = 42; if (!x) break; }  */
+      tree if_stmt;
+      FOR_COND (for_stmt) = NULL_TREE;
+
+      if_stmt = begin_if_stmt ();
+      cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0);
+      finish_if_stmt_cond (cond, if_stmt);
+      finish_break_stmt ();
+      finish_then_clause (if_stmt);
+      finish_if_stmt ();
+    }
 }
 
 /* Finish the increment-EXPRESSION in a for-statement, which may be
@@ -502,9 +524,9 @@ tree
 begin_switch_stmt ()
 {
   tree r;
+  do_pushlevel ();
   r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
   add_stmt (r);
-  do_pushlevel ();
   return r;
 }
 
@@ -560,8 +582,8 @@ finish_switch_stmt (switch_stmt)
 {
   RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
   pop_switch (); 
-  do_poplevel ();
   finish_stmt ();
+  do_poplevel ();
 }
 
 /* Generate the RTL for T, which is a TRY_BLOCK. */