From 4d9a1b48f98e8580eeec9f7f006a6c6a6deef4bd Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Mon, 15 Feb 1999 14:04:21 +0000 Subject: [PATCH] c-common.c (UNGETC [USE_CPPLIB=1]): Do nothing if c is EOF. 1999-02-15 16:59 -0500 Zack Weinberg * c-common.c (UNGETC [USE_CPPLIB=1]): Do nothing if c is EOF. * c-lex.c: Likewise. * cpplib.c (cpp_push_buffer, cpp_pop_buffer): Use a linked list in malloced memory for the buffer stack. (cpp_get_token): Don't pop the last buffer off the stack. Calls after CPP_EOF has been returned produce CPP_EOF with no state change. (cpp_finish): Pop last buffer here. (do_line): Don't free ip->last_nominal_fname if it is equal to ip->fname. (special_symbol): If a T_CONST is the empty string, push a single `@ ' escape instead. (macroexpand): Special symbol buffers have escapes too. * cpplib.h (struct cpp_buffer): Remove unused fields, add prev buffer pointer. (struct cpp_reader): Remove buffer_stack. Add buffer_stack_depth. (CPP_PREV_BUFFER, CPP_NULL_BUFFER): Buffer stack is now a linked list. From-SVN: r25218 --- gcc/ChangeLog | 23 +++++++++++++++++++++++ gcc/c-common.c | 2 +- gcc/c-lex.c | 2 +- gcc/cpplib.c | 57 ++++++++++++++++++++++++++++++++++++--------------------- gcc/cpplib.h | 23 +++++++++++++---------- 5 files changed, 74 insertions(+), 33 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6300fd6..37de7cb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,26 @@ + +1999-02-15 16:59 -0500 Zack Weinberg + + * c-common.c (UNGETC [USE_CPPLIB=1]): Do nothing if c is EOF. + * c-lex.c: Likewise. + * cpplib.c (cpp_push_buffer, cpp_pop_buffer): Use a linked + list in malloced memory for the buffer stack. + (cpp_get_token): Don't pop the last buffer off the stack. + Calls after CPP_EOF has been returned produce CPP_EOF with no + state change. + (cpp_finish): Pop last buffer here. + (do_line): Don't free ip->last_nominal_fname if it is equal to + ip->fname. + (special_symbol): If a T_CONST is the empty string, push a + single `@ ' escape instead. + (macroexpand): Special symbol buffers have escapes too. + * cpplib.h (struct cpp_buffer): Remove unused fields, add prev + buffer pointer. + (struct cpp_reader): Remove buffer_stack. Add + buffer_stack_depth. + (CPP_PREV_BUFFER, CPP_NULL_BUFFER): Buffer stack is now a + linked list. + Mon Feb 15 14:44:53 1999 Kaveh R. Ghazi * cccp.c: Don't define HOST_WIDE_INT. Replace all occurrences of diff --git a/gcc/c-common.c b/gcc/c-common.c index f78d524..5975236 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -2826,7 +2826,7 @@ truthvalue_conversion (expr) unsigned char *yy_cur, *yy_lim; #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ()) -#define UNGETC(c) ((c), yy_cur--) +#define UNGETC(c) ((c) == EOF ? 0 : yy_cur--) int yy_get_token () diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 71a21aa..54734af 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -79,7 +79,7 @@ extern unsigned char *yy_cur, *yy_lim; extern int yy_get_token (); #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ()) -#define UNGETC(c) ((void)(c), yy_cur--) +#define UNGETC(c) ((c) == EOF ? 0 : yy_cur--) #else #define GETC() getc (finput) #define UNGETC(c) ungetc (c, finput) diff --git a/gcc/cpplib.c b/gcc/cpplib.c index c6f616d..838935f 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -1479,23 +1479,25 @@ cpp_push_buffer (pfile, buffer, length) U_CHAR *buffer; long length; { - register cpp_buffer *buf = CPP_BUFFER (pfile); - if (buf == pfile->buffer_stack) + cpp_buffer *buf = CPP_BUFFER (pfile); + cpp_buffer *new; + if (++pfile->buffer_stack_depth == CPP_STACK_MAX) { - cpp_fatal (pfile, "%s: macro or `#include' recursion too deep", - buf->fname); + cpp_fatal (pfile, "macro or `#include' recursion too deep"); return NULL; } - buf--; - bzero ((char *) buf, sizeof (cpp_buffer)); - CPP_BUFFER (pfile) = buf; - buf->if_stack = pfile->if_stack; - buf->cleanup = null_cleanup; - buf->underflow = null_underflow; - buf->buf = buf->cur = buffer; - buf->alimit = buf->rlimit = buffer + length; - - return buf; + + new = xcalloc (sizeof (cpp_buffer), 1); + + new->if_stack = pfile->if_stack; + new->cleanup = null_cleanup; + new->underflow = null_underflow; + new->buf = new->cur = buffer; + new->alimit = new->rlimit = buffer + length; + new->prev = buf; + + CPP_BUFFER (pfile) = new; + return new; } cpp_buffer * @@ -1504,7 +1506,10 @@ cpp_pop_buffer (pfile) { cpp_buffer *buf = CPP_BUFFER (pfile); (*buf->cleanup) (buf, pfile); - return ++CPP_BUFFER (pfile); + CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf); + free (buf); + pfile->buffer_stack_depth--; + return CPP_BUFFER (pfile); } /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer. @@ -1940,6 +1945,8 @@ special_symbol (hp, pfile) buf = hp->value.cpval; if (!buf) return; + if (*buf == '\0') + buf = "@ "; len = strlen (buf); CPP_RESERVE (pfile, len + 1); @@ -2166,6 +2173,7 @@ macroexpand (pfile, hp) CPP_SET_WRITTEN (pfile, old_written); bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1); push_macro_expansion (pfile, xbuf, xbuf_len, hp); + CPP_BUFFER (pfile)->has_escapes = 1; return; } @@ -2976,7 +2984,8 @@ do_line (pfile, keyword) if (ip->last_nominal_fname && ip->last_nominal_fname != oldname - && ip->last_nominal_fname != newname) + && ip->last_nominal_fname != newname + && ip->last_nominal_fname != ip->fname) free (ip->last_nominal_fname); if (newname == ip->fname) @@ -3711,7 +3720,7 @@ cpp_get_token (pfile) long start_line, start_column; enum cpp_token token; struct cpp_options *opts = CPP_OPTIONS (pfile); - CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur; + get_next: c = GETC(); if (c == EOF) @@ -3719,10 +3728,11 @@ cpp_get_token (pfile) handle_eof: if (CPP_BUFFER (pfile)->seen_eof) { - if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile)) - goto get_next; - else + if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) == CPP_NULL_BUFFER (pfile)) return CPP_EOF; + + cpp_pop_buffer (pfile); + goto get_next; } else { @@ -5523,6 +5533,11 @@ cpp_finish (pfile) cpp_reader *pfile; { struct cpp_options *opts = CPP_OPTIONS (pfile); + + if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) != CPP_NULL_BUFFER (pfile)) + cpp_fatal (pfile, + "cpplib internal error: buffers still stacked in cpp_finish"); + cpp_pop_buffer (pfile); if (opts->print_deps) { @@ -5578,7 +5593,7 @@ cpp_cleanup (pfile) cpp_reader *pfile; { int i; - while ( CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile)) + while (CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile)) cpp_pop_buffer (pfile); if (pfile->token_buffer) diff --git a/gcc/cpplib.h b/gcc/cpplib.h index 9572bb8..8a33eed 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -98,13 +98,16 @@ extern void cpp_cleanup PARAMS ((cpp_reader *PFILE)); /* If we have a huge buffer, may need to cache more recent counts */ #define CPP_LINE_BASE(BUF) ((BUF)->buf + (BUF)->line_base) -struct cpp_buffer { - unsigned char *buf; - unsigned char *cur; +struct cpp_buffer +{ + unsigned char *cur; /* current position */ unsigned char *rlimit; /* end of valid data */ + unsigned char *buf; /* entire buffer */ unsigned char *alimit; /* end of allocated buffer */ - unsigned char *prev; /* start of current token */ + struct cpp_buffer *prev; + + /* Real filename. (Alias to ->ihash->fname, obsolete). */ char *fname; /* Filename specified with #line command. */ char *nominal_fname; @@ -114,8 +117,7 @@ struct cpp_buffer { struct file_name_list *actual_dir; /* Pointer into the include hash table. Used for include_next and - to record control macros. - ->fname is an alias to ->ihash->fname. */ + to record control macros. */ struct include_hash *ihash; long line_base; @@ -176,6 +178,9 @@ struct cpp_reader /* Current depth in #include directives that use <...>. */ int system_include_depth; + /* Current depth of buffer stack. */ + int buffer_stack_depth; + /* Hash table of other included files. See cppfiles.c */ #define ALL_INCLUDE_HASHSIZE 71 struct include_hash *all_include_files[ALL_INCLUDE_HASHSIZE]; @@ -244,8 +249,6 @@ struct cpp_reader #ifdef __cplusplus ~cpp_reader () { cpp_cleanup (this); } #endif - - cpp_buffer buffer_stack[CPP_STACK_MAX]; }; #define CPP_FATAL_LIMIT 1000 @@ -290,9 +293,9 @@ struct cpp_reader #define CPP_OPTIONS(PFILE) ((PFILE)->opts) #define CPP_BUFFER(PFILE) ((PFILE)->buffer) -#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)+1) +#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev) /* The bottom of the buffer stack. */ -#define CPP_NULL_BUFFER(PFILE) (&(PFILE)->buffer_stack[CPP_STACK_MAX]) +#define CPP_NULL_BUFFER(PFILE) NULL /* Pointed to by cpp_reader.opts. */ struct cpp_options { -- 2.7.4