Skip to content

Commit ce17240

Browse files
author
David Ungar
committed
Don’t output newline for simple_display of DeclContext. And clean up simple_display.
1 parent 6683de1 commit ce17240

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

include/swift/AST/DeclContext.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
588588

589589
void dumpContext() const;
590590
unsigned printContext(llvm::raw_ostream &OS, unsigned indent = 0,
591-
bool includeAncestors = true) const;
591+
bool onlyAPartialLine = false) const;
592592

593593
// Only allow allocation of DeclContext using the allocator in ASTContext.
594594
void *operator new(size_t Bytes, ASTContext &C,
@@ -783,15 +783,12 @@ class IterableDeclContext {
783783
/// avoid ambiguities with Decl* arguments.
784784
template <typename ParamT, typename = typename std::enable_if<
785785
std::is_same<ParamT, DeclContext>::value>::type>
786-
void simple_display(llvm::raw_ostream &out, const ParamT *x) {
787-
if (!std::is_same<ParamT, DeclContext>::value)
788-
llvm_unreachable("Template should only be defined for DeclConsts.");
789-
const DeclContext *dc = (const DeclContext *)x;
790-
if (!dc) {
786+
void simple_display(llvm::raw_ostream &out, const ParamT *dc) {
787+
if (!dc) {
791788
out << "(null)";
792789
return;
793790
}
794-
dc->printContext(out, 0, false);
791+
dc->printContext(out, 0, true);
795792
}
796793

797794
} // end namespace swift

lib/AST/DeclContext.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ static unsigned getLineNumber(DCType *DC) {
521521
}
522522

523523
unsigned DeclContext::printContext(raw_ostream &OS, const unsigned indent,
524-
const bool includeAncestors) const {
524+
const bool onlyAPartialLine) const {
525525
unsigned Depth = 0;
526-
if (includeAncestors)
526+
if (!onlyAPartialLine)
527527
if (auto *P = getParent())
528528
Depth = P->printContext(OS, indent);
529529

@@ -645,7 +645,8 @@ unsigned DeclContext::printContext(raw_ostream &OS, const unsigned indent,
645645
}
646646
}
647647

648-
OS << "\n";
648+
if (!onlyAPartialLine)
649+
OS << "\n";
649650
return Depth + 1;
650651
}
651652

0 commit comments

Comments
 (0)