mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01: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:
@@ -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