aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@casey.cygnus.com>2000-04-13 08:26:36 +0000
committerJason Merrill <jason@gcc.gnu.org>2000-04-13 04:26:36 -0400
commit5eec0563bbf419e126406df1fcc48ffd11d34279 (patch)
treeeaa3c6a6cc8753840e76c6036aded52ec06feb86
parentd28ff99006bc7c3435ef7ca0ef57ef2ba9893e06 (diff)
downloadgcc-5eec0563bbf419e126406df1fcc48ffd11d34279.zip
gcc-5eec0563bbf419e126406df1fcc48ffd11d34279.tar.gz
gcc-5eec0563bbf419e126406df1fcc48ffd11d34279.tar.bz2
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
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/cpplex.c100
2 files changed, 76 insertions, 29 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index fb5ba6e..87c0522 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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)
* i386.c (ix86_expand_binary_operator,
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index e337592..ccf1302 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -703,7 +703,7 @@ enum cpp_ttype
_cpp_lex_token (pfile)
cpp_reader *pfile;
{
- register int c, c2, c3;
+ register int c, c2;
enum cpp_ttype token;
get_next:
@@ -744,29 +744,43 @@ _cpp_lex_token (pfile)
}
case '#':
+ CPP_PUTC (pfile, c);
+
+ hash:
if (pfile->parsing_if_directive)
{
if (_cpp_parse_assertion (pfile))
return CPP_ASSERTION;
- goto randomchar;
+ return CPP_OTHER;
}
if (pfile->parsing_define_directive && ! CPP_TRADITIONAL (pfile))
{
- CPP_RESERVE (pfile, 3);
- CPP_PUTC_Q (pfile, '#');
- CPP_NUL_TERMINATE_Q (pfile);
- if (PEEKC () != '#')
+ c2 = PEEKC ();
+ if (c2 == '#')
+ {
+ 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;
-
- FORWARD (1);
- CPP_PUTC_Q (pfile, '#');
- CPP_NUL_TERMINATE_Q (pfile);
+
return CPP_TOKPASTE;
}
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;
case '\"':
@@ -780,7 +794,10 @@ _cpp_lex_token (pfile)
goto letter;
case ':':
- if (CPP_OPTION (pfile, cplusplus) && PEEKC () == ':')
+ c2 = PEEKC ();
+ /* Digraph: ":>" == "]". */
+ if (c2 == '>'
+ || (c2 == ':' && CPP_OPTION (pfile, cplusplus)))
goto op2;
goto randomchar;
@@ -792,9 +809,29 @@ _cpp_lex_token (pfile)
goto op2;
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 '^':
if (PEEKC () == '=')
@@ -822,7 +859,6 @@ _cpp_lex_token (pfile)
CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, GETC ());
CPP_PUTC_Q (pfile, GETC ());
- CPP_NUL_TERMINATE_Q (pfile);
return token;
}
goto op2;
@@ -865,6 +901,18 @@ _cpp_lex_token (pfile)
}
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 */
case '>':
c2 = PEEKC ();
@@ -874,21 +922,18 @@ _cpp_lex_token (pfile)
if (c2 != c && (!CPP_OPTION (pfile, cplusplus) || c2 != '?'))
goto randomchar;
FORWARD(1);
- CPP_RESERVE (pfile, 4);
- CPP_PUTC (pfile, c);
- CPP_PUTC (pfile, c2);
- c3 = PEEKC ();
- if (c3 == '=')
+ CPP_RESERVE (pfile, 3);
+ CPP_PUTC_Q (pfile, c);
+ CPP_PUTC_Q (pfile, c2);
+ if (PEEKC () == '=')
CPP_PUTC_Q (pfile, GETC ());
- CPP_NUL_TERMINATE_Q (pfile);
return CPP_OTHER;
case '.':
c2 = PEEKC ();
- if (ISDIGIT(c2))
+ if (ISDIGIT (c2))
{
- CPP_RESERVE(pfile, 2);
- CPP_PUTC_Q (pfile, '.');
+ CPP_PUTC (pfile, c);
c = GETC ();
goto number;
}
@@ -899,23 +944,20 @@ _cpp_lex_token (pfile)
if (c2 == '.' && PEEKN(1) == '.')
{
- CPP_RESERVE(pfile, 4);
+ CPP_RESERVE (pfile, 3);
CPP_PUTC_Q (pfile, '.');
CPP_PUTC_Q (pfile, '.');
CPP_PUTC_Q (pfile, '.');
FORWARD (2);
- CPP_NUL_TERMINATE_Q (pfile);
return CPP_3DOTS;
}
goto randomchar;
op2:
- token = CPP_OTHER;
- CPP_RESERVE(pfile, 3);
+ CPP_RESERVE (pfile, 2);
CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, GETC ());
- CPP_NUL_TERMINATE_Q (pfile);
- return token;
+ return CPP_OTHER;
case 'L':
c2 = PEEKC ();