Processing Macro Arguments

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Processing Macro Arguments

Kristof Beyls via cfe-dev

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.getNodeAs<clang::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?


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

smime.p7s (6K) Download Attachment