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]

RFA: change c_lex() prototype


It's more natural for c_lex() to return a token rather than a token
type.  This allows me to remove the function cpp_type2name, and with
the extra information simplify some diagnostic routines in the front
ends.

Bootstrapped without regressions on x86 Linux.  Compiled the altered
files successfully on a target for each of i960, c4x, powerpc-darwin,
i370 and v850.

OK to commit?

Neil.

	* c-lex.c: Include cpplib.h earlier.
	(c_lex): Change prototype.
	* c-lex.h (c_lex): Similarly.
	* c-parse.in (yyprint, yyerror, last_token, _yylex):
	Update to handle token pointers.
	(NAME): Remove.
	* c-pragma.c (handle_pragma_pack): Update for new c_lex prototype.
	(handle_pragma_weak): Similarly.
	* cpplex.c (token_spellings): Non-operators no longer have spellings.
	(cpp_spell_token, cpp_output_token): Update.
	(cpp_type2name): Remove.
	* cpplib.h (cpp_type2name): Remove.

	* cp/lex.c (parse_strconst_pragma,
	handle_pragma_java_exceptions): Update.
	* cp/spew.c (last_token, read_token, yyerror): Update to handle
	token pointers.
	(NAME): Remove.

	* config/darwin-c.c (darwin_pragma_options, darwin_pragma_unused):
	Update.
	* config/c4x/c4x.c (c_lex_func, c4x_init_pragma,
	c4x_parse_pragma): Update.
	config/c4x/c4x-protos.h (c4x_init_pragma): Update prototype.
	* config/i370/i370.c (i370_pr_map): Update.
	* config/i960/i960-c.c (i960_pr_align, i960_pr_noalign): Update.
	* config/v850/v850-c.c (ghs_pragma_section,
	ghs_pragma_interrupt, ghs_pragma_starttda, ghs_pragma_startsda,
	ghs_pragma_startzda, ghs_pragma_endtda, ghs_pragma_endsda,
	ghs_pragma_endzda): Update.

============================================================
Index: gcc/c-lex.c
--- gcc/c-lex.c	2001/10/07 16:50:50	1.153
+++ gcc/c-lex.c	2001/10/13 17:32:57
@@ -27,11 +27,11 @@ Software Foundation, 59 Temple Place - S
 #include "tree.h"
 #include "input.h"
 #include "output.h"
+#include "cpplib.h"
 #include "c-lex.h"
 #include "c-tree.h"
 #include "flags.h"
 #include "timevar.h"
-#include "cpplib.h"
 #include "c-pragma.h"
 #include "toplev.h"
 #include "intl.h"
@@ -763,7 +763,7 @@ parse_float (data)
     warning ("floating point number exceeds range of '%s'", typename);
 }
  
-int
+const cpp_token *
 c_lex (value)
      tree *value;
 {
@@ -823,7 +823,7 @@ c_lex (value)
     default: break;
     }
 
-  return tok->type;
+  return tok;
 }
 
 #define ERROR(msgid) do { error(msgid); goto syntax_error; } while(0)
============================================================
Index: gcc/c-lex.h
--- gcc/c-lex.h	2001/08/22 14:34:45	1.24
+++ gcc/c-lex.h	2001/10/13 17:32:58
@@ -24,7 +24,7 @@ Software Foundation, 59 Temple Place - S
 extern tree make_pointer_declarator PARAMS ((tree, tree));
 extern void position_after_white_space PARAMS ((void));
 
-extern int c_lex PARAMS ((tree *));
+extern const cpp_token *c_lex PARAMS ((tree *));
 extern const char *init_c_lex PARAMS ((const char *));
 
 extern int indent_level;
============================================================
Index: gcc/c-parse.in
--- gcc/c-parse.in	2001/10/11 07:07:26	1.108
+++ gcc/c-parse.in	2001/10/13 17:33:04
@@ -300,9 +300,9 @@ end ifc
 
 /* Tell yyparse how to print a token's value, if yydebug is set.  */
 
-#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
+#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE)
 
-static void yyprint	  PARAMS ((FILE *, int, YYSTYPE));
+static void yyprint	  PARAMS ((FILE *));
 static void yyerror	  PARAMS ((const char *));
 static int yylexname	  PARAMS ((void));
 static inline int _yylex  PARAMS ((void));
