Commit 2a87fbe8 by Zack Weinberg Committed by Zack Weinberg

cpplex.c (trigraph_map, speccase): Combine into single table, chartab.

	* cpplex.c (trigraph_map, speccase): Combine into single
	table, chartab.
	(NORMAL, NONTRI): New macros.
	(_cpp_read_and_prescan): Change to use unified table.  Use
	is_hspace to test for whitespace.

From-SVN: r32912
parent 21e62dfa
2000-04-04 Zack Weinberg <zack@wolery.cumb.org>
* cpplex.c (trigraph_map, speccase): Combine into single
table, chartab.
(NORMAL, NONTRI): New macros.
(_cpp_read_and_prescan): Change to use unified table. Use
is_hspace to test for whitespace.
2000-04-04 Clinton Popetz <cpopetz@cygnus.com> 2000-04-04 Clinton Popetz <cpopetz@cygnus.com>
* builtins.c (expand_builtin_strlen): Force the source to * builtins.c (expand_builtin_strlen): Force the source to
......
...@@ -1268,62 +1268,51 @@ find_position (start, limit, linep) ...@@ -1268,62 +1268,51 @@ find_position (start, limit, linep)
return lbase; return lbase;
} }
/* These are tables used by _cpp_read_and_prescan. If we have /* The following table is used by _cpp_read_and_prescan. If we have
designated initializers, they can be constant data; otherwise, they designated initializers, it can be constant data; otherwise, it is
are set up at runtime by _cpp_init_input_buffer. */ set up at runtime by _cpp_init_input_buffer. */
#ifndef UCHAR_MAX #ifndef UCHAR_MAX
#define UCHAR_MAX 255 /* assume 8-bit bytes */ #define UCHAR_MAX 255 /* assume 8-bit bytes */
#endif #endif
#if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L) #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
#define CHARTAB(name) static const unsigned char name[UCHAR_MAX + 1] #define init_chartab() /* nothing */
#define init_speccase() /* nothing */ #define CHARTAB static const unsigned char chartab[UCHAR_MAX + 1] = {
#define init_trigraph_map() /* nothing */
#define SPECCASE CHARTAB(speccase) = {
#define TRIGRAPH_MAP CHARTAB(trigraph_map) = {
#define END }; #define END };
#define s(p, v) [p] = v, #define s(p, v) [p] = v,
#else #else
#define CHARTAB(name) static unsigned char name[UCHAR_MAX + 1] #define CHARTAB static unsigned char chartab[UCHAR_MAX + 1] = { 0 }; \
#define SPECCASE CHARTAB(speccase) = { 0 }; \ static void init_chartab PARAMS ((void)) { \
static void init_speccase PARAMS ((void)) { \ unsigned char *x = chartab;
unsigned char *x = speccase;
#define TRIGRAPH_MAP CHARTAB(trigraph_map) = { 0 }; \
static void init_trigraph_map PARAMS ((void)) { \
unsigned char *x = trigraph_map;
#define END } #define END }
#define s(p, v) x[p] = v; #define s(p, v) x[p] = v;
#endif #endif
/* Table of characters that can't be handled in the inner loop. /* Table of characters that can't be handled in the inner loop.
Keep these contiguous to optimize the performance of the code generated Also contains the mapping between trigraph third characters and their
for the switch that uses them. */ replacements. */
#define SPECCASE_EMPTY 0
#define SPECCASE_CR 1 #define SPECCASE_CR 1
#define SPECCASE_BACKSLASH 2 #define SPECCASE_BACKSLASH 2
#define SPECCASE_QUESTION 3 #define SPECCASE_QUESTION 3
SPECCASE CHARTAB
s('\r', SPECCASE_CR) s('\r', SPECCASE_CR)
s('\\', SPECCASE_BACKSLASH) s('\\', SPECCASE_BACKSLASH)
s('?', SPECCASE_QUESTION) s('?', SPECCASE_QUESTION)
END
/* Map of trigraph third characters to their replacements. */
TRIGRAPH_MAP
s('=', '#') s(')', ']') s('!', '|') s('=', '#') s(')', ']') s('!', '|')
s('(', '[') s('\'', '^') s('>', '}') s('(', '[') s('\'', '^') s('>', '}')
s('/', '\\') s('<', '{') s('-', '~') s('/', '\\') s('<', '{') s('-', '~')
END END
#undef CHARTAB #undef CHARTAB
#undef SPECCASE
#undef TRIGRAPH_MAP
#undef END #undef END
#undef s #undef s
#define NORMAL(c) ((chartab[c]) == 0 || (chartab[c]) > SPECCASE_QUESTION)
#define NONTRI(c) ((c) <= SPECCASE_QUESTION)
/* Read the entire contents of file DESC into buffer BUF. LEN is how /* Read the entire contents of file DESC into buffer BUF. LEN is how
much memory to allocate initially; more will be allocated if much memory to allocate initially; more will be allocated if
necessary. Convert end-of-line markers (\n, \r, \r\n, \n\r) to necessary. Convert end-of-line markers (\n, \r, \r\n, \n\r) to
...@@ -1438,7 +1427,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len) ...@@ -1438,7 +1427,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
/* Deal with \-newline, potentially in the middle of a token. */ /* Deal with \-newline, potentially in the middle of a token. */
if (deferred_newlines) if (deferred_newlines)
{ {
if (op != buf && op[-1] != ' ' && op[-1] != '\n' && op[-1] != '\t' && op[-1] != '\r') if (op != buf && ! is_space (op[-1]) && op[-1] != '\r')
{ {
/* Previous was not white space. Skip to white /* Previous was not white space. Skip to white
space, if we can, before outputting the \r's */ space, if we can, before outputting the \r's */
...@@ -1446,12 +1435,12 @@ _cpp_read_and_prescan (pfile, fp, desc, len) ...@@ -1446,12 +1435,12 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
while (ip[span] != ' ' while (ip[span] != ' '
&& ip[span] != '\t' && ip[span] != '\t'
&& ip[span] != '\n' && ip[span] != '\n'
&& speccase[ip[span]] == SPECCASE_EMPTY) && NORMAL(ip[span]))
span++; span++;
memcpy (op, ip, span); memcpy (op, ip, span);
op += span; op += span;
ip += span; ip += span;
if (speccase[ip[0]] != SPECCASE_EMPTY) if (! NORMAL(ip[0]))
goto do_speccase; goto do_speccase;
} }
while (deferred_newlines) while (deferred_newlines)
...@@ -1460,7 +1449,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len) ...@@ -1460,7 +1449,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
/* Copy as much as we can without special treatment. */ /* Copy as much as we can without special treatment. */
span = 0; span = 0;
while (speccase[ip[span]] == SPECCASE_EMPTY) span++; while (NORMAL (ip[span])) span++;
memcpy (op, ip, span); memcpy (op, ip, span);
op += span; op += span;
ip += span; ip += span;
...@@ -1468,7 +1457,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len) ...@@ -1468,7 +1457,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
do_speccase: do_speccase:
if (ip > near_buff_end) /* Do we have enough chars? */ if (ip > near_buff_end) /* Do we have enough chars? */
break; break;
switch (speccase[*ip++]) switch (chartab[*ip++])
{ {
case SPECCASE_CR: /* \r */ case SPECCASE_CR: /* \r */
if (ip[-2] != '\n') if (ip[-2] != '\n')
...@@ -1505,8 +1494,8 @@ _cpp_read_and_prescan (pfile, fp, desc, len) ...@@ -1505,8 +1494,8 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
break; break;
d = ip[1]; d = ip[1];
t = trigraph_map[d]; t = chartab[d];
if (t == 0) if (NONTRI (t))
break; break;
if (CPP_OPTION (pfile, warn_trigraphs)) if (CPP_OPTION (pfile, warn_trigraphs))
...@@ -1578,8 +1567,8 @@ _cpp_read_and_prescan (pfile, fp, desc, len) ...@@ -1578,8 +1567,8 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
return -1; return -1;
} }
/* Allocate pfile->input_buffer, and initialize speccase[] and /* Allocate pfile->input_buffer, and initialize chartab[]
trigraph_map[] if it hasn't happened already. */ if it hasn't happened already. */
void void
_cpp_init_input_buffer (pfile) _cpp_init_input_buffer (pfile)
...@@ -1587,8 +1576,7 @@ _cpp_init_input_buffer (pfile) ...@@ -1587,8 +1576,7 @@ _cpp_init_input_buffer (pfile)
{ {
U_CHAR *tmp; U_CHAR *tmp;
init_speccase (); init_chartab ();
init_trigraph_map ();
/* Determine the appropriate size for the input buffer. Normal C /* Determine the appropriate size for the input buffer. Normal C
source files are smaller than eight K. */ source files are smaller than eight K. */
......
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