c-common.c (UNGETC [USE_CPPLIB=1]): Do nothing if c is EOF.
authorZack Weinberg <zack@midnite.ec.rhno.columbia.edu>
Mon, 15 Feb 1999 14:04:21 +0000 (14:04 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Mon, 15 Feb 1999 14:04:21 +0000 (14:04 +0000)
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.

From-SVN: r25218

gcc/ChangeLog
gcc/c-common.c
gcc/c-lex.c
gcc/cpplib.c
gcc/cpplib.h

index 6300fd65fe7b6353665d09cfd7c2906c74f9874a..37de7cb89a495a91483ffe7e972f6aa8658f6199 100644 (file)
@@ -1,3 +1,26 @@
+
+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
index f78d5240446cf7fde50706248a519f7968db0eb8..5975236a3931260c27b5041c5ef7b3f096e87b63 100644 (file)
@@ -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 ()
index 71a21aae8cb6e2c0c5fc085178dfd370df9dbba2..54734afef93defc27e3da1b878c12c1cb4b66bcb 100644 (file)
@@ -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)
index c6f616dd516d11a853bc4268daed8ee6313140a5..838935f9f6a9fa10fc3ee91af2aa676187748014 100644 (file)
@@ -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)
index 9572bb8d12e196f1d0a01871cb26fa84edf5e159..8a33eed346bf7ca8b3b1221130cd6791c1f991e2 100644 (file)
@@ -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 {