[cfe-dev] Getting the name of a macro passed as an argument to another macro

Phil King phil_king at rocketmail.com
Tue Feb 28 00:41:34 PST 2012


 <phil_king at rocketmail.com> wrote:

> Given:
> 
> #include <stdbool.h>
> 
> #define M(p) p
> 
> int f ( void )
> {
>    true;
>    M( true );
> }
> 
> then, as expected, I get IntegerLiteral Expr nodes of ( 'int' '1' ) for both lines in the function.
> 
> I can get the macro name corresponding to the first '1' (i.e. 'true') by using:
> 
>    SL = SM.getSpellingLoc( SM.getImmediateExpansionRange( SL ).first );
> 
>    std::pair< FileID, unsigned > ExpansionInfo = SM.getDecomposedLoc( SL );
> 
> How do I get the name of the macro passed as the argument to the function-like macro? The code above gives the argument name, 'p'.

Think I've got it:

while ( SM.isMacroArgExpansion( SL ) )
   SL = SM.getImmediateSpellingLoc();

Phil.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120228/5371665c/attachment.html>


More information about the cfe-dev mailing list