[cfe-dev] getLHS() and getRHS()

Yang Chen chenyang at cs.utah.edu
Tue Nov 20 13:56:34 PST 2012

Rambo wrote:
> As far as I know,IgnoreImpCasts, IgnoreParens, IgnoreParenCasts don't help to
> my question. http://a6128786ad6c6ad61b66ad4ddf09b1bd8
> <http://a6128786ad6c6ad61b66ad4ddf09b1bd8>  this link show us that
> "IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return its
> subexpression. If that subexpression is also a ParenExpr, then this method
> recursively returns its subexpression, and so forth. Otherwise, the method
> returns the current Expr. "I doubt your solution exactly.

I meant that often you don't need to explicitly dyn_cast an Expr to 
ImplicitCastExpr. Instead, you can use IgnoreXXX function to strip off 
casts and/or parentheses. For example, your code was:


 Expr *rhs=Decl2->getRHS();
         if(ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(rhs))
           if(DeclRefExpr *ICE1 = dyn_cast<DeclRefExpr>(Curr))


It could handle cases like "A[4]" based on your example. But how about 
"A[(4)]"? You might say that "A[(4)]" is ugly and does not exist in any 
real code base, but there is no such guarantee. Anyway, since I don't 
know what you are trying to achieve, just my 2 cents.

- Yang

More information about the cfe-dev mailing list