[cfe-dev] Array Size Information of the Outermost Dimension in ParamValDecl in AST
Reid Kleckner via cfe-dev
cfe-dev at lists.llvm.org
Mon Jul 1 13:30:39 PDT 2019
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.
On Mon, Jul 1, 2019 at 2:22 AM Tingyuan LIANG via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> 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!
>
> Best regards,
> ------------------------------------------
> Tingyuan LIANG
> MPhil Student
> Department of Electronic and Computer Engineering
> The Hong Kong University of Science and Technology
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190701/3912e5e5/attachment.html>
More information about the cfe-dev
mailing list