C++ PATCH for better label representation

Mark Mitchell mark@codesourcery.com
Thu Aug 26 23:07:00 GMT 1999


This patch improves our representation of labels in the tree
intermediate form.  I also improved the error-recover abilities of
do_decl_instantiation.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-08-26  Mark Mitchell  <mark@codesourcery.com>

	* decl.c (lookup_label): Build labels on the permanent obstack
	when building statement trees.  Don't build RTL for labels when
	building statement trees.
	* semantics.c (finish_goto_stmt): Use LABEL_DECLs even when
	building statement trees.
	(finish_label_stmt): Likewise.
	(expand_stmt): Adjust accordingly.
	* pt.c (tsubst_expr); Likewise.
	(do_decl_instantiation): Robustify.

Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.416
diff -c -p -r1.416 decl.c
*** decl.c	1999/08/27 03:52:43	1.416
--- decl.c	1999/08/27 05:58:55
*************** lookup_label (id)
*** 4829,4838 ****
        return decl;
      }
  
    decl = build_decl (LABEL_DECL, id, void_type_node);
! 
!   /* Make sure every label has an rtx.  */
!   label_rtx (decl);
  
    /* A label not explicitly declared must be local to where it's ref'd.  */
    DECL_CONTEXT (decl) = current_function_decl;
--- 4829,4842 ----
        return decl;
      }
  
+   if (building_stmt_tree ())
+     push_permanent_obstack ();
    decl = build_decl (LABEL_DECL, id, void_type_node);
!   if (building_stmt_tree ())
!     pop_obstacks ();
!   else
!     /* Make sure every label has an rtx.  */
!     label_rtx (decl);
  
    /* A label not explicitly declared must be local to where it's ref'd.  */
    DECL_CONTEXT (decl) = current_function_decl;
Index: pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.340
diff -c -p -r1.340 pt.c
*** pt.c	1999/08/25 22:07:15	1.340
--- pt.c	1999/08/27 05:59:04
*************** tsubst_expr (t, args, complain, in_decl)
*** 7401,7411 ****
      case GOTO_STMT:
        lineno = STMT_LINENO (t);
        t = GOTO_DESTINATION (t);
!       if (TREE_CODE (t) != IDENTIFIER_NODE)
  	/* Computed goto's must be tsubst'd into.  On the other hand,
  	   non-computed gotos must not be; the identifier in question
  	   will have no binding.  */
  	t = tsubst_expr (t, args, complain, in_decl);
        finish_goto_stmt (t);
        break;
  
--- 7401,7413 ----
      case GOTO_STMT:
        lineno = STMT_LINENO (t);
        t = GOTO_DESTINATION (t);
!       if (TREE_CODE (t) != LABEL_DECL)
  	/* Computed goto's must be tsubst'd into.  On the other hand,
  	   non-computed gotos must not be; the identifier in question
  	   will have no binding.  */
  	t = tsubst_expr (t, args, complain, in_decl);
+       else
+ 	t = DECL_NAME (t);
        finish_goto_stmt (t);
        break;
  
*************** do_decl_instantiation (declspecs, declar
*** 9132,9138 ****
    tree result = NULL_TREE;
    int extern_p = 0;
  
!   if (! DECL_LANG_SPECIFIC (decl))
      {
        cp_error ("explicit instantiation of non-template `%#D'", decl);
        return;
--- 9134,9144 ----
    tree result = NULL_TREE;
    int extern_p = 0;
  
!   if (!decl)
!     /* An error ocurred, for which grokdeclarator has already issued
!        an appropriate message.  */
!     return;
!   else if (! DECL_LANG_SPECIFIC (decl))
      {
        cp_error ("explicit instantiation of non-template `%#D'", decl);
        return;
Index: semantics.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/semantics.c,v
retrieving revision 1.65
diff -c -p -r1.65 semantics.c
*** semantics.c	1999/08/26 23:40:49	1.65
--- semantics.c	1999/08/27 05:59:05
*************** void
*** 599,615 ****
  finish_goto_stmt (destination)
       tree destination;
  {
    if (building_stmt_tree ())
      add_tree (build_min_nt (GOTO_STMT, destination));
    else
      {
        emit_line_note (input_filename, lineno);
  
!       if (TREE_CODE (destination) == IDENTIFIER_NODE)
  	{
! 	  tree decl = lookup_label (destination);
! 	  TREE_USED (decl) = 1;
! 	  expand_goto (decl); 
  	}
        else
  	expand_computed_goto (destination);
--- 599,617 ----
  finish_goto_stmt (destination)
       tree destination;
  {
+   if (TREE_CODE (destination) == IDENTIFIER_NODE)
+     destination = lookup_label (destination);
+ 
    if (building_stmt_tree ())
      add_tree (build_min_nt (GOTO_STMT, destination));
    else
      {
        emit_line_note (input_filename, lineno);
  
!       if (TREE_CODE (destination) == LABEL_DECL)
  	{
! 	  TREE_USED (destination) = 1;
! 	  expand_goto (destination); 
  	}
        else
  	expand_computed_goto (destination);
*************** void
*** 914,936 ****
  finish_label_stmt (name)
       tree name;
  {
!   tree decl;
  
    if (building_stmt_tree ())
!     {
!       push_permanent_obstack ();
!       decl = build_decl (LABEL_DECL, name, void_type_node);
!       pop_obstacks ();
!       DECL_SOURCE_LINE (decl) = lineno;
!       DECL_SOURCE_FILE (decl) = input_filename;
!       add_tree (decl);
!     }
!   else
!     {
!       decl = define_label (input_filename, lineno, name);
!       if (decl)
! 	expand_label (decl);
!     }
  }
  
  /* Create a declaration statement for the declaration given by the
--- 916,927 ----
  finish_label_stmt (name)
       tree name;
  {
!   tree decl = define_label (input_filename, lineno, name);
  
    if (building_stmt_tree ())
!     add_tree (decl);
!   else if (decl)
!     expand_label (decl);
  }
  
  /* Create a declaration statement for the declaration given by the
*************** expand_stmt (t)
*** 2129,2138 ****
        break;
  
      case LABEL_DECL:
!       t = define_label (DECL_SOURCE_FILE (t), DECL_SOURCE_LINE (t),
! 			DECL_NAME (t));
!       if (t)
! 	expand_label (t);
        break;
  
      case GOTO_STMT:
--- 2120,2128 ----
        break;
  
      case LABEL_DECL:
!       input_filename = DECL_SOURCE_FILE (t);
!       lineno = DECL_SOURCE_LINE (t);
!       finish_label_stmt (DECL_NAME (t));
        break;
  
      case GOTO_STMT:


More information about the Gcc-patches mailing list