mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 14:40:11 +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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user