Commit ff2b53ef by Zack Weinberg Committed by Zack Weinberg

cpphash.c (CPP_IS_MACRO_BUFFER, [...]): Delete.

	* cpphash.c (CPP_IS_MACRO_BUFFER, FORWARD, PEEKC): Delete.
	(macro_cleanup): No need to cast pbuf->macro.
	(collect_expansion): Use _cpp_get_define_token.  Goto done if
	it returns VSPACE.  Remove check for trailing space after
	CPP_COMMENT.
	(_cpp_create_definition): Don't diddle flags here.  Return
	directly on error.
	(unsafe_chars): Handle c1 being EOF.
	(push_macro_expansion): Use unsafe_chars for both accidental-paste
	checks.  Don't push the buffer till after we're done with
	them.
	* cpplex.c (PEEKBUF, GETBUF, FORWARDBUF): New.
	(PEEKN, FORWARD, GETC, PEEKC): Use them.
	(cpp_push_buffer): Don't set new->alimit.  Set new->mark
	appropriately.
	(_cpp_parse_assertion): Don't NUL terminate.
	(_cpp_lex_token): Fix -traditional macro handling.  Don't skip
	hspace before calling _cpp_parse_assertion.  Remove all sets
	of only_seen_white. Treat '\f' as hspace.  Don't do anything
	special with '\n' here.
	(maybe_macroexpand): Handle T_EMPTY hash entries without
	pushing a buffer at all.
	(cpp_get_token): Handle clearing only_seen_white here.  Handle
	incrementing the line number here.  Clear
	potential_control_macro as well as only_seen_white, if
	appropriate.
	(cpp_get_non_space_token): Don't eat CPP_POP tokens.
	(_cpp_get_define_token): New function, basically like
	_cpp_get_directive_token was but doesn't eat horizontal space.
	Don't do anything with only_seen_white here.
	(_cpp_get_directive_token): Just call _cpp_get_define_token
	repeatedly till it returns non-hspace.

	* cpplib.c (PEEKN, FORWARD, GETC, PEEKC): Delete.
	(conditional_skip, skip_if_group): Return int.
	(DIRECTIVE_TABLE): Change origin of all conditional directives
	to "COND".
	(TRAD_DIRECT_P): New macro.
	(_cpp_handle_directive): Use _cpp_get_directive_token.  Issue
	an error for a bogus directive, unless -lang-asm.  Use
	TRAD_DIRECT_P. Loop calling handler functions till one returns
	zero.
	(get_macro_name): Don't diddle flags here.
	(do_define): Diddle flags here.  Use _cpp_get_directive_token.
	Create T_EMPTY nodes for #define macro /* nothing */.
	(do_undef): Don't copy the name.  Use _cpp_get_directive_token.
	Use hp->name when calling pass_thru_directive.
	(do_if, do_else, do_elif, do_ifdef, do_ifndef, conditional_skip):
	Return the result of conditional_skip and/or skip_if_group.
	Don't call _cpp_output_line_command.
	(consider_directive_while_skipping): Use _cpp_get_directive_token.
	Issue -Wtraditional warnings as appropriate.  Don't complain
	about unrecognized directives.  If we are to stop skipping,
	return the number of the directive that ended the skip.
	(skip_if_group): Use _cpp_get_directive_token.  Turn off macro
	expansion and line commands while skipping.  Return the result
	of consider_directive_while_skipping, if nonzero.
	(do_endif): Just set potential_control_macro here.
	(validate_else): Use _cpp_get_directive_token.
	(do_assert, do_unassert): Don't save pointers into the
	token_buffer across calls to the lexer.  Use
	_cpp_get_directive_token.

	* cpplib.h (cpp_buffer): Remove alimit and colno.  Make mark a
	pointer, not an offset.  Replace 'data', which was a generic
	pointer, with 'macro', which points to a struct hashnode.
	(cpp_reader): Add 'potential_control_macro' pointer.
	* cpphash.h (T_UNUSED): Replace with T_EMPTY.
	(CPP_BUF_GET, CPP_FORWARD): Delete.
	(CPP_IN_COLUMN_1, ADJACENT_TO_MARK): New macros.
	(CPP_IS_MACRO_BUFFER, CPP_SET_BUF_MARK, CPP_GOTO_BUF_MARK,
	ACTIVE_MARK_P): Update.
	(_cpp_get_define_token): New internal function.
	* cppfiles.c (read_include_file): Don't set fp->alimit or fp->colno.

