This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Way to tell in libcpp if something is a macro...
- From: Tom Tromey <tromey at redhat dot com>
- To: Ed Smith-Rowland <3dw4rd at verizon dot net>
- Cc: gcc-patches <gcc at gcc dot gnu dot org>
- Date: Wed, 26 Jun 2013 11:39:17 -0600
- Subject: Re: Way to tell in libcpp if something is a macro...
- References: <51CB0DF0 dot 1000505 at verizon dot net>
>>>>> "Ed" == Ed Smith-Rowland <3dw4rd@verizon.net> writes:
Ed> I have a situation where I would like to detect if a string is a
Ed> currently defined macro.
Ed> Something like a
Ed> bool cpp_is_macro(const unsigned char *);
Ed> would be great.
Ed> Or perhaps I could construct something from the string and test that.
Ed> If something like this doesn't exist does anyone have some pointers on
Ed> how to make one for libcpp.
Call ht_lookup and convert to a cpp hash node, e.g., from grepping:
return CPP_HASHNODE (ht_lookup (pfile->hash_table,
buf, bufp - buf, HT_ALLOC));
Then see if the node's 'type' field is NT_MACRO.
I think that should work.
See directives.c:do_ifdef for some bits.
E.g., you may consider marking the macro as "used".
Tom