Skip to content

Commit b8df997

Browse files
committed
[gardening] Re-organize Cleanup.cpp so that methods on the same class are together and not interleaved.
This code was organized such that one had first definitions for CleanupManager, then CleanupStateRestorationScope, and then again CleanupManager. This is just confusing/hard to read. This commit fixes that by creating contiguous sections of definitions with comment flags to document said sections.
1 parent 23476e5 commit b8df997

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

lib/SILGen/Cleanup.cpp

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@
1919
using namespace swift;
2020
using namespace Lowering;
2121

22+
//===----------------------------------------------------------------------===//
23+
// CleanupState
24+
//===----------------------------------------------------------------------===//
25+
26+
llvm::raw_ostream &Lowering::operator<<(llvm::raw_ostream &os,
27+
CleanupState state) {
28+
switch (state) {
29+
case CleanupState::Dormant:
30+
return os << "Dormant";
31+
case CleanupState::Dead:
32+
return os << "Dead";
33+
case CleanupState::Active:
34+
return os << "Active";
35+
case CleanupState::PersistentlyActive:
36+
return os << "PersistentlyActive";
37+
}
38+
39+
llvm_unreachable("Unhandled CleanupState in switch.");
40+
}
41+
42+
//===----------------------------------------------------------------------===//
43+
// CleanupManager
44+
//===----------------------------------------------------------------------===//
45+
2246
/// Are there any active cleanups in the given range?
2347
static bool hasAnyActiveCleanups(DiverseStackImpl<Cleanup>::iterator begin,
2448
DiverseStackImpl<Cleanup>::iterator end) {
@@ -218,6 +242,38 @@ void CleanupManager::setCleanupState(Cleanup &cleanup, CleanupState state) {
218242
// code to be emitted at transition points.
219243
}
220244

245+
void CleanupManager::dump() const {
246+
#ifndef NDEBUG
247+
auto begin = stack.stable_begin();
248+
auto end = stack.stable_end();
249+
while (begin != end) {
250+
auto iter = stack.find(begin);
251+
const Cleanup &stackCleanup = *iter;
252+
llvm::errs() << "CLEANUP DEPTH: " << begin.getDepth() << "\n";
253+
stackCleanup.dump(SGF);
254+
begin = stack.stabilize(++iter);
255+
stack.checkIterator(begin);
256+
}
257+
#endif
258+
}
259+
260+
void CleanupManager::dump(CleanupHandle handle) const {
261+
auto iter = stack.find(handle);
262+
const Cleanup &stackCleanup = *iter;
263+
llvm::errs() << "CLEANUP DEPTH: " << handle.getDepth() << "\n";
264+
stackCleanup.dump(SGF);
265+
}
266+
267+
void CleanupManager::checkIterator(CleanupHandle handle) const {
268+
#ifndef NDEBUG
269+
stack.checkIterator(handle);
270+
#endif
271+
}
272+
273+
//===----------------------------------------------------------------------===//
274+
// CleanupStateRestorationScope
275+
//===----------------------------------------------------------------------===//
276+
221277
void CleanupStateRestorationScope::pushCleanupState(CleanupHandle handle,
222278
CleanupState newState) {
223279
// Don't put the cleanup in a state we can't restore it from.
@@ -267,50 +323,6 @@ void CleanupStateRestorationScope::popImpl() {
267323

268324
void CleanupStateRestorationScope::pop() && { popImpl(); }
269325

270-
llvm::raw_ostream &Lowering::operator<<(llvm::raw_ostream &os,
271-
CleanupState state) {
272-
switch (state) {
273-
case CleanupState::Dormant:
274-
return os << "Dormant";
275-
case CleanupState::Dead:
276-
return os << "Dead";
277-
case CleanupState::Active:
278-
return os << "Active";
279-
case CleanupState::PersistentlyActive:
280-
return os << "PersistentlyActive";
281-
}
282-
283-
llvm_unreachable("Unhandled CleanupState in switch.");
284-
}
285-
286-
void CleanupManager::dump() const {
287-
#ifndef NDEBUG
288-
auto begin = stack.stable_begin();
289-
auto end = stack.stable_end();
290-
while (begin != end) {
291-
auto iter = stack.find(begin);
292-
const Cleanup &stackCleanup = *iter;
293-
llvm::errs() << "CLEANUP DEPTH: " << begin.getDepth() << "\n";
294-
stackCleanup.dump(SGF);
295-
begin = stack.stabilize(++iter);
296-
stack.checkIterator(begin);
297-
}
298-
#endif
299-
}
300-
301-
void CleanupManager::dump(CleanupHandle handle) const {
302-
auto iter = stack.find(handle);
303-
const Cleanup &stackCleanup = *iter;
304-
llvm::errs() << "CLEANUP DEPTH: " << handle.getDepth() << "\n";
305-
stackCleanup.dump(SGF);
306-
}
307-
308-
void CleanupManager::checkIterator(CleanupHandle handle) const {
309-
#ifndef NDEBUG
310-
stack.checkIterator(handle);
311-
#endif
312-
}
313-
314326
//===----------------------------------------------------------------------===//
315327
// Cleanup Cloner
316328
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)