printing line number of the source codes Stmt using clang libtooling

1.3k views Asked by At

Hello I'm working with clang libtooling. I need to take a .c file and print the names of all functions present and the lines the function declaration is in. In the ASTRecursive class I have function VisitFunctionDecl and have found the functions but am very confused how to find the line number of the Stmts.

1

There are 1 answers

2
Eli Bendersky On

Given a FunctionDecl *f, f->getSourceRange() is its source range (beginning and end). Given a SourceRange sr, sr.getBegin() gives you a SourceLocation which is the beginning of the range.

Look up the documentation / declarations of the classes mentioned for more details.