This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

RFC: PATCH for multiple-file functions and the tree representation


I noticed that the source position info for cp/parse.c was wrong; tracking
this down, it appears that the function-as-trees code doesn't handle
functions that have lines from multiple files, as with yacced code.  Here's
a fix; any comments?

I haven't tested this yet, and I'm going away for the weekend, so I won't
check it in until I get back.

2002-01-11  Jason Merrill  <jason@redhat.com>

	* c-common.h (stmt_tree_s): Add x_last_filename.
	(last_filename): New macro.
	* c-semantics.c (begin_stmt_tree): Initialize it.
	(add_stmt): If the filename changed, also insert an
	EXPR_WITH_FILE_LOCATION.
	(expand_stmt): Handle seeing one.
	* tree.def (EXPR_WITH_FILE_LOCATION): Update description.
	* expr.c (expand_expr, EXPR_WITH_FILE_LOCATION): Don't restore
	saved values if EXPR_WFL_NODE is null.

*** tree.def.~1~	Fri Nov 23 17:27:53 2001
--- tree.def	Fri Jan 11 15:51:45 2002
*************** DEFTREECODE (EXIT_BLOCK_EXPR, "exit_bloc
*** 837,843 ****
     expanded as the contained node (EXPR_WFL_NODE);  a line note should
     be emitted first if EXPR_WFL_EMIT_LINE_NOTE.  
     The third operand is only used in the Java front-end, and will
!    eventually be removed.  */
  DEFTREECODE (EXPR_WITH_FILE_LOCATION, "expr_with_file_location", 'e', 3)
  
  /* Switch expression.
--- 837,846 ----
     expanded as the contained node (EXPR_WFL_NODE);  a line note should
     be emitted first if EXPR_WFL_EMIT_LINE_NOTE.  
     The third operand is only used in the Java front-end, and will
!    eventually be removed.
! 
!    If the contained node is NULL, the old source location information
!    is not restored after expansion.  */
  DEFTREECODE (EXPR_WITH_FILE_LOCATION, "expr_with_file_location", 'e', 3)
  
  /* Switch expression.
*** expr.c.~1~	Thu Jan 10 15:48:17 2002
--- expr.c	Fri Jan 11 15:52:12 2002
*************** expand_expr (exp, target, tmode, modifie
*** 6317,6324 ****
  	  emit_line_note (input_filename, lineno);
  	/* Possibly avoid switching back and forth here.  */
  	to_return = expand_expr (EXPR_WFL_NODE (exp), target, tmode, modifier);
! 	input_filename = saved_input_filename;
! 	lineno = saved_lineno;
  	return to_return;
        }
  
--- 6317,6327 ----
  	  emit_line_note (input_filename, lineno);
  	/* Possibly avoid switching back and forth here.  */
  	to_return = expand_expr (EXPR_WFL_NODE (exp), target, tmode, modifier);
! 	if (EXPR_WFL_NODE (exp))
! 	  {
! 	    input_filename = saved_input_filename;
! 	    lineno = saved_lineno;
! 	  }
  	return to_return;
        }
  
*** c-common.h.~1~	Mon Jan  7 19:06:42 2002
--- c-common.h	Fri Jan 11 15:48:10 2002
*************** struct stmt_tree_s {
*** 257,262 ****
--- 257,264 ----
    /* The type of the last expression statement.  (This information is
       needed to implement the statement-expression extension.)  */
    tree x_last_expr_type;
+   /* The last filename we recorded.  */
+   const char *x_last_filename;
    /* In C++, Non-zero if we should treat statements as full
       expressions.  In particular, this variable is no-zero if at the
       end of a statement we should destroy any temporaries created
*************** struct language_function {
*** 296,301 ****
--- 298,307 ----
  
  #define last_expr_type (current_stmt_tree ()->x_last_expr_type)
  
+ /* The name of the last file we have seen.  */
+ 
+ #define last_filename (current_stmt_tree ()->x_last_filename)
+ 
  /* LAST_TREE contains the last statement parsed.  These are chained
     together through the TREE_CHAIN field, but often need to be
     re-organized since the parse is performed bottom-up.  This macro
*** c-semantics.c.~1~	Mon Jan  7 19:06:43 2002
--- c-semantics.c	Fri Jan 11 15:47:54 2002
*************** begin_stmt_tree (t)
*** 60,65 ****
--- 60,66 ----
    *t = build_nt (EXPR_STMT, void_zero_node);
    last_tree = *t;
    last_expr_type = NULL_TREE;
+   last_filename = input_filename;
  }
  
  /* T is a statement.  Add it to the statement-tree.  */
*************** tree
*** 68,73 ****
--- 69,81 ----
  add_stmt (t)
       tree t;
  {
+   if (input_filename != last_filename)
+     {
+       tree pos = build_expr_wfl (NULL_TREE, input_filename, lineno, 0);
+       TREE_CHAIN (last_tree) = pos;
+       last_tree = pos;
+     }
+ 
    /* Add T to the statement-tree.  */
    TREE_CHAIN (last_tree) = t;
    last_tree = t;
*************** expand_stmt (t)
*** 760,765 ****
--- 768,777 ----
  
        switch (TREE_CODE (t))
  	{
+ 	case EXPR_WITH_FILE_LOCATION:
+ 	  input_filename = EXPR_WFL_FILENAME (t);
+ 	  break;
+ 
  	case RETURN_STMT:
  	  genrtl_return_stmt (t);
  	  break;
*************** expand_stmt (t)
*** 845,848 ****
        t = TREE_CHAIN (t);
      }
  }
- 
--- 857,859 ----

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