[gcjx] Patch: FYI: label cleanups

Tom Tromey tromey@redhat.com
Sun Mar 27 03:10:00 GMT 2005


I'm checking this in on the gcjx branch.

With this patch we now put locations on LABEL_EXPRs.  We also
correctly position the 'continue' label in a 'do' loop, and we
correctly create and use labels in switches.  (Previously I thought
that you could re-use a LABEL_DECL and that you needed a LABEL_EXPR
for each LABEL_DECL even if you had a CASE_LABEL_EXPR for it -- both
false.)

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* tree.hh (tree_generator::wrap_label): Declare.
	* tree.cc (visit_do): Put 'test' label before EXIT_EXPR.  Call
	fold() on exit expression.
	(visit_for): Call fold() on exit expression.
	(visit_while): Call fold() on exit expression.
	(wrap_label): New method.
	(visit_do): Use it.
	(visit_for): Likewise.
	(visit_label): Likewise.
	(visit_switch): Likewise.
	(visit_switch_block): Likewise.
	(visit_while): Likewise.
	(visit_switch_block): Create new label for each switch
	expression.  Don't create a LABEL_EXPR.
	(visit_switch): Don't create LABEL_EXPR for default case.  Set
	type on SWITCH_EXPR.

Index: tree.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.cc,v
retrieving revision 1.1.2.33
diff -u -r1.1.2.33 tree.cc
--- tree.cc 27 Mar 2005 03:01:24 -0000 1.1.2.33
+++ tree.cc 27 Mar 2005 03:05:35 -0000
@@ -91,6 +91,14 @@
 {
 }
 
+tree
+tree_generator::wrap_label (tree label_decl, model_element *request)
+{
+  tree result = build1 (LABEL_EXPR, void_type_node, label_decl);
+  annotate (result, request);
+  return result;
+}
+
 
 
 void
@@ -524,14 +532,12 @@
 
   // Set up the loop body and arrange to exit once the condition has
   // changed.
-  tsi_link_after (&out, build1 (LABEL_EXPR, void_type_node, test),
-		  TSI_CONTINUE_LINKING);
   tsi_link_after (&out, stmt_tree, TSI_CONTINUE_LINKING);
+  tsi_link_after (&out, wrap_label (test, expr.get ()), TSI_CONTINUE_LINKING);
   tsi_link_after (&out, build1 (EXIT_EXPR,
 				void_type_node,
-				build1 (TRUTH_NOT_EXPR,
-					type_jboolean,
-					expr_tree)),
+				fold (build1 (TRUTH_NOT_EXPR, type_jboolean,
+					      expr_tree))),
 		  TSI_CONTINUE_LINKING);
 
   // Wrap the body in a loop.
@@ -542,8 +548,8 @@
   tree outer = alloc_stmt_list ();
   out = tsi_start (outer);
   tsi_link_after (&out, body_tree, TSI_CONTINUE_LINKING);
-  tsi_link_after (&out, build1 (LABEL_EXPR, void_type_node, done),
-		  TSI_CONTINUE_LINKING);
+  // FIXME: location should be end of do statement, not beginning.
+  tsi_link_after (&out, wrap_label (done, dstmt), TSI_CONTINUE_LINKING);
   current = outer;
 }
 
@@ -619,15 +625,15 @@
     {
       cond->visit (this);
       tsi_link_after (&body_out, build1 (EXIT_EXPR, void_type_node,
-					 build1 (TRUTH_NOT_EXPR,
-						 type_jboolean,
-						 current)),
+					 fold (build1 (TRUTH_NOT_EXPR,
+						       type_jboolean,
+						       current))),
 		      TSI_CONTINUE_LINKING);
     }
   body->visit (this);
   tsi_link_after (&body_out, current, TSI_CONTINUE_LINKING);
 
