+
+1999-02-15 16:59 -0500 Zack Weinberg <zack@midnite.ec.rhno.columbia.edu>
+
+ * 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 <ghazi@caip.rutgers.edu>
* cccp.c: Don't define HOST_WIDE_INT. Replace all occurrences of
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 ()
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)
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 *
{
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.
buf = hp->value.cpval;
if (!buf)
return;
+ if (*buf == '\0')
+ buf = "@ ";
len = strlen (buf);
CPP_RESERVE (pfile, len + 1);
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;
}
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)
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)
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
{
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)
{
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)
/* 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;
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;
/* 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];
#ifdef __cplusplus
~cpp_reader () { cpp_cleanup (this); }
#endif
-
- cpp_buffer buffer_stack[CPP_STACK_MAX];
};
#define CPP_FATAL_LIMIT 1000
#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 {