OSDN Git Service

2000-08-20 Zack Weinberg <zack@wolery.cumb.org>
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 20 Aug 2000 21:36:18 +0000 (21:36 +0000)
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 20 Aug 2000 21:36:18 +0000 (21:36 +0000)
* cppinit.c (cpp_init): Set global flag when called.
(cpp_reader_init): Bomb out if cpp_init hasn't been called.

Sun Aug 20 01:41:35 MSD 2000 Dennis Chernoivanov <cdi@sparc.spb.su>

        * cpplex.c (cpp_scan_buffer): Move `output_line_command' just
        before `process_directive' so that newlines won't be missed
        for directives.
        (cpp_printf): Increment `print->lineno' when newline is emitted.

        * cppmain.c (cb_ident): Likewise.
        (cb_define): Likewise.
        (cb_undef): Likewise.
        (cb_include): Likewise.
        (cb_def_pragma): Likewise.
        (dump_macros_helper): Likewise.

* gcc.dg/cpp/pragma-1.c: New test.
* gcc.dg/cpp/pragma-2.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@35825 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/cppinit.c
gcc/cpplex.c
gcc/cppmain.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/pragma-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/pragma-2.c [new file with mode: 0644]

index d5467b5..1fd965f 100644 (file)
@@ -1,3 +1,22 @@
+2000-08-20  Zack Weinberg  <zack@wolery.cumb.org>
+
+       * cppinit.c (cpp_init): Set global flag when called.
+       (cpp_reader_init): Bomb out if cpp_init hasn't been called.
+
+Sun Aug 20 01:41:35 MSD 2000 Dennis Chernoivanov <cdi@sparc.spb.su>
+
+        * cpplex.c (cpp_scan_buffer): Move `output_line_command' just
+        before `process_directive' so that newlines won't be missed
+        for directives.
+        (cpp_printf): Increment `print->lineno' when newline is emitted.
+
+        * cppmain.c (cb_ident): Likewise.
+        (cb_define): Likewise.
+        (cb_undef): Likewise.
+        (cb_include): Likewise.
+        (cb_def_pragma): Likewise.
+        (dump_macros_helper): Likewise.
+
 2000-08-20  Richard Henderson  <rth@cygnus.com>
 
        * config/ia64/ia64.c (emit_insn_group_barriers): Stop if ar.lc
index c8a06e8..f1ed54f 100644 (file)
@@ -398,21 +398,28 @@ merge_include_chains (pfile)
   CPP_OPTION (pfile, bracket_include) = brack;
 }
 
+/* cpp_init initializes library global state.  It might not need to do
+   anything depending on the platform and compiler, so we have a static
+   flag to make sure it gets called before cpp_reader_init.  */
+
+static int cpp_init_completed = 0;
+
 void
 cpp_init (void)
 {
 #ifdef HOST_EBCDIC
-  /* For non-ASCII hosts, the array needs to be sorted at runtime.  */
+  /* For non-ASCII hosts, the cl_options array needs to be sorted at
+     runtime.  */
   qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
 #endif
 
-  /* Set up the trigraph map for trigraph_ok, trigraph_replace and
-     lex_line.  */
+  /* Set up the trigraph map and the IStable.  These don't need to do
+     anything if we were compiled with a compiler that supports C99
+     designated initializers.  */
   init_trigraph_map ();
-
-  /* Set up the IStable.  This doesn't do anything if we were compiled
-     with a compiler that supports C99 designated initializers.  */
   init_IStable ();
+
+  cpp_init_completed = 1;
 }
 
 /* Initialize a cpp_reader structure. */
