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]

Treat stdin's filename more consistently


With this patch, GCC's options handling represents stdin's filename
consistently as the empty string, and the line-number machinery
consistently represents it as "<stdin>".  This fixes a problem with
line directive output with -E.

Bootstrapped & tested on powerpc-darwin.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-stdinfilename.patch===================
2003-07-29  Geoffrey Keating  <geoffk@apple.com>

	* cppfiles.c (stack_file): Leave filename as "" rather than "<stdin>".
	* line-map.h (linemap_add): Update comments.
	* line-map.c (linemap_add): Update comments, interpret zero-length
	filename as "<stdin>".

Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.178
diff -u -p -u -p -r1.178 cppfiles.c
--- cppfiles.c	29 Jul 2003 22:26:09 -0000	1.178
+++ cppfiles.c	30 Jul 2003 06:40:24 -0000
@@ -558,8 +558,6 @@ stack_file (cpp_reader *pfile, _cpp_file
 
   /* Generate the call back.  */
   fname = file->name;
-  if (*fname == '\0')
-    fname = "<stdin>";
   _cpp_do_file_change (pfile, LC_ENTER, fname, 1, sysp);
 
   return true;
Index: line-map.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.c,v
retrieving revision 1.14
diff -u -p -u -p -r1.14 line-map.c
--- line-map.c	22 Jul 2003 23:11:34 -0000	1.14
+++ line-map.c	30 Jul 2003 06:40:24 -0000
@@ -61,11 +61,17 @@ linemap_free (struct line_maps *set)
 }
 
 /* Add a mapping of logical source line to physical source file and
-   line number.  The text pointed to by TO_FILE must have a lifetime
-   at least as long as the final call to lookup_line ().
+   line number.
+
+   The text pointed to by TO_FILE must have a lifetime
+   at least as long as the final call to lookup_line ().  An empty
+   TO_FILE means standard input.  If reason is LC_LEAVE, and
+   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
+   natural values considering the file we are returning to.
 
    FROM_LINE should be monotonic increasing across calls to this
-   function.  */
+   function.  A call to this function can relocate the previous set of
+   maps, so any stored line_map pointers should not be used.  */
 
 const struct line_map *
 linemap_add (struct line_maps *set, enum lc_reason reason,
@@ -84,6 +90,9 @@ linemap_add (struct line_maps *set, enum
     }
 
   map = &set->maps[set->used++];
+
+  if (to_file && *to_file == '\0')
+    to_file = "<stdin>";
 
   /* If we don't keep our line maps consistent, we can easily
      segfault.  Don't rely on the client to do it for us.  */
Index: line-map.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.h,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 line-map.h
--- line-map.h	22 Jul 2003 16:24:53 -0000	1.12
+++ line-map.h	30 Jul 2003 06:40:24 -0000
@@ -74,8 +74,11 @@ extern void linemap_init (struct line_ma
 extern void linemap_free (struct line_maps *);
 
 /* Add a mapping of logical source line to physical source file and
-   line number.  The text pointed to by TO_FILE must have a lifetime
-   at least as long as the line maps.  If reason is LC_LEAVE, and
+   line number.
+
+   The text pointed to by TO_FILE must have a lifetime
+   at least as long as the final call to lookup_line ().  An empty
+   TO_FILE means standard input.  If reason is LC_LEAVE, and
    TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
    natural values considering the file we are returning to.
 
============================================================


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