[cfe-dev] How to determine the dimensions of a ConstantArrayType

Georgiou, Andreas via cfe-dev cfe-dev at lists.llvm.org
Sun Jul 24 17:31:09 PDT 2016


Hi all,


I am trying to get the number of dimensions of a ConstantArrayType.

My code is the follwing:


if (var->getType().getTypePtr()->isArrayType()) //if the variable declaration is an array type, gets its dimensions
{

     const ConstantArrayType *array = astContext->getAsConstantArrayType(var->getType());
     string type;
     int i = 1; //dimensions counter
     do{
type = array->getElementType().getAsString();
i++;
const ConstantArrayType *array = astContext->getAsConstantArrayType(array->getElementType());
     }while();
     cout << type << " ";
     for (int k = 0; k < i; k++)
           cout << "[number] ";
      cout << endl;
}

What I want to achieve is when I find a declaration in the source code am analysing for example

int [111] [222] [333]

I want to print it like this

int [number] [number] [number]

I am having a hard time finding the number of dimensions of the declared array.
I dont know automatically keep extracting the dimensions of a multiimensional array as 1-dimensional arrays. The problem is inside the do-while loop.

Please help me ..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160725/a62d4767/attachment.html>


More information about the cfe-dev mailing list