aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zack@wolery.cumb.org>2000-04-04 21:17:20 +0000
committerZack Weinberg <zack@wolery.cumb.org>2000-04-04 21:17:20 +0000
commit0fef5fb7b7748ba53222b505575aabb645d06d96 (patch)
tree50de542f3dad2224ab018fa9f5a57ac0ea59b36b
parentabff493af07a21472ea8e4a0ee212b995ba8de55 (diff)
* 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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@32912 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/cpplex.c60
2 files changed, 32 insertions, 36 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 342c6a3065a..44c63873b7d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+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>
* builtins.c (expand_builtin_strlen): Force the source to
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index a57eb8b7f47..56f061ba6eb 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -1268,62 +1268,51 @@ find_position (start, limit, linep)
return lbase;
}
-/* These are tables used by _cpp_read_and_prescan. If we have
- designated initializers, they can be constant data; otherwise, they
- are set up at runtime by _cpp_init_input_buffer. */
+/* The following table is used by _cpp_read_and_prescan. If we have
+ designated initializers, it can be constant data; otherwise, it is
+ set up at runtime by _cpp_init_input_buffer. */
#ifndef UCHAR_MAX
#define UCHAR_MAX 255 /* assume 8-bit bytes */
#endif
#if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
-#define CHARTAB(name) static const unsigned char name[UCHAR_MAX + 1]
-#define init_speccase() /* nothing */
-#define init_trigraph_map() /* nothing */
-#define SPECCASE CHARTAB(speccase) = {
-#define TRIGRAPH_MAP CHARTAB(trigraph_map) = {
+#define init_chartab() /* nothing */
+#define CHARTAB static const unsigned char chartab[UCHAR_MAX + 1] = {
#define END };
#define s(p, v) [p] = v,
#else
-#define CHARTAB(name) static unsigned char name[UCHAR_MAX + 1]
-#define SPECCASE CHARTAB(speccase) = { 0 }; \
- static void init_speccase PARAMS ((void)) { \
- unsigned char *x = speccase;
-#define TRIGRAPH_MAP CHARTAB(trigraph_map) = { 0 }; \
- static void init_trigraph_map PARAMS ((void)) { \
- unsigned char *x = trigraph_map;
+#define CHARTAB static unsigned char chartab[UCHAR_MAX + 1] = { 0 }; \
+ static void init_chartab PARAMS ((void)) { \
+ unsigned char *x = chartab;
#define END }
#define s(p, v) x[p] = v;
#endif
/* Table of characters that can't be handled in the inner loop.
- Keep these contiguous to optimize the performance of the code generated
- for the switch that uses them. */
-#define SPECCASE_EMPTY 0
+ Also contains the mapping between trigraph third characters and their
+ replacements. */
#define SPECCASE_CR 1
#define SPECCASE_BACKSLASH 2
#define SPECCASE_QUESTION 3
-SPECCASE
+CHARTAB
s('\r', SPECCASE_CR)
s('\\', SPECCASE_BACKSLASH)
s('?', SPECCASE_QUESTION)
-END
-/* Map of trigraph third characters to their replacements. */
-
-TRIGRAPH_MAP
s('=', '#') s(')', ']') s('!', '|')
s('(', '[') s('\'', '^') s('>', '}')
s('/', '\\') s('<', '{') s('-', '~')
END
#undef CHARTAB
-#undef SPECCASE
-#undef TRIGRAPH_MAP
#undef END
#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
much memory to allocate initially; more will be allocated if
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)
/* Deal with \-newline, potentially in the middle of a token. */
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
space, if we can, before outputting the \r's */
@@ -1446,12 +1435,12 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
while (ip[span] != ' '
&& ip[span] != '\t'
&& ip[span] != '\n'
- && speccase[ip[span]] == SPECCASE_EMPTY)
+ && NORMAL(ip[span]))
span++;
memcpy (op, ip, span);
op += span;
ip += span;
- if (speccase[ip[0]] != SPECCASE_EMPTY)
+ if (! NORMAL(ip[0]))
goto do_speccase;
}
while (deferred_newlines)
@@ -1460,7 +1449,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
/* Copy as much as we can without special treatment. */
span = 0;
- while (speccase[ip[span]] == SPECCASE_EMPTY) span++;
+ while (NORMAL (ip[span])) span++;
memcpy (op, ip, span);
op += span;
ip += span;
@@ -1468,7 +1457,7 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
do_speccase:
if (ip > near_buff_end) /* Do we have enough chars? */
break;
- switch (speccase[*ip++])
+ switch (chartab[*ip++])
{
case SPECCASE_CR: /* \r */
if (ip[-2] != '\n')
@@ -1505,8 +1494,8 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
break;
d = ip[1];
- t = trigraph_map[d];
- if (t == 0)
+ t = chartab[d];
+ if (NONTRI (t))
break;
if (CPP_OPTION (pfile, warn_trigraphs))
@@ -1578,8 +1567,8 @@ _cpp_read_and_prescan (pfile, fp, desc, len)
return -1;
}
-/* Allocate pfile->input_buffer, and initialize speccase[] and
- trigraph_map[] if it hasn't happened already. */
+/* Allocate pfile->input_buffer, and initialize chartab[]
+ if it hasn't happened already. */
void
_cpp_init_input_buffer (pfile)
@@ -1587,8 +1576,7 @@ _cpp_init_input_buffer (pfile)
{
U_CHAR *tmp;
- init_speccase ();
- init_trigraph_map ();
+ init_chartab ();
/* Determine the appropriate size for the input buffer. Normal C
source files are smaller than eight K. */