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
This commit is contained in:
Neil Booth 2000-08-18 17:35:58 +00:00 committed by Neil Booth
parent 90d14f40a9
commit 61d0346df8
6 changed files with 69 additions and 56 deletions

View File

@ -1,3 +1,23 @@
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>
* arm/lib1funcs.asm (_umodsi3 THUMB VARIANT): Restore deleted return

View File

@ -165,13 +165,15 @@ struct spec_nodes
#define is_nvspace(x) ((_cpp_IStable[x] & (ISspace | ISvspace)) == 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
compiler that supports C99. */
#if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
extern const unsigned char _cpp_IStable[256];
#if HAVE_DESIGNATED_INITIALIZERS
extern const unsigned char _cpp_IStable[UCHAR_MAX + 1];
extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
#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
/* Macros. */

View File

@ -119,21 +119,34 @@ static int parse_option PARAMS ((const char *));
/* Fourth argument to append_include_chain: chain to use */
enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
/* If we have designated initializers (GCC >2.7) this table can be
initialized, constant data. Otherwise, it has to be filled in at
/* If we have designated initializers (GCC >2.7) these tables can be
initialized, constant data. Otherwise, they have to be filled in at
runtime. */
#if HAVE_DESIGNATED_INITIALIZERS
#if (GCC_VERSION >= 2007)
#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 s(p, v) [p] = v,
#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)) { \
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 s(p, v) x[p] = v;
#endif
#define A(x) s(x, ISidnum|ISidstart)
@ -162,6 +175,12 @@ ISTABLE
S('\0') S('\v') S('\f')
END
TRIGRAPH_MAP
s('=', '#') s(')', ']') s('!', '|')
s('(', '[') s('\'', '^') s('>', '}')
s('/', '\\') s('<', '{') s('-', '~')
END
#undef A
#undef N
#undef H
@ -170,6 +189,7 @@ END
#undef s
#undef ISTABLE
#undef END
#undef TRIGRAPH_MAP
/* Given a colon-separated list of file names PATH,
add all the names to the search path for include files. */
@ -386,6 +406,10 @@ cpp_init (void)
qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
#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
with a compiler that supports C99 designated initializers. */
init_IStable ();
@ -720,7 +744,7 @@ initialize_standard_includes (pfile)
&& !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
{
/* 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. */
int flen = strlen (p->fname);
@ -1087,7 +1111,7 @@ parse_option (input)
md = (mn + mx) / 2;
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)
mn = md + 1;
@ -1112,7 +1136,7 @@ parse_option (input)
for (; mn < N_OPTS; mn++)
{
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;
if (input[opt_len] == '\0')
return mn;

View File

@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
Cleanups to do:-
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 Distinguish integers, floats, and 'other' pp-numbers.
o Store ints and char constants as binary values.
@ -226,34 +225,6 @@ _cpp_token_spellings [N_TTYPES] = {TTYPE_TABLE };
#undef OP
#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,
or the current file name has changed. */
@ -748,7 +719,7 @@ trigraph_ok (pfile, end)
if (accept)
cpp_warning_with_line (pfile, pfile->buffer->lineno, col,
"trigraph ??%c converted to %c",
(int) *end, (int) trigraph_map[*end]);
(int) *end, (int) _cpp_trigraph_map[*end]);
else
cpp_warning_with_line (pfile, pfile->buffer->lineno, col,
"trigraph ??%c ignored", (int) *end);
@ -786,7 +757,7 @@ trigraph_replace (pfile, src, limit)
continue;
/* Check if it really is a trigraph. */
if (trigraph_map[src[2]] == 0)
if (_cpp_trigraph_map[src[2]] == 0)
continue;
dest = src;
@ -797,12 +768,12 @@ trigraph_replace (pfile, src, limit)
/* Now we have a trigraph, we need to scan the remaining buffer, and
copy-shifting its contents left if replacement is enabled. */
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:
src += 2;
if (trigraph_ok (pfile, pfile->buffer->cur - (limit - src)))
*dest = trigraph_map[*src];
*dest = _cpp_trigraph_map[*src];
}
/* Copy remaining (at most 2) characters. */
@ -1713,7 +1684,7 @@ lex_line (pfile, list)
case '?':
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. */
cur++;
@ -3536,7 +3507,7 @@ special_symbol (pfile, node, token)
}
#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. */
void
@ -3545,7 +3516,6 @@ _cpp_init_input_buffer (pfile)
{
cpp_context *base;
init_trigraph_map ();
_cpp_init_toklist (&pfile->token_list, DUMMY_TOKEN);
pfile->no_expand_level = UINT_MAX;
pfile->context_cap = 20;

View File

@ -61,10 +61,6 @@ static cpp_hashnode *
get_define_node PARAMS ((cpp_reader *));
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
frequency of occurrence; the numbers at the end are directive
counts from all the source code I have lying around (egcs and libc
@ -1308,9 +1304,6 @@ _cpp_find_answer (node, candidate)
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
do_assert (pfile)
cpp_reader *pfile;
@ -1346,7 +1339,7 @@ do_unassert (pfile)
cpp_reader *pfile;
{
cpp_hashnode *node;
struct answer *answer, *temp, *next;
struct answer *answer, *temp;
node = _cpp_parse_assertion (pfile, &answer);
if (node)

View File

@ -464,6 +464,10 @@ extern int setrlimit PARAMS ((int, const struct rlimit *));
extern void abort PARAMS ((void));
#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.
Note: if the argument passed to STRINGIFY is itself a macro, eg
#define foo bar, STRINGIFY(foo) will produce "foo", not "bar".