cpplib.h (_dollar_ok): New macro.

* cpplib.h (_dollar_ok): New macro.
	(is_idchar, is_idstart): Use it.
	(IStable): Rename to _cpp_IStable.  Declare it const if
	gcc >=2.7 or C99.  Delete all references to FAKE_CONST.
	(is_idchar, is_idstart, is_numchar, is_numstart, is_hspace,
	is_space): Update for renamed IStable.

	* cppinit.c: Delete all references to FAKE_CONST and CAT
	macros. Define init_IStable as empty macro if gcc >=2.7 or
	C99. Change TABLE() to ISTABLE and hardcode name of table.
	(cpp_start_read): Don't change the IStable based on
	dollars_in_ident.

	* cpphash.c (unsafe_chars): Add pfile argument.  All callers
	changed.  Handle '$' for char1 correctly.
	* cpplib.c (cpp_get_token): Use is_numchar when parsing numbers.

	* cppexp.c (tokentab2): Make const.
	(cpp_lex): Make toktab const.
	* cppinit.c (include_defaults_array): Make const.
	(initialize_standard_includes): Make default_include const.

From-SVN: r32321
This commit is contained in:
Zack Weinberg 2000-03-04 01:42:56 +00:00 committed by Zack Weinberg
parent fcd7f76b28
commit 455d25861f
6 changed files with 76 additions and 53 deletions

View File

@ -1,3 +1,27 @@
2000-03-03 Zack Weinberg <zack@wolery.cumb.org>
* cpplib.h (_dollar_ok): New macro.
(is_idchar, is_idstart): Use it.
(IStable): Rename to _cpp_IStable. Declare it const if
gcc >=2.7 or C99. Delete all references to FAKE_CONST.
(is_idchar, is_idstart, is_numchar, is_numstart, is_hspace,
is_space): Update for renamed IStable.
* cppinit.c: Delete all references to FAKE_CONST and CAT
macros. Define init_IStable as empty macro if gcc >=2.7 or
C99. Change TABLE() to ISTABLE and hardcode name of table.
(cpp_start_read): Don't change the IStable based on
dollars_in_ident.
* cpphash.c (unsafe_chars): Add pfile argument. All callers
changed. Handle '$' for char1 correctly.
* cpplib.c (cpp_get_token): Use is_numchar when parsing numbers.
* cppexp.c (tokentab2): Make const.
(cpp_lex): Make toktab const.
* cppinit.c (include_defaults_array): Make const.
(initialize_standard_includes): Make default_include const.
2000-03-03 Jason Merrill <jason@casey.cygnus.com>
* dwarf2out.c (dwarf2out_frame_debug): Add cast to silence warning.

View File

