[PATCH] Add debug method to visualize complex source locations

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



================
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
----------------
Jordan Rose wrote:
> Not super-happy about relying on the value of StringRef::npos here, but okay.
Me neither, that was left over from a previous attempt and I forgot to clean it up ... changed.

================
Comment at: lib/Basic/SourceLocation.cpp:73
@@ +72,3 @@
+  OS << "|" << Buffer.substr(First, Last - First) << "|\n" << IndentStr
+     << std::string(1 + LocInfo.second - First, ' ') << "^ ";
+}
----------------
Jordan Rose wrote:
> This is all nice and inline, but it does make an extra temporary std::string. raw_ostream::indent instead?
Cool, didn't know about that. Done.


http://llvm-reviews.chandlerc.com/D768



More information about the cfe-commits mailing list