@@ -434,6 +441,15 @@ cpp_reader_init (pfile)
   CPP_OPTION (pfile, pending) =
     (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
 
+  /* If cpp_init hasn't been called, generate a fatal error (by hand)
+     and call it here.  */
+  if (!cpp_init_completed)
+    {
+      fputs ("cpp_reader_init: internal error: cpp_init not called.\n", stderr);
+      pfile->errors = CPP_FATAL_LIMIT;
+      cpp_init ();
+    }
+
   _cpp_init_macros (pfile);
   _cpp_init_stacks (pfile);
   _cpp_init_includes (pfile);
index 7ab850b..7b07944 100644 (file)
@@ -299,7 +299,10 @@ cpp_printf VPARAMS ((cpp_reader *pfile, cpp_printer *print,
 
   /* End the previous line of text.  */
   if (pfile->need_newline)
-    putc ('\n', print->outf);
+    {
+      putc ('\n', print->outf);
+      print->lineno++;
+    }
   pfile->need_newline = 0;
 
   vfprintf (print->outf, fmt, ap);
@@ -363,14 +366,14 @@ cpp_scan_buffer (pfile, print)
 
       if (token->flags & BOL)
        {
+         output_line_command (pfile, print, pfile->token_list.line);
+         prev = 0;
+
          if (token->type == CPP_HASH && pfile->token_list.directive)
            {
              process_directive (pfile, token);
              continue;
            }
-
-         output_line_command (pfile, print, pfile->token_list.line);
-         prev = 0;
        }
 
       if (token->type != CPP_PLACEMARKER)
index 9dc431e..3e570be 100644 (file)
@@ -142,6 +142,7 @@ cb_ident (pfile, str, len)
      unsigned int len;
 {
   cpp_printf (pfile, &parse_out, "#ident \"%.*s\"\n", (int) len, str);
+  parse_out.lineno++;
 }
 
 static void
@@ -156,6 +157,7 @@ cb_define (pfile, hash)
          || CPP_OPTION (pfile, dump_macros) == dump_definitions)
        cpp_dump_definition (pfile, parse_out.outf, hash);
       putc ('\n', parse_out.outf);
+      parse_out.lineno++;
     }
 }
 
@@ -165,7 +167,10 @@ cb_undef (pfile, hash)
      cpp_hashnode *hash;
 {
   if (pfile->done_initializing)
-    cpp_printf (pfile, &parse_out, "#undef %s\n", hash->name);
+    {
+      cpp_printf (pfile, &parse_out, "#undef %s\n", hash->name);
+      parse_out.lineno++;
+    }
 }
 
 static void
@@ -183,6 +188,7 @@ cb_include (pfile, dir, str, len, ab)
     l = '"', r = '"';
 
   cpp_printf (pfile, &parse_out, "#%s %c%.*s%c\n", dir, l, (int) len, str, r);
+  parse_out.lineno++;
 }
 
 static void
@@ -233,6 +239,7 @@ cb_def_pragma (pfile)
   cpp_output_list (pfile, parse_out.outf, &pfile->token_list,
                   pfile->first_directive_token + 2);
   putc ('\n', parse_out.outf);
+  parse_out.lineno++;
 }
 
 static void
@@ -278,6 +285,7 @@ dump_macros_helper (pfile, hp)
       cpp_printf (pfile, &parse_out, "#define %s", hp->name);
       cpp_dump_definition (pfile, parse_out.outf, hp);
       putc ('\n', parse_out.outf);
+      parse_out.lineno++;
     }
 
   return 1;
index 2eb377a..5382c0a 100644 (file)
@@ -1,3 +1,8 @@
+Sun Aug 20 01:41:35 MSD 2000 Dennis Chernoivanov <cdi@sparc.spb.su>
+
+       * gcc.dg/cpp/pragma-1.c: New test.
+       * gcc.dg/cpp/pragma-2.c: New test.
+
 2000-08-18  Zack Weinberg  <zack@wolery.cumb.org>
 
        * gcc.dg/cpp/lexstrng.c: Don't include string.h.
diff --git a/gcc/testsuite/gcc.dg/cpp/pragma-1.c b/gcc/testsuite/gcc.dg/cpp/pragma-1.c
new file mode 100644 (file)
index 0000000..4b9295f
--- /dev/null
@@ -0,0 +1,13 @@
+/* Verify that preprocessor does not insert redundant newlines
+   after #pragma */
+/* { dg-do compile } */
+int
+main ()
+{
+#pragma unknown
+  {
+    error;
+  /* { dg-error "undeclared" "undeclared-variable message" { target *-*-* } { 9 } } */
+  /* { dg-error "function it appears in" "reminder message" { target *-*-* } { 9 } } */ 
+  }
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/pragma-2.c b/gcc/testsuite/gcc.dg/cpp/pragma-2.c
new file mode 100644 (file)
index 0000000..18d540f
--- /dev/null
@@ -0,0 +1,16 @@
+/* Verify that preprocessor does not insert redundant newlines
+   after #pragma, also check this for #include, #define and #undef */
+/* { dg-do compile } */
+/* { dg-options "-dD" } */
+#include <stdio.h>
+
+#undef unknow_def
+
+int main () {
+
+#pragma unknown
+  {}
+  error;
+  /* { dg-error "undeclared" "undeclared-variable message" { target *-*-* } { 13 } } */
+  /* { dg-error "function it appears in" "reminder message" { target *-*-* } { 13 } } */ 
+}