[cfe-dev] For-Loop and FunctionName

Richard Smith richard at metafoo.co.uk
Wed Jul 16 16:51:29 PDT 2014


On Tue, Jul 15, 2014 at 10:42 AM, Anja Gerbes <anja.gerbes at googlemail.com>
wrote:

> Hello all,
>
> i have a question about finding for-loops.
>
> How i can get the information in which function a for-loop is located.
>
> How i understand clang it is impossible to get the function name for a
> for-loop.
>
> I hope you can help me and give me a possibility to get the function name
> for a for-loop.
>

If you're in Sema, you can look at CurContext. If you're using a
RecursiveASTVisitor, you can track which function you're in during your
recursive descent. If you're using an ASTMatcher, you can use a
hasDescendent matcher to match a range-based for loop within a function and
bind both entities, or, failing that, a parent matcher. If all else fails,
you can use ASTContext::getParents.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140716/d04f5326/attachment.html>


More information about the cfe-dev mailing list