[cfe-dev] methods to access "base" and "index" in ArraySubscriptExpr

Ted Kremenek kremenek at apple.com
Fri Aug 17 11:38:20 PDT 2007


On Aug 17, 2007, at 10:10 AM, Steve Naroff wrote:

> I have no problem with the extra checking. I do have another  
> suggestion:
>
> Why not simply change the following...
>
>   return new ArraySubscriptExpr(LHSExp, RHSExp, ResultType, RLoc);
>
> to...
>
>   return new ArraySubscriptExpr(BaseExpr, IndexExpr, ResultType,  
> RLoc);
>
> ? And keep everything else the same...
>
> The only disadvantage with this is the crazy case of idx[base] will  
> always be output as base[idx] (if we are doing a pretty printer or  
> source analysis tool). From my perspective, this loss is extremely  
> minor (and can be fixed one day if necessary). In other words, I  
> think it makes sense for the AST to normalize this case.

Steve and I just discussed this in person.

We decided that we will have BaseExpr and IndexExpr refer to the true  
"base" and "index" respectively (just as in Steve's post), but then  
add getLHS() and getRHS() methods to ArraySubscriptExpr that return  
the lexically "left" and "right" expressions based on comparing their  
SourceLocations.

This will allow the common case that does semantic analysis on the AST  
to not have any extra logic when doing getBase() and getIdx().  For  
tools requiring manipulating expressions at the source level, we have  
getLHS() and getRHS().  This will be the slightly slower than  
getBase()/getIdx() (but likely unnoticeable in performance for such  
applications).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20070817/924dc8c8/attachment.html>


More information about the cfe-dev mailing list