cpphash.h (FIRST, [...]): New.

* cpphash.h (FIRST, LAST, CUR, RLIMIT): New.
	(struct cpp_context): Add traditional fields.
	* cppmacro.c (paste_all_tokens, push_ptoken_context,
	push_token_context, cpp_get_token, _cpp_backup_tokens): Update.
	* cpptrad.c (skip_comment, lex_identifier,
	_cpp_read_logical_line_trad, scan_out_logical_line): Update.

From-SVN: r54242
This commit is contained in:
Neil Booth 2002-06-04 13:07:06 +00:00 committed by Neil Booth
parent 589005ff21
commit 82eda77ed5
4 changed files with 64 additions and 31 deletions

View File

@ -1,3 +1,12 @@
2002-06-04 Neil Booth <neil@daikokuya.demon.co.uk>
* cpphash.h (FIRST, LAST, CUR, RLIMIT): New.
(struct cpp_context): Add traditional fields.
* cppmacro.c (paste_all_tokens, push_ptoken_context,
push_token_context, cpp_get_token, _cpp_backup_tokens): Update.
* cpptrad.c (skip_comment, lex_identifier,
_cpp_read_logical_line_trad, scan_out_logical_line): Update.
2002-06-04 Kazu Hirata <kazu@cs.umass.edu>
* gbl-ctors.h: Fix formatting.

View File

@ -126,16 +126,36 @@ struct tokenrun
cpp_token *base, *limit;
};
/* Accessor macros for struct cpp_context. */
#define FIRST(c) (c->u.iso.first)
#define LAST(c) (c->u.iso.last)
#define CUR(c) (c->u.trad.cur)
#define RLIMIT(c) (c->u.trad.rlimit)
typedef struct cpp_context cpp_context;
struct cpp_context
{
/* Doubly-linked list. */
cpp_context *next, *prev;
/* Contexts other than the base context are contiguous tokens.
e.g. macro expansions, expanded argument tokens. */
union utoken first;
union utoken last;
union
{
/* For ISO macro expansion. Contexts other than the base context
are contiguous tokens. e.g. macro expansions, expanded
argument tokens. */
struct
{
union utoken first;
union utoken last;
} iso;
/* For traditional macro expansion. */
struct
{
const uchar *cur;
const uchar *rlimit;
} trad;
} u;
/* If non-NULL, a buffer used for storage related to this context.
When the context is popped, the buffer is released. */

View File

@ -425,9 +425,9 @@ paste_all_tokens (pfile, lhs)
inserted. In either case, the constraints to #define
guarantee we have at least one more token. */
if (context->direct_p)
rhs = context->first.token++;
rhs = FIRST (context).token++;
else
rhs = *context->first.ptoken++;
rhs = *FIRST (context).ptoken++;
if (rhs->type == CPP_PADDING)
abort ();
@ -896,8 +896,8 @@ push_ptoken_context (pfile, macro, buff, first, count)
context->direct_p = false;
context->macro = macro;
context->buff = buff;
context->first.ptoken = first;
context->last.ptoken = first + count;
FIRST (context).ptoken = first;
LAST (context).ptoken = first + count;
}
/* Push a list of tokens. */
@ -913,8 +913,8 @@ push_token_context (pfile, macro, first, count)
context->direct_p = true;
context->macro = macro;
context->buff = NULL;
context->first.token = first;
context->last.token = first + count;
FIRST (context).token = first;
LAST (context).token = first + count;
}
/* Expand an argument ARG before replacing parameters in a
@ -1004,12 +1004,12 @@ cpp_get_token (pfile)
/* Context->prev == 0 <=> base context. */
if (!context->prev)
result = _cpp_lex_token (pfile);
else if (context->first.token != context->last.token)
else if (FIRST (context).token != LAST (context).token)
{
if (context->direct_p)
result = context->first.token++;
result = FIRST (context).token++;
else
result = *context->first.ptoken++;
result = *FIRST (context).ptoken++;
if (result->flags & PASTE_LEFT)
{
@ -1118,9 +1118,9 @@ _cpp_backup_tokens (pfile, count)
if (count != 1)
abort ();
if (pfile->context->direct_p)
pfile->context->first.token--;
FIRST (pfile->context).token--;
else
pfile->context->first.ptoken--;
FIRST (pfile->context).ptoken--;
}
}

View File

@ -23,7 +23,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Lexing TODO: Handle -C, maybe -CC, and space in escaped newlines.
Stop cpplex.c from recognizing comments and directives during its
lexing pass. */
lexing pass. Get rid of line_base usage - seems pointless? */
static const uchar *handle_newline PARAMS ((cpp_reader *, const uchar *));
static const uchar *skip_escaped_newlines PARAMS ((cpp_reader *,
@ -90,8 +90,8 @@ skip_comment (pfile, cur)
const uchar *cur;
{
unsigned int from_line = pfile->line;
unsigned int c = 0, prevc;
const uchar *limit = pfile->buffer->rlimit;
unsigned int c = 0, prevc = 0;
const uchar *limit = RLIMIT (pfile->context);
while (cur < limit)
{
@ -138,7 +138,7 @@ lex_identifier (pfile, cur)
}
while (ISIDNUM (*cur));
pfile->buffer->cur = cur;
CUR (pfile->context) = cur;
len = out - pfile->trad_out_cur;
pfile->trad_out_cur = out;
return (cpp_hashnode *) ht_lookup (pfile->hash_table, pfile->trad_out_cur,
@ -206,8 +206,12 @@ _cpp_read_logical_line_trad (pfile)
return false;
}
CUR (pfile->context) = buffer->cur;
RLIMIT (pfile->context) = buffer->rlimit;
pfile->trad_out_cur = pfile->trad_out_base;
scan_out_logical_line (pfile);
buffer->cur = CUR (pfile->context);
pfile->trad_line = pfile->line;
pfile->line = first_line;
_cpp_overlay_buffer (pfile, pfile->trad_out_base,
@ -222,12 +226,12 @@ static void
scan_out_logical_line (pfile)
cpp_reader *pfile;
{
cpp_buffer *buffer = pfile->buffer;
const uchar *cur = buffer->cur;
cpp_context *context = pfile->context;
const uchar *cur = CUR (context);
unsigned int c, quote = 0;
uchar *out;
check_output_buffer (pfile, buffer->rlimit - cur);
check_output_buffer (pfile, RLIMIT (context) - cur);
out = pfile->trad_out_cur;
for (;;)
@ -240,20 +244,20 @@ scan_out_logical_line (pfile)
switch (c)
{
case '\0':
if (cur - 1 != buffer->rlimit)
if (cur - 1 != RLIMIT (context))
break;
cur--;
if (!buffer->from_stage3)
if (!pfile->buffer->from_stage3)
cpp_error (pfile, DL_PEDWARN, "no newline at end of file");
pfile->line++;
if (0)
{
case '\r': case '\n':
cur = handle_newline (pfile, cur - 1);
}
goto finish_output;
case '\r': case '\n':
cur = handle_newline (pfile, cur - 1);
finish_output:
out[-1] = '\n';
out[0] = '\0';
buffer->cur = cur;
CUR (context) = cur;
pfile->trad_out_cur = out;
return;
@ -306,7 +310,7 @@ scan_out_logical_line (pfile)
pfile->trad_out_cur = --out;
node = lex_identifier (pfile, cur - 1);
out = pfile->trad_out_cur;
cur = buffer->cur;
cur = CUR (context);
}
break;