c-lex.c: s/change_file/file_change.
authorNeil Booth <neil@daikokuya.demon.co.uk>
Mon, 18 Dec 2000 19:00:26 +0000 (19:00 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Mon, 18 Dec 2000 19:00:26 +0000 (19:00 +0000)
        * c-lex.c: s/change_file/file_change.
        * cpplib.h: Similarly.
        * cppmain.c: Similarly.
        * fix-header.c: Similarly.
        * cppfiles.c (stack_include_file): Pass the buffer location and
        size to cpp_push_buffer.  Generate the file_change callback,
        so that sysp is already set.
        * cpphash.h: Add _cpp_do_file_change.
        * cpplib.c (do_line): Set buffer->sysp directly. Generate the
        file_change callback after setting sysp.
        (_cpp_do_file_change): Handle FC_ENTER and the FC_RENAME exception
        here.
        (cpp_push_buffer): Don't generate a callback.  Clear sysp.
        (cpp_pop_buffer): Clean up logic.

From-SVN: r38357

gcc/ChangeLog
gcc/c-lex.c
gcc/cppfiles.c
gcc/cpphash.h
gcc/cpplib.c
gcc/cpplib.h
gcc/cppmain.c
gcc/fix-header.c

index bc759f7f155cb2715bcac3a98bdf57cfc19529ec..76be2af58508d4f0d0122383d261aef2f888657e 100644 (file)
@@ -1,3 +1,20 @@
+2000-12-18  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+        * c-lex.c: s/change_file/file_change.
+        * cpplib.h: Similarly.
+        * cppmain.c: Similarly.
+        * fix-header.c: Similarly.
+        * cppfiles.c (stack_include_file): Pass the buffer location and
+        size to cpp_push_buffer.  Generate the file_change callback,
+        so that sysp is already set.
+        * cpphash.h: Add _cpp_do_file_change.
+        * cpplib.c (do_line): Set buffer->sysp directly. Generate the
+        file_change callback after setting sysp.
+        (_cpp_do_file_change): Handle FC_ENTER and the FC_RENAME exception
+        here.
+        (cpp_push_buffer): Don't generate a callback.  Clear sysp.
+        (cpp_pop_buffer): Clean up logic.
+
 2000-12-18  Benjamin Kosnik  <bkoz@redhat.com>
 
        * configure.in (gcc_gxx_include_dir): Simplify.
index 072aee74be5f3cb58c8066fadb13d843572eec15..645661d405956d88b81445dfebabaa3886f4118d 100644 (file)
@@ -90,7 +90,7 @@ static tree lex_charconst     PARAMS ((const char *, unsigned int, int));
 static void update_header_times        PARAMS ((const char *));
 static int dump_one_header     PARAMS ((splay_tree_node, void *));
 static void cb_ident           PARAMS ((cpp_reader *, const cpp_string *));
-static void cb_change_file    PARAMS ((cpp_reader *, const cpp_file_change *));
+static void cb_file_change    PARAMS ((cpp_reader *, const cpp_file_change *));
 static void cb_def_pragma      PARAMS ((cpp_reader *));
 \f
 const char *
@@ -120,7 +120,7 @@ init_c_lex (filename)
 #endif
 
   parse_in->cb.ident = cb_ident;
-  parse_in->cb.change_file = cb_change_file;
+  parse_in->cb.file_change = cb_file_change;
   parse_in->cb.def_pragma = cb_def_pragma;
 
   if (filename == 0 || !strcmp (filename, "-"))
@@ -226,7 +226,7 @@ cb_ident (pfile, str)
 }
 
 static void
