[cfe-dev] Array index detection
moataz ragab
mtzrgb at gmail.com
Sun Nov 1 17:57:56 PST 2009
I would like to detect the index expression of single or multi-dimensional
arrays.
I wrote the code below to accomplish this and wanted to check if there is a
better way to find the index expression(s).
if there is an expression like this : a[i][j][z]. The code below will find
the indices in the following order z, j, then i
Expr *Curr = LHS;
ArraySubscriptExpr *ASE;
while(ASE=dyn_cast<ArraySubscriptExpr>(Curr)) {
Expr *Idx = ASE->getIdx();
*Out<<"Index Expr is:";
Idx->dump();
Curr = ASE->getBase();
if(ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Curr)) {
Curr = ICE->getSubExpr();
}
*Out<<"Base Expr is:";
Curr->dump();
}
Thanks,
Moataz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091102/cb75d6f1/attachment.html>
More information about the cfe-dev
mailing list