[PATCH] D57159: [DiagnosticInfo] Add support for preserving newlines in remark arguments.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 25 08:59:52 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL352216: [DiagnosticInfo] Add support for preserving newlines in remark arguments. (authored by fhahn, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D57159?vs=183318&id=183556#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57159/new/
https://reviews.llvm.org/D57159
Files:
llvm/trunk/lib/IR/DiagnosticInfo.cpp
Index: llvm/trunk/lib/IR/DiagnosticInfo.cpp
===================================================================
--- llvm/trunk/lib/IR/DiagnosticInfo.cpp
+++ llvm/trunk/lib/IR/DiagnosticInfo.cpp
@@ -438,11 +438,33 @@
static const bool flow = true;
};
+/// Helper struct for multiline string block literals. Use this type to preserve
+/// newlines in strings.
+struct StringBlockVal {
+ StringRef Value;
+ StringBlockVal(const std::string &Value) : Value(Value) {}
+};
+
+template <> struct BlockScalarTraits<StringBlockVal> {
+ static void output(const StringBlockVal &S, void *Ctx, raw_ostream &OS) {
+ return ScalarTraits<StringRef>::output(S.Value, Ctx, OS);
+ }
+
+ static StringRef input(StringRef Scalar, void *Ctx, StringBlockVal &S) {
+ return ScalarTraits<StringRef>::input(Scalar, Ctx, S.Value);
+ }
+};
+
// Implement this as a mapping for now to get proper quotation for the value.
template <> struct MappingTraits<DiagnosticInfoOptimizationBase::Argument> {
static void mapping(IO &io, DiagnosticInfoOptimizationBase::Argument &A) {
assert(io.outputting() && "input not yet implemented");
- io.mapRequired(A.Key.data(), A.Val);
+ // Emit a string block scalar for multiline strings, to preserve newlines.
+ if (StringRef(A.Val).count('\n') > 1) {
+ StringBlockVal S(A.Val);
+ io.mapRequired(A.Key.data(), S);
+ } else
+ io.mapRequired(A.Key.data(), A.Val);
if (A.Loc.isValid())
io.mapOptional("DebugLoc", A.Loc);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57159.183556.patch
Type: text/x-patch
Size: 1497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190125/cbf157f7/attachment.bin>
More information about the llvm-commits
mailing list