Commit 3cb553b4 by Zack Weinberg

[multiple changes]

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.

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

From-SVN: r35825
parent 53e687fa
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> 2000-08-20 Richard Henderson <rth@cygnus.com>
* config/ia64/ia64.c (emit_insn_group_barriers): Stop if ar.lc * config/ia64/ia64.c (emit_insn_group_barriers): Stop if ar.lc
......
...@@ -398,21 +398,28 @@ merge_include_chains (pfile) ...@@ -398,21 +398,28 @@ merge_include_chains (pfile)
CPP_OPTION (pfile, bracket_include) = brack; 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 void
cpp_init (void) cpp_init (void)
{ {
#ifdef HOST_EBCDIC #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); qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
#endif #endif
/* Set up the trigraph map for trigraph_ok, trigraph_replace and /* Set up the trigraph map and the IStable. These don't need to do
lex_line. */ anything if we were compiled with a compiler that supports C99
designated initializers. */
init_trigraph_map (); 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 (); init_IStable ();
cpp_init_completed = 1;
} }
/* Initialize a cpp_reader structure. */ /* Initialize a cpp_reader structure. */
...@@ -434,6 +441,15 @@ cpp_reader_init (pfile) ...@@ -434,6 +441,15 @@ cpp_reader_init (pfile)
CPP_OPTION (pfile, pending) = CPP_OPTION (pfile, pending) =
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_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_macros (pfile);
_cpp_init_stacks (pfile); _cpp_init_stacks (pfile);
_cpp_init_includes (pfile); _cpp_init_includes (pfile);
......
...@@ -299,7 +299,10 @@ cpp_printf VPARAMS ((cpp_reader *pfile, cpp_printer *print, ...@@ -299,7 +299,10 @@ cpp_printf VPARAMS ((cpp_reader *pfile, cpp_printer *print,
/* End the previous line of text. */ /* End the previous line of text. */
if (pfile->need_newline) if (pfile->need_newline)
putc ('\n', print->outf); {
putc ('\n', print->outf);
print->lineno++;
}
pfile->need_newline = 0; pfile->need_newline = 0;
vfprintf (print->outf, fmt, ap); vfprintf (print->outf, fmt, ap);
...@@ -363,14 +366,14 @@ cpp_scan_buffer (pfile, print) ...@@ -363,14 +366,14 @@ cpp_scan_buffer (pfile, print)
if (token->flags & BOL) if (token->flags & BOL)
{ {
output_line_command (pfile, print, pfile->token_list.line);
prev = 0;
if (token->type == CPP_HASH && pfile->token_list.directive) if (token->type == CPP_HASH && pfile->token_list.directive)
{ {
process_directive (pfile, token); process_directive (pfile, token);
continue; continue;
} }
output_line_command (pfile, print, pfile->token_list.line);
prev = 0;
} }
if (token->type != CPP_PLACEMARKER) if (token->type != CPP_PLACEMARKER)
......
...@@ -142,6 +142,7 @@ cb_ident (pfile, str, len) ...@@ -142,6 +142,7 @@ cb_ident (pfile, str, len)
unsigned int len; unsigned int len;
{ {
cpp_printf (pfile, &parse_out, "#ident \"%.*s\"\n", (int) len, str); cpp_printf (pfile, &parse_out, "#ident \"%.*s\"\n", (int) len, str);
parse_out.lineno++;
} }
static void static void
...@@ -156,6 +157,7 @@ cb_define (pfile, hash) ...@@ -156,6 +157,7 @@ cb_define (pfile, hash)
|| CPP_OPTION (pfile, dump_macros) == dump_definitions) || CPP_OPTION (pfile, dump_macros) == dump_definitions)
cpp_dump_definition (pfile, parse_out.outf, hash); cpp_dump_definition (pfile, parse_out.outf, hash);
putc ('\n', parse_out.outf); putc ('\n', parse_out.outf);
parse_out.lineno++;
} }
} }
...@@ -165,7 +167,10 @@ cb_undef (pfile, hash) ...@@ -165,7 +167,10 @@ cb_undef (pfile, hash)
cpp_hashnode *hash; cpp_hashnode *hash;
{ {
if (pfile->done_initializing) 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 static void
...@@ -183,6 +188,7 @@ cb_include (pfile, dir, str, len, ab) ...@@ -183,6 +188,7 @@ cb_include (pfile, dir, str, len, ab)
l = '"', r = '"'; l = '"', r = '"';
cpp_printf (pfile, &parse_out, "#%s %c%.*s%c\n", dir, l, (int) len, str, r); cpp_printf (pfile, &parse_out, "#%s %c%.*s%c\n", dir, l, (int) len, str, r);
parse_out.lineno++;
} }
static void static void
...@@ -233,6 +239,7 @@ cb_def_pragma (pfile) ...@@ -233,6 +239,7 @@ cb_def_pragma (pfile)
cpp_output_list (pfile, parse_out.outf, &pfile->token_list, cpp_output_list (pfile, parse_out.outf, &pfile->token_list,
pfile->first_directive_token + 2); pfile->first_directive_token + 2);
putc ('\n', parse_out.outf); putc ('\n', parse_out.outf);
parse_out.lineno++;
} }
static void static void
...@@ -278,6 +285,7 @@ dump_macros_helper (pfile, hp) ...@@ -278,6 +285,7 @@ dump_macros_helper (pfile, hp)
cpp_printf (pfile, &parse_out, "#define %s", hp->name); cpp_printf (pfile, &parse_out, "#define %s", hp->name);
cpp_dump_definition (pfile, parse_out.outf, hp); cpp_dump_definition (pfile, parse_out.outf, hp);
putc ('\n', parse_out.outf); putc ('\n', parse_out.outf);
parse_out.lineno++;
} }
return 1; return 1;
......
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> 2000-08-18 Zack Weinberg <zack@wolery.cumb.org>
* gcc.dg/cpp/lexstrng.c: Don't include string.h. * gcc.dg/cpp/lexstrng.c: Don't include string.h.
......
/* 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 } } */
}
}
/* 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 } } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment