[PATCH] Add debug method to visualize complex source locations

Manuel Klimek klimek at google.com
Thu May 23 02:20:02 PDT 2013


On Wed, May 22, 2013 at 11:41 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> On Wed, May 22, 2013 at 9:20 AM, Jordan Rose <jordan_rose at apple.com>wrote:
>
>>
>>   You can tokenize without a lexer, but the line/caret combo might
>> actually be better. Nice work!
>>
>>
>> ================
>> Comment at: lib/Basic/SourceLocation.cpp:70-71
>> @@ +69,4 @@
>> +  StringRef Buffer = SM.getBufferData(LocInfo.first);
>> +  int First = std::max<int>(Buffer.rfind('\n', LocInfo.second) + 1, 0);
>> +  int Last = std::min<int>(Buffer.find('\n', LocInfo.second),
>> Buffer.size());
>> +  OS << "|" << Buffer.substr(First, Last - First) << "|\n" << IndentStr
>> ----------------
>> Not super-happy about relying on the value of StringRef::npos here, but
>> okay.
>>
>
> Aren't these min/max calls both redundant? Assuming we're not dealing with
> buffers longer than 2^31 characters, they're equivalent to:
>
> int First = Buffer.rfind('\n', LocInfo.second) + 1; // because this is
> never negative
> int Last = Buffer.find('\n', LocInfo.second); // because this is never >=
> Buffer.size() after conversion to int
>
>
These are both exactly what was wanted, but should be of type size_t (==
> StringRef::size_type).
>

They were left-overs that I didn't actually want to rely on, but forgot to
clean up :) I think the latest version is easier to understand, ptal...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130523/d2fcf819/attachment.html>


More information about the cfe-commits mailing list