[cfe-dev] A checker that checks macro calls

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Jun 27 11:48:54 PDT 2013


On 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. 

Starting from the source location of the statement you could use Preprocessor::getImmediateMacroName() to get the macro name.
You could also see if the location came from the macro argument via SourceManager::isMacroArgExpansion().

> 
> Thanks!
> 
> Sincerely,
> Todd Nowacki
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list