/* Part of CPP library. (Macro and #define handling.)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005,
- 2006, 2007, 2008 Free Software Foundation, Inc.
+ 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
+Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+along with this program; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>.
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
if (token->type == CPP_PADDING)
{
- if (source == NULL)
+ if (source == NULL
+ || (!(source->flags & PREV_WHITE)
+ && token->val.source == NULL))
source = token->val.source;
continue;
}
/* Conditional macros require that a predicate be evaluated
first. */
- if (((!(node->flags & NODE_CONDITIONAL))
- || (pfile->cb.macro_to_expand
- && (node = pfile->cb.macro_to_expand (pfile, result))))
- && (ret = enter_macro_context (pfile, node, result)))
+ if ((node->flags & NODE_CONDITIONAL) != 0)
+ {
+ if (pfile->cb.macro_to_expand)
+ {
+ bool whitespace_after;
+ const cpp_token *peek_tok = cpp_peek_token (pfile, 0);
+
+ whitespace_after = (peek_tok->type == CPP_PADDING
+ || (peek_tok->flags & PREV_WHITE));
+ node = pfile->cb.macro_to_expand (pfile, result);
+ if (node)
+ ret = enter_macro_context (pfile, node, result);
+ else if (whitespace_after)
+ {
+ /* If macro_to_expand hook returned NULL and it
+ ate some tokens, see if we don't need to add
+ a padding token in between this and the
+ next token. */
+ peek_tok = cpp_peek_token (pfile, 0);
+ if (peek_tok->type != CPP_PADDING
+ && (peek_tok->flags & PREV_WHITE) == 0)
+ _cpp_push_token_context (pfile, NULL,
+ padding_token (pfile,
+ peek_tok), 1);
+ }
+ }
+ }
+ else
+ ret = enter_macro_context (pfile, node, result);
+ if (ret)
{
if (pfile->state.in_directive || ret == 2)
continue;
if (node->flags & NODE_WARN)
return true;
+ /* Suppress warnings for builtins that lack the NODE_WARN flag. */
+ if (node->flags & NODE_BUILTIN)
+ return false;
+
/* Redefinitions of conditional (context-sensitive) macros, on
the other hand, must be allowed silently. */
if (node->flags & NODE_CONDITIONAL)
if (warn_of_redefinition (pfile, node, macro))
{
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->directive_line, 0,
- "\"%s\" redefined", NODE_NAME (node));
+ bool warned;
+ warned = cpp_error_with_line (pfile, CPP_DL_PEDWARN,
+ pfile->directive_line, 0,
+ "\"%s\" redefined", NODE_NAME (node));
- if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN,
+ if (warned && node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
+ cpp_error_with_line (pfile, CPP_DL_NOTE,
node->value.macro->line, 0,
"this is the location of the previous definition");
}