diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 044dc2cd5c5..f2dc8c7220d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2003-04-22 Neil Booth + + * 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. + 2003-04-22 David Turner * gbl-ctors.h: Add special license exception. diff --git a/gcc/c-lex.c b/gcc/c-lex.c index ec16c15397f..e6017d3141a 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -344,12 +344,9 @@ c_lex (value) *value = NULL_TREE; switch (tok->type) { - /* 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: diff --git a/gcc/cppexp.c b/gcc/cppexp.c index 9ab7b5fa14b..bb74d1a6423 100644 --- a/gcc/cppexp.c +++ b/gcc/cppexp.c @@ -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) diff --git a/gcc/cpplex.c b/gcc/cpplex.c index c148dad0792..552a40657e0 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -31,7 +31,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 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; } diff --git a/gcc/cpplib.h b/gcc/cpplib.h index a9bdb1d8e85..875fe5bf0b1 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -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; }; diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index 0898dac8cd1..84692f359d4 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -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;