Array index detection

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(Curr)) {
Expr *Idx = ASE->getIdx();
*Out<<“Index Expr is:”;
Idx->dump();
Curr = ASE->getBase();
if(ImplicitCastExpr *ICE = dyn_cast(Curr)) {
Curr = ICE->getSubExpr();
}
*Out<<“Base Expr is:”;
Curr->dump();
}

Thanks,
Moataz

The looks fine to me.

  - Doug