Commit 61d0346d by Neil Booth Committed by Neil Booth

cpphash.h: Use HAVE_DESIGNATED_INITIALIZERS.

	* cpphash.h: Use HAVE_DESIGNATED_INITIALIZERS.
	(_cpp_trigraph_map): Declaration moved from cpplex.c

	* cppinit.c: Define _cpp_trigraph_map.  Use UCHAR_MAX + 1
	instead	of 256.  Use consistent test for designated initializers.
	(cpp_init): Initialize trigraph_map.
	(initialize_standard_includes, parse_option):  Use memcmp
	instead of strncmp.

	* cpplex.c (init_trigraph_map): Remove.
	(trigraph_ok, trigraph_replace, lex_line): Refer to
	_cpp_trigraph_map.

	* cpplib.c (str_match, WARNING, ERROR, ICE): Delete.
	(do_unassert): Remove unused "next" local.

	* system.h (HAVE_DESIGNATED_INITIALIZERS): New prototype.

From-SVN: r35789
parent 90d14f40
Fri 18-Aug-2000 18:33:45 BST Neil Booth <NeilB@earthling.net>
* cpphash.h: Use HAVE_DESIGNATED_INITIALIZERS.
(_cpp_trigraph_map): Declaration moved from cpplex.c
* cppinit.c: Define _cpp_trigraph_map. Use UCHAR_MAX + 1
instead of 256. Use consistent test for designated initializers.
(cpp_init): Initialize trigraph_map.
(initialize_standard_includes, parse_option): Use memcmp
instead of strncmp.
* cpplex.c (init_trigraph_map): Remove.
(trigraph_ok, trigraph_replace, lex_line): Refer to
_cpp_trigraph_map.
* cpplib.c (str_match, WARNING, ERROR, ICE): Delete.
(do_unassert): Remove unused "next" local.
* system.h (HAVE_DESIGNATED_INITIALIZERS): New prototype.
2000-08-18 Emmanuel Marty <emarty@suntech.fr> 2000-08-18 Emmanuel Marty <emarty@suntech.fr>
* arm/lib1funcs.asm (_umodsi3 THUMB VARIANT): Restore deleted return * arm/lib1funcs.asm (_umodsi3 THUMB VARIANT): Restore deleted return
......
...@@ -165,13 +165,15 @@ struct spec_nodes ...@@ -165,13 +165,15 @@ struct spec_nodes
#define is_nvspace(x) ((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace) #define is_nvspace(x) ((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace)
#define is_space(x) (_cpp_IStable[x] & ISspace) #define is_space(x) (_cpp_IStable[x] & ISspace)
/* This table is constant if it can be initialized at compile time, /* These tables are constant if they can be initialized at compile time,
which is the case if cpp was compiled with GCC >=2.7, or another which is the case if cpp was compiled with GCC >=2.7, or another
compiler that supports C99. */ compiler that supports C99. */
#if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L) #if HAVE_DESIGNATED_INITIALIZERS
extern const unsigned char _cpp_IStable[256]; extern const unsigned char _cpp_IStable[UCHAR_MAX + 1];
extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
#else #else
extern unsigned char _cpp_IStable[256]; extern unsigned char _cpp_IStable[UCHAR_MAX + 1];
extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
#endif #endif
/* Macros. */ /* Macros. */
......
...@@ -119,21 +119,34 @@ static int parse_option PARAMS ((const char *)); ...@@ -119,21 +119,34 @@ static int parse_option PARAMS ((const char *));
/* Fourth argument to append_include_chain: chain to use */ /* Fourth argument to append_include_chain: chain to use */
enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
/* If we have designated initializers (GCC >2.7) this table can be /* If we have designated initializers (GCC >2.7) these tables can be
initialized, constant data. Otherwise, it has to be filled in at initialized, constant data. Otherwise, they have to be filled in at
runtime. */ runtime. */
#if HAVE_DESIGNATED_INITIALIZERS
#if (GCC_VERSION >= 2007)
#define init_IStable() /* nothing */ #define init_IStable() /* nothing */
#define ISTABLE __extension__ const unsigned char _cpp_IStable[256] = { #define ISTABLE __extension__ const U_CHAR _cpp_IStable[UCHAR_MAX + 1] = {
#define init_trigraph_map() /* nothing */
#define TRIGRAPH_MAP \
__extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = {
#define END }; #define END };
#define s(p, v) [p] = v, #define s(p, v) [p] = v,
#else #else
#define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \
#define ISTABLE unsigned char _cpp_IStable[UCHAR_MAX + 1] = { 0 }; \
static void init_IStable PARAMS ((void)) { \ static void init_IStable PARAMS ((void)) { \
unsigned char *x = _cpp_IStable; unsigned char *x = _cpp_IStable;
#define TRIGRAPH_MAP U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
static void init_trigraph_map PARAMS ((void)) { \
unsigned char *x = _cpp_trigraph_map;
#define END } #define END }
#define s(p, v) x[p] = v; #define s(p, v) x[p] = v;
#endif #endif
#define A(x) s(x, ISidnum|ISidstart) #define A(x) s(x, ISidnum|ISidstart)
...@@ -162,6 +175,12 @@ ISTABLE ...@@ -162,6 +175,12 @@ ISTABLE
S('\0') S('\v') S('\f') S('\0') S('\v') S('\f')
END END
TRIGRAPH_MAP
s('=', '#') s(')', ']') s('!', '|')
s('(', '[') s('\'', '^') s('>', '}')
s('/', '\\') s('<', '{') s('-', '~')
END
#undef A #undef A
#undef N #undef N
#undef H #undef H
...@@ -170,6 +189,7 @@ END ...@@ -170,6 +189,7 @@ END
#undef s #undef s
#undef ISTABLE #undef ISTABLE
#undef END #undef END
#undef TRIGRAPH_MAP
/* Given a colon-separated list of file names PATH, /* Given a colon-separated list of file names PATH,
add all the names to the search path for include files. */ add all the names to the search path for include files. */
...@@ -386,6 +406,10 @@ cpp_init (void) ...@@ -386,6 +406,10 @@ cpp_init (void)
qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp); qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
#endif #endif
/* Set up the trigraph map for trigraph_ok, trigraph_replace and
lex_line. */
init_trigraph_map ();
/* Set up the IStable. This doesn't do anything if we were compiled /* Set up the IStable. This doesn't do anything if we were compiled
with a compiler that supports C99 designated initializers. */ with a compiler that supports C99 designated initializers. */
init_IStable (); init_IStable ();
...@@ -720,7 +744,7 @@ initialize_standard_includes (pfile) ...@@ -720,7 +744,7 @@ initialize_standard_includes (pfile)
&& !CPP_OPTION (pfile, no_standard_cplusplus_includes))) && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
{ {
/* Does this dir start with the prefix? */ /* Does this dir start with the prefix? */
if (!strncmp (p->fname, default_prefix, default_len)) if (!memcmp (p->fname, default_prefix, default_len))
{ {
/* Yes; change prefix and add to search list. */ /* Yes; change prefix and add to search list. */
int flen = strlen (p->fname); int flen = strlen (p->fname);
...@@ -1087,7 +1111,7 @@ parse_option (input) ...@@ -1087,7 +1111,7 @@ parse_option (input)
md = (mn + mx) / 2; md = (mn + mx) / 2;
opt_len = cl_options[md].opt_len; opt_len = cl_options[md].opt_len;
comp = strncmp (input, cl_options[md].opt_text, opt_len); comp = memcmp (input, cl_options[md].opt_text, opt_len);
if (comp > 0) if (comp > 0)
mn = md + 1; mn = md + 1;
...@@ -1112,7 +1136,7 @@ parse_option (input) ...@@ -1112,7 +1136,7 @@ parse_option (input)
for (; mn < N_OPTS; mn++) for (; mn < N_OPTS; mn++)
{ {
opt_len = cl_options[mn].opt_len; opt_len = cl_options[mn].opt_len;
if (strncmp (input, cl_options[mn].opt_text, opt_len)) if (memcmp (input, cl_options[mn].opt_text, opt_len))
break; break;
if (input[opt_len] == '\0') if (input[opt_len] == '\0')
return mn; return mn;
......
...@@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
Cleanups to do:- Cleanups to do:-
o Check line numbers assigned to all errors. o Check line numbers assigned to all errors.
o Replace strncmp with memcmp almost everywhere.
o lex_line's use of cur_token, flags and list->token_used is a bit opaque. o lex_line's use of cur_token, flags and list->token_used is a bit opaque.
o Distinguish integers, floats, and 'other' pp-numbers. o Distinguish integers, floats, and 'other' pp-numbers.
o Store ints and char constants as binary values. o Store ints and char constants as binary values.
...@@ -226,34 +225,6 @@ _cpp_token_spellings [N_TTYPES] = {TTYPE_TABLE }; ...@@ -226,34 +225,6 @@ _cpp_token_spellings [N_TTYPES] = {TTYPE_TABLE };
#undef OP #undef OP
#undef TK #undef TK
/* The following table is used by trigraph_ok/trigraph_replace. If we
have designated initializers, it can be constant data; otherwise,
it is set up at runtime by _cpp_init_input_buffer. */
#if (GCC_VERSION >= 2007)
#define init_trigraph_map() /* nothing */
#define TRIGRAPH_MAP \
__extension__ static const U_CHAR trigraph_map[UCHAR_MAX + 1] = {
#define END };
#define s(p, v) [p] = v,
#else
#define TRIGRAPH_MAP static U_CHAR trigraph_map[UCHAR_MAX + 1] = { 0 }; \
static void init_trigraph_map PARAMS ((void)) { \
unsigned char *x = trigraph_map;
#define END }
#define s(p, v) x[p] = v;
#endif
TRIGRAPH_MAP
s('=', '#') s(')', ']') s('!', '|')
s('(', '[') s('\'', '^') s('>', '}')
s('/', '\\') s('<', '{') s('-', '~')
END
#undef TRIGRAPH_MAP
#undef END
#undef s
/* Notify the compiler proper that the current line number has jumped, /* Notify the compiler proper that the current line number has jumped,
or the current file name has changed. */ or the current file name has changed. */
...@@ -748,7 +719,7 @@ trigraph_ok (pfile, end) ...@@ -748,7 +719,7 @@ trigraph_ok (pfile, end)
if (accept) if (accept)
cpp_warning_with_line (pfile, pfile->buffer->lineno, col, cpp_warning_with_line (pfile, pfile->buffer->lineno, col,
"trigraph ??%c converted to %c", "trigraph ??%c converted to %c",
(int) *end, (int) trigraph_map[*end]); (int) *end, (int) _cpp_trigraph_map[*end]);
else else
cpp_warning_with_line (pfile, pfile->buffer->lineno, col, cpp_warning_with_line (pfile, pfile->buffer->lineno, col,
"trigraph ??%c ignored", (int) *end); "trigraph ??%c ignored", (int) *end);
...@@ -786,7 +757,7 @@ trigraph_replace (pfile, src, limit) ...@@ -786,7 +757,7 @@ trigraph_replace (pfile, src, limit)
continue; continue;
/* Check if it really is a trigraph. */ /* Check if it really is a trigraph. */
if (trigraph_map[src[2]] == 0) if (_cpp_trigraph_map[src[2]] == 0)
continue; continue;
dest = src; dest = src;
...@@ -797,12 +768,12 @@ trigraph_replace (pfile, src, limit) ...@@ -797,12 +768,12 @@ trigraph_replace (pfile, src, limit)
/* Now we have a trigraph, we need to scan the remaining buffer, and /* Now we have a trigraph, we need to scan the remaining buffer, and
copy-shifting its contents left if replacement is enabled. */ copy-shifting its contents left if replacement is enabled. */
for (; src + 2 < limit; dest++, src++) for (; src + 2 < limit; dest++, src++)
if ((*dest = *src) == '?' && src[1] == '?' && trigraph_map[src[2]]) if ((*dest = *src) == '?' && src[1] == '?' && _cpp_trigraph_map[src[2]])
{ {
trigraph_found: trigraph_found:
src += 2; src += 2;
if (trigraph_ok (pfile, pfile->buffer->cur - (limit - src))) if (trigraph_ok (pfile, pfile->buffer->cur - (limit - src)))
*dest = trigraph_map[*src]; *dest = _cpp_trigraph_map[*src];
} }
/* Copy remaining (at most 2) characters. */ /* Copy remaining (at most 2) characters. */
...@@ -1713,7 +1684,7 @@ lex_line (pfile, list) ...@@ -1713,7 +1684,7 @@ lex_line (pfile, list)
case '?': case '?':
if (cur + 1 < buffer->rlimit && *cur == '?' if (cur + 1 < buffer->rlimit && *cur == '?'
&& trigraph_map[cur[1]] && trigraph_ok (pfile, cur + 1)) && _cpp_trigraph_map[cur[1]] && trigraph_ok (pfile, cur + 1))
{ {
/* Handle trigraph. */ /* Handle trigraph. */
cur++; cur++;
...@@ -3536,7 +3507,7 @@ special_symbol (pfile, node, token) ...@@ -3536,7 +3507,7 @@ special_symbol (pfile, node, token)
} }
#undef DSC #undef DSC
/* Allocate pfile->input_buffer, and initialize trigraph_map[] /* Allocate pfile->input_buffer, and initialize _cpp_trigraph_map[]
if it hasn't happened already. */ if it hasn't happened already. */
void void
...@@ -3545,7 +3516,6 @@ _cpp_init_input_buffer (pfile) ...@@ -3545,7 +3516,6 @@ _cpp_init_input_buffer (pfile)
{ {
cpp_context *base; cpp_context *base;
init_trigraph_map ();
_cpp_init_toklist (&pfile->token_list, DUMMY_TOKEN); _cpp_init_toklist (&pfile->token_list, DUMMY_TOKEN);
pfile->no_expand_level = UINT_MAX; pfile->no_expand_level = UINT_MAX;
pfile->context_cap = 20; pfile->context_cap = 20;
......
...@@ -61,10 +61,6 @@ static cpp_hashnode * ...@@ -61,10 +61,6 @@ static cpp_hashnode *
get_define_node PARAMS ((cpp_reader *)); get_define_node PARAMS ((cpp_reader *));
static void unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *)); static void unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *));
/* Utility. */
#define str_match(sym, len, str) \
((len) == (sizeof (str) - 1) && !ustrncmp ((sym), U(str), sizeof (str) - 1))
/* This is the table of directive handlers. It is ordered by /* This is the table of directive handlers. It is ordered by
frequency of occurrence; the numbers at the end are directive frequency of occurrence; the numbers at the end are directive
counts from all the source code I have lying around (egcs and libc counts from all the source code I have lying around (egcs and libc
...@@ -1308,9 +1304,6 @@ _cpp_find_answer (node, candidate) ...@@ -1308,9 +1304,6 @@ _cpp_find_answer (node, candidate)
return result; return result;
} }
#define WARNING(msgid) do { cpp_warning(pfile, msgid); goto error; } while (0)
#define ERROR(msgid) do { cpp_error(pfile, msgid); goto error; } while (0)
#define ICE(msgid) do { cpp_ice(pfile, msgid); goto error; } while (0)
static void static void
do_assert (pfile) do_assert (pfile)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -1346,7 +1339,7 @@ do_unassert (pfile) ...@@ -1346,7 +1339,7 @@ do_unassert (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_hashnode *node; cpp_hashnode *node;
struct answer *answer, *temp, *next; struct answer *answer, *temp;
node = _cpp_parse_assertion (pfile, &answer); node = _cpp_parse_assertion (pfile, &answer);
if (node) if (node)
......
...@@ -464,6 +464,10 @@ extern int setrlimit PARAMS ((int, const struct rlimit *)); ...@@ -464,6 +464,10 @@ extern int setrlimit PARAMS ((int, const struct rlimit *));
extern void abort PARAMS ((void)); extern void abort PARAMS ((void));
#endif #endif
/* 1 if we have C99 designated initializers. */
#define HAVE_DESIGNATED_INITIALIZERS \
((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
/* Define a STRINGIFY macro that's right for ANSI or traditional C. /* Define a STRINGIFY macro that's right for ANSI or traditional C.
Note: if the argument passed to STRINGIFY is itself a macro, eg Note: if the argument passed to STRINGIFY is itself a macro, eg
#define foo bar, STRINGIFY(foo) will produce "foo", not "bar". #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
......
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