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]

cpplib: Tweak CPP_OTHER tokens


This patch has us storing CPP_OTHER tokens with their spellig, rather
than the character.

I have two reasons for wanting this: more uniform spelling, moving
towards the case where every token's spelling is what appears in the
cleaned lines, and that it's convenient to make unterminated literals
have type CPP_OTHER.  If I do that, we can have unterminated charconsts
and literals in skipped blocks, for example, without diagnostics.  It's
also nice to be able to -E preprocess unterminated literals without
diagnostics, provided they're not in directives.  It would also mean
that -lang-asm ceases to be a special case for this.

Some time soon I want to make CPP_OTHER tokens internal to cpplib, and
not to leak out to c-lex.c, but that's for later.

Neil.

	* c-lex.c (c_lex): Handle CPP_OTHER differently.
	* cppexp.c (_cpp_parse_expr): Similarly.
	* cpplex.c (SPELL_CHAR): Remove.
	(_cpp_lex_direct): Stray chars are saved as byte strings.
	(cpp_spell_token, cpp_output_token, _cpp_equiv_token): Don't
	handle SPELL_CHAR.
	(cpp_avoid_paste): Update handling of CPP_OTHER.
	* cpplib.h: Spell CPP_OTHER like a number.
	(struct cpp_token): Remove member c.
	* cppmacro.c (stringify_arg): Update handling of CPP_OTHER.

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.200
diff -u -p -r1.200 c-lex.c
--- c-lex.c	20 Apr 2003 07:29:19 -0000	1.200
+++ c-lex.c	21 Apr 2003 21:06:35 -0000
@@ -346,10 +346,8 @@ c_lex (value)
     {
     /* Issue this error here, where we can get at tok->val.c.  */
     case CPP_OTHER:
-      if (ISGRAPH (tok->val.c))
-	error ("stray '%c' in program", tok->val.c);
-      else
-	error ("stray '\\%o' in program", tok->val.c);
+      error ("stray token \"%s\" in program",
+	     cpp_token_as_text (parse_in, tok));
       goto retry;
       
     case CPP_NAME:
Index: cppexp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppexp.c,v
retrieving revision 1.138
diff -u -p -r1.138 cppexp.c
--- cppexp.c	19 Apr 2003 10:04:21 -0000	1.138
+++ cppexp.c	21 Apr 2003 21:06:36 -0000
@@ -746,12 +746,6 @@ _cpp_parse_expr (pfile)
 	  if (want_value)
 	    op.op = CPP_UMINUS;
 	  break;
-	case CPP_OTHER:
-	  if (ISGRAPH (op.token->val.c))
-	    SYNTAX_ERROR2 ("invalid character '%c' in #if", op.token->val.c);
-	  else
-	    SYNTAX_ERROR2 ("invalid character '\\%03o' in #if",
-			   op.token->val.c);
 
 	default:
 	  if ((int) op.op <= (int) CPP_EQ || (int) op.op >= (int) CPP_PLUS_EQ)
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.227
diff -u -p -r1.227 cpplex.c
--- cpplex.c	20 Apr 2003 19:02:52 -0000	1.227
+++ cpplex.c	21 Apr 2003 21:06:36 -0000
@@ -31,7 +31,6 @@ Foundation, 59 Temple Place - Suite 330,
 enum spell_type
 {
   SPELL_OPERATOR = 0,
-  SPELL_CHAR,
   SPELL_IDENT,
   SPELL_NUMBER,
   SPELL_STRING,
@@ -1076,10 +1075,16 @@ _cpp_lex_direct (pfile)
 	    break;
 	  }
 	buffer->cur++;
+      }
 
-      default:
+    default:
+      {
+	uchar *dest = _cpp_unaligned_alloc (pfile, 1 + 1);
+	dest[0] = c;
+	dest[1] = '\0';
 	result->type = CPP_OTHER;
-	result->val.c = c;
+	result->val.str.len = 1;
+	result->val.str.text = dest;
 	break;
       }
     }
@@ -1136,10 +1141,6 @@ cpp_spell_token (pfile, token, buffer)
       }
       break;
 
-    case SPELL_CHAR:
-      *buffer++ = token->val.c;
-      break;
-
     spell_ident:
     case SPELL_IDENT:
       memcpy (buffer, NODE_NAME (token->val.node), NODE_LEN (token->val.node));
@@ -1237,10 +1238,6 @@ cpp_output_token (token, fp)
       }
       break;
 
-    case SPELL_CHAR:
-      putc (token->val.c, fp);
-      break;
-
     spell_ident:
     case SPELL_IDENT:
       fwrite (NODE_NAME (token->val.node), 1, NODE_LEN (token->val.node), fp);
@@ -1288,8 +1285,6 @@ _cpp_equiv_tokens (a, b)
       default:			/* Keep compiler happy.  */
       case SPELL_OPERATOR:
 	return 1;
-      case SPELL_CHAR:
-	return a->val.c == b->val.c; /* Character.  */
       case SPELL_NONE:
 	return (a->type != CPP_MACRO_ARG || a->val.arg_no == b->val.arg_no);
       case SPELL_IDENT:
@@ -1352,9 +1347,10 @@ cpp_avoid_paste (pfile, token1, token2)
     case CPP_NUMBER:	return (b == CPP_NUMBER || b == CPP_NAME
 				|| c == '.' || c == '+' || c == '-');
 				      /* UCNs */
-    case CPP_OTHER:	return ((token1->val.c == '\\' && b == CPP_NAME)
+    case CPP_OTHER:	return ((token1->val.str.text[0] == '\\'
+				 && b == CPP_NAME)
 				|| (CPP_OPTION (pfile, objc)
-				    && token1->val.c == '@'
+				    && token1->val.str.text[0] == '@'
 				    && (b == CPP_NAME || b == CPP_STRING)));
     default:		break;
     }
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.251
diff -u -p -r1.251 cpplib.h
--- cpplib.h	21 Apr 2003 19:21:59 -0000	1.251
+++ cpplib.h	21 Apr 2003 21:06:36 -0000
@@ -128,7 +128,7 @@ struct file_name_map_list;
 \
   TK(CPP_CHAR,		SPELL_STRING)	/* 'char' */			\
   TK(CPP_WCHAR,		SPELL_STRING)	/* L'char' */			\
-  TK(CPP_OTHER,		SPELL_CHAR)	/* stray punctuation */		\
+  TK(CPP_OTHER,		SPELL_NUMBER)	/* stray punctuation */		\
 \
   TK(CPP_STRING,	SPELL_STRING)	/* "string" */			\
   TK(CPP_WSTRING,	SPELL_STRING)	/* L"string" */			\
@@ -184,7 +184,6 @@ struct cpp_token
     const cpp_token *source;	/* Inherit padding from this token.  */
     struct cpp_string str;	/* A string, or number.  */
     unsigned int arg_no;	/* Argument no. for a CPP_MACRO_ARG.  */
-    unsigned char c;		/* Character represented by CPP_OTHER.  */
   } val;
 };
 
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.130
diff -u -p -r1.130 cppmacro.c
--- cppmacro.c	19 Apr 2003 00:22:49 -0000	1.130
+++ cppmacro.c	21 Apr 2003 21:06:37 -0000
@@ -395,7 +395,7 @@ stringify_arg (pfile, arg)
       else
 	dest = cpp_spell_token (pfile, token, dest);
 
-      if (token->type == CPP_OTHER && token->val.c == '\\')
+      if (token->type == CPP_OTHER && token->val.str.text[0] == '\\')
 	backslash_count++;
       else
 	backslash_count = 0;


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