Skip to content

Commit 5561698

Browse files
authored
Merge pull request swiftlang#23203 from gottesmm/pr-0e0ce29c3de5830682e4acbcfae7f36e572a08a5
2 parents bef1746 + 6af14bd commit 5561698

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

include/swift/Basic/TreeScopedHashTable.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,16 @@ class TreeScopedHashTable {
356356
return iterator(I->second);
357357
}
358358

359+
using DebugVisitValueTy = TreeScopedHashTableVal<K, V> *;
360+
361+
/// Visit each entry in the map without regard to order. Meant to be used with
362+
/// in the debugger in coordination with other dumpers that can dump whatever
363+
/// is stored in the map. No-op when asserts are disabled.
364+
LLVM_ATTRIBUTE_DEPRECATED(
365+
void debugVisit(std::function<void(const DebugVisitValueTy &)> &&func)
366+
const LLVM_ATTRIBUTE_USED,
367+
"Only for use in the debugger");
368+
359369
/// This inserts the specified key/value at the specified
360370
/// (possibly not the current) scope. While it is ok to insert into a scope
361371
/// that isn't the current one, it isn't ok to insert *underneath* an existing
@@ -382,6 +392,16 @@ class TreeScopedHashTable {
382392
}
383393
};
384394

395+
template <typename K, typename V, typename Allocator>
396+
void TreeScopedHashTable<K, V, Allocator>::debugVisit(
397+
std::function<void(const DebugVisitValueTy &)> &&func) const {
398+
#ifndef NDEBUG
399+
for (auto entry : TopLevelMap) {
400+
func(entry.second);
401+
}
402+
#endif
403+
}
404+
385405
template <typename K, typename V, typename Allocator>
386406
TreeScopedHashTableScopeImpl<K, V, Allocator>::~TreeScopedHashTableScopeImpl() {
387407
if (MovedFrom)

include/swift/Parse/Scope.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class ScopeInfo {
5757
bool isInactiveConfigBlock() const;
5858

5959
SavedScope saveCurrentScope();
60+
61+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
62+
"Only for use in the debugger");
6063
};
6164

6265
enum class ScopeKind {

lib/Parse/Scope.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,26 @@ void ScopeInfo::addToScope(ValueDecl *D, Parser &TheParser) {
139139
D->getFullName(),
140140
std::make_pair(CurScope->getDepth(), D));
141141
}
142+
143+
void ScopeInfo::dump() const {
144+
#ifndef NDEBUG
145+
// Dump out the current list of scopes.
146+
if (!CurScope->isResolvable())
147+
return;
148+
149+
assert(CurScope->getDepth() >= ResolvableDepth &&
150+
"Attempting to dump a non-resolvable scope?!");
151+
152+
llvm::dbgs() << "--- Dumping ScopeInfo ---\n";
153+
std::function<void(decltype(HT)::DebugVisitValueTy)> func =
154+
[&](const decltype(HT)::DebugVisitValueTy &iter) -> void {
155+
llvm::dbgs() << "DeclName: " << iter->getKey() << "\n"
156+
<< "KeyScopeID: " << iter->getValue().first << "\n"
157+
<< "Decl: ";
158+
iter->getValue().second->dumpRef(llvm::dbgs());
159+
llvm::dbgs() << "\n";
160+
};
161+
HT.debugVisit(std::move(func));
162+
llvm::dbgs() << "\n";
163+
#endif
164+
}

0 commit comments

Comments
 (0)