[cfe-dev] A checker that checks macro calls

Eli Friedman eli.friedman at gmail.com
Mon Jun 24 15:55:37 PDT 2013


On Mon, Jun 24, 2013 at 3:53 PM, Eli Friedman <eli.friedman at gmail.com>wrote:

> On Mon, Jun 24, 2013 at 3:15 PM, Todd Nowacki <nowacki724 at gmail.com>wrote:
>
>> Hi,
>>
>> I'm currently trying to implement a checker that needs to know when a
>> certain macro is invoked.
>>
>> For example, if I had something like:
>> #define MY_MACRO(x)  ...
>>
>> I would want to check if the statement is MY_MACRO and then inspect its
>> argument.
>>
>> I see that with checkPreStmt or checkPostStmt. I can check if it is a
>> macro, via getLocStart and isMacroID. Is there a way to get the name of the
>> macro and it's argument (if it has one)?
>> I see that MacroInfo could be used to get the args possibly, but it
>> doesn't seem to give me the name.
>>
>
>
> You can get the name of the macro by looking into the source buffer; get
> the expansion location and use something like Lexer::getRawToken to pull
> out the name.
>

Err, actually you probably want Lexer::getSpelling(), which returns
something a bit easier to work with.

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130624/f6495aaa/attachment.html>


More information about the cfe-dev mailing list