Skip to content

Commit e7600fe

Browse files
author
Amritpan Kaur
committed
[CSBindings] Fix spacing issues in potential bindings.
Reformat direct bindings and default literal bindings to print as a list.
1 parent fefd952 commit e7600fe

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

Diff for: lib/Sema/CSBindings.cpp

+31-16
Original file line numberDiff line numberDiff line change
@@ -1766,35 +1766,50 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
17661766
out << "(default type of literal) ";
17671767
break;
17681768
}
1769-
out << BindingType.getString(PO);
1769+
BindingType.print(out);
17701770
}
17711771
};
17721772

17731773
out << "[with possible bindings: ";
1774-
interleave(Bindings, printBinding, [&]() { out << "; "; });
1775-
if (!Literals.empty()) {
1776-
std::vector<std::string> defaultLiterals;
1777-
for (const auto &literal : Literals) {
1778-
if (literal.second.viableAsBinding()) {
1779-
auto defaultWithType = "(default type of literal) " +
1780-
literal.second.getDefaultType().getString(PO);
1781-
defaultLiterals.push_back(defaultWithType);
1782-
}
1774+
SmallVector<PrintableBinding, 2> potentialBindings;
1775+
for (const auto &binding : Bindings) {
1776+
switch (binding.Kind) {
1777+
case AllowedBindingKind::Exact:
1778+
potentialBindings.push_back(PrintableBinding::exact(binding.BindingType));
1779+
break;
1780+
case AllowedBindingKind::Supertypes:
1781+
potentialBindings.push_back(
1782+
PrintableBinding::supertypesOf(binding.BindingType));
1783+
break;
1784+
case AllowedBindingKind::Subtypes:
1785+
potentialBindings.push_back(
1786+
PrintableBinding::subtypesOf(binding.BindingType));
1787+
break;
17831788
}
1784-
interleave(defaultLiterals, out, ", ");
17851789
}
1786-
if (Bindings.empty() && Literals.empty()) {
1790+
for (const auto &literal : Literals) {
1791+
if (literal.second.viableAsBinding()) {
1792+
potentialBindings.push_back(PrintableBinding::literalDefaultType(
1793+
literal.second.getDefaultType()));
1794+
}
1795+
}
1796+
if (potentialBindings.empty()) {
17871797
out << "<empty>";
1798+
} else {
1799+
interleave(
1800+
potentialBindings,
1801+
[&](const PrintableBinding &binding) { binding.print(out, PO); },
1802+
[&] { out << ", "; });
17881803
}
17891804
out << "]";
17901805

17911806
if (!Defaults.empty()) {
1792-
out << "[defaults: ";
1807+
out << " [defaults: ";
17931808
for (const auto &entry : Defaults) {
17941809
auto *constraint = entry.second;
1795-
PotentialBinding binding{constraint->getSecondType(),
1796-
AllowedBindingKind::Exact, constraint};
1797-
printBinding(binding);
1810+
auto defaultBinding =
1811+
PrintableBinding::exact(constraint->getSecondType());
1812+
defaultBinding.print(out, PO);
17981813
}
17991814
out << "]";
18001815
}

0 commit comments

Comments
 (0)