This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Way to tell in libcpp if something is a macro...


>>>>> "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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]