[cfe-dev] A checker that checks macro calls

Todd Nowacki nowacki724 at gmail.com
Thu Jun 27 12:45:49 PDT 2013


Right now, I've been using checkPostStmt and then using the source location
of the expression to check isMacroId() and using the CheckerContext
function getMacroNameOrSpelling. The reason being that I need the SymbolRef
for the argument to the macro, and I can't see a way to get that via a
MacroArg or Token (which is what I get if I used the Preprocessor).

The PPCallback seems much cleaner; if there was a way to get a SymbolRef
fromt that method, that would be awesome.

-Todd


On Thu, Jun 27, 2013 at 12:04 PM, Thompson, John <
John_Thompson at playstation.sony.com> wrote:

>  Todd,****
>
> ** **
>
> Since you say “when a certain macro is invoked”, could this be a case for
> deriving a class from PPCallbacks which overrides MacroExpands to watch for
> instances of the macro? You call the Preprocessor’s addPPCallbacks function
> to hook up an instance of your callbacks class.****
>
> ** **
>
> -John****
>
> ** **
>
> *From:* cfe-dev-bounces at cs.uiuc.edu [mailto:cfe-dev-bounces at cs.uiuc.edu] *On
> Behalf Of *Todd Nowacki
> *Sent:* Monday, June 24, 2013 3:16 PM
> *To:* cfe-dev at cs.uiuc.edu
> *Subject:* [cfe-dev] A checker that checks macro calls****
>
> ** **
>
> 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. ****
>
> ** **
>
> Thanks!****
>
> ** **
>
> Sincerely,****
>
> Todd Nowacki****
>
> ** **
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130627/511abb63/attachment.html>


More information about the cfe-dev mailing list