/* Part of CPP library. (Macro and #define handling.)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
- 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003 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
cpp_macro *macro = node->value.macro;
if (!macro->used
- /* Skip front-end built-ins and command line macros. */
- && macro->line >= pfile->first_unused_line
&& MAIN_FILE_P (lookup_line (&pfile->line_maps, macro->line)))
cpp_error_with_line (pfile, DL_WARNING, macro->line, 0,
"macro \"%s\" is not used", NODE_NAME (node));
cpp_hashnode *node;
{
const uchar *buf;
+ size_t len;
+ char *nbuf;
if (node->value.builtin == BT_PRAGMA)
{
}
buf = _cpp_builtin_macro_text (pfile, node);
+ len = ustrlen (buf);
+ nbuf = alloca (len + 1);
+ memcpy (nbuf, buf, len);
+ nbuf[len]='\n';
- cpp_push_buffer (pfile, buf, ustrlen (buf), /* from_stage3 */ true, 1);
-
- /* Tweak the column number the lexer will report. */
- pfile->buffer->col_adjust = pfile->cur_token[-1].col - 1;
-
- /* We don't want a leading # to be interpreted as a directive. */
- pfile->buffer->saved_flags = 0;
+ cpp_push_buffer (pfile, (uchar *) nbuf, len, /* from_stage3 */ true, 1);
+ _cpp_clean_line (pfile);
/* Set pfile->cur_token as required by _cpp_lex_direct. */
pfile->cur_token = _cpp_temp_token (pfile);
cpp_reader *pfile;
macro_arg *arg;
{
- unsigned char *dest = BUFF_FRONT (pfile->u_buff);
+ unsigned char *dest;
unsigned int i, escape_it, backslash_count = 0;
const cpp_token *source = NULL;
size_t len;
+ if (BUFF_ROOM (pfile->u_buff) < 3)
+ _cpp_extend_buff (pfile, &pfile->u_buff, 3);
+ dest = BUFF_FRONT (pfile->u_buff);
+ *dest++ = '"';
+
/* Loop, reading in the argument's tokens. */
for (i = 0; i < arg->count; i++)
{
|| token->type == CPP_CHAR || token->type == CPP_WCHAR);
/* Room for each char being written in octal, initial space and
- final NUL. */
+ final quote and NUL. */
len = cpp_token_len (token);
if (escape_it)
len *= 4;
- len += 2;
+ len += 3;
if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < len)
{
}
/* Leading white space? */
- if (dest != BUFF_FRONT (pfile->u_buff))
+ if (dest - 1 != BUFF_FRONT (pfile->u_buff))
{
if (source == NULL)
source = token;
else
dest = cpp_spell_token (pfile, token, dest);
- if (token->type == CPP_OTHER && token->val.c == '\\')
+ if (token->type == CPP_OTHER && token->val.str.text[0] == '\\')
backslash_count++;
else
backslash_count = 0;
}
/* Commit the memory, including NUL, and return the token. */
- if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < 1)
- {
- size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff);
- _cpp_extend_buff (pfile, &pfile->u_buff, 1);
- dest = BUFF_FRONT (pfile->u_buff) + len_so_far;
- }
+ *dest++ = '"';
len = dest - BUFF_FRONT (pfile->u_buff);
BUFF_FRONT (pfile->u_buff) = dest + 1;
return new_string_token (pfile, dest - len, len);
if (lhs->type == CPP_DIV && rhs->type != CPP_EQ)
*end++ = ' ';
end = cpp_spell_token (pfile, rhs, end);
- *end = '\0';
+ *end = '\n';
cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true, 1);
-
- /* Tweak the column number the lexer will report. */
- pfile->buffer->col_adjust = pfile->cur_token[-1].col - 1;
-
- /* We don't want a leading # to be interpreted as a directive. */
- pfile->buffer->saved_flags = 0;
+ _cpp_clean_line (pfile);
/* Set pfile->cur_token as required by _cpp_lex_direct. */
pfile->cur_token = _cpp_temp_token (pfile);
if (CPP_OPTION (pfile, traditional))
return _cpp_expansions_different_trad (macro1, macro2);
- if (macro1->count == macro2->count)
- for (i = 0; i < macro1->count; i++)
- if (!_cpp_equiv_tokens (¯o1->exp.tokens[i], ¯o2->exp.tokens[i]))
- return true;
+ if (macro1->count != macro2->count)
+ return true;
+
+ for (i = 0; i < macro1->count; i++)
+ if (!_cpp_equiv_tokens (¯o1->exp.tokens[i], ¯o2->exp.tokens[i]))
+ return true;
return false;
}
macro->params = 0;
macro->paramc = 0;
macro->variadic = 0;
- macro->used = 0;
+ macro->used = !CPP_OPTION (pfile, warn_unused_macros);
macro->count = 0;
macro->fun_like = 0;
/* To suppress some diagnostics. */
const cpp_string *string;
{
unsigned int i, len;
- const uchar *p, *q, *limit = string->text + string->len;
+ const uchar *p, *q, *limit;
/* Loop over the string. */
- for (p = string->text; p < limit; p = q)
+ limit = string->text + string->len - 1;
+ for (p = string->text + 1; p < limit; p = q)
{
/* Find the start of an identifier. */
while (p < limit && !is_idstart (*p))
if (token->type == CPP_MACRO_ARG)
len += NODE_LEN (macro->params[token->val.arg_no - 1]);
else
- len += cpp_token_len (token); /* Includes room for ' '. */
+ len += cpp_token_len (token) + 1; /* Includes room for ' '. */
if (token->flags & STRINGIFY_ARG)
len++; /* "#" */
if (token->flags & PASTE_LEFT)