[cfe-dev] getEndLoc of a DeclRefExpr

Jan Bierbaum s3306700 at inf.tu-dresden.de
Tue Oct 26 05:27:26 PDT 2010


Douglas Gregor meinte am 25.10.2010 18:44:
>> DeclRefExpr::getEndLoc() always returns the same as
>> DeclRefExpr::getBeginLoc(). Is there a reason for this? It's a bit
>> annoying when using the Rewriter with DeclRefExprs.
>> 
>> This happens because getEndLoc() delegates to the SourceRange of the
>> DeclRefExpr's NameInfo (see DeclRefExpr::getSourceRange() in
>> Expr.cpp).
> 
> This *is* by design; for example, the diagnostic printer handles
> these ranges correctly. The SourceRange points to the beginning of
> the start/end tokens, and you can use
> Preprocessor::getLocForEndOfToken() to get the ending location in
> characters.

Since this is at least the third time in a few months that somebody
(including myself) got confused about the way SourceRange works, how
about adding a small section about this to the "Clang Internals" on the
web site?

Attached is my take on this, based on your earlier post [1] to this list.


Regards, Jan.



[1] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-August/010595.html
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: internals.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101026/38dbc46f/attachment.ksh>


More information about the cfe-dev mailing list