Commit 455d2586 by Zack Weinberg Committed by Zack Weinberg

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
parent fcd7f76b
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> 2000-03-03 Jason Merrill <jason@casey.cygnus.com>
* dwarf2out.c (dwarf2out_frame_debug): Add cast to silence warning. * dwarf2out.c (dwarf2out_frame_debug): Add cast to silence warning.
......
...@@ -403,7 +403,7 @@ struct token { ...@@ -403,7 +403,7 @@ struct token {
int token; int token;
}; };
static struct token tokentab2[] = { static const struct token tokentab2[] = {
{"&&", ANDAND}, {"&&", ANDAND},
{"||", OROR}, {"||", OROR},
{"<<", LSH}, {"<<", LSH},
...@@ -424,7 +424,7 @@ cpp_lex (pfile, skip_evaluation) ...@@ -424,7 +424,7 @@ cpp_lex (pfile, skip_evaluation)
cpp_reader *pfile; cpp_reader *pfile;
int skip_evaluation; int skip_evaluation;
{ {
struct token *toktab; const struct token *toktab;
enum cpp_token token; enum cpp_token token;
struct operation op; struct operation op;
U_CHAR *tok_start, *tok_end; U_CHAR *tok_start, *tok_end;
......
...@@ -35,7 +35,7 @@ static int comp_def_part PARAMS ((int, U_CHAR *, int, U_CHAR *, ...@@ -35,7 +35,7 @@ static int comp_def_part PARAMS ((int, U_CHAR *, int, U_CHAR *,
int, int)); int, int));
static void push_macro_expansion PARAMS ((cpp_reader *, static void push_macro_expansion PARAMS ((cpp_reader *,
U_CHAR *, int, HASHNODE *)); 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 int macro_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
static enum cpp_token macarg PARAMS ((cpp_reader *, int)); static enum cpp_token macarg PARAMS ((cpp_reader *, int));
static struct tm *timestamp PARAMS ((cpp_reader *)); static struct tm *timestamp PARAMS ((cpp_reader *));
...@@ -1317,7 +1317,7 @@ macroexpand (pfile, hp) ...@@ -1317,7 +1317,7 @@ macroexpand (pfile, hp)
U_CHAR *expanded = ARG_BASE + arg->expanded; U_CHAR *expanded = ARG_BASE + arg->expanded;
if (!ap->raw_before && totlen > 0 && arg->expand_length if (!ap->raw_before && totlen > 0 && arg->expand_length
&& !CPP_TRADITIONAL (pfile) && !CPP_TRADITIONAL (pfile)
&& unsafe_chars (xbuf[totlen - 1], expanded[0])) && unsafe_chars (pfile, xbuf[totlen - 1], expanded[0]))
{ {
xbuf[totlen++] = '\r'; xbuf[totlen++] = '\r';
xbuf[totlen++] = ' '; xbuf[totlen++] = ' ';
...@@ -1328,7 +1328,7 @@ macroexpand (pfile, hp) ...@@ -1328,7 +1328,7 @@ macroexpand (pfile, hp)
if (!ap->raw_after && totlen > 0 && offset < defn->length if (!ap->raw_after && totlen > 0 && offset < defn->length
&& !CPP_TRADITIONAL (pfile) && !CPP_TRADITIONAL (pfile)
&& unsafe_chars (xbuf[totlen - 1], exp[offset])) && unsafe_chars (pfile, xbuf[totlen - 1], exp[offset]))
{ {
xbuf[totlen++] = '\r'; xbuf[totlen++] = '\r';
xbuf[totlen++] = ' '; xbuf[totlen++] = ' ';
...@@ -1382,7 +1382,8 @@ macroexpand (pfile, hp) ...@@ -1382,7 +1382,8 @@ macroexpand (pfile, hp)
could cause mis-tokenization. */ could cause mis-tokenization. */
static int static int
unsafe_chars (c1, c2) unsafe_chars (pfile, c1, c2)
cpp_reader *pfile;
int c1, c2; int c1, c2;
{ {
switch (c1) switch (c1)
...@@ -1397,6 +1398,11 @@ unsafe_chars (c1, c2) ...@@ -1397,6 +1398,11 @@ unsafe_chars (c1, c2)
return 1; /* could extend a pre-processing number */ return 1; /* could extend a pre-processing number */
goto letter; goto letter;
case '$':
if (CPP_OPTIONS (pfile)->dollars_in_ident)
goto letter;
return 0;
case 'L': case 'L':
if (c2 == '\'' || c2 == '\"') if (c2 == '\'' || c2 == '\"')
return 1; /* Could turn into L"xxx" or L'xxx'. */ return 1; /* Could turn into L"xxx" or L'xxx'. */
...@@ -1468,7 +1474,7 @@ push_macro_expansion (pfile, xbuf, xbuf_len, hp) ...@@ -1468,7 +1474,7 @@ push_macro_expansion (pfile, xbuf, xbuf_len, hp)
{ {
int c1 = mbuf->rlimit[-3]; int c1 = mbuf->rlimit[-3];
int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile))); 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; mbuf->rlimit -= 2;
} }
} }
......
...@@ -22,7 +22,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -22,7 +22,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#define FAKE_CONST
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
#include "output.h" #include "output.h"
...@@ -103,7 +102,7 @@ static const char * const known_suffixes[] = ...@@ -103,7 +102,7 @@ static const char * const known_suffixes[] =
All these directories are treated as `system' include directories All these directories are treated as `system' include directories
(they are not subject to pedantic warnings in some cases). */ (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 *fname; /* The name of the directory. */
const char *component; /* The component containing the directory const char *component; /* The component containing the directory
...@@ -112,8 +111,9 @@ static struct default_include ...@@ -112,8 +111,9 @@ static struct default_include
int cxx_aware; /* Includes in this directory don't need to int cxx_aware; /* Includes in this directory don't need to
be wrapped in extern "C" when compiling be wrapped in extern "C" when compiling
C++. */ C++. */
} };
include_defaults_array[]
static const struct default_include include_defaults_array[]
#ifdef INCLUDE_DEFAULTS #ifdef INCLUDE_DEFAULTS
= INCLUDE_DEFAULTS; = INCLUDE_DEFAULTS;
#else #else
...@@ -204,24 +204,21 @@ static void new_pending_define PARAMS ((struct cpp_options *, ...@@ -204,24 +204,21 @@ static void new_pending_define PARAMS ((struct cpp_options *,
/* 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 gcc is in use (stage2/stage3) we can make this table initialized data. */ /* If we have designated initializers (GCC >2.7, or C99) this table
#ifdef __STDC__ can be initialized, constant data. Otherwise, it has to be filled
#define CAT(a, b) a##b in at runtime. */
#else
#define CAT(a, b) a/**/b
#endif
#if (GCC_VERSION >= 2007) #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
#define TABLE(id) static inline void CAT(init_, id) PARAMS ((void)) {} \ #define init_IStable() /* nothing */
unsigned char id[256] = { #define ISTABLE const unsigned char _cpp_IStable[256] = {
#define s(p, v) [p] = v,
#define END }; #define END };
#define s(p, v) [p] = v,
#else #else
#define TABLE(id) unsigned char id[256] = { 0 }; \ #define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \
static void CAT(init_,id) PARAMS ((void)) { \ static void init_IStable PARAMS ((void)) { \
unsigned char *x = id; unsigned char *x = id;
#define s(p, v) x[p] = v;
#define END } #define END }
#define s(p, v) x[p] = v;
#endif #endif
#define A(x) s(x, ISidnum|ISidstart) #define A(x) s(x, ISidnum|ISidstart)
...@@ -229,7 +226,7 @@ unsigned char *x = id; ...@@ -229,7 +226,7 @@ unsigned char *x = id;
#define H(x) s(x, IShspace|ISspace) #define H(x) s(x, IShspace|ISspace)
#define S(x) s(x, ISspace) #define S(x) s(x, ISspace)
TABLE (IStable) ISTABLE
A('_') A('_')
A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i') A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i')
...@@ -251,10 +248,9 @@ END ...@@ -251,10 +248,9 @@ END
#undef N #undef N
#undef H #undef H
#undef S #undef S
#undef TABLE
#undef END
#undef s #undef s
#undef CAT #undef ISTABLE
#undef END
/* 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. */
...@@ -668,7 +664,7 @@ initialize_standard_includes (pfile) ...@@ -668,7 +664,7 @@ initialize_standard_includes (pfile)
{ {
cpp_options *opts = CPP_OPTIONS (pfile); cpp_options *opts = CPP_OPTIONS (pfile);
char *path; char *path;
struct default_include *p = include_defaults_array; const struct default_include *p;
char *specd_prefix = opts->include_prefix; char *specd_prefix = opts->include_prefix;
/* Several environment variables may add to the include search path. /* Several environment variables may add to the include search path.
...@@ -793,14 +789,10 @@ cpp_start_read (pfile, fname) ...@@ -793,14 +789,10 @@ cpp_start_read (pfile, fname)
preprocessing. */ preprocessing. */
if (opts->preprocessed) if (opts->preprocessed)
pfile->no_macro_expand++; pfile->no_macro_expand++;
/* Now that we know dollars_in_ident, we can initialize the syntax /* Set up the IStable. This doesn't do anything if we were compiled
tables. */ with a compiler that supports C99 designated initializers. */
init_IStable (); 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. */ /* Set up the include search path now. */
if (! opts->no_standard_includes) if (! opts->no_standard_includes)
......
...@@ -2615,7 +2615,7 @@ cpp_get_token (pfile) ...@@ -2615,7 +2615,7 @@ cpp_get_token (pfile)
c = PEEKC (); c = PEEKC ();
if (c == EOF) if (c == EOF)
break; break;
if (!is_idchar(c) && c != '.' if (!is_numchar(c) && c != '.'
&& ((c2 != 'e' && c2 != 'E' && ((c2 != 'e' && c2 != 'E'
&& ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile))) && ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile)))
|| (c != '+' && c != '-'))) || (c != '+' && c != '-')))
...@@ -2640,7 +2640,7 @@ cpp_get_token (pfile) ...@@ -2640,7 +2640,7 @@ cpp_get_token (pfile)
c = GETC(); c = GETC();
if (c == EOF) if (c == EOF)
goto chill_number_eof; goto chill_number_eof;
if (!is_idchar(c)) if (!is_numchar(c))
break; break;
CPP_PUTC (pfile, c); CPP_PUTC (pfile, c);
} }
......
...@@ -612,22 +612,23 @@ enum node_type { ...@@ -612,22 +612,23 @@ enum node_type {
#define IShspace 0x08 /* ' ' \t \f \v */ #define IShspace 0x08 /* ' ' \t \f \v */
#define ISspace 0x10 /* ' ' \t \f \v \n */ #define ISspace 0x10 /* ' ' \t \f \v \n */
#define is_idchar(x) (IStable[x] & ISidnum) #define _dollar_ok(x) ((x) == '$' && CPP_OPTIONS (pfile)->dollars_in_ident)
#define is_numchar(x) (IStable[x] & ISidnum)
#define is_idstart(x) (IStable[x] & ISidstart) #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
#define is_numstart(x) (IStable[x] & ISnumstart) #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
#define is_hspace(x) (IStable[x] & IShspace) #define is_numchar(x) (_cpp_IStable[x] & ISidnum)
#define is_space(x) (IStable[x] & ISspace) #define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
#define is_hspace(x) (_cpp_IStable[x] & IShspace)
/* This table is not really `const', but it is only modified at #define is_space(x) (_cpp_IStable[x] & ISspace)
initialization time, in a separate translation unit from the rest
of the library. We let the rest of the library think it is `const' /* This table is constant if it can be initialized at compile time,
to get better code and some additional compile-time checks. */ which is the case if cpp was compiled with GCC >=2.7, or another
#ifndef FAKE_CONST compiler that supports C99. */
#define FAKE_CONST const #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
extern const unsigned char _cpp_IStable[256];
#else
extern unsigned char _cpp_IStable[256];
#endif #endif
extern FAKE_CONST unsigned char IStable[256];
#undef FAKE_CONST
/* Stack of conditionals currently in progress /* Stack of conditionals currently in progress
(including both successful and failing conditionals). */ (including both successful and failing conditionals). */
......
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