Commit a9ae4483 by Zack Weinberg Committed by Zack Weinberg

cpplib.h (struct cpp_buffer: fname, [...]): Mark const.

1999-10-28 21:27 -0700  Zack Weinberg  <zack@bitmover.com>

	* cpplib.h (struct cpp_buffer: fname, nominal_fname,
	last_nominal_fname): Mark const.
	(struct include_hash: name, nshort, control_macro): Mark
	const.
	(struct macrodef: symnam): Mark const.
	(struct if_stack: fname): Mark const.
	(is_idchar, is_idstart, is_hor_space, trigraph_table): Delete.
	(IStable): New character-syntax array which encompasses all
	the old is_foo arrays.
	(is_idchar, is_numchar, is_idstart, is_numstart, is_hspace,
	is_space): New macros for interrogating IStable.
	(check_macro_name): Kill last argument.  All callers changed.

	* cppinit.c (initialize_char_syntax): Delete.
	(is_idchar, is_idstart, is_hor_space, is_space,
	trigraph_table): Delete.
	(IStable): New.  Initialize with clever macros to avoid
	information duplication.
	(builtin_array): Table of builtins to get rid of explicit list
	in initialize_builtins.
	(initialize_builtins): Use builtins_array.
	(cpp_start_read): Call init_IStable, and set IStable['$'] if
	opts->dollars_in_ident.

	* cppexp.c: Change all refs to is_xyz[] arrays to use new
	is_xyz() macros.
	(cpp_parse_expr): Avoid 'format string is not constant'
	warning. Use ISGRAPH to identify printable chars.
	* cppfiles.c: Change all refs to is_xyz[] arrays to use new
	is_xyz() macros.
	(read_and_prescan): Map trigraphs to chars with open-coded
	if-else-if-... sequence, not a lookup table.
	* cpphash.c: Change all refs to is_xyz[] arrays to use new
	is_xyz() macros.
	* cpplib.c: Change all refs to is_xyz[] arrays to use new
	is_xyz() macros.  Kill SKIP_ALL_WHITE_SPACE (unused).
	(check_macro_name): Remove ability to report an invalid
	assertion name, which is never used.
	(do_line): Constify a couple of char *'s.
	* cppmain.c (main): Call cpp_cleanup before returning.

