mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-01 22:02:45 +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:
@@ -13,6 +13,7 @@
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "executable_semantics/ast/function_definition.h"
|
||||
#include "executable_semantics/interpreter/stack.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -74,24 +75,21 @@ void Action::Print(llvm::raw_ostream& out) const {
|
||||
out << "<" << pos << ">";
|
||||
if (results.size() > 0) {
|
||||
out << "(";
|
||||
llvm::ListSeparator sep;
|
||||
for (auto& result : results) {
|
||||
out << sep;
|
||||
if (result) {
|
||||
out << *result;
|
||||
}
|
||||
out << ",";
|
||||
}
|
||||
out << ")";
|
||||
}
|
||||
}
|
||||
|
||||
void Action::PrintList(const Stack<Action*>& ls, llvm::raw_ostream& out) {
|
||||
auto it = ls.begin();
|
||||
while (it != ls.end()) {
|
||||
out << **it;
|
||||
++it;
|
||||
if (it != ls.end()) {
|
||||
out << " :: ";
|
||||
}
|
||||
llvm::ListSeparator sep(" :: ");
|
||||
for (const auto& action : ls) {
|
||||
out << sep << *action;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user