I'm using the clang library to do some c++ AST manipulation. I would like to get the location of the right parenthesis of a condition of an IfStmt.
I tried:
auto condLocEnd = statement->getCond()->getLocEnd();
auto condLoc = Lexer::findLocationAfterToken(condLocEnd, tok::r_paren, sm, LangOptions(), false);
Unfortunately condLoc is invalid when the condition contains a macro.
Eg: if(p == NULL). I can't figure out how to get the location. How to get it ?
Thanks to the cfe-dev mailing list, I found that this answer https://stackoverflow.com/a/24223347. I needed to get the expansion location for the LocEnd() of my condition expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With