<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi all,</p>
<p><br>
</p>
<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>
<p><br>
</p>
<p></p>
<div>bool VisitVarDecl(VarDecl *var)</div>
<div>    {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (astContext->getSourceManager().isInMainFile(var->getLocStart())) //checks if the node is in the main = input file.</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>FullSourceLoc FullLocation = astContext->getFullLoc(var->getLocStart());</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if((var->hasLocalStorage() || var->isStaticLocal ()))</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (!var->isDefinedOutsideFunctionOrMethod())</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if(avoid == 0)</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>numVariables++;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>string varName = var->getQualifiedNameAsString();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>string varType = var->getType().getAsString();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>const Type *type = var->getType().getTypePtr();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if(type->isConstantArrayType())</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>const ArrayType *Array = type->castAsArrayTypeUnsafe();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>cout << "Is array of type: "  << Array->getElementType().getAsString() << endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>REPORT << "[" << FullLocation.getSpellingLineNumber() << "," << FullLocation.getSpellingColumnNumber() << "]Variable Declaration: " << varName << " of type " << varType << "\n";</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>APIs << varType << ";";</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>else</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>avoid--;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>REPORT << "Avoid is: " << avoid << endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div>        return true;</div>
<div>    }</div>
<br>
<p></p>
<p><br>
</p>
<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.</p>
<p>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><br>
</p>
<p>Thank you all.</p>
</div>
</body>
</html>