@ -403,7 +403,7 @@ struct token {
int token;
};
static struct token tokentab2[] = {
static const struct token tokentab2[] = {
{"&&", ANDAND},
{"||", OROR},
{"<<", LSH},
@ -424,7 +424,7 @@ cpp_lex (pfile, skip_evaluation)
cpp_reader *pfile;
int skip_evaluation;
{
struct token *toktab;
const struct token *toktab;
enum cpp_token token;
struct operation op;
U_CHAR *tok_start, *tok_end;

View File

@ -35,7 +35,7 @@ static int comp_def_part PARAMS ((int, U_CHAR *, int, U_CHAR *,
int, int));
static void push_macro_expansion PARAMS ((cpp_reader *,
U_CHAR *, int, HASHNODE *));
static int unsafe_chars PARAMS ((int, int));
static int unsafe_chars PARAMS ((cpp_reader *, int, int));
static int macro_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
static enum cpp_token macarg PARAMS ((cpp_reader *, int));
static struct tm *timestamp PARAMS ((cpp_reader *));
@ -1317,7 +1317,7 @@ macroexpand (pfile, hp)
U_CHAR *expanded = ARG_BASE + arg->expanded;
if (!ap->raw_before && totlen > 0 && arg->expand_length
&& !CPP_TRADITIONAL (pfile)
&& unsafe_chars (xbuf[totlen - 1], expanded[0]))
&& unsafe_chars (pfile, xbuf[totlen - 1], expanded[0]))
{
xbuf[totlen++] = '\r';
xbuf[totlen++] = ' ';
@ -1328,7 +1328,7 @@ macroexpand (pfile, hp)
if (!ap->raw_after && totlen > 0 && offset < defn->length
&& !CPP_TRADITIONAL (pfile)
&& unsafe_chars (xbuf[totlen - 1], exp[offset]))
&& unsafe_chars (pfile, xbuf[totlen - 1], exp[offset]))
{
xbuf[totlen++] = '\r';
xbuf[totlen++] = ' ';
@ -1382,7 +1382,8 @@ macroexpand (pfile, hp)
could cause mis-tokenization. */
static int
unsafe_chars (c1, c2)
unsafe_chars (pfile, c1, c2)
cpp_reader *pfile;
int c1, c2;
{
switch (c1)
@ -1397,6 +1398,11 @@ unsafe_chars (c1, c2)
return 1; /* could extend a pre-processing number */
goto letter;
case '$':
if (CPP_OPTIONS (pfile)->dollars_in_ident)
goto letter;
return 0;
case 'L':
if (c2 == '\'' || c2 == '\"')
return 1; /* Could turn into L"xxx" or L'xxx'. */
@ -1468,7 +1474,7 @@ push_macro_expansion (pfile, xbuf, xbuf_len, hp)
{
int c1 = mbuf->rlimit[-3];
int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
if (c2 == EOF || !unsafe_chars (c1, c2))
if (c2 == EOF || !unsafe_chars (pfile, c1, c2))
mbuf->rlimit -= 2;
}
}

View File

@ -22,7 +22,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
#define FAKE_CONST
#include "cpplib.h"
#include "cpphash.h"
#include "output.h"
@ -103,7 +102,7 @@ static const char * const known_suffixes[] =
All these directories are treated as `system' include directories
(they are not subject to pedantic warnings in some cases). */
static struct default_include
struct default_include
{
const char *fname; /* The name of the directory. */
const char *component; /* The component containing the directory
@ -112,8 +111,9 @@ static struct default_include
int cxx_aware; /* Includes in this directory don't need to
be wrapped in extern "C" when compiling
C++. */
}
include_defaults_array[]
};
static const struct default_include include_defaults_array[]
#ifdef INCLUDE_DEFAULTS
= INCLUDE_DEFAULTS;
#else
@ -204,24 +204,21 @@ static void new_pending_define PARAMS ((struct cpp_options *,
/* Fourth argument to append_include_chain: chain to use */
enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
/* If gcc is in use (stage2/stage3) we can make this table initialized data. */
#ifdef __STDC__
#define CAT(a, b) a##b
#else
#define CAT(a, b) a/**/b
#endif
/* If we have designated initializers (GCC >2.7, or C99) this table
can be initialized, constant data. Otherwise, it has to be filled
in at runtime. */
#if (GCC_VERSION >= 2007)
#define TABLE(id) static inline void CAT(init_, id) PARAMS ((void)) {} \
unsigned char id[256] = {
#define s(p, v) [p] = v,
#if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
#define init_IStable() /* nothing */
#define ISTABLE const unsigned char _cpp_IStable[256] = {
#define END };
#define s(p, v) [p] = v,
#else
#define TABLE(id) unsigned char id[256] = { 0 }; \
static void CAT(init_,id) PARAMS ((void)) { \
unsigned char *x = id;
#define s(p, v) x[p] = v;
#define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \
static void init_IStable PARAMS ((void)) { \
unsigned char *x = id;
#define END }
#define s(p, v) x[p] = v;
#endif
#define A(x) s(x, ISidnum|ISidstart)
@ -229,7 +226,7 @@ unsigned char *x = id;
#define H(x) s(x, IShspace|ISspace)
#define S(x) s(x, ISspace)
TABLE (IStable)
ISTABLE
A('_')
A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i')
@ -251,10 +248,9 @@ END
#undef N
#undef H
#undef S
#undef TABLE
#undef END
#undef s
#undef CAT
#undef ISTABLE
#undef END
/* Given a colon-separated list of file names PATH,
add all the names to the search path for include files. */
@ -668,7 +664,7 @@ initialize_standard_includes (pfile)
{
cpp_options *opts = CPP_OPTIONS (pfile);
char *path;
struct default_include *p = include_defaults_array;
const struct default_include *p;
char *specd_prefix = opts->include_prefix;
/* Several environment variables may add to the include search path.
@ -793,14 +789,10 @@ cpp_start_read (pfile, fname)
preprocessing. */
if (opts->preprocessed)
pfile->no_macro_expand++;
/* Now that we know dollars_in_ident, we can initialize the syntax
tables. */
/* Set up the IStable. This doesn't do anything if we were compiled
with a compiler that supports C99 designated initializers. */
init_IStable ();
/* XXX Get rid of code that depends on this, then IStable can
be truly const. */
if (opts->dollars_in_ident)
IStable['$'] = ISidstart|ISidnum;
/* Set up the include search path now. */
if (! opts->no_standard_includes)

View File

@ -2615,7 +2615,7 @@ cpp_get_token (pfile)
c = PEEKC ();
if (c == EOF)
break;
if (!is_idchar(c) && c != '.'
if (!is_numchar(c) && c != '.'
&& ((c2 != 'e' && c2 != 'E'
&& ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile)))
|| (c != '+' && c != '-')))
@ -2640,7 +2640,7 @@ cpp_get_token (pfile)
c = GETC();
if (c == EOF)
goto chill_number_eof;
if (!is_idchar(c))
if (!is_numchar(c))
break;
CPP_PUTC (pfile, c);
}

View File

@ -612,22 +612,23 @@ enum node_type {
#define IShspace 0x08 /* ' ' \t \f \v */
#define ISspace 0x10 /* ' ' \t \f \v \n */
#define is_idchar(x) (IStable[x] & ISidnum)
#define is_numchar(x) (IStable[x] & ISidnum)
#define is_idstart(x) (IStable[x] & ISidstart)
#define is_numstart(x) (IStable[x] & ISnumstart)
#define is_hspace(x) (IStable[x] & IShspace)
#define is_space(x) (IStable[x] & ISspace)
#define _dollar_ok(x) ((x) == '$' && CPP_OPTIONS (pfile)->dollars_in_ident)
/* This table is not really `const', but it is only modified at
initialization time, in a separate translation unit from the rest
of the library. We let the rest of the library think it is `const'
to get better code and some additional compile-time checks. */
#ifndef FAKE_CONST
#define FAKE_CONST const
#define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
#define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
#define is_numchar(x) (_cpp_IStable[x] & ISidnum)
#define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
#define is_hspace(x) (_cpp_IStable[x] & IShspace)
#define is_space(x) (_cpp_IStable[x] & ISspace)
/* This table is constant if it 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];
#else
extern unsigned char _cpp_IStable[256];
#endif
extern FAKE_CONST unsigned char IStable[256];
#undef FAKE_CONST
/* Stack of conditionals currently in progress
(including both successful and failing conditionals). */