From: Neil Booth Date: Tue, 4 Jun 2002 13:07:06 +0000 (+0000) Subject: cpphash.h (FIRST, [...]): New. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=82eda77ed5c4548bd5cbb3f5bbe6f3453a3d1eea;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3f2df697a8f..8a198ec0031 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2002-06-04 Neil Booth + + * 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 * gbl-ctors.h: Fix formatting. diff --git a/gcc/cpphash.h b/gcc/cpphash.h index a059e2b0aac..6d3f1b9fb09 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -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. */ diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index 28095f25e9e..ae5dfa92ec9 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -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--; } } diff --git a/gcc/cpptrad.c b/gcc/cpptrad.c index d5c2126a55a..4f4d97c9ca7 100644 --- a/gcc/cpptrad.c +++ b/gcc/cpptrad.c @@ -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;