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]

PATCH column number support


This is actually two related patches, relative to the tree-ssa
branch.  (I don't think there is anything ssa-branch-specific,
but this kind of change is probably not appropriate for 3.4.)

The first patch enhances the line_map data structure to support
column numbers.  The source_location typedef (renamed from
fileline) now also encodes column numbers that you can extract
using the SOURCE_COLUMN macro.  Column number are recorded in
the low-order column_bits of a source_location.  The number of
bits can vary from line_map to line_map, and default to 8.
If more bits are needed, a new line_map is added.  The 'col'
field of a cpp_token is no longer needed.

This patch is clean and I believe ready to go into the tree-ssa
branch (after another test-run with a clean tree).

The second patch is a kludge, but demonstrates how we can get
column numbers in decl diagnostics.  Compiling this source file:

int    sdsa   ;
float    sdsa   ;
#define  12

with a patched cc1plus results in:

/tmp/bad.c:2:10: error: conflicting declaration 'float sdsa'
/tmp/bad.c:1:8: error: 'sdsa' has a previous declaration as `int sdsa'
/tmp/bad.c:2:17: error: type mismatch with previous external decl of `float sdsa'
/tmp/bad.c:1:8: error: previous external decl of `int sdsa'
/tmp/bad.c:2:17: error: declaration of `float sdsa'
/tmp/bad.c:1:8: error: conflicts with previous declaration `int sdsa'
/tmp/bad.c:3:10: macro names must be identifiers


(The duplicated error messages are a bug that pre-existed
this patch.)

This works by adding a source_location field to location_t.
This is of course not what we want to do.  Instead the goal
is to *replace* location_t by source_location.  I do have a
patch for this (both mainline and tree-ssa), though so far only
for the C front-end.  Also, the way I set DECL_LOCATION using a
declarator_location global is obviously bogus, but I'll let
someone more familiar with the C++ parser do it more cleanly.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


2003-11-29  Per Bothner  <per@bothner.com>

	* line-map.h (struct line_map):  New column_bits field.
	Rename fron_line field to start_location.
	(linemap_add):  Add column_bits parameter.
	(SOURCE_LINE, LAST_SOURCE_LINE):  Modify to use column_bits.
	(SOURCE_COLUMN):  New field.
	* line-map.c (linemap_add):  Set column_bits.  Various updates.
	(linemap_lookeup):  Update for new field names.
	* cpplib.h (struct cpp_token):  Rename line field to src_loc.
	Rename col field as it is now subsumed by src_loc.
	* cpphash.h:  Some renames of fileline to source_location.
	* cpperror.c:  Update various field, parameter, and macro names.
	(print_location):  If col==0, try SOURCE_COLUMN of line.
	(cpp_error):  Use cur_token's src_loc field, rather than line+col.
	* cpplex.c (_cpp_process_line_notes, _cpp_lex_direct):  Incrementing
	line number must adjust by column_bits.
	(_cpp_skip_block_comment): Likewise.  Also if current line_map's
	column_bits is too small or needlessly big, call linemap_add.
	(_cpp_temp_token):  Replace cpp_token's line+col fields by src_loc.
	(_cpp_lex_direct):  Mask in column number to token's src_loc.
	* cpplib.c (linemap_add):  Pass 8 for column_bits to linemap_add.
	(do_diagnostic):  Token's src_loc fields replaces line+col.
	* cppmacro.c (_cpp_builtin_macro_text):  Likewise.
	* c-ppoutput.c (cb_line_change):  Likewise.
	(maybe_print_line, cb_line_change):  Adjust for column_bits.
	(pp_file_change):  Likewise.  Update for renamed fields.
	* cpptrad.c (copy_comment):  Rename variable.
	* c-lex.c (cb_line_change):  Token's line field replaced by src_loc.
	(fe_file_change):  Use LAST_SOURCE_LINE macro.

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.182.2.16
diff -u -p -r1.182.2.16 c-lex.c
--- c-lex.c	6 Oct 2003 17:36:12 -0000	1.182.2.16
+++ c-lex.c	30 Nov 2003 06:31:35 -0000
@@ -199,7 +199,7 @@ cb_line_change (cpp_reader *pfile ATTRIB
   if (token->type == CPP_EOF || parsing_args)
     return;
 
-  input_line = SOURCE_LINE (map, token->line);
+  input_line = SOURCE_LINE (map, token->src_loc);
 }
 
 static void
@@ -226,7 +227,7 @@ fe_file_change (const struct line_map *n
 	main_input_filename = new_map->to_file;
       else
 	{
-          int included_at = SOURCE_LINE (new_map - 1, new_map->from_line - 1);
+          int included_at = LAST_SOURCE_LINE (new_map - 1);
 
 	  input_line = included_at;
 	  push_srcloc (new_map->to_file, 1);
Index: cpperror.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpperror.c,v
retrieving revision 1.60.2.9
diff -u -p -r1.60.2.9 cpperror.c
--- cpperror.c	13 Nov 2003 02:37:47 -0000	1.60.2.9
+++ cpperror.c	30 Nov 2003 06:31:37 -0000
@@ -29,14 +29,14 @@ Foundation, 59 Temple Place - Suite 330,
 #include "cpphash.h"
 #include "intl.h"
 
-static void print_location (cpp_reader *, fileline, unsigned int);
+static void print_location (cpp_reader *, source_location, unsigned int);
 
 /* Print the logical file location (LINE, COL) in preparation for a
    diagnostic.  Outputs the #include chain if it has changed.  A line
    of zero suppresses the include stack, and outputs the program name
    instead.  */
 static void
-print_location (cpp_reader *pfile, fileline line, unsigned int col)
+print_location (cpp_reader *pfile, source_location line, unsigned int col)
 {
   if (line == 0)
     fprintf (stderr, "%s: ", progname);
@@ -50,7 +50,11 @@ print_location (cpp_reader *pfile, filel
 
       lin = SOURCE_LINE (map, line);
       if (col == 0)
-	col = 1;
+	{
+	  col = SOURCE_COLUMN (map, line);
+	  if (col == 0)
+	    col = 1;
+	}
 
       if (lin == 0)
 	fprintf (stderr, "%s:", map->to_file);
@@ -64,13 +68,18 @@ print_location (cpp_reader *pfile, filel
 }
 
 /* Set up for a diagnostic: print the file and line, bump the error
-   counter, etc.  LINE is the logical line number; zero means to print
+   counter, etc.  SRC_LOC is the logical line number; zero means to print
    at the location of the previously lexed token, which tends to be
-   the correct place by default.  Returns 0 if the error has been
-   suppressed.  */
+   the correct place by default.  The column number can be specified either
+   using COLUMN or (if COLUMN==0) extracting SOURCE_COLUMN from SRC_LOC.
+   (This may seem redundant, but is useful when pre-scanning (cleaning) a line,
+   when we haven't yet verified whether the current line_map has a
+   big enough column_bits.)
+
+   Returns 0 if the error has been suppressed.  */
 int
-_cpp_begin_message (cpp_reader *pfile, int code, fileline line,
-		    unsigned int column)
+_cpp_begin_message (cpp_reader *pfile, int code,
+		    source_location src_loc, unsigned int column)
 {
   int level = CPP_DL_EXTRACT (code);
 
@@ -105,7 +114,7 @@ _cpp_begin_message (cpp_reader *pfile, i
       break;
     }
 
-  print_location (pfile, line, column);
+  print_location (pfile, src_loc, column);
   if (CPP_DL_WARNING_P (level))
     fputs (_("warning: "), stderr);
   else if (level == CPP_DL_ICE)
@@ -125,8 +134,7 @@ _cpp_begin_message (cpp_reader *pfile, i
 void
 cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
 {
-  fileline line;
-  unsigned int column;
+  source_location src_loc;
   va_list ap;
   
   va_start (ap, msgid);
@@ -134,18 +142,16 @@ cpp_error (cpp_reader * pfile, int level
   if (CPP_OPTION (pfile, traditional))
     {
       if (pfile->state.in_directive)
-	line = pfile->directive_line;
+	src_loc = pfile->directive_line;
       else
-	line = pfile->line;
-      column = 0;
+	src_loc = pfile->line;
     }
   else
     {
-      line = pfile->cur_token[-1].line;
-      column = pfile->cur_token[-1].col;
+      src_loc = pfile->cur_token[-1].src_loc;
     }
 
-  if (_cpp_begin_message (pfile, level, line, column))
+  if (_cpp_begin_message (pfile, level, src_loc, 0))
     v_message (msgid, ap);
 
   va_end (ap);
@@ -154,14 +160,14 @@ cpp_error (cpp_reader * pfile, int level
 /* Print an error at a specific location.  */
 void
 cpp_error_with_line (cpp_reader *pfile, int level,
-		     fileline line, unsigned int column,
+		     source_location src_loc, unsigned int column,
 		     const char *msgid, ...)
 {
   va_list ap;
   
   va_start (ap, msgid);
 
-  if (_cpp_begin_message (pfile, level, line, column))
+  if (_cpp_begin_message (pfile, level, src_loc, column))
     v_message (msgid, ap);
 
   va_end (ap);
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.166.2.17
diff -u -p -r1.166.2.17 cpphash.h
--- cpphash.h	6 Oct 2003 17:36:24 -0000	1.166.2.17
+++ cpphash.h	30 Nov 2003 06:31:37 -0000
@@ -332,7 +332,8 @@ struct cpp_reader
   /* Source line tracking.  */
   struct line_maps line_maps;
   const struct line_map *map;
-  fileline line;
+  /* Current line (with column==0). */
+  source_location line;
 
   /* The line of the '#' of the current directive.  */
   fileline directive_line;
@@ -494,7 +495,8 @@ extern unsigned char _cpp_trigraph_map[U
 #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
 
 /* In cpperror.c  */
-extern int _cpp_begin_message (cpp_reader *, int, fileline, unsigned int);
+extern int _cpp_begin_message (cpp_reader *, int,
+			       source_location, unsigned int);
 
 /* In cppmacro.c */
 extern void _cpp_free_definition (cpp_hashnode *);
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.211.2.16
diff -u -p -r1.211.2.16 cpplex.c
--- cpplex.c	13 Nov 2003 02:37:49 -0000	1.211.2.16
+++ cpplex.c	30 Nov 2003 06:31:37 -0000
@@ -282,7 +282,7 @@ _cpp_process_line_notes (cpp_reader *pfi
 	    }
 
 	  buffer->line_base = note->pos;
-	  pfile->line++;
+	  pfile->line += 1 << pfile->map->column_bits;
 	}
       else if (_cpp_trigraph_map[note->type])
 	{
@@ -349,12 +349,36 @@ _cpp_skip_block_comment (cpp_reader *pfi
 	}
       else if (c == '\n')
 	{
+	  unsigned int cols, column_bits, line;
 	  buffer->cur = cur - 1;
 	  _cpp_process_line_notes (pfile, true);
 	  if (buffer->next_line >= buffer->rlimit)
 	    return true;
 	  _cpp_clean_line (pfile);
-	  pfile->line++;
+
+	  cols = buffer->next_line - buffer->line_base;
+	  column_bits = pfile->map->column_bits;
+	  line = SOURCE_LINE (pfile->map, pfile->line);
+	  pfile->line += 1 << column_bits;
+	  if (cols >= (1U << column_bits))
+	    {
+	      column_bits = 10;
+	      while (cols >= (1U << column_bits))
+		column_bits++;
+	    }
+	  else if (column_bits >= 10 && cols <= 100
+		   && pfile->line - pfile->map->start_location >= (1 << 15))
+	    column_bits = 8;
+	  else /* ok as we are */
+	    column_bits = 0;
+	  if (column_bits)
+	    {
+	      unsigned int sysp = pfile->map->sysp;
+	      pfile->map = linemap_add (&pfile->line_maps, LC_RENAME, sysp,
+					pfile->line,
+					pfile->map->to_file, line + 1,
+					column_bits);
+	    }
 	  cur = buffer->cur;
 	}
     }
@@ -680,8 +704,7 @@ _cpp_temp_token (cpp_reader *pfile)
     }
 
   result = pfile->cur_token++;
-  result->line = old->line;
-  result->col = old->col;
+  result->src_loc = old->src_loc;
   return result;
 }
 
@@ -810,6 +833,7 @@ _cpp_lex_direct (cpp_reader *pfile)
   cpp_buffer *buffer;
   const unsigned char *comment_start;
   cpp_token *result = pfile->cur_token++;
+  source_location mask;
 
  fresh_line:
   result->flags = 0;
@@ -822,7 +846,7 @@ _cpp_lex_direct (cpp_reader *pfile)
 	  if (!pfile->state.in_directive)
 	    {
 	      /* Tell the compiler the line number of the EOF token.  */
-	      result->line = pfile->line;
+	      result->src_loc = pfile->line;
 	      result->flags = BOL;
 	    }
 	  return result;
@@ -839,17 +863,20 @@ _cpp_lex_direct (cpp_reader *pfile)
     }
   buffer = pfile->buffer;
  update_tokens_line:
-  result->line = pfile->line;
+  result->src_loc = pfile->line;
 
  skipped_white:
   if (buffer->cur >= buffer->notes[buffer->cur_note].pos
       && !pfile->overlaid_buffer)
     {
       _cpp_process_line_notes (pfile, false);
-      result->line = pfile->line;
+      result->src_loc = pfile->line;
     }
   c = *buffer->cur++;
-  result->col = CPP_BUF_COLUMN (buffer, buffer->cur);
+  mask = (1 << pfile->map->column_bits) - 1;
+  result->src_loc
+    = ((result->src_loc & ~mask)
+       | ((CPP_BUF_COLUMN (buffer, buffer->cur) + 1) & mask));
 
   switch (c)
     {
@@ -859,7 +886,7 @@ _cpp_lex_direct (cpp_reader *pfile)
       goto skipped_white;
 
     case '\n':
-      pfile->line++;
+      pfile->line += 1 << pfile->map->column_bits;
       buffer->need_line = true;
       goto fresh_line;
 
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.311.2.21
diff -u -p -r1.311.2.21 cpplib.c
--- cpplib.c	13 Nov 2003 02:37:49 -0000	1.311.2.21
+++ cpplib.c	30 Nov 2003 06:31:38 -0000
@@ -893,8 +893,9 @@ _cpp_do_file_change (cpp_reader *pfile, 
 		     const char *to_file, unsigned int file_line,
 		     unsigned int sysp)
 {
+  /* Use 8 bits as the default for column numbers. */
   pfile->map = linemap_add (&pfile->line_maps, reason, sysp,
-			    pfile->line, to_file, file_line);
+			    pfile->line, to_file, file_line, 8);
 
   if (pfile->cb.file_change)
     pfile->cb.file_change (pfile, pfile->map);
@@ -905,9 +906,7 @@ _cpp_do_file_change (cpp_reader *pfile, 
 static void
 do_diagnostic (cpp_reader *pfile, int code, int print_dir)
 {
-  if (_cpp_begin_message (pfile, code,
-			  pfile->cur_token[-1].line,
-			  pfile->cur_token[-1].col))
+  if (_cpp_begin_message (pfile, code, pfile->cur_token[-1].src_loc, 0))
     {
       if (print_dir)
 	fprintf (stderr, "#%s ", pfile->directive->name);
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.224.2.20
diff -u -p -r1.224.2.20 cpplib.h
--- cpplib.h	13 Nov 2003 02:37:50 -0000	1.224.2.20
+++ cpplib.h	30 Nov 2003 06:31:38 -0000
@@ -174,8 +174,7 @@ struct cpp_string
    occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts.  */
 struct cpp_token
 {
-  fileline line;		/* Logical line of first char of token.  */
-  unsigned short col;		/* Column of first char of token.  */
+  source_location src_loc;	/* Location of first char of token.  */
   ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT;  /* token type */
   unsigned char flags;		/* flags - see above */
 
@@ -688,7 +687,8 @@ extern void cpp_errno (cpp_reader *, int
 /* Same as cpp_error, except additionally specifies a position as a
    (translation unit) physical line and physical column.  If the line is
    zero, then no location is printed.  */
-extern void cpp_error_with_line (cpp_reader *, int, fileline, unsigned,
+extern void cpp_error_with_line (cpp_reader *, int,
+				 source_location, unsigned int,
 				 const char *msgid, ...) ATTRIBUTE_PRINTF_5;
 
 /* In cpplex.c */
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.115.2.17
diff -u -p -r1.115.2.17 cppmacro.c
--- cppmacro.c	13 Nov 2003 02:37:50 -0000	1.115.2.17
+++ cppmacro.c	30 Nov 2003 06:31:39 -0000
@@ -163,7 +163,7 @@ _cpp_builtin_macro_text (cpp_reader *pfi
       if (CPP_OPTION (pfile, traditional))
 	number = pfile->line;
       else
-	number = pfile->cur_token[-1].line;
+	number = pfile->cur_token[-1].src_loc;
       number = SOURCE_LINE (pfile->map, number);
       break;
 
Index: c-ppoutput.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-ppoutput.c,v
retrieving revision 1.4.2.7
diff -u -p -r1.4.2.7 c-ppoutput.c
--- c-ppoutput.c	6 Oct 2003 17:36:12 -0000	1.4.2.7
+++ c-ppoutput.c	30 Nov 2003 06:31:39 -0000
@@ -205,16 +205,16 @@ maybe_print_line (const struct line_map 
   if (print.printed)
     {
       putc ('\n', print.outf);
-      print.line++;
+      print.line += 1 << map->column_bits;
       print.printed = 0;
     }
 
-  if (line >= print.line && line < print.line + 8)
+  if (line >= print.line && line < print.line + (8 << map->column_bits))
     {
       while (line > print.line)
 	{
 	  putc ('\n', print.outf);
-	  print.line++;
+	  print.line += 1 << map->column_bits;
 	}
     }
   else
@@ -265,7 +265,7 @@ cb_line_change (cpp_reader *pfile, const
   if (token->type == CPP_EOF || parsing_args)
     return;
 
-  maybe_print_line (print.map, token->line);
+  maybe_print_line (print.map, token->src_loc);
   print.prev = 0;
   print.source = 0;
 
@@ -276,14 +276,11 @@ cb_line_change (cpp_reader *pfile, const
      ought to care.  Some things do care; the fault lies with them.  */
   if (!CPP_OPTION (pfile, traditional))
     {
+      int spaces = SOURCE_COLUMN (print.map, token->src_loc) - 2;
       print.printed = 1;
-      if (token->col > 2)
-	{
-	  unsigned int spaces = token->col - 2;
 
-	  while (spaces--)
-	    putc (' ', print.outf);
-	}
+      while (-- spaces >= 0)
+	putc (' ', print.outf);
     }
 }
 
@@ -353,19 +350,20 @@ pp_file_change (const struct line_map *m
 	{
 	  /* Avoid printing foo.i when the main file is foo.c.  */
 	  if (!cpp_get_options (parse_in)->preprocessed)
-	    print_line (map, map->from_line, flags);
+	    print_line (map, map->start_location, flags);
 	}
       else
 	{
 	  /* Bring current file to correct line when entering a new file.  */
 	  if (map->reason == LC_ENTER)
-	    maybe_print_line (map - 1, map->from_line - 1);
+	    maybe_print_line (map - 1,
+			      map->start_location - (1 << (map)->column_bits));
 
 	  if (map->reason == LC_ENTER)
 	    flags = " 1";
 	  else if (map->reason == LC_LEAVE)
 	    flags = " 2";
-	  print_line (map, map->from_line, flags);
+	  print_line (map, map->start_location, flags);
 	}
     }
 
Index: cpptrad.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpptrad.c,v
retrieving revision 1.15.2.15
diff -u -p -r1.15.2.15 cpptrad.c
--- cpptrad.c	25 Nov 2003 02:09:41 -0000	1.15.2.15
+++ cpptrad.c	30 Nov 2003 06:31:39 -0000
@@ -148,7 +148,7 @@ static const uchar *
 copy_comment (cpp_reader *pfile, const uchar *cur, int in_define)
 {
   bool unterminated, copy = false;
-  unsigned int from_line = pfile->line;
+  source_location src_loc = pfile->line;
   cpp_buffer *buffer = pfile->buffer;
 
   buffer->cur = cur;
@@ -158,7 +158,7 @@ copy_comment (cpp_reader *pfile, const u
     unterminated = _cpp_skip_block_comment (pfile);
     
   if (unterminated)
-    cpp_error_with_line (pfile, CPP_DL_ERROR, from_line, 0,
+    cpp_error_with_line (pfile, CPP_DL_ERROR, src_loc, 0,
 			 "unterminated comment");
 
   /* Comments in directives become spaces so that tokens are properly
Index: line-map.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.c,v
retrieving revision 1.6.18.5
diff -u -p -r1.6.18.5 line-map.c
--- line-map.c	20 Aug 2003 20:44:25 -0000	1.6.18.5
+++ line-map.c	30 Nov 2003 06:31:39 -0000
@@ -1,5 +1,5 @@
 /* Map logical line numbers to (source file, line number) pairs.
-   Copyright (C) 2001
+   Copyright (C) 2001, 2003
    Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify it
@@ -69,18 +69,18 @@ linemap_free (struct line_maps *set)
    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
+   START_LOCATION should be monotonic increasing across calls to this
    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,
-	     unsigned int sysp, unsigned int from_line,
-	     const char *to_file, unsigned int to_line)
+	     unsigned int sysp, source_location start_location,
+	     const char *to_file, unsigned int to_line, int column_bits)
 {
   struct line_map *map;
 
-  if (set->used && from_line < set->maps[set->used - 1].from_line)
+  if (set->used && start_location < set->maps[set->used - 1].start_location)
     abort ();
 
   if (set->used == set->allocated)
@@ -131,16 +131,17 @@ linemap_add (struct line_maps *set, enum
       if (error || to_file == NULL)
 	{
 	  to_file = from->to_file;
-	  to_line = LAST_SOURCE_LINE (from) + 1;
+	  to_line = SOURCE_LINE (from, from[1].start_location);
 	  sysp = from->sysp;
 	}
     }
 
   map->reason = reason;
   map->sysp = sysp;
-  map->from_line = from_line;
+  map->start_location = start_location;
   map->to_file = to_file;
   map->to_line = to_line;
+  map->column_bits = column_bits;
 
   if (reason == LC_ENTER)
     {
@@ -166,7 +167,7 @@ linemap_add (struct line_maps *set, enum
    the list is sorted and we can use a binary search.  */
 
 const struct line_map *
-linemap_lookup (struct line_maps *set, unsigned int line)
+linemap_lookup (struct line_maps *set, source_location line)
 {
   unsigned int md, mn = 0, mx = set->used;
 
@@ -176,7 +177,7 @@ linemap_lookup (struct line_maps *set, u
   while (mx - mn > 1)
     {
       md = (mn + mx) / 2;
-      if (set->maps[md].from_line > line)
+      if (set->maps[md].start_location > line)
 	mx = md;
       else
 	mn = md;
Index: line-map.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.h,v
retrieving revision 1.9.18.4
diff -u -p -r1.9.18.4 line-map.h
--- line-map.h	28 Sep 2003 06:06:29 -0000	1.9.18.4
+++ line-map.h	30 Nov 2003 06:31:39 -0000
@@ -1,5 +1,5 @@
 /* Map logical line numbers to (source file, line number) pairs.
-   Copyright (C) 2001
+   Copyright (C) 2001, 2003
    Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify it
@@ -30,27 +30,34 @@ Foundation, 59 Temple Place - Suite 330,
    (e.g. a #line directive in C).  */
 enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME};
 
-/* A logical line number, i,e, an "index" into a line_map.  */
+/* A logical line/column number, i,e, an "index" into a line_map.  */
 /* Long-term, we want to use this to replace struct location_s (in input.h),
-   and effectively typedef fileline location_t.  */
-typedef unsigned int fileline;
-
-/* The logical line FROM_LINE maps to physical source file TO_FILE at
-   line TO_LINE, and subsequently one-to-one until the next line_map
-   structure in the set.  INCLUDED_FROM is an index into the set that
-   gives the line mapping at whose end the current one was included.
-   File(s) at the bottom of the include stack have this set to -1.
-   REASON is the reason for creation of this line map, SYSP is one for
-   a system header, two for a C system header file that therefore
-   needs to be extern "C" protected in C++, and zero otherwise.  */
+   and effectively typedef source_location location_t.  */
+typedef unsigned int source_location;
+typedef source_location fileline; /* deprecated name */
+
+/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
+   by the logical START_LOCATION.  TO_LINE+L at column C is represented by
+   START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
+   and the result_location is less than the next line_map's start_location.
+   (The top line is line 1 and the leftmost column is column 1; line/column 0
+   means "entire file/line" or "unknown line/column" or "not applicable".)
+   INCLUDED_FROM is an index into the set that gives the line mapping
+   at whose end the current one was included.  File(s) at the bottom
+   of the include stack have this set to -1.  REASON is the reason for
+   creation of this line map, SYSP is one for a system header, two for
+   a C system header file that therefore needs to be extern "C"
+   protected in C++, and zero otherwise.  */
 struct line_map
 {
   const char *to_file;
   unsigned int to_line;
-  fileline from_line;
+  source_location start_location;
   int included_from;
   ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
   unsigned char sysp;
+  /* Number of the low-order source_location bits used for a column number. */
+  unsigned int column_bits : 8;
 };
 
 /* A set of chronological line_map structures.  */
@@ -87,16 +94,18 @@ extern void linemap_free (struct line_ma
    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
+   START_LOCATION should be monotonic increasing across calls to this
    function.  A call to this function can relocate the previous set of
    maps, so any stored line_map pointers should not be used.  */
 extern const struct line_map *linemap_add
   (struct line_maps *, enum lc_reason, unsigned int sysp,
-   fileline from_line, const char *to_file, unsigned int to_line);
+   source_location start_location, const char *to_file, unsigned int to_line,
+   int column_bits);
 
 /* Given a logical line, returns the map from which the corresponding
    (source file, line) pair can be deduced.  */
-extern const struct line_map *linemap_lookup (struct line_maps *, fileline);
+extern const struct line_map *linemap_lookup
+  (struct line_maps *, source_location);
 
 /* Print the file names and line numbers of the #include commands
    which led to the map MAP, if any, to stderr.  Nothing is output if
@@ -104,12 +113,17 @@ extern const struct line_map *linemap_lo
 extern void linemap_print_containing_files (struct line_maps *,
 					    const struct line_map *);
 
-/* Converts a map and logical line to source line.  */
-#define SOURCE_LINE(MAP, LINE) ((LINE) + (MAP)->to_line - (MAP)->from_line)
+/* Converts a map and a source_location to source line.  */
+#define SOURCE_LINE(MAP, LINE) \
+  ((((LINE) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line)
+
+#define SOURCE_COLUMN(MAP, LINE) \
+  (((LINE) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1))
 
 /* Returns the last source line within a map.  This is the (last) line
    of the #include, or other directive, that caused a map change.  */
-#define LAST_SOURCE_LINE(MAP) SOURCE_LINE ((MAP), (MAP)[1].from_line - 1)
+#define LAST_SOURCE_LINE(MAP) \
+  SOURCE_LINE ((MAP), (MAP)[1].start_location - (1 << (MAP)->column_bits))
 
 /* Returns the map a given map was included from.  */
 #define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.182.2.16
diff -u -p -r1.182.2.16 c-lex.c
--- c-lex.c	6 Oct 2003 17:36:12 -0000	1.182.2.16
+++ c-lex.c	30 Nov 2003 06:31:35 -0000
@@ -199,7 +199,8 @@ cb_line_change (cpp_reader *pfile ATTRIB
   if (token->type == CPP_EOF || parsing_args)
     return;
 
   input_line = SOURCE_LINE (map, token->src_loc);
+  input_location.location = token->src_loc;
 }
 
 static void
@@ -435,6 +436,7 @@ c_lex (tree *value)
       no_more_pch = true;
       c_common_no_more_pch ();
     }
+  input_location.location = tok->src_loc;;
 
   return tok->type;
 }
Index: input.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/input.h,v
retrieving revision 1.8.2.4
diff -u -p -r1.8.2.4 input.h
--- input.h	28 Sep 2003 06:06:28 -0000	1.8.2.4
+++ input.h	30 Nov 2003 06:31:39 -0000
@@ -22,6 +22,8 @@ Software Foundation, 59 Temple Place - S
 #ifndef GCC_INPUT_H
 #define GCC_INPUT_H
 
+/*#include "line-map.h"*/
+
 /* The data structure used to record a location in a translation unit.  */
 /* Long-term, we want to get rid of this and typedef fileline location_t.  */
 struct location_s GTY (())
@@ -31,6 +33,9 @@ struct location_s GTY (())
 
   /* The line-location in the source file.  */
   int line;
+
+  /* EXPERIMENTAL - for column number. */
+  /*source_location*/ unsigned int location;
 };
 typedef struct location_s location_t;
 
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/diagnostic.c,v
retrieving revision 1.91.2.25
diff -u -p -r1.91.2.25 diagnostic.c
--- diagnostic.c	28 Sep 2003 06:06:17 -0000	1.91.2.25
+++ diagnostic.c	30 Nov 2003 06:31:39 -0000
@@ -38,7 +38,10 @@ Software Foundation, 59 Temple Place - S
 #include "diagnostic.h"
 #include "langhooks.h"
 #include "langhooks-def.h"
-
+#include "cpplib.h"
+#include "cpphash.h"
+extern struct cpp_reader* parse_in;
+#include "line-map.h"
 
 /* Prototypes.  */
 static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
@@ -176,13 +179,35 @@ diagnostic_build_prefix (diagnostic_info
    if (diagnostic->kind >= DK_LAST_DIAGNOSTIC_KIND)
      abort();
 
-  return diagnostic->location.file
-    ? build_message_string ("%s:%d: %s",
+   if (diagnostic->location.file)
+     {
+       if (diagnostic->location.location)
+	 {
+	   const struct line_map *map
+	     = linemap_lookup (&parse_in->line_maps,
+			       diagnostic->location.location);
+	   const char *file = map->to_file;
+	   int line = SOURCE_LINE (map, diagnostic->location.location);
+	   int column = SOURCE_COLUMN (map, diagnostic->location.location);
+	   if (file != NULL && line > 0)
+	     {
+	       if (column != 0)
+		 return build_message_string ("%s:%d:%d: %s", file, line,
+					      column,
+					    _(diagnostic_kind_text[diagnostic->kind]));
+	       else
+		 return build_message_string ("%s:%d: %s", file, line,
+					    _(diagnostic_kind_text[diagnostic->kind]));
+	     }
+	 }
+       return build_message_string ("%s:%d: %s",
                             diagnostic->location.file,
                             diagnostic->location.line,
-                            _(diagnostic_kind_text[diagnostic->kind]))
-    : build_message_string ("%s: %s", progname,
-                            _(diagnostic_kind_text[diagnostic->kind]));
+				    _(diagnostic_kind_text[diagnostic->kind]));
+     }
+   else
+     return build_message_string ("%s: d%s", progname,
+				  _(diagnostic_kind_text[diagnostic->kind]));
 }
 
 /* Count a diagnostic.  Return true if the message should be printed.  */
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.911.2.57
diff -u -p -r1.911.2.57 decl.c
--- cp/decl.c	25 Nov 2003 02:10:45 -0000	1.911.2.57
+++ cp/decl.c	30 Nov 2003 06:31:43 -0000
@@ -1379,7 +1379,7 @@ duplicate_decls (tree newdecl, tree oldd
       else if (current_class_type == NULL_TREE
 	  || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
 	{
-	  error ("conflicting declaration '%#D'", newdecl);
+	  cp_error_at ("conflicting declaration '%#D'", newdecl);
 	  cp_error_at ("'%D' has a previous declaration as `%#D'",
                        olddecl, olddecl);
           return NULL_TREE;