-cb_change_file (pfile, fc)
+cb_file_change (pfile, fc)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      const cpp_file_change *fc;
 {
index 96ce7e48511dabf31463ad42f4e328c3471de078..ddf2e800f0afc2153c19c68d4ef49833e25968b1 100644 (file)
@@ -245,21 +245,19 @@ stack_include_file (pfile, inc)
      cpp_reader *pfile;
      struct include_file *inc;
 {
+  size_t len = 0;
   cpp_buffer *fp;
 
   /* Not in cache?  */
   if (! inc->buffer)
     read_include_file (pfile, inc);
 
-  /* Push a null buffer.  */
-  fp = cpp_push_buffer (pfile, NULL, 0, BUF_FILE, inc->name);
-  fp->inc = inc;
-  fp->buf = inc->buffer;
-  fp->rlimit = fp->buf;
   if (! DO_NOT_REREAD (inc))
-    fp->rlimit += inc->st.st_size;
-  fp->cur = fp->buf;
-  fp->line_base = fp->buf;
+    len = inc->st.st_size;
+
+  /* Push a buffer.  */
+  fp = cpp_push_buffer (pfile, inc->buffer, len, BUF_FILE, inc->name);
+  fp->inc = inc;
   fp->inc->refcnt++;
   if (inc->foundhere)
     fp->sysp = inc->foundhere->sysp;
@@ -273,6 +271,11 @@ stack_include_file (pfile, inc)
   pfile->mi_state = MI_OUTSIDE;
   pfile->mi_cmacro = 0;
   pfile->include_depth++;
+
+  /* Generate the call back.  */
+  fp->lineno = 0;
+  _cpp_do_file_change (pfile, FC_ENTER, 0, 0);
+  fp->lineno = 1;
 }
 
 /* Read the file referenced by INC into the file cache.
index a528f9127cd32f7e32e32dae258ecc894d444104..6cd162181a0d47243f60296a364ce63822868202 100644 (file)
@@ -229,6 +229,8 @@ extern void _cpp_do__Pragma PARAMS ((cpp_reader *));
 extern void _cpp_init_stacks   PARAMS ((cpp_reader *));
 extern void _cpp_cleanup_stacks        PARAMS ((cpp_reader *));
 extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
+extern void _cpp_do_file_change PARAMS ((cpp_reader *, enum cpp_fc_reason,
+                                        const char *, unsigned int));
 
 /* Utility routines and macros.  */
 #define DSC(str) (const U_CHAR *)str, sizeof str - 1
index 76d6cc3c58080fee84ae580e8e67764ebbc55068..c915f77454035aedd697f756e3c93d747cd31ecc 100644 (file)
@@ -108,8 +108,6 @@ static cpp_hashnode *parse_assertion PARAMS ((cpp_reader *, struct answer **,
 static struct answer ** find_answer PARAMS ((cpp_hashnode *,
                                             const struct answer *));
 static void handle_assertion   PARAMS ((cpp_reader *, const char *, int));
-static void do_file_change     PARAMS ((cpp_reader *, enum cpp_fc_reason,
-                                        const char *, unsigned int));
 
 /* This is the table of directive handlers.  It is ordered by
    frequency of occurrence; the numbers at the end are directive
@@ -768,10 +766,8 @@ do_line (pfile)
                                 buffer->nominal_fname);
                }
            }
-
-         cpp_make_system_header (pfile, sysp, sysp == 2);
+         buffer->sysp = sysp;
        }
-
       buffer->nominal_fname = fname;
     }
   else if (token.type != CPP_EOF)
@@ -783,37 +779,47 @@ do_line (pfile)
 
   /* Our line number is incremented after the directive is processed.  */
   buffer->lineno = new_lineno - 1;
-
-  if (reason == FC_RENAME)
-    {
-      /* Special case for file "foo.i" with "# 1 foo.c" on first line.  */
-      if (! buffer->prev && pfile->directive_pos.line == 1)
-       filename = 0;
-      do_file_change (pfile, reason, filename, lineno);
-    }
+  _cpp_do_file_change (pfile, reason, filename, lineno);
 }
 
 /* Arrange the file_change callback.  */
-static void
-do_file_change (pfile, reason, from_file, from_lineno)
+void
+_cpp_do_file_change (pfile, reason, from_file, from_lineno)
      cpp_reader *pfile;
      enum cpp_fc_reason reason;
      const char *from_file;
      unsigned int from_lineno;
 {
-  if (pfile->cb.change_file)
+  if (pfile->cb.file_change)
     {
       cpp_file_change fc;
       cpp_buffer *buffer = pfile->buffer;
 
       fc.reason = reason;
-      fc.from.filename = from_file;
-      fc.from.lineno = from_lineno;
       fc.to.filename = buffer->nominal_fname;
       fc.to.lineno = buffer->lineno + 1;
       fc.sysp = buffer->sysp;
       fc.externc = CPP_OPTION (pfile, cplusplus) && buffer->sysp == 2;
-      pfile->cb.change_file (pfile, &fc);
+
+      /* Caller doesn't need to handle FC_ENTER.  */
+      if (reason == FC_ENTER)
+       {
+         if (buffer->prev)
+           {
+             from_file = buffer->prev->nominal_fname;
+             from_lineno = buffer->prev->lineno;
+           }
+         else
+           from_file = 0;
+       }
+      /* Special case for file "foo.i" with "# 1 foo.c" on first line.  */
+      else if (reason == FC_RENAME && ! buffer->prev
+              && pfile->directive_pos.line == 1)
+       from_file = 0;
+
+      fc.from.filename = from_file;
+      fc.from.lineno = from_lineno;
+      pfile->cb.file_change (pfile, &fc);
     }
 }
 
@@ -1708,9 +1714,9 @@ handle_assertion (pfile, str, type)
   run_directive (pfile, type, BUF_CL_OPTION, str, count);
 }
 
-/* Push a new buffer on the buffer stack.  Buffer can be NULL, but
-   then LEN should be 0.  Returns the new buffer; it doesn't fail.  */
-
+/* Push a new buffer on the buffer stack.  Returns the new buffer; it
+   doesn't fail.  It does not generate a file change call back; that
+   is the responsibility of the caller.  */
 cpp_buffer *
 cpp_push_buffer (pfile, buffer, len, type, filename)
      cpp_reader *pfile;
@@ -1741,6 +1747,7 @@ cpp_push_buffer (pfile, buffer, len, type, filename)
 
       new->line_base = new->buf = new->cur = buffer;
       new->rlimit = buffer + len;
+      new->sysp = 0;
 
       /* No read ahead or extra char initially.  */
       new->read_ahead = EOF;
@@ -1758,38 +1765,26 @@ cpp_push_buffer (pfile, buffer, len, type, filename)
   new->prev = pfile->buffer;
   new->pfile = pfile;
   new->include_stack_listed = 0;
+  new->lineno = 1;
 
   pfile->state.next_bol = 1;
   pfile->buffer_stack_depth++;
   pfile->buffer = new;
 
-  if (type == BUF_FILE || type == BUF_FAKE)
-    {
-      const char *filename = 0;
-      unsigned int lineno = 0;
-
-      if (new->prev)
-       {
-         filename = new->prev->nominal_fname;
-         lineno = new->prev->lineno;
-       }
-      new->lineno = 0;
-      do_file_change (pfile, FC_ENTER, filename, lineno);
-    }
-
-  new->lineno = 1;
   return new;
 }
 
