Hi all,
I’m trying to find the arguments given to a macro with a specific name, but I have not had any luck. I’m still fairly new to Clang, so if anyone has any advice, I’d be happy to hear it.
Given the following code, I get absolutely nothing from output:
(Assume we used a matcher to get every expr):
ASTContext* ast = /* AST Context */;
If(const Expr* expr = Result.Nodes.getNodeAsclang::Expr(“expr”)){
auto& SM = ast->getSourceManager();
auto loc = expr->getLocStart();
if(SM.isMacroArgExpansion(loc){
const auto expLoc = SM.getImmediateExpansionRange(loc).first;
const auto name = Lexer::getImmediateMacroName(expLoc, SM, ast->getLangOpts());
if(name == “MACRO_NAME”){
Token tok;
If(!cpp->getRawToken(expLoc,tok)){
std::cout << cpp->getSpelling(tok) << std::endl;
}
}
}
}
I was thinking that I could use matchers to match against all expressions, then filter for macros with the isMacroArgExpansion(loc) check, then filter for the macros I care about with getImmediateMacroName(). What am I missing here? Is the issue in how I jump from the macro to tokens?