Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the location of the right parenthesis of a condition in Clang?

Tags:

c++

clang

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 ?

like image 507
Dorian Avatar asked Jan 19 '26 17:01

Dorian


1 Answers

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.

like image 88
Dorian Avatar answered Jan 21 '26 07:01

Dorian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!