-  tsi_link_after (&body_out, build1 (LABEL_EXPR, void_type_node, update_tree),
+  tsi_link_after (&body_out, wrap_label (update_tree, fstmt),
 		  TSI_CONTINUE_LINKING);
   if (update)
     {
@@ -641,7 +647,7 @@
   annotate (body_tree, fstmt);
   tsi_link_after (&result_out, body_tree, TSI_CONTINUE_LINKING);
 
-  tsi_link_after (&result_out, build1 (LABEL_EXPR, void_type_node, done_tree),
+  tsi_link_after (&result_out, wrap_label (done_tree, fstmt),
 		  TSI_CONTINUE_LINKING);
 
   current = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (current_block),
@@ -691,9 +697,7 @@
 
       stmt->visit (this);
       tsi_link_after (&out, current, TSI_CONTINUE_LINKING);
-      tsi_link_after (&out, build1 (LABEL_EXPR, void_type_node,
-				    brk),
-		      TSI_CONTINUE_LINKING);
+      tsi_link_after (&out, wrap_label (brk, label), TSI_CONTINUE_LINKING);
 
       current = body_tree;
     }
@@ -743,8 +747,6 @@
 	{
 	  tree label = build0 (LABEL_DECL, NULL_TREE);
 	  DECL_CONTEXT (label) = current_block;
-	  tsi_link_after (&out, build1 (LABEL_EXPR, void_type_node, label),
-			  TSI_CONTINUE_LINKING);
 
 	  tree case_label = build3 (CASE_LABEL_EXPR, NULL_TREE, NULL_TREE,
 				    NULL_TREE, label);
@@ -755,14 +757,14 @@
       tsi_link_after (&out, current, TSI_CONTINUE_LINKING);
     }
 
-  current = build3 (SWITCH_EXPR, NULL_TREE, expr_tree, body_tree, NULL_TREE);
+  current = build3 (SWITCH_EXPR, TREE_TYPE (expr_tree), expr_tree,
+		    body_tree, NULL_TREE);
   annotate (current, swstmt);
 
   body_tree = alloc_stmt_list ();
   out = tsi_start (body_tree);
   tsi_link_after (&out, current, TSI_CONTINUE_LINKING);
-  tsi_link_after (&out, build1 (LABEL_EXPR, void_type_node, done),
-		  TSI_CONTINUE_LINKING);
+  tsi_link_after (&out, wrap_label (done, swstmt), TSI_CONTINUE_LINKING);
   current = body_tree;
 }
 
@@ -778,15 +780,14 @@
   tree body_tree = alloc_stmt_list ();
   tree_stmt_iterator out = tsi_start (body_tree);
 
-  // Multiple switch labels point at the same label in the code.
-  tree label = build0 (LABEL_DECL, NULL_TREE);
-  DECL_CONTEXT (label) = current_block;
-
   std::list<ref_expression> labels = swblock->get_labels ();
   for (std::list<ref_expression>::const_iterator i = labels.begin ();
        i != labels.end ();
        ++i)
     {
+      tree label = build0 (LABEL_DECL, NULL_TREE);
+      DECL_CONTEXT (label) = current_block;
+
       jint value = jint (intb->convert ((*i)->type (), (*i)->value ()));
       tree new_label = build3 (CASE_LABEL_EXPR, NULL_TREE, build_int (value),
 			       NULL_TREE, label);
@@ -794,8 +795,6 @@
       tsi_link_after (&out, new_label, TSI_CONTINUE_LINKING);
     }
 
-  tsi_link_after (&out, build1 (LABEL_EXPR, void_type_node, label),
-		  TSI_CONTINUE_LINKING);
   tree stmt_tree = transform_list (statements);
   tsi_link_after (&out, stmt_tree, TSI_CONTINUE_LINKING);
 
@@ -942,14 +941,12 @@
   // exit expression, then the actual body.
   tree body_tree = alloc_stmt_list ();
   tree_stmt_iterator out = tsi_start (body_tree);
-  tsi_link_after (&out, build1 (LABEL_EXPR, void_type_node, again),
-		  TSI_CONTINUE_LINKING);
+  tsi_link_after (&out, wrap_label (again, wstmt), TSI_CONTINUE_LINKING);
 
   cond->visit (this);
   tsi_link_after (&out, build1 (EXIT_EXPR, void_type_node,
-				build1 (TRUTH_NOT_EXPR,
-					type_jboolean,
-					current)),
+				fold (build1 (TRUTH_NOT_EXPR, type_jboolean,
+					      current))),
 		  TSI_CONTINUE_LINKING);
 
   body->visit (this);
@@ -962,8 +959,7 @@
   current = alloc_stmt_list ();
   out = tsi_start (current);
   tsi_link_after (&out, body_tree, TSI_CONTINUE_LINKING);
-  tsi_link_after (&out, build1 (LABEL_EXPR, void_type_node, done),
-		  TSI_CONTINUE_LINKING);
+  tsi_link_after (&out, wrap_label (done, wstmt), TSI_CONTINUE_LINKING);
 }
 
 
Index: tree.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.hh,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 tree.hh
--- tree.hh 27 Mar 2005 02:53:27 -0000 1.1.2.9
+++ tree.hh 27 Mar 2005 03:05:35 -0000
@@ -102,6 +102,7 @@
   tree transform_list (const std::list<ref_stmt> &);
   void annotate (tree, model_element *);
   tree wrap_synchronized (tree, tree);
+  tree wrap_label (tree, model_element *);
   tree add_var (const ref_variable_decl &);
   tree build_class_ref (model_type *, model_element *);
   tree build_class_ref (const std::string &);



More information about the Java-patches mailing list