This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Warning from cpp on macro argument stringification is missing
- To: NeilB at earthling dot net
- Subject: Re: Warning from cpp on macro argument stringification is missing
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Thu, 7 Sep 2000 15:17:13 -0400 (EDT)
- Cc: gcc-bugs at gcc dot gnu dot org, zack at wolery dot cumb dot org
> From: Neil Booth <NeilB@earthling.net>
>
> Kaveh R. Ghazi wrote:-
>
> > I suspect that since you ripped out the traditional stuff from cpplib,
> > that there is no place where you parse function macro specifically to
> > see if any strings in the replacement contains an argument of the
> > macro. Is this true, or can you point out the function where this
> > magic happens?
>
> Exactly - strings are lexed as strings (which is not traditional in
> itself), so you would need to scan CPP_STRING and CPP_CHAR tokens'
> text (which are not null-terminated b.t.w.) for the tokens of the
> macro arguments.
>
> This is a bit nasty, as you'll have to figure out whether a match
> really is a match (e.g. the first character is not escaped). In view
> of this, I suspect it would be easier to find all tokens within the
> string and try to match against the tokens in the arguments (and this
> would allow a quick length-based comparison, too) rather than the
> other way round.
> Neil.
Ugh, it's as I feared.
Okay, I got as far as that on my own. When I added the CPP_STRING and
CPP_CHAR cases in save_expansion, the relevant string came up in
token->val.str.text. As you say, the nasty part is that I have to
tokenize the string. E.g. given:
> #define foo(A, hello, E) "A B hello C,hello,DhelloE"
I suppose I have to warn about `A', and the first two `hello's but not
the third `hello' or the 'E' since they are not standalone tokens and
wouldn't get replaced in traditional C. (Right?)
That means chopping up the string at ID separators and checking each
token against each function macro parameter.
Sooo, what's the best way to do that? Is there some handy routine in
cpplex.c to tokenize arbitrary strings or should I dup the string and
use strtok?
Once I can loop over the tokens in the replacement string, what's the
best way to check whether a token is contained in the parameter list?
The find_param function seems to segv when I call it, but I could be
using it wrong. I experimented and passed it (info->first_param,
token) just as the CPP_NAME case did, but I got a core.
Thanks,
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions