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>
* 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. */
# define MMAP_THRESHOLD 0
#endif
static IHASH *redundant_include_p PARAMS ((cpp_reader *, IHASH *,
struct file_name_list *));
static IHASH *redundant_include_p PARAMS ((IHASH *, struct file_name_list *));
static IHASH *make_IHASH PARAMS ((const char *, const char *,
struct file_name_list *,
unsigned int, IHASH **));
......@@ -124,8 +123,7 @@ _cpp_init_include_hash (pfile)
the directories are in fact the same. */
static IHASH *
redundant_include_p (pfile, ihash, ilist)
cpp_reader *pfile;
redundant_include_p (ihash, ilist)
IHASH *ihash;
struct file_name_list *ilist;
{
......@@ -138,14 +136,14 @@ redundant_include_p (pfile, ihash, ilist)
for (i = ihash; i; i = i->next_this_file)
for (l = ilist; l; l = l->next)
if (i->foundhere == l)
/* The control_macro works like this: If it's NULL, the file
is to be included again. If it's "", the file is never to
be included again. If it's a string, the file is not to be
included again if the string is the name of a defined macro. */
return (i->control_macro
&& (i->control_macro[0] == '\0'
|| cpp_defined (pfile, i->control_macro,
ustrlen (i->control_macro))))
/* The cmacro works like this: If it's NULL, the file is to
be included again. If it's NEVER_REINCLUDE, the file is
never to be included again. Otherwise it is a macro
hashnode, and the file is to be included again if the
macro is not defined. */
return (i->cmacro
&& (i->cmacro == NEVER_REINCLUDE
|| i->cmacro->type != T_VOID))
? (IHASH *)-1 : i;
return 0;
......@@ -199,7 +197,7 @@ make_IHASH (name, fname, path, hash, slot)
}
strcpy ((char *)ih->name, name);
ih->foundhere = path;
ih->control_macro = NULL;
ih->cmacro = NULL;
ih->hash = hash;
ih->next_this_file = *slot;
*slot = ih;
......@@ -256,7 +254,7 @@ find_include_file (pfile, fname, search_start, ihash, before)
(const void *) &dummy,
dummy.hash, INSERT);
if (*slot && (ih = redundant_include_p (pfile, *slot, path)))
if (*slot && (ih = redundant_include_p (*slot, path)))
{
if (ih == (IHASH *)-1)
return -2;
......@@ -629,7 +627,7 @@ _cpp_execute_include (pfile, f, len, no_reinclude, search_start)
/* Actually process the file. */
if (no_reinclude)
ihash->control_macro = U"";
ihash->cmacro = NEVER_REINCLUDE;
if (read_include_file (pfile, fd, ihash))
{
......@@ -662,7 +660,7 @@ cpp_read_file (pfile, fname)
slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files,
(const void *) &dummy,
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)
return 1; /* Already included. */
......@@ -759,7 +757,7 @@ read_include_file (pfile, fd, ihash)
fp->nominal_fname = ihash->name;
if (length == 0)
ihash->control_macro = U""; /* never re-include */
ihash->cmacro = NEVER_REINCLUDE;
else
/* Temporary - I hope. */
length = _cpp_prescan (pfile, fp, length);
......
......@@ -69,10 +69,11 @@ struct ihash
unsigned int hash; /* save hash value for future reference */
const char *nshort; /* name of file as referenced in #include;
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 */
};
typedef struct ihash IHASH;
#define NEVER_REINCLUDE ((const cpp_hashnode *)-1)
/* Character classes.
If the definition of `numchar' looks odd to you, please look up the
......
......@@ -193,7 +193,6 @@ cpp_push_buffer (pfile, buffer, length)
new = (cpp_buffer *) xcalloc (1, sizeof (cpp_buffer));
new->if_stack = pfile->if_stack;
new->buf = new->cur = buffer;
new->rlimit = buffer + length;
new->prev = buf;
......@@ -221,7 +220,7 @@ cpp_pop_buffer (pfile)
pfile->system_include_depth--;
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->input_stack_listing_current = 0;
......@@ -1743,6 +1742,7 @@ cpp_get_token (pfile)
{
enum cpp_ttype token;
long written = CPP_WRITTEN (pfile);
int macro_buffer;
get_next:
token = _cpp_lex_token (pfile);
......@@ -1750,24 +1750,26 @@ cpp_get_token (pfile)
switch (token)
{
default:
if (pfile->skipping)
break;
pfile->potential_control_macro = 0;
pfile->only_seen_white = 0;
return token;
break;
case CPP_HSPACE:
case CPP_COMMENT:
break;
case CPP_VSPACE:
if (pfile->only_seen_white == 0)
pfile->only_seen_white = 1;
CPP_BUMP_LINE (pfile);
return token;
case CPP_HSPACE:
case CPP_COMMENT:
return token;
break;
case CPP_HASH:
pfile->potential_control_macro = 0;
if (!pfile->only_seen_white)
return CPP_HASH;
break;
/* XXX shouldn't have to do this - remove the hash or %: from
the token buffer. */
if (CPP_PWRITTEN (pfile)[-1] == '#')
......@@ -1776,30 +1778,43 @@ cpp_get_token (pfile)
CPP_ADJUST_WRITTEN (pfile, -2);
if (_cpp_handle_directive (pfile))
return CPP_DIRECTIVE;
{
token = CPP_DIRECTIVE;
break;
}
pfile->only_seen_white = 0;
CPP_PUTC (pfile, '#');
return CPP_HASH;
break;
case CPP_MACRO:
if (pfile->skipping)
break;
pfile->potential_control_macro = 0;
pfile->only_seen_white = 0;
if (! pfile->no_macro_expand
&& maybe_macroexpand (pfile, written))
goto get_next;
return CPP_NAME;
token = CPP_NAME;
break;
/* Do not run this case through the 'skipping' logic. */
case CPP_EOF:
if (CPP_BUFFER (pfile) == NULL)
return CPP_EOF;
if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
{
cpp_pop_buffer (pfile);
goto get_next;
}
macro_buffer = CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile));
cpp_pop_buffer (pfile);
if (macro_buffer)
goto get_next;
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. */
......
......@@ -509,8 +509,7 @@ struct cpp_reader
for include files. (Altered as we get more of them.) */
unsigned int max_include_len;
struct if_stack *if_stack;
const unsigned char *potential_control_macro;
const cpp_hashnode *potential_control_macro;
/* Token column position adjustment owing to tabs in whitespace. */
unsigned int col_adjust;
......@@ -555,6 +554,9 @@ struct cpp_reader
/* True after cpp_start_read completes. Used to inhibit some
warnings while parsing the command line. */
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
......
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>
* gcc.c-torture/execute/20000528-1.c: New test.
......
......@@ -8,6 +8,7 @@
extern "C" {
int printf (const char *, ...);
void exit (int);
void abort (void);
};
__complex__ double cd;
......
// GROUPS passed references
// execution test - XFAIL *-*-*
// execution test
#include <stdio.h>
#include <stdlib.h>
......
......@@ -4,6 +4,9 @@
// execution test - XFAIL *-*-*
extern "C" void abort (void);
extern "C" void exit (int);
int i, j;
const int &f(const int& I, const int& J) {
......
......@@ -17,6 +17,10 @@
#include "cpp-mindp.h"
#include "cpp-mindp.h"
#define CPP_MIX_H
#include "cpp-mix.h"
#include "cpp-mix.h"
int
main (void)
{
......@@ -28,7 +32,7 @@ main (void)
{ dg-final { set tmp [grep cpp-mi.i {cpp-mi.*\.h} line] } }
{ 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 { \} else \{ } }
{ 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 @@
/* You can't get away with this in your own code... */
#ifdef KERNEL
#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. */
#line 10 "endif-label.c" 3 /* { dg-warning "garbage at end" "#line extension" } */
......@@ -12,4 +12,4 @@
/* ... but in a system header, it's acceptable. */
#ifdef KERNEL
#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