[cfe-dev] getEndLoc of a DeclRefExpr

Jacob Carlborg doob at me.com
Tue Oct 26 05:40:46 PDT 2010


On 2010-10-26 14:27, Jan Bierbaum wrote:
> 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
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

I had the same problem just now. I'm having a hard time to know what 
location functions to use, specially since there is almost no 
documentation. I'm actually having this problem quite a lot due to 
almost no documentation in Clang. When two functions seem to do almost 
exactly the same thing it's just trial-and-error.

-- 
/Jacob Carlborg




More information about the cfe-dev mailing list