cpplib: Restore original trigraph warnings

Neil Booth neil@daikokuya.co.uk
Sun Apr 20 16:50:00 GMT 2003


With the stage12 separation, I dumbed down the trigraph warnings
as at the time I couldn't think of a clean way to keep the info
about what conversion occurred.  The current CVS code warns about
what a converted trigraph was converted to by looking in the clean
line; however, this doesn't work if it formed an escaped newline.
It also doesn't mention what character it was converted from,
as this info isn't handy.

The solution is obvious; I should have realized initially.  We just
have the 'from' character, such as '=', as the note type.  This
patch does that, and restores the warning to its former verbosity.

Neil.

	* cpphash.h (NOTE_ESC_NL, NOTE_ESC_SPACE_NL, NOTE_TRIGRAPH,
	NOTE_NEWLINE): Remove.
	* cpplex.c (_cpp_clean_line, _cpp_process_line_notes): Update
	to handle new form of line note type.

Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.184
diff -u -p -r1.184 cpphash.h
--- cpphash.h	20 Apr 2003 07:29:20 -0000	1.184
+++ cpphash.h	20 Apr 2003 16:43:17 -0000
@@ -243,11 +243,10 @@ struct _cpp_line_note
   /* Location in the clean line the note refers to.  */
   const uchar *pos;
 
-  /* Type of note.  */
-  enum { NOTE_ESC_NL = 0,
-	 NOTE_ESC_SPACE_NL,
-	 NOTE_TRIGRAPH,
-	 NOTE_NEWLINE } type;
+  /* Type of note.  The 9 'from' trigraph characters represent those
+     trigraphs, '\\' an escaped newline, ' ' an escaped newline with
+     intervening space, and anything else is invalid.  */
+  unsigned int type;
 };
 
 /* Represents the contents of a file cpplib has read in.  */
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.226
diff -u -p -r1.226 cpplex.c
--- cpplex.c	20 Apr 2003 11:57:37 -0000	1.226
+++ cpplex.c	20 Apr 2003 16:43:18 -0000
@@ -148,15 +148,14 @@ _cpp_clean_line (pfile)
 	      if (p == buffer->next_line || p[-1] != '\\')
 		break;
 
-	      add_line_note (buffer, p - 1,
-			     p != d ? NOTE_ESC_SPACE_NL: NOTE_ESC_NL);
+	      add_line_note (buffer, p - 1, p != d ? ' ': '\\');
 	      d = p - 2;
 	      buffer->next_line = p - 1;
 	    }
 	  else if (c == '?' && s[1] == '?' && _cpp_trigraph_map[s[2]])
 	    {
 	      /* Add a note regardless, for the benefit of -Wtrigraphs.  */
-	      add_line_note (buffer, d, NOTE_TRIGRAPH);
+	      add_line_note (buffer, d, s[2]);
 	      if (CPP_OPTION (pfile, trigraphs))
 		{
 		  *d = _cpp_trigraph_map[s[2]];
@@ -178,7 +177,8 @@ _cpp_clean_line (pfile)
     }
 
   *d = '\n';
-  add_line_note (buffer, d + 1, NOTE_NEWLINE);
+  /* A sentinel note that should never be processed.  */
+  add_line_note (buffer, d + 1, '\n');
   buffer->next_line = s + 1;
 }
 
@@ -202,32 +202,12 @@ _cpp_process_line_notes (pfile, in_comme
       buffer->cur_note++;
       col = CPP_BUF_COLUMN (buffer, note->pos + 1);
 
-      switch (note->type)
+      if (note->type == '\\' || note->type == ' ')
 	{
-	case NOTE_NEWLINE:
-	  /* This note is a kind of sentinel we should never reach.  */
-	  abort ();
-
-	case NOTE_TRIGRAPH:
-	  if (!in_comment && CPP_OPTION (pfile, warn_trigraphs))
-	    {
-	      if (CPP_OPTION (pfile, trigraphs))
-		cpp_error_with_line (pfile, DL_WARNING, pfile->line, col,
-				     "trigraph converted to %c",
-				     (int) note->pos[0]);
-	      else
-		cpp_error_with_line (pfile, DL_WARNING, pfile->line, col,
-				     "trigraph ??%c ignored",
-				     (int) note->pos[2]);
-	    }
-	  break;
-
-	case NOTE_ESC_SPACE_NL:
-	  if (!in_comment)
+	  if (note->type == ' ' && !in_comment)
 	    cpp_error_with_line (pfile, DL_WARNING, pfile->line, col,
 				 "backslash and newline separated by space");
-	  /* Fall through... */
-	case NOTE_ESC_NL:
+
 	  if (buffer->next_line > buffer->rlimit)
 	    {
 	      cpp_error_with_line (pfile, DL_PEDWARN, pfile->line, col,
@@ -239,6 +219,23 @@ _cpp_process_line_notes (pfile, in_comme
 	  buffer->line_base = note->pos;
 	  pfile->line++;
 	}
+      else if (_cpp_trigraph_map[note->type])
+	{
+	  if (!in_comment && CPP_OPTION (pfile, warn_trigraphs))
+	    {
+	      if (CPP_OPTION (pfile, trigraphs))
+		cpp_error_with_line (pfile, DL_WARNING, pfile->line, col,
+				     "trigraph ??%c converted to %c",
+				     note->type,
+				     (int) _cpp_trigraph_map[note->type]);
+	      else
+		cpp_error_with_line (pfile, DL_WARNING, pfile->line, col,
+				     "trigraph ??%c ignored",
+				     note->type);
+	    }
+	}
+      else
+	abort ();
     }
 }
 



More information about the Gcc-patches mailing list