From-SVN: r32965
parent edea3682
2000-04-06 Zack Weinberg <zack@wolery.cumb.org>
* cpphash.c (CPP_IS_MACRO_BUFFER, FORWARD, PEEKC): Delete.
(macro_cleanup): No need to cast pbuf->macro.
(collect_expansion): Use _cpp_get_define_token. Goto done if
it returns VSPACE. Remove check for trailing space after
CPP_COMMENT.
(_cpp_create_definition): Don't diddle flags here. Return
directly on error.
(unsafe_chars): Handle c1 being EOF.
(push_macro_expansion): Use unsafe_chars for both accidental-paste
checks. Don't push the buffer till after we're done with
them.
* cpplex.c (PEEKBUF, GETBUF, FORWARDBUF): New.
(PEEKN, FORWARD, GETC, PEEKC): Use them.
(cpp_push_buffer): Don't set new->alimit. Set new->mark
appropriately.
(_cpp_parse_assertion): Don't NUL terminate.
(_cpp_lex_token): Fix -traditional macro handling. Don't skip
hspace before calling _cpp_parse_assertion. Remove all sets
of only_seen_white. Treat '\f' as hspace. Don't do anything
special with '\n' here.
(maybe_macroexpand): Handle T_EMPTY hash entries without
pushing a buffer at all.
(cpp_get_token): Handle clearing only_seen_white here. Handle
incrementing the line number here. Clear
potential_control_macro as well as only_seen_white, if
appropriate.
(cpp_get_non_space_token): Don't eat CPP_POP tokens.
(_cpp_get_define_token): New function, basically like
_cpp_get_directive_token was but doesn't eat horizontal space.
Don't do anything with only_seen_white here.
(_cpp_get_directive_token): Just call _cpp_get_define_token
repeatedly till it returns non-hspace.
* cpplib.c (PEEKN, FORWARD, GETC, PEEKC): Delete.
(conditional_skip, skip_if_group): Return int.
(DIRECTIVE_TABLE): Change origin of all conditional directives
to "COND".
(TRAD_DIRECT_P): New macro.
(_cpp_handle_directive): Use _cpp_get_directive_token. Issue
an error for a bogus directive, unless -lang-asm. Use
TRAD_DIRECT_P. Loop calling handler functions till one returns
zero.
(get_macro_name): Don't diddle flags here.
(do_define): Diddle flags here. Use _cpp_get_directive_token.
Create T_EMPTY nodes for #define macro /* nothing */.
(do_undef): Don't copy the name. Use _cpp_get_directive_token.
Use hp->name when calling pass_thru_directive.
(do_if, do_else, do_elif, do_ifdef, do_ifndef, conditional_skip):
Return the result of conditional_skip and/or skip_if_group.
Don't call _cpp_output_line_command.
(consider_directive_while_skipping): Use _cpp_get_directive_token.
Issue -Wtraditional warnings as appropriate. Don't complain
about unrecognized directives. If we are to stop skipping,
return the number of the directive that ended the skip.
(skip_if_group): Use _cpp_get_directive_token. Turn off macro
expansion and line commands while skipping. Return the result
of consider_directive_while_skipping, if nonzero.
(do_endif): Just set potential_control_macro here.
(validate_else): Use _cpp_get_directive_token.
(do_assert, do_unassert): Don't save pointers into the
token_buffer across calls to the lexer. Use
_cpp_get_directive_token.
* cpplib.h (cpp_buffer): Remove alimit and colno. Make mark a
pointer, not an offset. Replace 'data', which was a generic
pointer, with 'macro', which points to a struct hashnode.
(cpp_reader): Add 'potential_control_macro' pointer.
* cpphash.h (T_UNUSED): Replace with T_EMPTY.
(CPP_BUF_GET, CPP_FORWARD): Delete.
(CPP_IN_COLUMN_1, ADJACENT_TO_MARK): New macros.
(CPP_IS_MACRO_BUFFER, CPP_SET_BUF_MARK, CPP_GOTO_BUF_MARK,
ACTIVE_MARK_P): Update.
(_cpp_get_define_token): New internal function.
* cppfiles.c (read_include_file): Don't set fp->alimit or fp->colno.
2000-04-05 Benjamin Kosnik <bkoz@cygnus.com>
* configure.in: And here.
......
......@@ -742,12 +742,11 @@ read_include_file (pfile, fd, ihash)
ihash->control_macro = (const U_CHAR *) ""; /* never re-include */
close (fd);
fp->rlimit = fp->alimit = fp->buf + length;
fp->rlimit = fp->buf + length;
fp->cur = fp->buf;
if (ihash->foundhere != ABSOLUTE_PATH)
fp->system_header_p = ihash->foundhere->sysp;
fp->lineno = 1;
fp->colno = 1;
fp->line_base = fp->buf;
fp->cleanup = file_cleanup;
......
......@@ -45,10 +45,6 @@ static enum cpp_token macarg PARAMS ((cpp_reader *, int));
static struct tm *timestamp PARAMS ((cpp_reader *));
static void special_symbol PARAMS ((HASHNODE *, cpp_reader *));
#define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->data != NULL)
#define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
#define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
/* Initial hash table size. (It can grow if necessary - see hashtab.c.) */
#define HASHSIZE 500
......@@ -266,7 +262,7 @@ macro_cleanup (pbuf, pfile)
cpp_buffer *pbuf;
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
HASHNODE *macro = (HASHNODE *) pbuf->data;
HASHNODE *macro = pbuf->macro;
if (macro->type == T_DISABLED)
macro->type = T_MACRO;
if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
......@@ -314,26 +310,18 @@ collect_expansion (pfile, arglist)
last -= 2; /* two extra chars for the leading escape */
for (;;)
{
/* We use cpp_get_token because _cpp_get_directive_token would
discard whitespace and we can't cope with that yet. Macro
expansion is off, so we are guaranteed not to see POP or EOF. */
while (PEEKC () == '\r')
{
FORWARD (1);
CPP_BUMP_LINE (pfile);
}
if (PEEKC () == '\n')
goto done;
/* Macro expansion is off, so we are guaranteed not to see POP
or EOF. */
here = CPP_WRITTEN (pfile);
token = cpp_get_token (pfile);
token = _cpp_get_define_token (pfile);
tok = pfile->token_buffer + here;
switch (token)
{
case CPP_POP:
case CPP_EOF:
cpp_ice (pfile, "EOF in collect_expansion");
/* fall through */
case CPP_VSPACE:
cpp_ice (pfile, "EOF or VSPACE in collect_expansion");
goto done;
case CPP_HSPACE:
......@@ -386,16 +374,14 @@ collect_expansion (pfile, arglist)
case CPP_COMMENT:
/* We must be in -traditional mode. Pretend this was a
token paste, but only if there was no leading or
trailing space and it's in the middle of the line. */
trailing space and it's in the middle of the line.
_cpp_lex_token won't return a COMMENT if there was trailing
space. */
CPP_SET_WRITTEN (pfile, here);
if (last_token == START)
break;
if (is_hspace (pfile->token_buffer[here-1]))
break;
if (is_hspace (PEEKC ()))
break;
if (PEEKC () == '\n')
break;
if (last_token == ARG)
endpat->raw_after = 1;
last_token = PASTE;
......@@ -738,38 +724,21 @@ _cpp_create_definition (pfile, funlike)
cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
file = CPP_BUFFER (pfile)->nominal_fname;
pfile->no_macro_expand++;
pfile->parsing_define_directive++;
CPP_OPTION (pfile, discard_comments)++;
CPP_OPTION (pfile, no_line_commands)++;
if (funlike)
{
args = collect_formal_parameters (pfile);
if (args == 0)
goto err;
return 0;
}
defn = collect_expansion (pfile, args);
if (defn == 0)
goto err;
return 0;
defn->line = line;
defn->file = file;
defn->col = col;
pfile->no_macro_expand--;
pfile->parsing_define_directive--;
CPP_OPTION (pfile, discard_comments)--;
CPP_OPTION (pfile, no_line_commands)--;
return defn;
err:
pfile->no_macro_expand--;
pfile->parsing_define_directive--;
CPP_OPTION (pfile, discard_comments)--;
CPP_OPTION (pfile, no_line_commands)--;
return 0;
}
/*
......@@ -1446,6 +1415,18 @@ unsafe_chars (pfile, c1, c2)
{
switch (c1)
{
case EOF:
/* We don't know what the previous character was. We do know
that it can't have been an idchar (or else it would have been
pasted with the idchars of the macro name), and there are a
number of second characters for which it doesn't matter what
the first was. */
if (is_idchar (c2) || c2 == '\'' || c2 == '\"'
|| c2 == '(' || c2 == '[' || c2 == '{'
|| c2 == ')' || c2 == ']' || c2 == '}')
return 0;
return 1;
case '+': case '-':
if (c2 == c1 || c2 == '=')
return 1;
......@@ -1488,17 +1469,14 @@ unsafe_chars (pfile, c1, c2)
}
static void
push_macro_expansion (pfile, xbuf, xbuf_len, hp)
push_macro_expansion (pfile, xbuf, len, hp)
cpp_reader *pfile;
register U_CHAR *xbuf;
int xbuf_len;
int len;
HASHNODE *hp;
{
register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len);
if (mbuf == NULL)
return;
mbuf->cleanup = macro_cleanup;
mbuf->data = hp;
cpp_buffer *mbuf;
int advance_cur = 0;
/* The first chars of the expansion should be a "\r " added by
collect_expansion. This is to prevent accidental token-pasting
......@@ -1507,34 +1485,31 @@ push_macro_expansion (pfile, xbuf, xbuf_len, hp)
We would like to avoid adding unneeded spaces (for the sake of
tools that use cpp, such as imake). In some common cases we can
tell that it is safe to omit the space.
The character before the macro invocation cannot have been an
idchar (or else it would have been pasted with the idchars of
the macro name). Therefore, if the first non-space character
of the expansion is an idchar, we do not need the extra space
to prevent token pasting.
Also, we don't need the extra space if the first char is '(',
or some other (less common) characters. */
tell that it is safe to omit the space. */
if (xbuf[0] == '\r' && xbuf[1] == ' '
&& (is_idchar(xbuf[2]) || xbuf[2] == '(' || xbuf[2] == '\''
|| xbuf[2] == '\"'))
mbuf->cur += 2;
&& !unsafe_chars (pfile, EOF, xbuf[2]))
advance_cur = 1;
/* Likewise, avoid the extra space at the end of the macro expansion
if this is safe. We can do a better job here since we can know
what the next char will be. */
if (xbuf_len >= 3
&& mbuf->rlimit[-2] == '\r'
&& mbuf->rlimit[-1] == ' ')
if (len >= 3
&& xbuf[len-2] == '\r'
&& xbuf[len-1] == ' ')
{
int c1 = mbuf->rlimit[-3];
int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
if (c2 == EOF || !unsafe_chars (pfile, c1, c2))
mbuf->rlimit -= 2;
int c = CPP_BUF_PEEK (CPP_BUFFER (pfile));
if (c == EOF || !unsafe_chars (pfile, xbuf[len-3], c))
len -= 2;
}
mbuf = cpp_push_buffer (pfile, xbuf, len);
if (mbuf == NULL)
return;
if (advance_cur)
mbuf->cur += 2;
mbuf->cleanup = macro_cleanup;
mbuf->macro = hp;
}
/* Return zero if two DEFINITIONs are isomorphic. */
......
......@@ -98,7 +98,7 @@ enum node_type
T_MACRO, /* macro defined by `#define' */
T_DISABLED, /* macro temporarily turned off for rescan */
T_POISON, /* macro defined with `#pragma poison' */
T_UNUSED /* Used for something not defined. */
T_EMPTY /* macro defined to nothing */
};
/* different kinds of things that can appear in the value field
......@@ -192,11 +192,11 @@ extern unsigned char _cpp_IStable[256];
/* Macros. */
/* One character lookahead in the input buffer. Note that if this
returns EOF, it does *not* necessarily mean the file's end has been
reached. */
#define CPP_BUF_PEEK(BUFFER) \
((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF)
#define CPP_BUF_GET(BUFFER) \
((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur++ : EOF)
#define CPP_FORWARD(BUFFER, N) ((BUFFER)->cur += (N))
/* Make sure PFILE->token_buffer has space for at least N more characters. */
#define CPP_RESERVE(PFILE, N) \
......@@ -223,6 +223,11 @@ extern unsigned char _cpp_IStable[256];
#define CPP_BUMP_LINE(PFILE) CPP_BUMP_BUFFER_LINE(CPP_BUFFER(PFILE))
#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
/* Are we in column 1 right now? Used mainly for -traditional handling
of directives. */
#define CPP_IN_COLUMN_1(PFILE) \
(CPP_BUFFER (PFILE)->cur - CPP_BUFFER (PFILE)->line_base == 1)
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
#define CPP_PEDANTIC(PFILE) \
......@@ -232,7 +237,7 @@ extern unsigned char _cpp_IStable[256];
/* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
(Note that it is false while we're expanding macro *arguments*.) */
#define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->data != NULL)
#define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->macro != NULL)
/* Remember the current position of PFILE so it may be returned to
after looking ahead a bit.
......@@ -241,14 +246,18 @@ extern unsigned char _cpp_IStable[256];
may not forget about it and continue parsing. You may not pop a
buffer with an active mark. You may not call CPP_BUMP_LINE while a
mark is active. */
#define CPP_SET_BUF_MARK(IP) ((IP)->mark = (IP)->cur - (IP)->buf)
#define CPP_GOTO_BUF_MARK(IP) ((IP)->cur = (IP)->buf + (IP)->mark, \
(IP)->mark = -1)
#define CPP_SET_BUF_MARK(IP) ((IP)->mark = (IP)->cur)
#define CPP_GOTO_BUF_MARK(IP) ((IP)->cur = (IP)->mark, (IP)->mark = 0)
#define CPP_SET_MARK(PFILE) CPP_SET_BUF_MARK(CPP_BUFFER(PFILE))
#define CPP_GOTO_MARK(PFILE) CPP_GOTO_BUF_MARK(CPP_BUFFER(PFILE))
/* ACTIVE_MARK_P is true if there's a live mark in the buffer. */
#define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != -1)
#define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != 0)
/* Are mark and point adjacent characters? Used mostly to deal with
the somewhat annoying semantic of #define. */
#define ADJACENT_TO_MARK(PFILE) \
(CPP_BUFFER(PFILE)->cur - CPP_BUFFER(PFILE)->mark == 1)
/* Last arg to output_line_command. */
enum file_change_code {same_file, rename_file, enter_file, leave_file};
......@@ -296,6 +305,8 @@ extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
extern enum cpp_token _cpp_get_directive_token
PARAMS ((cpp_reader *));
extern enum cpp_token _cpp_get_define_token
PARAMS ((cpp_reader *));
/* In cpplib.c */
extern int _cpp_handle_directive PARAMS ((cpp_reader *));
......
......@@ -67,8 +67,8 @@ struct cpp_buffer
const unsigned char *cur; /* current position */
const unsigned char *rlimit; /* end of valid data */
const unsigned char *buf; /* entire buffer */
const unsigned char *alimit; /* end of allocated buffer */
const unsigned char *line_base; /* start of current line */
const unsigned char *mark; /* Saved position for lengthy backtrack. */
struct cpp_buffer *prev;
......@@ -84,10 +84,11 @@ struct cpp_buffer
struct ihash *ihash;
long lineno; /* Line number at CPP_LINE_BASE. */
long colno; /* Column number at CPP_LINE_BASE. */
long mark; /* Saved position for lengthy backtrack. */
parse_cleanup_t cleanup;
void *data;
/* If the buffer is the expansion of a macro, this points to the
macro's hash table entry. */
struct hashnode *macro;
/* Value of if_stack at start of this file.
Used to prohibit unmatched #endif (etc) in an include file. */
......@@ -347,6 +348,7 @@ struct cpp_reader
unsigned int max_include_len;
struct if_stack *if_stack;
const unsigned char *potential_control_macro;
long lineno;
......
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