/* 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 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005 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_buff *buff = _cpp_get_buff (pfile, len);
unsigned char *buf = BUFF_FRONT (buff);
- len = cpp_spell_token (pfile, token, buf) - buf;
+ len = cpp_spell_token (pfile, token, buf, true) - buf;
dest = cpp_quote_string (dest, buf, len);
_cpp_release_buff (pfile, buff);
}
else
- dest = cpp_spell_token (pfile, token, dest);
+ dest = cpp_spell_token (pfile, token, dest, true);
if (token->type == CPP_OTHER && token->val.str.text[0] == '\\')
backslash_count++;
lhs = *plhs;
len = cpp_token_len (lhs) + cpp_token_len (rhs) + 1;
buf = alloca (len);
- end = cpp_spell_token (pfile, lhs, buf);
+ end = cpp_spell_token (pfile, lhs, buf, false);
/* Avoid comment headers, since they are still processed in stage 3.
It is simpler to insert a space here, rather than modifying the
false doesn't work, since we want to clear the PASTE_LEFT flag. */
if (lhs->type == CPP_DIV && rhs->type != CPP_EQ)
*end++ = ' ';
- end = cpp_spell_token (pfile, rhs, end);
+ end = cpp_spell_token (pfile, rhs, end, false);
*end = '\n';
cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true);
{
cpp_token *token = _cpp_temp_token (pfile);
token->type = (*paste_flag)->type;
- token->val.str = (*paste_flag)->val.str;
+ token->val = (*paste_flag)->val;
if (src->flags & PASTE_LEFT)
token->flags = (*paste_flag)->flags | PASTE_LEFT;
else
cpp_token *t = _cpp_temp_token (pfile);
t->type = result->type;
t->flags = result->flags | NO_EXPAND;
- t->val.str = result->val.str;
+ t->val = result->val;
result = t;
}
macro->fun_like = 1;
}
else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE))
- cpp_error (pfile, CPP_DL_PEDWARN,
- "ISO C requires whitespace after the macro name");
+ {
+ /* While ISO C99 requires whitespace before replacement text
+ in a macro definition, ISO C90 with TC1 allows there characters
+ from the basic source character set. */
+ if (CPP_OPTION (pfile, c99))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "ISO C99 requires whitespace after the macro name");
+ else
+ {
+ int warntype = CPP_DL_WARNING;
+ switch (ctoken->type)
+ {
+ case CPP_ATSIGN:
+ case CPP_AT_NAME:
+ case CPP_OBJC_STRING:
+ /* '@' is not in basic character set. */
+ warntype = CPP_DL_PEDWARN;
+ break;
+ case CPP_OTHER:
+ /* Basic character set sans letters, digits and _. */
+ if (strchr ("!\"#%&'()*+,-./:;<=>?[\\]^{|}~",
+ ctoken->val.str.text[0]) == NULL)
+ warntype = CPP_DL_PEDWARN;
+ break;
+ default:
+ /* All other tokens start with a character from basic
+ character set. */
+ break;
+ }
+ cpp_error (pfile, warntype,
+ "missing whitespace after the macro name");
+ }
+ }
if (macro->fun_like)
token = lex_expansion_token (pfile, macro);
len += NODE_LEN (macro->params[i]) + 1; /* "," */
}
+ /* This should match below where we fill in the buffer. */
if (CPP_OPTION (pfile, traditional))
len += _cpp_replacement_text_len (macro);
else
if (token->type == CPP_MACRO_ARG)
len += NODE_LEN (macro->params[token->val.arg_no - 1]);
else
- len += cpp_token_len (token) + 1; /* Includes room for ' '. */
+ len += cpp_token_len (token);
+
if (token->flags & STRINGIFY_ARG)
len++; /* "#" */
if (token->flags & PASTE_LEFT)
len += 3; /* " ##" */
+ if (token->flags & PREV_WHITE)
+ len++; /* " " */
}
}
if (token->type == CPP_MACRO_ARG)
{
- len = NODE_LEN (macro->params[token->val.arg_no - 1]);
memcpy (buffer,
- NODE_NAME (macro->params[token->val.arg_no - 1]), len);
- buffer += len;
+ NODE_NAME (macro->params[token->val.arg_no - 1]),
+ NODE_LEN (macro->params[token->val.arg_no - 1]));
+ buffer += NODE_LEN (macro->params[token->val.arg_no - 1]);
}
else
- buffer = cpp_spell_token (pfile, token, buffer);
+ buffer = cpp_spell_token (pfile, token, buffer, false);
if (token->flags & PASTE_LEFT)
{