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
+4 -6
View File
@@ -5,6 +5,7 @@
#include "executable_semantics/ast/expression.h"
#include "executable_semantics/common/error.h"
#include "llvm/ADT/StringExtras.h"
namespace Carbon {
@@ -221,12 +222,9 @@ static void PrintOp(llvm::raw_ostream& out, Operator op) {
static void PrintFields(llvm::raw_ostream& out,
const std::vector<FieldInitializer>& fields) {
int i = 0;
for (auto iter = fields.begin(); iter != fields.end(); ++iter, ++i) {
if (i != 0) {
out << ", ";
}
out << iter->name << " = " << *iter->expression;
llvm::ListSeparator sep;
for (const auto& field : fields) {
out << sep << field.name << " = " << field.expression;
}
}