Commit 5eec0563 by Jason Merrill Committed by Jason Merrill

cpplex.c (_cpp_lex_token): Handle digraphs.

        * cpplex.c (_cpp_lex_token): Handle digraphs.  Don't null-terminate
        the token except for numbers and identifiers.

From-SVN: r33136
parent d28ff990
2000-04-13 Jason Merrill <jason@casey.cygnus.com>
* cpplex.c (_cpp_lex_token): Handle digraphs. Don't null-terminate
the token except for numbers and identifiers.
Thu Apr 13 00:09:16 EDT 2000 John Wehle (john@feith.com) Thu Apr 13 00:09:16 EDT 2000 John Wehle (john@feith.com)
* i386.c (ix86_expand_binary_operator, * i386.c (ix86_expand_binary_operator,
......
...@@ -703,7 +703,7 @@ enum cpp_ttype ...@@ -703,7 +703,7 @@ enum cpp_ttype
_cpp_lex_token (pfile) _cpp_lex_token (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
register int c, c2, c3; register int c, c2;
enum cpp_ttype token; enum cpp_ttype token;
get_next: get_next:
...@@ -744,29 +744,43 @@ _cpp_lex_token (pfile) ...@@ -744,29 +744,43 @@ _cpp_lex_token (pfile)
} }
case '#': case '#':
CPP_PUTC (pfile, c);
hash:
if (pfile->parsing_if_directive) if (pfile->parsing_if_directive)
{ {
if (_cpp_parse_assertion (pfile)) if (_cpp_parse_assertion (pfile))
return CPP_ASSERTION; return CPP_ASSERTION;
goto randomchar; return CPP_OTHER;
} }
if (pfile->parsing_define_directive && ! CPP_TRADITIONAL (pfile)) if (pfile->parsing_define_directive && ! CPP_TRADITIONAL (pfile))
{ {
CPP_RESERVE (pfile, 3); c2 = PEEKC ();
CPP_PUTC_Q (pfile, '#'); if (c2 == '#')
CPP_NUL_TERMINATE_Q (pfile); {
if (PEEKC () != '#') FORWARD (1);
CPP_PUTC (pfile, c2);
}
else if (c2 == '%' && PEEKN (1) == ':')
{
/* Digraph: "%:" == "#". */
FORWARD (1);
CPP_RESERVE (pfile, 2);
CPP_PUTC_Q (pfile, c2);
CPP_PUTC_Q (pfile, GETC ());
}
else
return CPP_STRINGIZE; return CPP_STRINGIZE;
FORWARD (1);
CPP_PUTC_Q (pfile, '#');
CPP_NUL_TERMINATE_Q (pfile);
return CPP_TOKPASTE; return CPP_TOKPASTE;
} }
if (!pfile->only_seen_white) if (!pfile->only_seen_white)
goto randomchar; return CPP_OTHER;
/* Remove the "#" or "%:" from the token buffer. */
CPP_ADJUST_WRITTEN (pfile, (c == '#' ? -1 : -2));
return CPP_DIRECTIVE; return CPP_DIRECTIVE;
case '\"': case '\"':
...@@ -780,7 +794,10 @@ _cpp_lex_token (pfile) ...@@ -780,7 +794,10 @@ _cpp_lex_token (pfile)
goto letter; goto letter;
case ':': case ':':
if (CPP_OPTION (pfile, cplusplus) && PEEKC () == ':') c2 = PEEKC ();
/* Digraph: ":>" == "]". */
if (c2 == '>'
|| (c2 == ':' && CPP_OPTION (pfile, cplusplus)))
goto op2; goto op2;
goto randomchar; goto randomchar;
...@@ -792,9 +809,29 @@ _cpp_lex_token (pfile) ...@@ -792,9 +809,29 @@ _cpp_lex_token (pfile)
goto op2; goto op2;
goto randomchar; goto randomchar;
case '%':
/* Digraphs: "%:" == "#", "%>" == "}". */
c2 = PEEKC ();
if (c2 == ':')
{
FORWARD (1);
CPP_RESERVE (pfile, 2);
CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, c2);
goto hash;
}
else if (c2 == '>')
{
FORWARD (1);
CPP_RESERVE (pfile, 2);
CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, c2);
return CPP_RBRACE;
}
/* else fall through */
case '*': case '*':
case '!': case '!':
case '%':
case '=': case '=':
case '^': case '^':
if (PEEKC () == '=') if (PEEKC () == '=')
...@@ -822,7 +859,6 @@ _cpp_lex_token (pfile) ...@@ -822,7 +859,6 @@ _cpp_lex_token (pfile)
CPP_PUTC_Q (pfile, c); CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, GETC ()); CPP_PUTC_Q (pfile, GETC ());
CPP_PUTC_Q (pfile, GETC ()); CPP_PUTC_Q (pfile, GETC ());
CPP_NUL_TERMINATE_Q (pfile);
return token; return token;
} }
goto op2; goto op2;
...@@ -865,6 +901,18 @@ _cpp_lex_token (pfile) ...@@ -865,6 +901,18 @@ _cpp_lex_token (pfile)
} }
return CPP_STRING; return CPP_STRING;
} }
/* Digraphs: "<%" == "{", "<:" == "[". */
c2 = PEEKC ();
if (c2 == '%')
{
FORWARD (1);
CPP_RESERVE (pfile, 2);
CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, c2);
return CPP_LBRACE;
}
else if (c2 == ':')
goto op2;
/* else fall through */ /* else fall through */
case '>': case '>':
c2 = PEEKC (); c2 = PEEKC ();
...@@ -874,21 +922,18 @@ _cpp_lex_token (pfile) ...@@ -874,21 +922,18 @@ _cpp_lex_token (pfile)
if (c2 != c && (!CPP_OPTION (pfile, cplusplus) || c2 != '?')) if (c2 != c && (!CPP_OPTION (pfile, cplusplus) || c2 != '?'))
goto randomchar; goto randomchar;
FORWARD(1); FORWARD(1);
CPP_RESERVE (pfile, 4); CPP_RESERVE (pfile, 3);
CPP_PUTC (pfile, c); CPP_PUTC_Q (pfile, c);
CPP_PUTC (pfile, c2); CPP_PUTC_Q (pfile, c2);
c3 = PEEKC (); if (PEEKC () == '=')
if (c3 == '=')
CPP_PUTC_Q (pfile, GETC ()); CPP_PUTC_Q (pfile, GETC ());
CPP_NUL_TERMINATE_Q (pfile);
return CPP_OTHER; return CPP_OTHER;
case '.': case '.':
c2 = PEEKC (); c2 = PEEKC ();
if (ISDIGIT(c2)) if (ISDIGIT (c2))
{ {
CPP_RESERVE(pfile, 2); CPP_PUTC (pfile, c);
CPP_PUTC_Q (pfile, '.');
c = GETC (); c = GETC ();
goto number; goto number;
} }
...@@ -899,23 +944,20 @@ _cpp_lex_token (pfile) ...@@ -899,23 +944,20 @@ _cpp_lex_token (pfile)
if (c2 == '.' && PEEKN(1) == '.') if (c2 == '.' && PEEKN(1) == '.')
{ {
CPP_RESERVE(pfile, 4); CPP_RESERVE (pfile, 3);
CPP_PUTC_Q (pfile, '.'); CPP_PUTC_Q (pfile, '.');
CPP_PUTC_Q (pfile, '.'); CPP_PUTC_Q (pfile, '.');
CPP_PUTC_Q (pfile, '.'); CPP_PUTC_Q (pfile, '.');
FORWARD (2); FORWARD (2);
CPP_NUL_TERMINATE_Q (pfile);
return CPP_3DOTS; return CPP_3DOTS;
} }
goto randomchar; goto randomchar;
op2: op2:
token = CPP_OTHER; CPP_RESERVE (pfile, 2);
CPP_RESERVE(pfile, 3);
CPP_PUTC_Q (pfile, c); CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, GETC ()); CPP_PUTC_Q (pfile, GETC ());
CPP_NUL_TERMINATE_Q (pfile); return CPP_OTHER;
return token;
case 'L': case 'L':
c2 = PEEKC (); c2 = PEEKC ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment