Count number of array references

Hi,
How can we count number of array references in a given C code with clang?
Assume code looks like this,
void main()
{
     int a[10];
    a[5]=a[5]+1;
}

in the above code, number of array references are 2.

Probably easiest to do by deriving from RecursiveASTVisitor and incrementing your counter by one for each ArraySubscriptExpr. That’s assuming you want to count all ‘array[index]’ expressions. If you want to count all references to array-typed variables, it’s best to look for DeclRefExpr-s whose type is an ArrayType. If you also want to find array references from functions calls, I think you’d better visit all Expr-s, and check their type for ArrayType.

Hope this helps!