How to check if a variable declaration in Clang ASTvisitor is an array
<p>I am trying to determine whether a variable declaration in ASTvisitor is an array and if is an array I want to determine the number of dimensions of the array. Below you can find my code.</p>

<pre><code>bool VisitVarDecl(VarDecl *var)
    {
        if (astContext-&gt;getSourceManager().isInMainFile(var-&gt;getLocStart())) //checks if the node is in the main = input file.
        {
            FullSourceLoc FullLocation = astContext-&gt;getFullLoc(var-&gt;getLocStart());
            if((var-&gt;hasLocalStorage() || var-&gt;isStaticLocal ()))
            {
                if (!var-&gt;isDefinedOutsideFunctionOrMethod())
                {
                    if(avoid == 0)
                    {
                        numVariables++;
                        string varName = var-&gt;getQualifiedNameAsString();
                        string varType = var-&gt;getType().getAsString();
                        const Type *type = var-&gt;getType().getTypePtr();
                        if(type-&gt;isConstantArrayType())
                        {
                            const ArrayType *Array = type-&gt;castAsArrayTypeUnsafe();
                            cout &lt;&lt; "Is array of type: "  &lt;&lt; Array-&gt;getElementType().getAsString() &lt;&lt; endl;
                        }
                        REPORT &lt;&lt; "[" &lt;&lt; FullLocation.getSpellingLineNumber() &lt;&lt; "," &lt;&lt; FullLocation.getSpellingColumnNumber() &lt;&lt; "]Variable Declaration: " &lt;&lt; varName &lt;&lt; " of type " &lt;&lt; varType &lt;&lt; "\n";
                        APIs &lt;&lt; varType &lt;&lt; ";";
                    }
                    else
                    {
                        avoid--;
                        REPORT &lt;&lt; "Avoid is: " &lt;&lt; avoid &lt;&lt; endl;
                    }
                }
            }
        }
        return true;
    }
</code></pre>

<p>I don't know if I have correctly did the "casting" from VarDecl to ArrayType. If you have a better, safer, and  less sloppy way to do it please am open to any opinions.
Furthermore my main problem right now is how to get the number of dimensions of the array and even its size in terms of cells.</p>

<p>Thank you all.</p>