@@ -3244,7 +3244,7 @@ end ifobjc
 /* yylex() is a thin wrapper around c_lex(), all it does is translate
    cpplib.h's token codes into yacc's token codes.  */
 
-static enum cpp_ttype last_token;
+static const cpp_token *last_token;
 
 /* The reserved keyword table.  */
 struct resword
@@ -3563,34 +3563,30 @@ finish_parse ()
   errorcount += cpp_errors (parse_in);
 }
 
-#define NAME(type) cpp_type2name (type)
-
+/* Simple diagnostics that mention the following token.  */
 static void
 yyerror (msgid)
      const char *msgid;
 {
   const char *string = _(msgid);
 
-  if (last_token == CPP_EOF)
-    error ("%s at end of input", string);
-  else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
+  switch (last_token->type)
     {
-      unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
-      const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
-      if (val <= UCHAR_MAX && ISGRAPH (val))
-	error ("%s before %s'%c'", string, ell, val);
-      else
-	error ("%s before %s'\\x%x'", string, ell, val);
+    case CPP_EOF:
+      error ("%s at end of input", string);
+      break;
+
+    case CPP_STRING:
+    case CPP_WSTRING:
+      error ("%s before string literal %s",
+	     string, cpp_token_as_text (parse_in, last_token));
+      break;
+
+    default:
+      error ("%s before \"%s\" token",
+	     string, cpp_token_as_text (parse_in, last_token));
+      break;
     }
-  else if (last_token == CPP_STRING
-	   || last_token == CPP_WSTRING)
-    error ("%s before string constant", string);
-  else if (last_token == CPP_NUMBER)
-    error ("%s before numeric constant", string);
-  else if (last_token == CPP_NAME)
-    error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
-  else
-    error ("%s before '%s' token", string, NAME(last_token));
 }
 
 static int
@@ -3629,7 +3625,6 @@ end ifobjc
 	    const char *name = fname_string (rid_code);
 	  
 	    yylval.ttype = build_string (strlen (name) + 1, name);
-	    last_token = CPP_STRING;  /* so yyerror won't choke */
 	    return STRING;
 	  }
       
