I'm currently using libclang to do static code analysis for a school project. I've got it set up and working, and have so far managed to get the file location and physical length (number of lines) of a function, but the next thing I want to get is the depth of a function.
To be clear, for my purposes the depth of a function on any given line would be the number of nested if/for/while/etc. blocks surround that line. Assuming standard syntax, the depth would be related to the number of tabs/spaces at the start of the line.
The depth of a function overall would then simply be the depth of it's deepest line. For example this would have a depth of 2:
int foo()
{
int n = 0; // Depth 0
for (int i = 0; i < 10; ++i)
{
n = bar(i); // Depth 1
if (i < n)
++n; // Depth 2, deepest line
}
}