+/* If called from do_line, pops a single buffer.  Otherwise pops all
+   buffers until a real file is reached.  Generates appropriate
+   call-backs.  */
 cpp_buffer *
 cpp_pop_buffer (pfile)
      cpp_reader *pfile;
 {
   cpp_buffer *buffer;
   struct if_stack *ifs;
-  int in_do_line = pfile->directive == &dtable[T_LINE];
 
-  do
+  for (;;)
     {
       buffer = pfile->buffer;
       /* Walk back up the conditional stack till we reach its level at
@@ -1799,28 +1794,34 @@ cpp_pop_buffer (pfile)
                             "unterminated #%s", dtable[ifs->type].name);
 
       if (buffer->type == BUF_FAKE)
-       {
-         if (!in_do_line)
-           cpp_warning (pfile, "file \"%s\" entered but not left",
-                        buffer->nominal_fname);
-
-         buffer->prev->cur = buffer->cur;
-       }
+       buffer->prev->cur = buffer->cur;
       else if (buffer->type == BUF_FILE)
        _cpp_pop_file_buffer (pfile, buffer);
 
       pfile->buffer = buffer->prev;
       pfile->buffer_stack_depth--;
 
-      if ((buffer->type == BUF_FILE || buffer->type == BUF_FAKE)
-         && pfile->buffer)
-       {
-         do_file_change (pfile, FC_LEAVE, buffer->nominal_fname,
-                         buffer->lineno);
-         pfile->buffer->include_stack_listed = 0;
-       }
+      /* Callbacks only generated for faked or real files.  */
+      if (buffer->type != BUF_FILE && buffer->type != BUF_FAKE)
+       break;
+         
+      /* No callback for EOF of last file.  */
+      if (!pfile->buffer)
+       break;
+
+      /* do_line does its own call backs.  */
+      pfile->buffer->include_stack_listed = 0;
+      if (pfile->directive == &dtable[T_LINE])
+       break;
+
+      _cpp_do_file_change (pfile, FC_LEAVE, buffer->nominal_fname,
+                          buffer->lineno);
+      if (pfile->buffer->type == BUF_FILE)
+       break;
+
+      cpp_warning (pfile, "file \"%s\" entered but not left",
+                  buffer->nominal_fname);
     }
-  while (pfile->buffer && pfile->buffer->type == BUF_FAKE && !in_do_line);
 
   obstack_free (pfile->buffer_ob, buffer);
   return pfile->buffer;
index 32ebb747db23ca0de66765914cf6eef54906782f..3c71188c480726bcba7a14e7400967cde233bc15 100644 (file)
@@ -590,7 +590,7 @@ struct cpp_reader
 
   /* Call backs.  */
   struct {
-    void (*change_file) PARAMS ((cpp_reader *, const cpp_file_change *));
+    void (*file_change) PARAMS ((cpp_reader *, const cpp_file_change *));
     void (*include) PARAMS ((cpp_reader *, const unsigned char *,
                             const cpp_token *));
     void (*define) PARAMS ((cpp_reader *, cpp_hashnode *));
index 706ff2f85cd89bdc6ba6e798ba23d4bede64254b..ed6858e3c1f3045e9031ac9f5a68ce25b175ef77 100644 (file)
@@ -57,7 +57,7 @@ static void cb_undef  PARAMS ((cpp_reader *, cpp_hashnode *));
 static void cb_include PARAMS ((cpp_reader *, const unsigned char *,
                                 const cpp_token *));
 static void cb_ident     PARAMS ((cpp_reader *, const cpp_string *));
-static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *));
+static void cb_file_change PARAMS ((cpp_reader *, const cpp_file_change *));
 static void cb_def_pragma PARAMS ((cpp_reader *));
 static void do_pragma_implementation PARAMS ((cpp_reader *));
 
