Commit 6ead1e99 by Zack Weinberg

[multiple changes]

2000-07-31  Jakub Jelinek  <jakub@redhat.com>

	* cpplex.c (_cpp_get_line): If index is 0, return line 0 col 0.
	(_cpp_get_token): Don't macro expand a just pasted token if it
	was pasted at no_expand_level.

	* testsuite/gcc.dg/cpp/paste7.c: New test.

2000-07-31  Zack Weinberg  <zack@wolery.cumb.org>

	* cppmacro.c (find_param, count_params, save_expansion):
	Permit 'defined' as a macro parameter name.

From-SVN: r35394
parent ed39843b
2000-07-31 Jakub Jelinek <jakub@redhat.com>
* cpplex.c (_cpp_get_line): If index is 0, return line 0 col 0.
(_cpp_get_token): Don't macro expand a just pasted token if it
was pasted at no_expand_level.
2000-07-31 Zack Weinberg <zack@wolery.cumb.org>
* cppmacro.c (find_param, count_params, save_expansion):
Permit 'defined' as a macro parameter name.
2000-07-31 Zack Weinberg <zack@wolery.cumb.org> 2000-07-31 Zack Weinberg <zack@wolery.cumb.org>
* Makefile.in: Rename cpp to cpp0, tradcpp to tradcpp0, and * Makefile.in: Rename cpp to cpp0, tradcpp to tradcpp0, and
......
...@@ -3082,7 +3082,7 @@ const cpp_token * ...@@ -3082,7 +3082,7 @@ const cpp_token *
_cpp_get_token (pfile) _cpp_get_token (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
const cpp_token *token; const cpp_token *token, *old_token;
cpp_hashnode *node; cpp_hashnode *node;
/* Loop until we hit a non-macro token. */ /* Loop until we hit a non-macro token. */
...@@ -3111,6 +3111,8 @@ _cpp_get_token (pfile) ...@@ -3111,6 +3111,8 @@ _cpp_get_token (pfile)
be taken as a control macro. */ be taken as a control macro. */
pfile->potential_control_macro = 0; pfile->potential_control_macro = 0;
old_token = token;
/* See if there's a token to paste with this one. */ /* See if there's a token to paste with this one. */
if (!pfile->paste_level) if (!pfile->paste_level)
token = maybe_paste_with_next (pfile, token); token = maybe_paste_with_next (pfile, token);
...@@ -3120,10 +3122,17 @@ _cpp_get_token (pfile) ...@@ -3120,10 +3122,17 @@ _cpp_get_token (pfile)
return token; return token;
/* Is macro expansion disabled in general, or are we in the /* Is macro expansion disabled in general, or are we in the
middle of a token paste? */ middle of a token paste, or was this token just pasted?
if (pfile->no_expand_level == pfile->cur_context || pfile->paste_level) (Note we don't check token->flags & PASTED, because that
counts tokens that were pasted at some point in the past,
we're only interested in tokens that were pasted by this call
to maybe_paste_with_next.) */
if (pfile->no_expand_level == pfile->cur_context
|| pfile->paste_level
|| (token != old_token
&& pfile->no_expand_level + 1 == pfile->cur_context))
return token; return token;
node = token->val.node; node = token->val.node;
if (node->type != T_MACRO) if (node->type != T_MACRO)
return special_symbol (pfile, node, token); return special_symbol (pfile, node, token);
...@@ -3337,6 +3346,13 @@ _cpp_get_line (pfile, pcol) ...@@ -3337,6 +3346,13 @@ _cpp_get_line (pfile, pcol)
else else
index = pfile->contexts[0].posn; index = pfile->contexts[0].posn;
if (index == 0)
{
if (pcol)
*pcol = 0;
return 0;
}
cur_token = &pfile->token_list.tokens[index - 1]; cur_token = &pfile->token_list.tokens[index - 1];
if (pcol) if (pcol)
*pcol = cur_token->col; *pcol = cur_token->col;
......
...@@ -72,7 +72,7 @@ find_param (first, token) ...@@ -72,7 +72,7 @@ find_param (first, token)
unsigned int param = 0; unsigned int param = 0;
for (; first < token && first->type != CPP_CLOSE_PAREN; first++) for (; first < token && first->type != CPP_CLOSE_PAREN; first++)
if (first->type == CPP_NAME) if (first->type == CPP_NAME || first->type == CPP_DEFINED)
{ {
param++; param++;
if (first->val.node == token->val.node) if (first->val.node == token->val.node)
...@@ -139,6 +139,8 @@ count_params (pfile, info) ...@@ -139,6 +139,8 @@ count_params (pfile, info)
case CPP_COMMENT: case CPP_COMMENT:
continue; /* Ignore -C comments. */ continue; /* Ignore -C comments. */
case CPP_DEFINED: /* 'defined' may be used as a macro
parameter name. */
case CPP_NAME: case CPP_NAME:
if (prev_ident) if (prev_ident)
{ {
...@@ -429,7 +431,7 @@ save_expansion (pfile, info) ...@@ -429,7 +431,7 @@ save_expansion (pfile, info)
dumping macro definitions. They must go first. */ dumping macro definitions. They must go first. */
if (list->params_len) if (list->params_len)
for (token = info->first_param; token < info->first; token++) for (token = info->first_param; token < info->first; token++)
if (token->type == CPP_NAME) if (token->type == CPP_NAME || token->type == CPP_DEFINED)
{ {
/* Copy null too. */ /* Copy null too. */
memcpy (buf, token->val.node->name, token->val.node->length + 1); memcpy (buf, token->val.node->name, token->val.node->length + 1);
...@@ -443,6 +445,7 @@ save_expansion (pfile, info) ...@@ -443,6 +445,7 @@ save_expansion (pfile, info)
switch (token->type) switch (token->type)
{ {
case CPP_DEFINED:
case CPP_NAME: case CPP_NAME:
if (list->paramc == -1) if (list->paramc == -1)
break; break;
......
2000-07-31 Jakub Jelinek <jakub@redhat.com> 2000-07-31 Jakub Jelinek <jakub@redhat.com>
* testsuite/gcc.dg/cpp/paste7.c: New test.
* gcc.dg/cpp/20000725-1.c: New test. * gcc.dg/cpp/20000725-1.c: New test.
2000-07-31 Zack Weinberg <zack@wolery.cumb.org> 2000-07-31 Zack Weinberg <zack@wolery.cumb.org>
......
/* { dg-do run } */
#define D_2 1, 2
#define C_2(X, I0, I1) X##_a = I0, X##_b = I1
#define B_2(X, I) C_2(X, I)
#define A(N, X) B_##N (X, D_##N)
extern void abort(void);
extern void exit(int);
int x_a, x_b;
int main(void)
{
A(2, x);
if (x_a != 1 || x_b != 2)
abort();
exit(0);
}
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