[cfe-dev] Array Size Information of the Outermost Dimension in ParamValDecl in AST

Tingyuan LIANG via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 2 02:43:45 PDT 2019


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 !!!^_^

Best regards,
------------------------------------------
Tingyuan LIANG
MPhil Student
Department of Electronic and Computer Engineering
The Hong Kong University of Science and Technology
________________________________
From: Reid Kleckner <rnk at google.com>
Sent: Tuesday, July 2, 2019 4:30 AM
To: Tingyuan LIANG
Cc: Clang Dev
Subject: Re: [cfe-dev] Array Size Information of the Outermost Dimension in ParamValDecl in AST

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<mailto: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<mailto: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/20190702/c65bf9f5/attachment.html>


More information about the cfe-dev mailing list