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:
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 !!!