Array Size Information of the Outermost Dimension in ParamValDecl in AST

Dear all,

Hi! I am trying to extracting the size of array from ParamValDecl in AST but I notice the following situation:
The type of an array “int A[50][100]” in the function interface in source code will turn out to be “int (*)[100]” in AST, which means that I lose the information of the outermost dimension, i.e. the number “50”.

I wonder how I can get the size of the outermost dimension of the array with Clang AST visitor, except processing the string of source code or implementing a specific parser.
THANKS a lot in advance for your time and patience!

The AST actually does retain the information you are looking for. I introduced the DecayedType pointer type so that we could retain it. It’s difficult to see with the AST dumper, but if you manually traverse the nodes and handle DecayedType, you will find what you are looking for.

Consider this program:
int f(int A[50][100]) {
typedef decltype(A) P;
P o;
return A[0][0];
}

Dumping it shows how the decayed type appears inside decltype:

-TypedefDecl 0x1cb1da4b4c8 <col:3, col:23> col:23 referenced P 'decltype(A)':'int (*)[100]' -DecltypeType 0x1cb1da4b490 ‘decltype(A)’ sugar

-DeclRefExpr 0x1cb1da4b470 col:20 ‘int ()[100]’:'int ()[100]’ lvalue ParmVar 0x1cb1da4b280 ‘A’ ‘int ()[100]’:'int ()[100]’ non_odr_use_unevaluated
-DecayedType 0x1cb1d816580 'int (*)[100]' sugar -ConstantArrayType 0x1cb1d8164e0 'int [50][100]' 50 -ConstantArrayType 0x1cb1d816480 ‘int [100]’ 100
-BuiltinType 0x1cb1d8156d0 'int' -PointerType 0x1cb1d816550 ‘int (*)[100]’
-ConstantArrayType 0x1cb1d816480 'int [100]' 100 -BuiltinType 0x1cb1d8156d0 ‘int’

Hopefully that helps.

Dear Reid,

THANKS a lot for your detailed explanation!
According to your suggestion, I use the function getOriginalType() and successfully get complete information for the array!
Thanks !!!:slight_smile: