Use llvm::ListSeparator for simpler separators (#671)

I was looking for something like this, I think it's a straightforward simplification for code. Internally, it handles skipping the separator on the first print.

See the bottom of: https://llvm.org/doxygen/StringExtras_8h_source.html
This commit is contained in:
Jon Meow
2021-07-23 08:39:58 -07:00
committed by GitHub
parent f35cda7a99
commit edbc3f7716
5 changed files with 23 additions and 32 deletions
+3 -8
View File
@@ -7,6 +7,7 @@
#include <algorithm>
#include "common/check.h"
#include "llvm/ADT/StringExtras.h"
namespace Carbon {
@@ -373,15 +374,9 @@ void Value::Print(llvm::raw_ostream& out) const {
}
case ValKind::TupleValue: {
out << "(";
bool add_commas = false;
llvm::ListSeparator sep;
for (const TupleElement& element : GetTupleValue().elements) {
if (add_commas) {
out << ", ";
} else {
add_commas = true;
}
out << element.name << " = " << *element.value;
out << sep << element.name << " = " << *element.value;
}
out << ")";
break;