[cfe-dev] Array index detection

Douglas Gregor dgregor at apple.com
Mon Nov 2 09:37:38 PST 2009


On Nov 1, 2009, at 5:57 PM, moataz ragab wrote:

> 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();
>           }


The looks fine to me.

	- Doug



More information about the cfe-dev mailing list