From-SVN: r30252
parent 3277221c
1999-10-28 21:27 -0700 Zack Weinberg <zack@bitmover.com>
* cpplib.h (struct cpp_buffer: fname, nominal_fname,
last_nominal_fname): Mark const.
(struct include_hash: name, nshort, control_macro): Mark
const.
(struct macrodef: symnam): Mark const.
(struct if_stack: fname): Mark const.
(is_idchar, is_idstart, is_hor_space, trigraph_table): Delete.
(IStable): New character-syntax array which encompasses all
the old is_foo arrays.
(is_idchar, is_numchar, is_idstart, is_numstart, is_hspace,
is_space): New macros for interrogating IStable.
(check_macro_name): Kill last argument. All callers changed.
* cppinit.c (initialize_char_syntax): Delete.
(is_idchar, is_idstart, is_hor_space, is_space,
trigraph_table): Delete.
(IStable): New. Initialize with clever macros to avoid
information duplication.
(builtin_array): Table of builtins to get rid of explicit list
in initialize_builtins.
(initialize_builtins): Use builtins_array.
(cpp_start_read): Call init_IStable, and set IStable['$'] if
opts->dollars_in_ident.
* cppexp.c: Change all refs to is_xyz[] arrays to use new
is_xyz() macros.
(cpp_parse_expr): Avoid 'format string is not constant'
warning. Use ISGRAPH to identify printable chars.
* cppfiles.c: Change all refs to is_xyz[] arrays to use new
is_xyz() macros.
(read_and_prescan): Map trigraphs to chars with open-coded
if-else-if-... sequence, not a lookup table.
* cpphash.c: Change all refs to is_xyz[] arrays to use new
is_xyz() macros.
* cpplib.c: Change all refs to is_xyz[] arrays to use new
is_xyz() macros. Kill SKIP_ALL_WHITE_SPACE (unused).
(check_macro_name): Remove ability to report an invalid
assertion name, which is never used.
(do_line): Constify a couple of char *'s.
* cppmain.c (main): Call cpp_cleanup before returning.
Thu Oct 28 21:16:35 1999 Mark Mitchell <mark@codesourcery.com> Thu Oct 28 21:16:35 1999 Mark Mitchell <mark@codesourcery.com>
* ggc.h (struct ggc_statistics): New type. * ggc.h (struct ggc_statistics): New type.
......
...@@ -457,12 +457,12 @@ cpp_lex (pfile, skip_evaluation) ...@@ -457,12 +457,12 @@ cpp_lex (pfile, skip_evaluation)
cpp_skip_hspace (pfile); cpp_skip_hspace (pfile);
} }
if (!is_idstart[*ip->cur]) if (!is_idstart(*ip->cur))
goto oops; goto oops;
if (ip->cur[0] == 'L' && (ip->cur[1] == '\'' || ip->cur[1] == '"')) if (ip->cur[0] == 'L' && (ip->cur[1] == '\'' || ip->cur[1] == '"'))
goto oops; goto oops;
tok = ip->cur; tok = ip->cur;
while (is_idchar[*ip->cur]) while (is_idchar(*ip->cur))
++ip->cur; ++ip->cur;
len = ip->cur - tok; len = ip->cur - tok;
cpp_skip_hspace (pfile); cpp_skip_hspace (pfile);
...@@ -1010,10 +1010,10 @@ cpp_parse_expr (pfile) ...@@ -1010,10 +1010,10 @@ cpp_parse_expr (pfile)
} }
break; break;
default: default:
cpp_error (pfile, if (ISGRAPH (top[1].op))
(top[1].op >= ' ' && top[1].op <= '~' cpp_error (pfile, "unimplemented operator '%c'\n", top[1].op);
? "unimplemented operator '%c'\n" else
: "unimplemented operator '\\%03o'\n"), cpp_error (pfile, "unimplemented operator '\\%03o'\n",
top[1].op); top[1].op);
} }
} }
......
...@@ -437,10 +437,10 @@ read_filename_string (ch, f) ...@@ -437,10 +437,10 @@ read_filename_string (ch, f)
len = 20; len = 20;
set = alloc = xmalloc (len + 1); set = alloc = xmalloc (len + 1);
if (! is_space[ch]) if (! is_space(ch))
{ {
*set++ = ch; *set++ = ch;
while ((ch = getc (f)) != EOF && ! is_space[ch]) while ((ch = getc (f)) != EOF && ! is_space(ch))
{ {
if (set - alloc == len) if (set - alloc == len)
{ {
...@@ -503,10 +503,10 @@ read_name_map (pfile, dirname) ...@@ -503,10 +503,10 @@ read_name_map (pfile, dirname)
char *from, *to; char *from, *to;
struct file_name_map *ptr; struct file_name_map *ptr;
if (is_space[ch]) if (is_space(ch))
continue; continue;
from = read_filename_string (ch, f); from = read_filename_string (ch, f);
while ((ch = getc (f)) != EOF && is_hor_space[ch]) while ((ch = getc (f)) != EOF && is_hspace(ch))
; ;
to = read_filename_string (ch, f); to = read_filename_string (ch, f);
...@@ -976,7 +976,7 @@ read_and_prescan (pfile, fp, desc, len) ...@@ -976,7 +976,7 @@ read_and_prescan (pfile, fp, desc, len)
case SPECCASE_QUESTION: /* ? */ case SPECCASE_QUESTION: /* ? */
{ {
unsigned int d; unsigned int d, t;
/* If we're at the end of the intermediate buffer, /* If we're at the end of the intermediate buffer,
we have to shift the ?'s down to the start and we have to shift the ?'s down to the start and
come back next pass. */ come back next pass. */
...@@ -998,12 +998,27 @@ read_and_prescan (pfile, fp, desc, len) ...@@ -998,12 +998,27 @@ read_and_prescan (pfile, fp, desc, len)
*--ibase = '?'; *--ibase = '?';
goto read_next; goto read_next;
} }
if (!trigraph_table[d])
/* Trigraph map:
* from to from to from to
* ?? = # ?? ) ] ?? ! |
* ?? ( [ ?? ' ^ ?? > }
* ?? / \ ?? < { ?? - ~
*/
if (d == '=') t = '#';
else if (d == ')') t = ']';
else if (d == '!') t = '|';
else if (d == '(') t = '[';
else if (d == '\'') t = '^';
else if (d == '>') t = '}';
else if (d == '/') t = '\\';
else if (d == '<') t = '{';
else if (d == '-') t = '~';
else
{ {
*op++ = '?'; *op++ = '?';
break; break;
} }
if (CPP_OPTIONS (pfile)->warn_trigraphs) if (CPP_OPTIONS (pfile)->warn_trigraphs)
{ {
unsigned long col; unsigned long col;
...@@ -1014,10 +1029,10 @@ read_and_prescan (pfile, fp, desc, len) ...@@ -1014,10 +1029,10 @@ read_and_prescan (pfile, fp, desc, len)
} }
if (CPP_OPTIONS (pfile)->trigraphs) if (CPP_OPTIONS (pfile)->trigraphs)
{ {
if (trigraph_table[d] == '\\') if (t == '\\')
goto backslash; goto backslash;
else else
*op++ = trigraph_table[d]; *op++ = t;
} }
else else
{ {
......
...@@ -40,7 +40,7 @@ static struct tm *timestamp PARAMS ((cpp_reader *)); ...@@ -40,7 +40,7 @@ static struct tm *timestamp PARAMS ((cpp_reader *));
static void special_symbol PARAMS ((HASHNODE *, cpp_reader *)); static void special_symbol PARAMS ((HASHNODE *, cpp_reader *));
#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0) #define SKIP_WHITE_SPACE(p) do { while (is_hspace(*p)) p++; } while (0)
#define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->data != NULL) #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->data != NULL)
#define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N)) #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
...@@ -131,7 +131,7 @@ cpp_lookup (pfile, name, len, hash) ...@@ -131,7 +131,7 @@ cpp_lookup (pfile, name, len, hash)
if (len < 0) if (len < 0)
{ {
for (bp = name; is_idchar[*bp]; bp++); for (bp = name; is_idchar(*bp); bp++);
len = bp - name; len = bp - name;
} }
...@@ -224,7 +224,7 @@ cpp_install (pfile, name, len, type, value, hash) ...@@ -224,7 +224,7 @@ cpp_install (pfile, name, len, type, value, hash)
if (len < 0) if (len < 0)
{ {
p = name; p = name;
while (is_idchar[*p]) while (is_idchar(*p))
p++; p++;
len = p - name; len = p - name;
} }
...@@ -306,7 +306,7 @@ collect_expansion (pfile, buf, limit, nargs, arglist) ...@@ -306,7 +306,7 @@ collect_expansion (pfile, buf, limit, nargs, arglist)
/* Find the beginning of the trailing whitespace. */ /* Find the beginning of the trailing whitespace. */
p = buf; p = buf;
while (p < limit && is_space[limit[-1]]) while (p < limit && is_space(limit[-1]))
limit--; limit--;
/* Allocate space for the text in the macro definition. /* Allocate space for the text in the macro definition.
...@@ -376,7 +376,7 @@ collect_expansion (pfile, buf, limit, nargs, arglist) ...@@ -376,7 +376,7 @@ collect_expansion (pfile, buf, limit, nargs, arglist)
/* ##: concatenate preceding and following tokens. */ /* ##: concatenate preceding and following tokens. */
/* Take out the first #, discard preceding whitespace. */ /* Take out the first #, discard preceding whitespace. */
exp_p--; exp_p--;
while (exp_p > lastp && is_hor_space[exp_p[-1]]) while (exp_p > lastp && is_hspace(exp_p[-1]))
--exp_p; --exp_p;
/* Skip the second #. */ /* Skip the second #. */
p++; p++;
...@@ -392,7 +392,7 @@ collect_expansion (pfile, buf, limit, nargs, arglist) ...@@ -392,7 +392,7 @@ collect_expansion (pfile, buf, limit, nargs, arglist)
Don't leave the # in the expansion. */ Don't leave the # in the expansion. */
exp_p--; exp_p--;
SKIP_WHITE_SPACE (p); SKIP_WHITE_SPACE (p);
if (p == limit || !is_idstart[*p] if (p == limit || !is_idstart(*p)
|| (*p == 'L' && p + 1 < limit && (p[1] == '\'' || || (*p == 'L' && p + 1 < limit && (p[1] == '\'' ||
p[1] == '"'))) p[1] == '"')))
cpp_error (pfile, cpp_error (pfile,
...@@ -457,17 +457,17 @@ collect_expansion (pfile, buf, limit, nargs, arglist) ...@@ -457,17 +457,17 @@ collect_expansion (pfile, buf, limit, nargs, arglist)
} }
/* Handle the start of a symbol. */ /* Handle the start of a symbol. */
if (is_idchar[c] && nargs > 0) if (is_idchar(c) && nargs > 0)
{ {
U_CHAR *id_beg = p - 1; U_CHAR *id_beg = p - 1;
int id_len; int id_len;
--exp_p; --exp_p;
while (p != limit && is_idchar[*p]) while (p != limit && is_idchar(*p))
p++; p++;
id_len = p - id_beg; id_len = p - id_beg;
if (is_idstart[c] if (is_idstart(c)
&& !(id_len == 1 && c == 'L' && (*p == '\'' || *p == '"'))) && !(id_len == 1 && c == 'L' && (*p == '\'' || *p == '"')))
{ {
register struct arglist *arg; register struct arglist *arg;
...@@ -612,12 +612,12 @@ create_definition (buf, limit, pfile, predefinition) ...@@ -612,12 +612,12 @@ create_definition (buf, limit, pfile, predefinition)
bp = buf; bp = buf;
while (is_hor_space[*bp]) while (is_hspace(*bp))
bp++; bp++;
symname = bp; /* remember where it starts */ symname = bp; /* remember where it starts */
sym_length = check_macro_name (pfile, bp, 0); sym_length = check_macro_name (pfile, bp);
bp += sym_length; bp += sym_length;
/* Lossage will occur if identifiers or control keywords are broken /* Lossage will occur if identifiers or control keywords are broken
...@@ -648,11 +648,11 @@ create_definition (buf, limit, pfile, predefinition) ...@@ -648,11 +648,11 @@ create_definition (buf, limit, pfile, predefinition)
cpp_pedwarn (pfile, "another parameter follows `%s'", cpp_pedwarn (pfile, "another parameter follows `%s'",
rest_extension); rest_extension);
if (!is_idstart[*bp]) if (!is_idstart(*bp))
cpp_pedwarn (pfile, "invalid character in macro parameter name"); cpp_pedwarn (pfile, "invalid character in macro parameter name");
/* Find the end of the arg name. */ /* Find the end of the arg name. */
while (is_idchar[*bp]) while (is_idchar(*bp))
{ {
bp++; bp++;
/* do we have a "special" rest-args extension here? */ /* do we have a "special" rest-args extension here? */
...@@ -737,7 +737,7 @@ create_definition (buf, limit, pfile, predefinition) ...@@ -737,7 +737,7 @@ create_definition (buf, limit, pfile, predefinition)
if (bp < limit) if (bp < limit)
{ {
if (is_hor_space[*bp]) if (is_hspace(*bp))
{ {
bp++; bp++;
SKIP_WHITE_SPACE (bp); SKIP_WHITE_SPACE (bp);
...@@ -1141,7 +1141,7 @@ macroexpand (pfile, hp) ...@@ -1141,7 +1141,7 @@ macroexpand (pfile, hp)
/* cpp.texi says for foo ( ) we provide one argument. /* cpp.texi says for foo ( ) we provide one argument.
However, if foo wants just 0 arguments, treat this as 0. */ However, if foo wants just 0 arguments, treat this as 0. */
if (nargs == 0) if (nargs == 0)
while (bp != lim && is_space[*bp]) while (bp != lim && is_space(*bp))
bp++; bp++;
if (bp == lim) if (bp == lim)
i = 0; i = 0;
...@@ -1227,7 +1227,7 @@ macroexpand (pfile, hp) ...@@ -1227,7 +1227,7 @@ macroexpand (pfile, hp)
/* Internal sequences of whitespace are /* Internal sequences of whitespace are
replaced by one space except within replaced by one space except within
a string or char token. */ a string or char token. */
if (is_space[c]) if (is_space(c))
{ {
if (CPP_WRITTEN (pfile) > (unsigned) arg->stringified if (CPP_WRITTEN (pfile) > (unsigned) arg->stringified
&& (CPP_PWRITTEN (pfile))[-1] == '\r') && (CPP_PWRITTEN (pfile))[-1] == '\r')
...@@ -1333,11 +1333,11 @@ macroexpand (pfile, hp) ...@@ -1333,11 +1333,11 @@ macroexpand (pfile, hp)
&& last_ap->raw_after))) && last_ap->raw_after)))
{ {
/* Delete final whitespace. */ /* Delete final whitespace. */
while (totlen > count_before && is_space[xbuf[totlen - 1]]) while (totlen > count_before && is_space(xbuf[totlen - 1]))
totlen--; totlen--;
/* Delete the nonwhites before them. */ /* Delete the nonwhites before them. */
while (totlen > count_before && !is_space[xbuf[totlen - 1]]) while (totlen > count_before && !is_space(xbuf[totlen - 1]))
totlen--; totlen--;
} }
...@@ -1357,7 +1357,7 @@ macroexpand (pfile, hp) ...@@ -1357,7 +1357,7 @@ macroexpand (pfile, hp)
whitespace markers, and no-reexpansion markers. */ whitespace markers, and no-reexpansion markers. */
while (p1 != l1) while (p1 != l1)
{ {
if (is_space[p1[0]]) if (is_space(p1[0]))
p1++; p1++;
else if (p1[0] == '\r') else if (p1[0] == '\r')
p1 += 2; p1 += 2;
...@@ -1371,7 +1371,7 @@ macroexpand (pfile, hp) ...@@ -1371,7 +1371,7 @@ macroexpand (pfile, hp)
whitespace markers, and no-reexpansion markers. */ whitespace markers, and no-reexpansion markers. */
while (p1 != l1) while (p1 != l1)
{ {
if (is_space[l1[-1]]) if (is_space(l1[-1]))
l1--; l1--;
else if (l1[-1] == '\r') else if (l1[-1] == '\r')
l1--; l1--;
...@@ -1510,7 +1510,7 @@ unsafe_chars (c1, c2) ...@@ -1510,7 +1510,7 @@ unsafe_chars (c1, c2)
case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
letter: letter:
/* We're in the middle of either a name or a pre-processing number. */ /* We're in the middle of either a name or a pre-processing number. */
return (is_idchar[c2] || c2 == '.'); return (is_idchar(c2) || c2 == '.');
case '<': case '>': case '!': case '%': case '#': case ':': case '<': case '>': case '!': case '%': case '#': case ':':
case '^': case '&': case '|': case '*': case '/': case '=': case '^': case '&': case '|': case '*': case '/': case '=':
...@@ -1551,7 +1551,7 @@ push_macro_expansion (pfile, xbuf, xbuf_len, hp) ...@@ -1551,7 +1551,7 @@ push_macro_expansion (pfile, xbuf, xbuf_len, hp)
or some other (less common) characters. */ or some other (less common) characters. */
if (xbuf[0] == '\r' && xbuf[1] == ' ' if (xbuf[0] == '\r' && xbuf[1] == ' '
&& (is_idchar[xbuf[2]] || xbuf[2] == '(' || xbuf[2] == '\'' && (is_idchar(xbuf[2]) || xbuf[2] == '(' || xbuf[2] == '\''
|| xbuf[2] == '\"')) || xbuf[2] == '\"'))
mbuf->cur += 2; mbuf->cur += 2;
...@@ -1627,25 +1627,25 @@ comp_def_part (first, beg1, len1, beg2, len2, last) ...@@ -1627,25 +1627,25 @@ comp_def_part (first, beg1, len1, beg2, len2, last)
register U_CHAR *end2 = beg2 + len2; register U_CHAR *end2 = beg2 + len2;
if (first) if (first)
{ {
while (beg1 != end1 && is_space[*beg1]) while (beg1 != end1 && is_space(*beg1))
beg1++; beg1++;
while (beg2 != end2 && is_space[*beg2]) while (beg2 != end2 && is_space(*beg2))
beg2++; beg2++;
} }
if (last) if (last)
{ {
while (beg1 != end1 && is_space[end1[-1]]) while (beg1 != end1 && is_space(end1[-1]))
end1--; end1--;
while (beg2 != end2 && is_space[end2[-1]]) while (beg2 != end2 && is_space(end2[-1]))
end2--; end2--;
} }
while (beg1 != end1 && beg2 != end2) while (beg1 != end1 && beg2 != end2)
{ {
if (is_space[*beg1] && is_space[*beg2]) if (is_space(*beg1) && is_space(*beg2))
{ {
while (beg1 != end1 && is_space[*beg1]) while (beg1 != end1 && is_space(*beg1))
beg1++; beg1++;
while (beg2 != end2 && is_space[*beg2]) while (beg2 != end2 && is_space(*beg2))
beg2++; beg2++;
} }
else if (*beg1 == *beg2) else if (*beg1 == *beg2)
......
...@@ -25,8 +25,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -25,8 +25,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "cpphash.h" #include "cpphash.h"
#include "intl.h" #include "intl.h"
#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0) #define SKIP_WHITE_SPACE(p) do { while (is_hspace(*p)) p++; } while (0)
#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
#define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF) #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
#define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N)) #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
...@@ -411,7 +410,7 @@ cpp_skip_hspace (pfile) ...@@ -411,7 +410,7 @@ cpp_skip_hspace (pfile)
c = GETC(); c = GETC();
if (c == EOF) if (c == EOF)
return; return;
else if (is_hor_space[c]) else if (is_hspace(c))
{ {
if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile)) if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "%s in preprocessing directive", cpp_pedwarn (pfile, "%s in preprocessing directive",
...@@ -596,36 +595,29 @@ pass_thru_directive (buf, len, pfile, keyword) ...@@ -596,36 +595,29 @@ pass_thru_directive (buf, len, pfile, keyword)
CPP_PUTS_Q (pfile, buf, len); CPP_PUTS_Q (pfile, buf, len);
} }
/* Check a purported macro name SYMNAME, and yield its length. /* Check a purported macro name SYMNAME, and yield its length. */
ASSERTION is nonzero if this is really for an assertion name. */
int int
check_macro_name (pfile, symname, assertion) check_macro_name (pfile, symname)
cpp_reader *pfile; cpp_reader *pfile;
const U_CHAR *symname; const U_CHAR *symname;
int assertion;
{ {
const U_CHAR *p; const U_CHAR *p;
int sym_length; int sym_length;
for (p = symname; is_idchar[*p]; p++) for (p = symname; is_idchar(*p); p++)
; ;
sym_length = p - symname; sym_length = p - symname;
if (sym_length == 0 if (sym_length == 0
|| (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"'))) || (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
cpp_error (pfile, cpp_error (pfile, "invalid macro name");
assertion ? "invalid assertion name" : "invalid macro name"); else if (!is_idstart(*symname)
else if (!is_idstart[*symname]
|| (! strncmp (symname, "defined", 7) && sym_length == 7)) { || (! strncmp (symname, "defined", 7) && sym_length == 7)) {
U_CHAR *msg; /* what pain... */ U_CHAR *msg; /* what pain... */
msg = (U_CHAR *) alloca (sym_length + 1); msg = (U_CHAR *) alloca (sym_length + 1);
bcopy (symname, msg, sym_length); bcopy (symname, msg, sym_length);
msg[sym_length] = 0; msg[sym_length] = 0;
cpp_error (pfile, cpp_error (pfile, "invalid macro name `%s'", msg);
(assertion
? "invalid assertion name `%s'"
: "invalid macro name `%s'"),
msg);
} }
return sym_length; return sym_length;
} }
...@@ -1354,7 +1346,7 @@ do_line (pfile, keyword) ...@@ -1354,7 +1346,7 @@ do_line (pfile, keyword)
if (strcmp (fname, ip->nominal_fname)) if (strcmp (fname, ip->nominal_fname))
{ {
char *newname, *oldname; const char *newname, *oldname;
if (!strcmp (fname, ip->fname)) if (!strcmp (fname, ip->fname))
newname = ip->fname; newname = ip->fname;
else if (ip->last_nominal_fname else if (ip->last_nominal_fname
...@@ -1370,7 +1362,7 @@ do_line (pfile, keyword) ...@@ -1370,7 +1362,7 @@ do_line (pfile, keyword)
&& ip->last_nominal_fname != oldname && ip->last_nominal_fname != oldname
&& ip->last_nominal_fname != newname && ip->last_nominal_fname != newname
&& ip->last_nominal_fname != ip->fname) && ip->last_nominal_fname != ip->fname)
free (ip->last_nominal_fname); free ((void *) ip->last_nominal_fname);
if (newname == ip->fname) if (newname == ip->fname)
ip->last_nominal_fname = NULL; ip->last_nominal_fname = NULL;
...@@ -1415,7 +1407,7 @@ do_undef (pfile, keyword) ...@@ -1415,7 +1407,7 @@ do_undef (pfile, keyword)
cpp_skip_hspace (pfile); cpp_skip_hspace (pfile);
c = GETC(); c = GETC();
if (! is_idstart[c]) if (! is_idstart(c))
{ {
cpp_error (pfile, "token after #undef is not an identifier"); cpp_error (pfile, "token after #undef is not an identifier");
skip_rest_of_line (pfile); skip_rest_of_line (pfile);
...@@ -1440,7 +1432,7 @@ do_undef (pfile, keyword) ...@@ -1440,7 +1432,7 @@ do_undef (pfile, keyword)
CPP_SET_WRITTEN (pfile, here); CPP_SET_WRITTEN (pfile, here);
sym_length = check_macro_name (pfile, buf, 0); sym_length = check_macro_name (pfile, buf);
while ((hp = cpp_lookup (pfile, name, sym_length, -1)) != NULL) while ((hp = cpp_lookup (pfile, name, sym_length, -1)) != NULL)
{ {
...@@ -1643,10 +1635,10 @@ do_pragma (pfile, keyword) ...@@ -1643,10 +1635,10 @@ do_pragma (pfile, keyword)
{ {
U_CHAR *end = syms; U_CHAR *end = syms;
while (is_idchar[*end]) while (is_idchar(*end))
end++; end++;
if (!is_hor_space[*end] && *end != '\0') if (!is_hspace(*end) && *end != '\0')
{ {
cpp_error (pfile, "invalid #pragma poison directive"); cpp_error (pfile, "invalid #pragma poison directive");
return 1; return 1;
...@@ -1924,7 +1916,7 @@ do_xifdef (pfile, keyword) ...@@ -1924,7 +1916,7 @@ do_xifdef (pfile, keyword)
else { else {
U_CHAR *cp = buf; U_CHAR *cp = buf;
fprintf (pcp_outfile, "#undef "); fprintf (pcp_outfile, "#undef ");
while (is_idchar[*cp]) /* Ick! */ while (is_idchar(*cp)) /* Ick! */
fputc (*cp++, pcp_outfile); fputc (*cp++, pcp_outfile);
putc ('\n', pcp_outfile); putc ('\n', pcp_outfile);
} }
...@@ -2573,7 +2565,7 @@ cpp_get_token (pfile) ...@@ -2573,7 +2565,7 @@ cpp_get_token (pfile)
c = PEEKC (); c = PEEKC ();
if (c == EOF) if (c == EOF)
break; break;
if (!is_idchar[c] && c != '.' if (!is_idchar(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 != '-')))
...@@ -2598,7 +2590,7 @@ cpp_get_token (pfile) ...@@ -2598,7 +2590,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_idchar(c))
break; break;
CPP_PUTC (pfile, c); CPP_PUTC (pfile, c);
} }
...@@ -2720,7 +2712,7 @@ cpp_get_token (pfile) ...@@ -2720,7 +2712,7 @@ cpp_get_token (pfile)
{ {
CPP_PUTC (pfile, c); CPP_PUTC (pfile, c);
c = PEEKC (); c = PEEKC ();
if (c == EOF || !is_hor_space[c]) if (c == EOF || !is_hspace(c))
break; break;
FORWARD(1); FORWARD(1);
} }
...@@ -2816,7 +2808,7 @@ parse_name (pfile, c) ...@@ -2816,7 +2808,7 @@ parse_name (pfile, c)
{ {
for (;;) for (;;)
{ {
if (! is_idchar[c]) if (! is_idchar(c))
{ {
FORWARD (-1); FORWARD (-1);
break; break;
...@@ -2939,7 +2931,7 @@ parse_assertion (pfile) ...@@ -2939,7 +2931,7 @@ parse_assertion (pfile)
int c, dropwhite; int c, dropwhite;
cpp_skip_hspace (pfile); cpp_skip_hspace (pfile);
c = PEEKC(); c = PEEKC();
if (! is_idstart[c]) if (! is_idstart(c))
{ {
cpp_error (pfile, "assertion predicate is not an identifier"); cpp_error (pfile, "assertion predicate is not an identifier");
return 0; return 0;
...@@ -2951,7 +2943,7 @@ parse_assertion (pfile) ...@@ -2951,7 +2943,7 @@ parse_assertion (pfile)
c = PEEKC(); c = PEEKC();
if (c != '(') if (c != '(')
{ {
if (is_hor_space[c] || c == '\r') if (is_hspace(c) || c == '\r')
cpp_skip_hspace (pfile); cpp_skip_hspace (pfile);
c = PEEKC(); c = PEEKC();
} }
...@@ -2963,7 +2955,7 @@ parse_assertion (pfile) ...@@ -2963,7 +2955,7 @@ parse_assertion (pfile)
dropwhite = 1; dropwhite = 1;
while ((c = GETC()) != ')') while ((c = GETC()) != ')')
{ {
if (is_hor_space[c]) if (is_space(c))
{ {
if (! dropwhite) if (! dropwhite)
{ {
......
...@@ -96,11 +96,11 @@ struct cpp_buffer ...@@ -96,11 +96,11 @@ struct cpp_buffer
struct cpp_buffer *prev; struct cpp_buffer *prev;
/* Real filename. (Alias to ->ihash->fname, obsolete). */ /* Real filename. (Alias to ->ihash->fname, obsolete). */
char *fname; const char *fname;
/* Filename specified with #line command. */ /* Filename specified with #line command. */
char *nominal_fname; const char *nominal_fname;
/* Last filename specified with #line command. */ /* Last filename specified with #line command. */
char *last_nominal_fname; const char *last_nominal_fname;
/* Actual directory of this file, used only for "" includes */ /* Actual directory of this file, used only for "" includes */
struct file_name_list *actual_dir; struct file_name_list *actual_dir;
...@@ -550,11 +550,12 @@ struct include_hash ...@@ -550,11 +550,12 @@ struct include_hash
/* Location of the file in the include search path. /* Location of the file in the include search path.
Used for include_next */ Used for include_next */
struct file_name_list *foundhere; struct file_name_list *foundhere;
char *name; /* (partial) pathname of file */ const char *name; /* (partial) pathname of file */
char *nshort; /* name of file as referenced in #include */ const char *nshort; /* name of file as referenced in #include */
const char *control_macro; /* macro, if any, preventing reinclusion - see const char *control_macro; /* macro, if any, preventing reinclusion -
redundant_include_p */ see redundant_include_p */
char *buf, *limit; /* for file content cache, not yet implemented */ char *buf, *limit; /* for file content cache,
not yet implemented */
}; };
/* Name under which this program was invoked. */ /* Name under which this program was invoked. */
...@@ -610,7 +611,7 @@ typedef struct macrodef MACRODEF; ...@@ -610,7 +611,7 @@ typedef struct macrodef MACRODEF;
struct macrodef struct macrodef
{ {
struct definition *defn; struct definition *defn;
unsigned char *symnam; const U_CHAR *symnam;
int symlen; int symlen;
}; };
...@@ -665,18 +666,30 @@ struct definition { ...@@ -665,18 +666,30 @@ struct definition {
} args; } args;
}; };
/* These tables are not really `const', but they are only modified at /* Character classes.
If the definition of `numchar' looks odd to you, please look up the
definition of a pp-number in the C standard [section 6.4.8 of C99] */
#define ISidnum 0x01 /* a-zA-Z0-9_ */
#define ISidstart 0x02 /* _a-zA-Z */
#define ISnumstart 0x04 /* 0-9 */
#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)
/* This table is not really `const', but it is only modified at
initialization time, in a separate translation unit from the rest initialization time, in a separate translation unit from the rest
of the library. We let the rest of the library think they are `const' of the library. We let the rest of the library think it is `const'
to get better code and some additional sanity checks. */ to get better code and some additional compile-time checks. */
#ifndef FAKE_CONST #ifndef FAKE_CONST
#define FAKE_CONST const #define FAKE_CONST const
#endif #endif
extern FAKE_CONST unsigned char is_idstart[256]; extern FAKE_CONST unsigned char IStable[256];
extern FAKE_CONST unsigned char is_idchar[256];
extern FAKE_CONST unsigned char is_hor_space[256];
extern FAKE_CONST unsigned char is_space[256];
extern FAKE_CONST unsigned char trigraph_table[256];
#undef FAKE_CONST #undef FAKE_CONST
/* Stack of conditionals currently in progress /* Stack of conditionals currently in progress
...@@ -684,7 +697,7 @@ extern FAKE_CONST unsigned char trigraph_table[256]; ...@@ -684,7 +697,7 @@ extern FAKE_CONST unsigned char trigraph_table[256];
struct if_stack { struct if_stack {
struct if_stack *next; /* for chaining to the next stack frame */ struct if_stack *next; /* for chaining to the next stack frame */
char *fname; /* copied from input when frame is made */ const char *fname; /* copied from input when frame is made */
int lineno; /* similarly */ int lineno; /* similarly */
int if_succeeded; /* true if a leg of this if-group int if_succeeded; /* true if a leg of this if-group
has been passed through rescan */ has been passed through rescan */
...@@ -739,7 +752,7 @@ extern void quote_string PARAMS ((cpp_reader *, const char *)); ...@@ -739,7 +752,7 @@ extern void quote_string PARAMS ((cpp_reader *, const char *));
extern void cpp_expand_to_buffer PARAMS ((cpp_reader *, const U_CHAR *, extern void cpp_expand_to_buffer PARAMS ((cpp_reader *, const U_CHAR *,
int)); int));
extern void cpp_scan_buffer PARAMS ((cpp_reader *)); extern void cpp_scan_buffer PARAMS ((cpp_reader *));
extern int check_macro_name PARAMS ((cpp_reader *, const U_CHAR *, int)); extern int check_macro_name PARAMS ((cpp_reader *, const U_CHAR *));
/* Last arg to output_line_command. */ /* Last arg to output_line_command. */
enum file_change_code {same_file, enter_file, leave_file}; enum file_change_code {same_file, enter_file, leave_file};
......
...@@ -117,6 +117,8 @@ main (argc, argv) ...@@ -117,6 +117,8 @@ main (argc, argv)
< CPP_WRITTEN (&parse_in)) < CPP_WRITTEN (&parse_in))
cpp_pfatal_with_name (&parse_in, opts->out_fname); cpp_pfatal_with_name (&parse_in, opts->out_fname);
cpp_cleanup (&parse_in);
if (parse_in.errors) if (parse_in.errors)
return (FATAL_EXIT_CODE); return (FATAL_EXIT_CODE);
return (SUCCESS_EXIT_CODE); return (SUCCESS_EXIT_CODE);
......
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