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.
Asked
Active
Viewed 1,264 times
1 Answers
1
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.

Eli Bendersky
- 263,248
- 89
- 350
- 412
-
I want print these line or show them on the terminal. How can I do that? – Awaid Shaheen Jul 07 '15 at 11:32
-
Given a SourceLocation, you can use its `print` or `printToString` methods and pass it a `SourceManager` (possibly from your matched `ASTContext`). – tropicalmug Sep 21 '17 at 14:27