Getting the name of a macro passed as an argument to another macro


#include <stdbool.h>

#define M(p) p

int f ( void )
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();