[cfe-dev] Processing Macro Arguments
Josh Parker via cfe-dev
cfe-dev at lists.llvm.org
Wed Oct 23 07:24:09 PDT 2019
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191023/fe57c33e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191023/fe57c33e/attachment.bin>
More information about the cfe-dev
mailing list