@@ -154,7 +154,7 @@ setup_callbacks ()
       pfile->cb.ident      = cb_ident;
       pfile->cb.def_pragma = cb_def_pragma;
       if (! CPP_OPTION (pfile, no_line_commands))
-       pfile->cb.change_file = cb_change_file;
+       pfile->cb.file_change = cb_file_change;
     }
 
   if (CPP_OPTION (pfile, dump_includes))
@@ -374,7 +374,7 @@ cb_include (pfile, dir, header)
 }
 
 static void
-cb_change_file (pfile, fc)
+cb_file_change (pfile, fc)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      const cpp_file_change *fc;
 {
index 6549b37e7f0d8901a60c71f3a92943f60f9ac864..28cfe870974e8e6dfeccc365726155ca6e46749f 100644 (file)
@@ -199,7 +199,7 @@ static int inf_skip_spaces PARAMS ((int));
 static int inf_read_upto PARAMS ((sstring *, int));
 static int inf_scan_ident PARAMS ((sstring *, int));
 static int check_protection PARAMS ((int *, int *));
-static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *));
+static void cb_file_change PARAMS ((cpp_reader *, const cpp_file_change *));
 
 static void
 add_symbols (flags, names)
@@ -598,7 +598,7 @@ check_macro_names (pfile, names)
 }
 
 static void
-cb_change_file (pfile, fc)
+cb_file_change (pfile, fc)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      const cpp_file_change *fc;
 {
@@ -620,7 +620,7 @@ read_scan_file (in_fname, argc, argv)
   obstack_init (&scan_file_obstack); 
 
   scan_in = cpp_create_reader (CLK_GNUC89);
-  scan_in->cb.change_file = cb_change_file;
+  scan_in->cb.file_change = cb_file_change;
 
   /* We are going to be scanning a header file out of its proper context,
      so ignore warnings and errors.  */