Commit ea4a453b by Zack Weinberg Committed by Zack Weinberg

cpplib.h (cpp_reader): Remove if_stack.

	* cpplib.h (cpp_reader): Remove if_stack.  Change
	potential_control_macro to a cpp_hashnode *.  Add skipping flag.
	* cpphash.h (struct ihash): Change control_macro to a
	cpp_hashnode * and shorten name to cmacro.
	Add NEVER_REINCLUDE constant.

	* cppfiles.c (redundant_include_p): Drop cpp_reader argument.
	Examine the cmacro node directly, no need to call cpp_defined.
	(_cpp_execute_include, read_include_file): Set cmacro to
	NEVER_REINCLUDE, not U"".
	* cpplex.c (cpp_push_buffer): Don't set new->if_stack.
	(cpp_get_token): If pfile->skipping is true, discard text and
	keep scanning until we hit a directive; don't expand macros.

	* cpplib.c (struct if_stack): Remove if_succeeded, add
	was_skipping. Change control_macro to a cpp_hashnode * and
	shorten name to cmacro.  Remove typedef IF_STACK.
	(parse_ifdef), detect_if_not_defined): Return a cpp_hashnode *.
	(conditional_skip, skip_if_group,
	consider_directive_while_skipping): Delete.
	(push_conditional): New.
	(_cpp_handle_directive): Don't process directives other than
	conditionals if we are skipping.

	(do_ifdef, do_ifndef, do_if, do_else, do_elif, do_endif):
	Update to new scheme.
	(validate_else): Skip rest of line here, unconditionally.
	(_cpp_unwind_if_stack): The stack is per-buffer.  Force
	pfile->skipping off.

	(all): Remove `scare quotes' from error messages.

	* gcc.dg/cpp-mi.c: Add another case, cpp-mix.h, where the
	guard macro is already defined when the header is first
	included.
	* gcc.dg/cpp-mix.h: New file.
	* gcc.dg/endif-label.c: Update patterns to match compiler.

	* g++.brendan/complex1.C: Declare abort.
	* g++.law/refs4.C: Remove XFAIL.
	* g++.oliva/expr2.C: Declare abort and exit.

From-SVN: r34253
parent 1b50716d
2000-05-29 Zack Weinberg <zack@wolery.cumb.org>
* cpplib.h (cpp_reader): Remove if_stack. Change
potential_control_macro to a cpp_hashnode *. Add skipping flag.
* cpphash.h (struct ihash): Change control_macro to a
cpp_hashnode * and shorten name to cmacro.
Add NEVER_REINCLUDE constant.
* cppfiles.c (redundant_include_p): Drop cpp_reader argument.
Examine the cmacro node directly, no need to call cpp_defined.
(_cpp_execute_include, read_include_file): Set cmacro to
NEVER_REINCLUDE, not U"".
* cpplex.c (cpp_push_buffer): Don't set new->if_stack.
(cpp_get_token): If pfile->skipping is true, discard text and
keep scanning until we hit a directive; don't expand macros.
* cpplib.c (struct if_stack): Remove if_succeeded, add
was_skipping. Change control_macro to a cpp_hashnode * and
shorten name to cmacro. Remove typedef IF_STACK.
(parse_ifdef), detect_if_not_defined): Return a cpp_hashnode *.
(conditional_skip, skip_if_group,
consider_directive_while_skipping): Delete.
(push_conditional): New.
(_cpp_handle_directive): Don't process directives other than
conditionals if we are skipping.
(do_ifdef, do_ifndef, do_if, do_else, do_elif, do_endif):
Update to new scheme.
(validate_else): Skip rest of line here, unconditionally.
(_cpp_unwind_if_stack): The stack is per-buffer. Force
pfile->skipping off.
(all): Remove `scare quotes' from error messages.
2000-05-29 Richard Henderson <rth@cygnus.com> 2000-05-29 Richard Henderson <rth@cygnus.com>
* function.c (emit_return_into_block): New line_note arg; emit it. * function.c (emit_return_into_block): New line_note arg; emit it.
...@@ -39,8 +39,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -39,8 +39,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
# define MMAP_THRESHOLD 0 # define MMAP_THRESHOLD 0
#endif #endif
static IHASH *redundant_include_p PARAMS ((cpp_reader *, IHASH *, static IHASH *redundant_include_p PARAMS ((IHASH *, struct file_name_list *));
struct file_name_list *));
static IHASH *make_IHASH PARAMS ((const char *, const char *, static IHASH *make_IHASH PARAMS ((const char *, const char *,
struct file_name_list *, struct file_name_list *,
unsigned int, IHASH **)); unsigned int, IHASH **));
...@@ -124,8 +123,7 @@ _cpp_init_include_hash (pfile) ...@@ -124,8 +123,7 @@ _cpp_init_include_hash (pfile)
the directories are in fact the same. */ the directories are in fact the same. */
static IHASH * static IHASH *
redundant_include_p (pfile, ihash, ilist) redundant_include_p (ihash, ilist)
cpp_reader *pfile;
IHASH *ihash; IHASH *ihash;
struct file_name_list *ilist; struct file_name_list *ilist;
{ {
...@@ -138,14 +136,14 @@ redundant_include_p (pfile, ihash, ilist) ...@@ -138,14 +136,14 @@ redundant_include_p (pfile, ihash, ilist)
for (i = ihash; i; i = i->next_this_file) for (i = ihash; i; i = i->next_this_file)
for (l = ilist; l; l = l->next) for (l = ilist; l; l = l->next)
if (i->foundhere == l) if (i->foundhere == l)
/* The control_macro works like this: If it's NULL, the file /* The cmacro works like this: If it's NULL, the file is to
is to be included again. If it's "", the file is never to be included again. If it's NEVER_REINCLUDE, the file is
be included again. If it's a string, the file is not to be never to be included again. Otherwise it is a macro
included again if the string is the name of a defined macro. */ hashnode, and the file is to be included again if the
return (i->control_macro macro is not defined. */
&& (i->control_macro[0] == '\0' return (i->cmacro
|| cpp_defined (pfile, i->control_macro, && (i->cmacro == NEVER_REINCLUDE
ustrlen (i->control_macro)))) || i->cmacro->type != T_VOID))
? (IHASH *)-1 : i; ? (IHASH *)-1 : i;
return 0; return 0;
...@@ -199,7 +197,7 @@ make_IHASH (name, fname, path, hash, slot) ...@@ -199,7 +197,7 @@ make_IHASH (name, fname, path, hash, slot)
} }
strcpy ((char *)ih->name, name); strcpy ((char *)ih->name, name);
ih->foundhere = path; ih->foundhere = path;
ih->control_macro = NULL; ih->cmacro = NULL;
ih->hash = hash; ih->hash = hash;
ih->next_this_file = *slot; ih->next_this_file = *slot;
*slot = ih; *slot = ih;
...@@ -256,7 +254,7 @@ find_include_file (pfile, fname, search_start, ihash, before) ...@@ -256,7 +254,7 @@ find_include_file (pfile, fname, search_start, ihash, before)
(const void *) &dummy, (const void *) &dummy,
dummy.hash, INSERT); dummy.hash, INSERT);
if (*slot && (ih = redundant_include_p (pfile, *slot, path))) if (*slot && (ih = redundant_include_p (*slot, path)))
{ {
if (ih == (IHASH *)-1) if (ih == (IHASH *)-1)
return -2; return -2;
...@@ -629,7 +627,7 @@ _cpp_execute_include (pfile, f, len, no_reinclude, search_start) ...@@ -629,7 +627,7 @@ _cpp_execute_include (pfile, f, len, no_reinclude, search_start)
/* Actually process the file. */ /* Actually process the file. */
if (no_reinclude) if (no_reinclude)
ihash->control_macro = U""; ihash->cmacro = NEVER_REINCLUDE;
if (read_include_file (pfile, fd, ihash)) if (read_include_file (pfile, fd, ihash))
{ {
...@@ -662,7 +660,7 @@ cpp_read_file (pfile, fname) ...@@ -662,7 +660,7 @@ cpp_read_file (pfile, fname)
slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files, slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files,
(const void *) &dummy, (const void *) &dummy,
dummy.hash, INSERT); dummy.hash, INSERT);
if (*slot && (ih = redundant_include_p (pfile, *slot, ABSOLUTE_PATH))) if (*slot && (ih = redundant_include_p (*slot, ABSOLUTE_PATH)))
{ {
if (ih == (IHASH *) -1) if (ih == (IHASH *) -1)
return 1; /* Already included. */ return 1; /* Already included. */
...@@ -759,7 +757,7 @@ read_include_file (pfile, fd, ihash) ...@@ -759,7 +757,7 @@ read_include_file (pfile, fd, ihash)
fp->nominal_fname = ihash->name; fp->nominal_fname = ihash->name;
if (length == 0) if (length == 0)
ihash->control_macro = U""; /* never re-include */ ihash->cmacro = NEVER_REINCLUDE;
else else
/* Temporary - I hope. */ /* Temporary - I hope. */
length = _cpp_prescan (pfile, fp, length); length = _cpp_prescan (pfile, fp, length);
......
...@@ -69,10 +69,11 @@ struct ihash ...@@ -69,10 +69,11 @@ struct ihash
unsigned int hash; /* save hash value for future reference */ unsigned int hash; /* save hash value for future reference */
const char *nshort; /* name of file as referenced in #include; const char *nshort; /* name of file as referenced in #include;
points into name[] */ points into name[] */
const U_CHAR *control_macro; /* macro, if any, preventing reinclusion. */ const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
const char name[1]; /* (partial) pathname of file */ const char name[1]; /* (partial) pathname of file */
}; };
typedef struct ihash IHASH; typedef struct ihash IHASH;
#define NEVER_REINCLUDE ((const cpp_hashnode *)-1)
/* Character classes. /* Character classes.
If the definition of `numchar' looks odd to you, please look up the If the definition of `numchar' looks odd to you, please look up the
......
...@@ -193,7 +193,6 @@ cpp_push_buffer (pfile, buffer, length) ...@@ -193,7 +193,6 @@ cpp_push_buffer (pfile, buffer, length)
new = (cpp_buffer *) xcalloc (1, sizeof (cpp_buffer)); new = (cpp_buffer *) xcalloc (1, sizeof (cpp_buffer));
new->if_stack = pfile->if_stack;
new->buf = new->cur = buffer; new->buf = new->cur = buffer;
new->rlimit = buffer + length; new->rlimit = buffer + length;
new->prev = buf; new->prev = buf;
...@@ -221,7 +220,7 @@ cpp_pop_buffer (pfile) ...@@ -221,7 +220,7 @@ cpp_pop_buffer (pfile)
pfile->system_include_depth--; pfile->system_include_depth--;
if (pfile->potential_control_macro) if (pfile->potential_control_macro)
{ {
buf->ihash->control_macro = pfile->potential_control_macro; buf->ihash->cmacro = pfile->potential_control_macro;
pfile->potential_control_macro = 0; pfile->potential_control_macro = 0;
} }
pfile->input_stack_listing_current = 0; pfile->input_stack_listing_current = 0;
...@@ -1743,6 +1742,7 @@ cpp_get_token (pfile) ...@@ -1743,6 +1742,7 @@ cpp_get_token (pfile)
{ {
enum cpp_ttype token; enum cpp_ttype token;
long written = CPP_WRITTEN (pfile); long written = CPP_WRITTEN (pfile);
int macro_buffer;
get_next: get_next:
token = _cpp_lex_token (pfile); token = _cpp_lex_token (pfile);
...@@ -1750,24 +1750,26 @@ cpp_get_token (pfile) ...@@ -1750,24 +1750,26 @@ cpp_get_token (pfile)
switch (token) switch (token)
{ {
default: default:
if (pfile->skipping)
break;
pfile->potential_control_macro = 0; pfile->potential_control_macro = 0;
pfile->only_seen_white = 0; pfile->only_seen_white = 0;
return token; break;
case CPP_HSPACE:
case CPP_COMMENT:
break;
case CPP_VSPACE: case CPP_VSPACE:
if (pfile->only_seen_white == 0) if (pfile->only_seen_white == 0)
pfile->only_seen_white = 1; pfile->only_seen_white = 1;
CPP_BUMP_LINE (pfile); CPP_BUMP_LINE (pfile);
return token; break;
case CPP_HSPACE:
case CPP_COMMENT:
return token;
case CPP_HASH: case CPP_HASH:
pfile->potential_control_macro = 0; pfile->potential_control_macro = 0;
if (!pfile->only_seen_white) if (!pfile->only_seen_white)
return CPP_HASH; break;
/* XXX shouldn't have to do this - remove the hash or %: from /* XXX shouldn't have to do this - remove the hash or %: from
the token buffer. */ the token buffer. */
if (CPP_PWRITTEN (pfile)[-1] == '#') if (CPP_PWRITTEN (pfile)[-1] == '#')
...@@ -1776,30 +1778,43 @@ cpp_get_token (pfile) ...@@ -1776,30 +1778,43 @@ cpp_get_token (pfile)
CPP_ADJUST_WRITTEN (pfile, -2); CPP_ADJUST_WRITTEN (pfile, -2);
if (_cpp_handle_directive (pfile)) if (_cpp_handle_directive (pfile))
return CPP_DIRECTIVE; {
token = CPP_DIRECTIVE;
break;
}
pfile->only_seen_white = 0; pfile->only_seen_white = 0;
CPP_PUTC (pfile, '#'); CPP_PUTC (pfile, '#');
return CPP_HASH; break;
case CPP_MACRO: case CPP_MACRO:
if (pfile->skipping)
break;
pfile->potential_control_macro = 0; pfile->potential_control_macro = 0;
pfile->only_seen_white = 0; pfile->only_seen_white = 0;
if (! pfile->no_macro_expand if (! pfile->no_macro_expand
&& maybe_macroexpand (pfile, written)) && maybe_macroexpand (pfile, written))
goto get_next; goto get_next;
return CPP_NAME; token = CPP_NAME;
break;
/* Do not run this case through the 'skipping' logic. */
case CPP_EOF: case CPP_EOF:
if (CPP_BUFFER (pfile) == NULL) if (CPP_BUFFER (pfile) == NULL)
return CPP_EOF; return CPP_EOF;
if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) macro_buffer = CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile));
{
cpp_pop_buffer (pfile);
goto get_next;
}
cpp_pop_buffer (pfile); cpp_pop_buffer (pfile);
if (macro_buffer)
goto get_next;
return CPP_EOF; return CPP_EOF;
} }
if (pfile->skipping)
{
CPP_SET_WRITTEN (pfile, written);
goto get_next;
}
return token;
} }
/* Like cpp_get_token, but skip spaces and comments. */ /* Like cpp_get_token, but skip spaces and comments. */
......
...@@ -509,8 +509,7 @@ struct cpp_reader ...@@ -509,8 +509,7 @@ struct cpp_reader
for include files. (Altered as we get more of them.) */ for include files. (Altered as we get more of them.) */
unsigned int max_include_len; unsigned int max_include_len;
struct if_stack *if_stack; const cpp_hashnode *potential_control_macro;
const unsigned char *potential_control_macro;
/* Token column position adjustment owing to tabs in whitespace. */ /* Token column position adjustment owing to tabs in whitespace. */
unsigned int col_adjust; unsigned int col_adjust;
...@@ -555,6 +554,9 @@ struct cpp_reader ...@@ -555,6 +554,9 @@ struct cpp_reader
/* True after cpp_start_read completes. Used to inhibit some /* True after cpp_start_read completes. Used to inhibit some
warnings while parsing the command line. */ warnings while parsing the command line. */
unsigned char done_initializing; unsigned char done_initializing;
/* True if we are skipping a failed conditional group. */
unsigned char skipping;
}; };
/* struct cpp_printer encapsulates state used to convert the stream of /* struct cpp_printer encapsulates state used to convert the stream of
......
2000-05-29 Zack Weinberg <zack@wolery.cumb.org>
* gcc.dg/cpp-mi.c: Add another case, cpp-mix.h, where the
guard macro is already defined when the header is first
included.
* gcc.dg/cpp-mix.h: New file.
* gcc.dg/endif-label.c: Update patterns to match compiler.
* g++.brendan/complex1.C: Declare abort.
* g++.law/refs4.C: Remove XFAIL.
* g++.oliva/expr2.C: Declare abort and exit.
2000-05-28 Alexandre Oliva <aoliva@cygnus.com> 2000-05-28 Alexandre Oliva <aoliva@cygnus.com>
* gcc.c-torture/execute/20000528-1.c: New test. * gcc.c-torture/execute/20000528-1.c: New test.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
extern "C" { extern "C" {
int printf (const char *, ...); int printf (const char *, ...);
void exit (int); void exit (int);
void abort (void);
}; };
__complex__ double cd; __complex__ double cd;
......
// GROUPS passed references // GROUPS passed references
// execution test - XFAIL *-*-* // execution test
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
// execution test - XFAIL *-*-* // execution test - XFAIL *-*-*
extern "C" void abort (void);
extern "C" void exit (int);
int i, j; int i, j;
const int &f(const int& I, const int& J) { const int &f(const int& I, const int& J) {
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
#include "cpp-mindp.h" #include "cpp-mindp.h"
#include "cpp-mindp.h" #include "cpp-mindp.h"
#define CPP_MIX_H
#include "cpp-mix.h"
#include "cpp-mix.h"
int int
main (void) main (void)
{ {
...@@ -28,7 +32,7 @@ main (void) ...@@ -28,7 +32,7 @@ main (void)
{ dg-final { set tmp [grep cpp-mi.i {cpp-mi.*\.h} line] } } { dg-final { set tmp [grep cpp-mi.i {cpp-mi.*\.h} line] } }
{ dg-final { # send_user "$tmp\n" } } { dg-final { # send_user "$tmp\n" } }
{ dg-final { if [regexp "^{\[0-9\]+ cpp-mic\.h} {\[0-9\]+ cpp-micc\.h} {\[0-9\]+ cpp-mind\.h} {\[0-9\]+ cpp-mindp\.h}$" $tmp] \{ } } { dg-final { if [regexp "^{\[0-9\]+ cpp-mic\.h} {\[0-9\]+ cpp-micc\.h} {\[0-9\]+ cpp-mind\.h} {\[0-9\]+ cpp-mindp\.h} {\[0-9]+ cpp-mix\.h}$" $tmp] \{ } }
{ dg-final { pass "cpp-mi.c: redundant include check" } } { dg-final { pass "cpp-mi.c: redundant include check" } }
{ dg-final { \} else \{ } } { dg-final { \} else \{ } }
{ dg-final { fail "cpp-mi.c: redundant include check" } } { dg-final { fail "cpp-mi.c: redundant include check" } }
......
/* This header is never to have its contents visible, but it should
still receive the optimization. */
#ifndef CPP_MIX_H
#define CPP_MIX_H
#define main wibble
#endif
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
/* You can't get away with this in your own code... */ /* You can't get away with this in your own code... */
#ifdef KERNEL #ifdef KERNEL
#define foo #define foo
#endif KERNEL /* { dg-warning "text following" "good warning" } */ #endif KERNEL /* { dg-warning "forbids text after" "good warning" } */
/* This will provoke a warning because the '3' is an extension. */ /* This will provoke a warning because the '3' is an extension. */
#line 10 "endif-label.c" 3 /* { dg-warning "garbage at end" "#line extension" } */ #line 10 "endif-label.c" 3 /* { dg-warning "garbage at end" "#line extension" } */
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
/* ... but in a system header, it's acceptable. */ /* ... but in a system header, it's acceptable. */
#ifdef KERNEL #ifdef KERNEL
#define foo #define foo
#endif KERNEL /* { dg-bogus "text following" "bad warning" } */ #endif KERNEL /* { dg-bogus "forbids text after" "bad warning" } */
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