mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 20:58:15 +00:00
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:
1 parent
f35cda7a99
commit
edbc3f7716
5 files changed
+23
-32
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user