@@ -3670,7 +3665,7 @@ _yylex ()
 {
  get_next:
   last_token = c_lex (&yylval.ttype);
-  switch (last_token)
+  switch (last_token->type)
     {
     case CPP_EQ:					return '=';
     case CPP_NOT:					return '!';
@@ -3747,16 +3742,15 @@ _yylex ()
 ifobjc
       {
 	tree after_at;
-	enum cpp_ttype after_at_type;
+	const cpp_token *after_at_token;
 
-	after_at_type = c_lex (&after_at);
+	after_at_token = c_lex (&after_at);
 
-	if (after_at_type == CPP_NAME
+	if (after_at_token->type == CPP_NAME
 	    && C_IS_RESERVED_WORD (after_at)
 	    && OBJC_IS_AT_KEYWORD (C_RID_CODE (after_at)))
 	  {
 	    yylval.ttype = after_at;
-	    last_token = after_at_type;
 	    return rid_to_yy [(int) C_RID_CODE (after_at)];
 	  }
 	_cpp_backup_tokens (parse_in, 1);
@@ -3776,7 +3770,8 @@ end ifobjc
       /* These tokens should not survive translation phase 4.  */
     case CPP_HASH:
     case CPP_PASTE:
-      error ("syntax error at '%s' token", NAME(last_token));
+      error ("syntax error at \"%s\" token",
+	     cpp_token_as_text (parse_in, last_token));
       goto get_next;
 
     default:
@@ -3813,51 +3808,10 @@ set_yydebug (value)
 /* Function used when yydebug is set, to print a token in more detail.  */
 
 static void
-yyprint (file, yychar, yyl)
+yyprint (file)
      FILE *file;
-     int yychar;
-     YYSTYPE yyl;
 {
-  tree t = yyl.ttype;
-
-  fprintf (file, " [%s]", NAME(last_token));
-  
-  switch (yychar)
-    {
-    case IDENTIFIER:
-    case TYPENAME:
-    case OBJECTNAME:
-    case TYPESPEC:
-    case TYPE_QUAL:
-    case SCSPEC:
-      if (IDENTIFIER_POINTER (t))
-	fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
-      break;
-
-    case CONSTANT:
-      fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
-      if (TREE_CODE (t) == INTEGER_CST)
-	fprintf (file,
-#if HOST_BITS_PER_WIDE_INT == 64
-#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
-		 " 0x%x%016x",
-#else
-#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
-		 " 0x%lx%016lx",
-#else
-		 " 0x%llx%016llx",
-#endif
-#endif
-#else
-#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
-		 " 0x%lx%08lx",
-#else
-		 " 0x%x%08x",
-#endif
-#endif
-		 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
-      break;
-    }
+  fprintf (file, " [%s]", cpp_token_as_text (parse_in, last_token));
 }
 
 /* This is not the ideal place to put these, but we have to get them out
============================================================
Index: gcc/c-pragma.c
--- gcc/c-pragma.c	2001/08/31 19:27:12	1.45
+++ gcc/c-pragma.c	2001/10/13 17:33:05
@@ -180,10 +180,10 @@ handle_pragma_pack (dummy)
   enum cpp_ttype token;
   enum { set, push, pop } action;
 
-  if (c_lex (&x) != CPP_OPEN_PAREN)
+  if (c_lex (&x)->type != CPP_OPEN_PAREN)
     BAD ("missing '(' after '#pragma pack' - ignored");
 
-  token = c_lex (&x);
+  token = c_lex (&x)->type;
   if (token == CPP_CLOSE_PAREN)
     {
       action = set;
@@ -193,7 +193,7 @@ handle_pragma_pack (dummy)
     {
       align = TREE_INT_CST_LOW (x);
       action = set;
-      if (c_lex (&x) != CPP_CLOSE_PAREN)
+      if (c_lex (&x)->type != CPP_CLOSE_PAREN)
 	BAD ("malformed '#pragma pack' - ignored");
     }
   else if (token == CPP_NAME)
@@ -212,19 +212,19 @@ handle_pragma_pack (dummy)
       else
 	BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
 
-      token = c_lex (&x);
+      token = c_lex (&x)->type;
       if (token != CPP_COMMA && action == push)
 	BAD_ACTION;
 
       if (token == CPP_COMMA)
 	{
-	  token = c_lex (&x);
+	  token = c_lex (&x)->type;
 	  if (token == CPP_NAME)
 	    {
 	      id = x;
-	      if (action == push && c_lex (&x) != CPP_COMMA)
+	      if (action == push && c_lex (&x)->type != CPP_COMMA)
 		BAD_ACTION;
-	      token = c_lex (&x);
+	      token = c_lex (&x)->type;
 	    }
 
 	  if (action == push)
@@ -232,7 +232,7 @@ handle_pragma_pack (dummy)
 	      if (token == CPP_NUMBER)
 		{
 		  align = TREE_INT_CST_LOW (x);
-		  token = c_lex (&x);
+		  token = c_lex (&x)->type;
 		}
 	      else
 		BAD_ACTION;
@@ -246,7 +246,7 @@ handle_pragma_pack (dummy)
   else
     BAD ("malformed '#pragma pack' - ignored");
 
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of '#pragma pack'");
 
   if (action != pop)
@@ -286,14 +286,14 @@ handle_pragma_weak (dummy)
 
   value = 0;
 
-  if (c_lex (&name) != CPP_NAME)
+  if (c_lex (&name)->type != CPP_NAME)
     BAD ("malformed #pragma weak, ignored");
-  t = c_lex (&x);
+  t = c_lex (&x)->type;
   if (t == CPP_EQ)
     {
-      if (c_lex (&value) != CPP_NAME)
+      if (c_lex (&value)->type != CPP_NAME)
 	BAD ("malformed #pragma weak, ignored");
-      t = c_lex (&x);
+      t = c_lex (&x)->type;
     }
   if (t != CPP_EOF)
     warning ("junk at end of #pragma weak");
============================================================
Index: gcc/cpplex.c
--- gcc/cpplex.c	2001/10/11 21:21:57	1.175
+++ gcc/cpplex.c	2001/10/13 17:33:14
@@ -72,8 +72,8 @@ struct token_spelling
 static const unsigned char *const digraph_spellings[] =
 { U"%:", U"%:%:", U"<:", U":>", U"<%", U"%>" };
 
-#define OP(e, s) { SPELL_OPERATOR, U s           },
-#define TK(e, s) { s,              U STRINGX (e) },
+#define OP(e, s) { SPELL_OPERATOR, U s  },
+#define TK(e, s) { s,              NULL },
 static const struct token_spelling token_spellings[N_TTYPES] = { TTYPE_TABLE };
 #undef OP
 #undef TK
@@ -1477,7 +1477,7 @@ cpp_spell_token (pfile, token, buffer)
     	  case CPP_WCHAR:	left = '\''; right = '\''; tag = 'L';  break;
 	  case CPP_HEADER_NAME:	left = '<';  right = '>';  tag = '\0'; break;
 	  default:
-	    cpp_ice (pfile, "unknown string token %s\n", TOKEN_NAME (token));
+	    cpp_ice (pfile, "impossible string token, code %u", token->type);
 	    return buffer;
 	  }
 	if (tag) *buffer++ = tag;
@@ -1489,7 +1489,7 @@ cpp_spell_token (pfile, token, buffer)
       break;
 
     case SPELL_NONE:
-      cpp_ice (pfile, "Unspellable token %s", TOKEN_NAME (token));
+      cpp_ice (pfile, "unspellable token, code %u", token->type);
       break;
     }
 
@@ -1512,14 +1512,6 @@ cpp_token_as_text (pfile, token)
   return start;
 }
 
-/* Used by C front ends.  Should really move to using cpp_token_as_text.  */
-const char *
-cpp_type2name (type)
-     enum cpp_ttype type;
-{
-  return (const char *) token_spellings[type].name;
-}
-
 /* Writes the spelling of token to FP, without any preceding space.
    Separated from cpp_spell_token for efficiency - to avoid stdio
    double-buffering.  */
@@ -1574,7 +1566,7 @@ cpp_output_token (token, fp)
     	  case CPP_WCHAR:	left = '\''; right = '\''; tag = 'L';  break;
 	  case CPP_HEADER_NAME:	left = '<';  right = '>';  tag = '\0'; break;
 	  default:
-	    fprintf (stderr, "impossible STRING token %s\n", TOKEN_NAME (token));
+	    fprintf (stderr, "impossible string token, code %u", token->type);
 	    return;
 	  }
 	if (tag) putc (tag, fp);
============================================================
Index: gcc/cpplib.h
--- gcc/cpplib.h	2001/10/11 12:43:39	1.196
+++ gcc/cpplib.h	2001/10/13 17:33:14
@@ -552,7 +552,6 @@ extern int cpp_ideq			PARAMS ((const cpp
 						 const char *));
 extern void cpp_output_line		PARAMS ((cpp_reader *, FILE *));
 extern void cpp_output_token		PARAMS ((const cpp_token *, FILE *));
-extern const char *cpp_type2name	PARAMS ((enum cpp_ttype));
 extern unsigned int cpp_parse_escape	PARAMS ((cpp_reader *,
 						 const unsigned char **,
 						 const unsigned char *,
============================================================
Index: gcc/config/darwin-c.c
--- gcc/config/darwin-c.c	2001/06/28 19:55:52	1.1
+++ gcc/config/darwin-c.c	2001/10/13 17:33:15
@@ -94,17 +94,17 @@ darwin_pragma_options (pfile)
   char *arg;
   tree t, x;
 
-  if (c_lex (&t) != CPP_NAME)
+  if (c_lex (&t)->type != CPP_NAME)
     BAD ("malformed '#pragma options', ignoring");
   arg = IDENTIFIER_POINTER (t);
   if (strcmp (arg, "align"))
     BAD ("malformed '#pragma options', ignoring");
-  if (c_lex (&t) != CPP_EQ)
+  if (c_lex (&t)->type != CPP_EQ)
     BAD ("malformed '#pragma options', ignoring");
-  if (c_lex (&t) != CPP_NAME)
+  if (c_lex (&t)->type != CPP_NAME)
     BAD ("malformed '#pragma options', ignoring");
 
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of '#pragma options'");
 
   arg = IDENTIFIER_POINTER (t);
@@ -127,19 +127,19 @@ darwin_pragma_unused (pfile)
   tree decl, x;
   int tok;
 
-  if (c_lex (&x) != CPP_OPEN_PAREN)
+  if (c_lex (&x)->type != CPP_OPEN_PAREN)
     BAD ("missing '(' after '#pragma unused', ignoring");
 
   while (1)
     {
-      tok = c_lex (&decl);
+      tok = c_lex (&decl)->type;
       if (tok == CPP_NAME && decl)
 	{
 	  tree local = IDENTIFIER_LOCAL_VALUE (decl);
 	  if (local && (TREE_CODE (local) == PARM_DECL
 			|| TREE_CODE (local) == VAR_DECL))
 	    TREE_USED (local) = 1;
-	  tok = c_lex (&x);
+	  tok = c_lex (&x)->type;
 	  if (tok != CPP_COMMA)
 	    break;
 	}
@@ -148,6 +148,6 @@ darwin_pragma_unused (pfile)
   if (tok != CPP_CLOSE_PAREN)
     BAD ("missing ')' after '#pragma unused', ignoring");
 
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of '#pragma unused'");
 }
============================================================
Index: gcc/config/c4x/c4x-protos.h
--- gcc/config/c4x/c4x-protos.h	2001/08/18 20:25:51	1.21
+++ gcc/config/c4x/c4x-protos.h	2001/10/13 17:33:15
@@ -304,7 +304,7 @@ extern void c4x_pr_FUNC_IS_PURE		PARAMS 
 extern void c4x_pr_FUNC_NEVER_RETURNS	PARAMS ((cpp_reader *));
 extern void c4x_pr_INTERRUPT		PARAMS ((cpp_reader *));
 extern void c4x_pr_ignored		PARAMS ((cpp_reader *));
-extern void c4x_init_pragma		PARAMS ((int (*) (tree *)));
+extern void c4x_init_pragma		PARAMS ((const cpp_token * (*) (tree *)));
 #endif
 
 #endif /* ! GCC_C4X_PROTOS_H */
============================================================
Index: gcc/config/c4x/c4x.c
--- gcc/config/c4x/c4x.c	2001/10/07 16:51:09	1.95
+++ gcc/config/c4x/c4x.c	2001/10/13 17:33:20
@@ -4512,11 +4512,11 @@ c4x_operand_subword (op, i, validate_add
    -1 for a malformed pragma.  */
 #define BAD(msgid, arg) do { warning (msgid, arg); return -1; } while (0)
 
-static int (*c_lex_func) (tree *);
+static const cpp_token * (*c_lex_func) (tree *);
 
 void
 c4x_init_pragma (get_token)
-  int (*get_token) PARAMS ((tree *));
+  const cpp_token * (*get_token) PARAMS ((tree *));
 {
   c_lex_func = get_token;
 }
@@ -4530,25 +4530,25 @@ c4x_parse_pragma (name, func, sect)
 {
   tree f, s, x;
 
-  if (c_lex_func (&x) != CPP_OPEN_PAREN)
+  if (c_lex_func (&x)->type != CPP_OPEN_PAREN)
     BAD ("missing '(' after '#pragma %s' - ignored", name);
 
-  if (c_lex_func (&f) != CPP_NAME)
+  if (c_lex_func (&f)->type != CPP_NAME)
     BAD ("missing function name in '#pragma %s' - ignored", name);
 
   if (sect)
     {
-      if (c_lex_func (&x) != CPP_COMMA)
+      if (c_lex_func (&x)->type != CPP_COMMA)
 	BAD ("malformed '#pragma %s' - ignored", name);
-      if (c_lex_func (&s) != CPP_STRING)
+      if (c_lex_func (&s)->type != CPP_STRING)
 	BAD ("missing section name in '#pragma %s' - ignored", name);
       *sect = s;
     }
 
-  if (c_lex_func (&x) != CPP_CLOSE_PAREN)
+  if (c_lex_func (&x)->type != CPP_CLOSE_PAREN)
     BAD ("missing ')' for '#pragma %s' - ignored", name);
 
-  if (c_lex_func (&x) != CPP_EOF)
+  if (c_lex_func (&x)->type != CPP_EOF)
     warning ("junk at end of '#pragma %s'", name);
 
   *func = f;
============================================================
Index: gcc/config/i370/i370.c
--- gcc/config/i370/i370.c	2001/08/10 16:19:18	1.20
+++ gcc/config/i370/i370.c	2001/10/13 17:33:24
@@ -1042,13 +1042,13 @@ i370_pr_map (pfile)
 {
   tree name, alias, x;
 
-  if (c_lex (&x)        == CPP_OPEN_PAREN
-      && c_lex (&name)  == CPP_NAME
-      && c_lex (&x)     == CPP_COMMA
-      && c_lex (&alias) == CPP_NAME
-      && c_lex (&x)     == CPP_CLOSE_PAREN)
+  if (c_lex (&x)->type        == CPP_OPEN_PAREN
+      && c_lex (&name)->type  == CPP_NAME
+      && c_lex (&x)->type     == CPP_COMMA
+      && c_lex (&alias)->type == CPP_NAME
+      && c_lex (&x)->type     == CPP_CLOSE_PAREN)
     {
-      if (c_lex (&x) != CPP_EOF)
+      if (c_lex (&x)->type != CPP_EOF)
 	warning ("junk at end of #pragma map");
 
       mvs_add_alias (IDENTIFIER_POINTER (name), IDENTIFIER_POINTER (alias), 1);
============================================================
Index: gcc/config/i960/i960-c.c
--- gcc/config/i960/i960-c.c	2001/03/15 16:29:10	1.1
+++ gcc/config/i960/i960-c.c	2001/10/13 17:33:25
@@ -59,9 +59,9 @@ i960_pr_align (pfile)
   enum cpp_ttype type;
   int align;
 
-  type = c_lex (&number);
+  type = c_lex (&number)->type;
   if (type == CPP_OPEN_PAREN)
-    type = c_lex (&number);
+    type = c_lex (&number)->type;
   if (type == CPP_NAME)
     {
       warning ("sorry, not implemented: #pragma align NAME=SIZE");
@@ -102,9 +102,9 @@ i960_pr_noalign (pfile)
   enum cpp_ttype type;
   tree number;
 
-  type = c_lex (&number);
+  type = c_lex (&number)->type;
   if (type == CPP_OPEN_PAREN)
-    type = c_lex (&number);
+    type = c_lex (&number)->type;
   if (type == CPP_NAME)
     {
       warning ("sorry, not implemented: #pragma noalign NAME");
============================================================
Index: gcc/config/v850/v850-c.c
--- gcc/config/v850/v850-c.c	2001/09/21 01:27:06	1.2
+++ gcc/config/v850/v850-c.c	2001/10/13 17:33:25
@@ -125,7 +125,7 @@ ghs_pragma_section (pfile)
       const char *sect, *alias;
       enum GHS_section_kind kind;
       
-      type = c_lex (&x);
+      type = c_lex (&x)->type;
       
       if (type == CPP_EOF && !repeat)
 	goto reset;
@@ -135,14 +135,14 @@ ghs_pragma_section (pfile)
 	goto bad;
       repeat = 0;
       
-      if (c_lex (&x) != CPP_EQ)
+      if (c_lex (&x)->type != CPP_EQ)
 	goto bad;
-      if (c_lex (&x) != CPP_NAME)
+      if (c_lex (&x)->type != CPP_NAME)
 	goto bad;
       
       alias = IDENTIFIER_POINTER (x);
       
-      type = c_lex (&x);
+      type = c_lex (&x)->type;
       if (type == CPP_COMMA)
 	repeat = 1;
       else if (type != CPP_EOF)
@@ -197,7 +197,7 @@ ghs_pragma_interrupt (pfile)
 {
   tree x;
   
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of #pragma ghs interrupt");
   
   mark_current_function_as_interrupt ();
@@ -209,7 +209,7 @@ ghs_pragma_starttda (pfile)
 {
   tree x;
   
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of #pragma ghs starttda");
   
   push_data_area (DATA_AREA_TDA);
@@ -221,7 +221,7 @@ ghs_pragma_startsda (pfile)
 {
   tree x;
   
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of #pragma ghs startsda");
   
   push_data_area (DATA_AREA_SDA);
@@ -233,7 +233,7 @@ ghs_pragma_startzda (pfile)
 {
   tree x;
   
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of #pragma ghs startzda");
   
   push_data_area (DATA_AREA_ZDA);
@@ -245,7 +245,7 @@ ghs_pragma_endtda (pfile)
 {
   tree x;
   
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of #pragma ghs endtda");
   
   pop_data_area (DATA_AREA_TDA);
@@ -257,7 +257,7 @@ ghs_pragma_endsda (pfile)
 {
   tree x;
   
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of #pragma ghs endsda");
   
   pop_data_area (DATA_AREA_SDA);
@@ -269,7 +269,7 @@ ghs_pragma_endzda (pfile)
 {
   tree x;
   
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of #pragma ghs endzda");
   
   pop_data_area (DATA_AREA_ZDA);
============================================================
Index: gcc/cp/lex.c
--- gcc/cp/lex.c	2001/10/13 13:24:34	1.251
+++ gcc/cp/lex.c	2001/10/13 17:33:29
@@ -1059,11 +1059,11 @@ parse_strconst_pragma (name, opt)
   tree result, x;
   enum cpp_ttype t;
 
-  t = c_lex (&x);
+  t = c_lex (&x)->type;
   if (t == CPP_STRING)
     {
       result = x;
-      if (c_lex (&x) != CPP_EOF)
+      if (c_lex (&x)->type != CPP_EOF)
 	warning ("junk at end of #pragma %s", name);
       return result;
     }
@@ -1181,7 +1181,7 @@ handle_pragma_java_exceptions (dfile)
      cpp_reader *dfile ATTRIBUTE_UNUSED;
 {
   tree x;
-  if (c_lex (&x) != CPP_EOF)
+  if (c_lex (&x)->type != CPP_EOF)
     warning ("junk at end of #pragma GCC java_exceptions");
 
   choose_personality_routine (lang_java);
============================================================
Index: gcc/cp/spew.c
--- gcc/cp/spew.c	2001/10/02 15:43:44	1.53
+++ gcc/cp/spew.c	2001/10/13 17:33:31
@@ -138,7 +138,7 @@ static void debug_yychar PARAMS ((int));
 /* In parse.y: */
 extern char *debug_yytranslate PARAMS ((int));
 #endif
-static enum cpp_ttype last_token;
+static const cpp_token *last_token;
 static tree last_token_id;
 
 /* From lex.c: */
@@ -262,7 +262,7 @@ read_token (t)
   last_token = c_lex (&last_token_id);
   t->yylval.ttype = last_token_id;
 
-  switch (last_token)
+  switch (last_token->type)
     {
 #define YYCHAR(yy)	t->yychar = yy;	break;
 #define YYCODE(c)	t->yylval.code = c;
@@ -1468,39 +1468,28 @@ debug_yychar (yy)
 
 #endif
 
-#define NAME(type) cpp_type2name (type)
-
+/* Simple diagnostics that mention the following token.  */
 void
 yyerror (msgid)
      const char *msgid;
 {
   const char *string = _(msgid);
 
-  if (last_token == CPP_EOF)
-    error ("%s at end of input", string);
-  else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
-    {
-      unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
-      const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
-      if (val <= UCHAR_MAX && ISGRAPH (val))
-	error ("%s before %s'%c'", string, ell, val);
-      else
-	error ("%s before %s'\\x%x'", string, ell, val);
-    }
-  else if (last_token == CPP_STRING
-	   || last_token == CPP_WSTRING)
-    error ("%s before string constant", string);
-  else if (last_token == CPP_NUMBER)
-    error ("%s before numeric constant", string);
-  else if (last_token == CPP_NAME)
-    {
-      if (TREE_CODE (last_token_id) == IDENTIFIER_NODE)
-        error ("%s before `%s'", string, IDENTIFIER_POINTER (last_token_id));
-      else if (ISGRAPH (yychar))
-        error ("%s before `%c'", string, yychar);
-      else
-	error ("%s before `\%o'", string, yychar);
+  switch (last_token->type)
+    {
+    case CPP_EOF:
+      error ("%s at end of input", string);
+      break;
+
+    case CPP_STRING:
+    case CPP_WSTRING:
+      error ("%s before string literal %s",
+	     string, cpp_token_as_text (parse_in, last_token));
+      break;
+
+    default:
+      error ("%s before \"%s\" token",
+	     string, cpp_token_as_text (parse_in, last_token));
+      break;
     }
-  else
-    error ("%s before `%s' token", string, NAME (last_token));
 }


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