@@ -3654,6 +3654,10 @@ start_decl (tree declarator, 
 
   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
 			 &attributes);
+  {
+    extern location_t declarator_location;
+    DECL_SOURCE_LOCATION(decl) = declarator_location;
+  }
 
   deprecated_state = DEPRECATED_NORMAL;
 
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.32.2.17
diff -u -p -r1.32.2.17 parser.c
--- cp/parser.c	25 Nov 2003 02:10:50 -0000	1.32.2.17
+++ cp/parser.c	30 Nov 2003 06:31:47 -0000
@@ -78,6 +78,8 @@ typedef struct cp_token GTY (())
   location_t location;
 } cp_token;
 
+location_t declarator_location;
+
 /* The number of tokens in a single token block.
    Computed so that cp_token_block fits in a 512B allocation unit.  */
 
@@ -9453,6 +9455,7 @@ cp_parser_init_declarator (cp_parser* pa
 	}
       decl = start_decl (declarator, decl_specifiers,
 			 is_initialized, attributes, prefix_attributes);
+      DECL_SOURCE_LOCATION(decl) = declarator_location;
     }
 
   /* Enter the SCOPE.  That way unqualified names appearing in the
@@ -9620,7 +9623,8 @@ cp_parser_declarator (cp_parser* parser,
   
   /* Peek at the next token.  */
   token = cp_lexer_peek_token (parser->lexer);
-  
+  declarator_location = token->location;
+
   /* Check for the ptr-operator production.  */
   cp_parser_parse_tentatively (parser);
   /* Parse the ptr-operator.  */

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