Ensure that reexpansion does not lose scopes.

This commit is contained in:
David Ungar
2019-09-22 09:01:52 -07:00
parent 9674643779
commit 10583f89c6
3 changed files with 25 additions and 1 deletions

View File

@@ -288,3 +288,21 @@ const StmtConditionElement &
ConditionalClauseScope::getStmtConditionElement() const {
return getCond()[index];
}
unsigned ASTScopeImpl::countDescendants() const {
unsigned count = 0;
const_cast<ASTScopeImpl *>(this)->preOrderDo(
[&](ASTScopeImpl *) { ++count; });
return count - 1;
}
void ASTScopeImpl::assertThatTreeDoesNotShrink(function_ref<void()> fn) {
#ifndef NDEBUG
unsigned beforeCount = countDescendants();
#endif
fn();
#ifndef NDEBUG
unsigned afterCount = countDescendants();
ASTScopeAssert(beforeCount <= afterCount, "shrank?!");
#endif
}