@@ -229,12 +229,8 @@ class ScopeCreator final {
229
229
ArrayRef<ASTNode> nodesOrDeclsToAdd) {
230
230
auto *ip = insertionPoint;
231
231
for (auto nd : sortBySourceRange (cull (nodesOrDeclsToAdd))) {
232
- const unsigned preCount = ip->getChildren ().size ();
233
232
auto *const newIP =
234
233
addToScopeTreeAndReturnInsertionPoint (nd, ip).getPtrOr (ip);
235
- if (ip != organicInsertionPoint)
236
- ip->increaseASTAncestorScopeCount (ip->getChildren ().size () -
237
- preCount);
238
234
ip = newIP;
239
235
}
240
236
return ip;
@@ -923,20 +919,6 @@ void ASTScopeImpl::addChild(ASTScopeImpl *child, ASTContext &ctx) {
923
919
clearCachedSourceRangesOfMeAndAncestors ();
924
920
}
925
921
926
- void ASTScopeImpl::removeChildren () {
927
- clearCachedSourceRangesOfMeAndAncestors ();
928
- storedChildren.clear ();
929
- }
930
-
931
- void ASTScopeImpl::disownDescendants (ScopeCreator &scopeCreator) {
932
- for (auto *c : getChildren ()) {
933
- c->disownDescendants (scopeCreator);
934
- c->emancipate ();
935
- scopeCreator.scopedNodes .erase (c);
936
- }
937
- removeChildren ();
938
- }
939
-
940
922
#pragma mark implementations of expansion
941
923
942
924
ASTScopeImpl *
@@ -955,26 +937,7 @@ ExpandASTScopeRequest::evaluate(Evaluator &evaluator, ASTScopeImpl *parent,
955
937
return insertionPoint;
956
938
}
957
939
958
- bool ASTScopeImpl::doesExpansionOnlyAddNewDeclsAtEnd () const { return false ; }
959
- bool ASTSourceFileScope::doesExpansionOnlyAddNewDeclsAtEnd () const {
960
- return true ;
961
- }
962
-
963
940
ASTScopeImpl *ASTScopeImpl::expandAndBeCurrent (ScopeCreator &scopeCreator) {
964
-
965
- // We might be reexpanding, so save any scopes that were inserted here from
966
- // above it in the AST
967
- auto astAncestorScopes = rescueASTAncestorScopesForReuseFromMeOrDescendants ();
968
- ASTScopeAssert (astAncestorScopes.empty () ||
969
- !doesExpansionOnlyAddNewDeclsAtEnd (),
970
- " ASTSourceFileScope has no ancestors to be rescued." );
971
-
972
- // If reexpanding, we need to remove descendant decls from the duplication set
973
- // in order to re-add them as sub-scopes. Since expansion only adds new Decls
974
- // at end, don't bother with descendants
975
- if (!doesExpansionOnlyAddNewDeclsAtEnd ())
976
- disownDescendants (scopeCreator);
977
-
978
941
auto *insertionPoint = expandSpecifically (scopeCreator);
979
942
ASTScopeAssert (!insertionPointForDeferredExpansion () ||
980
943
insertionPointForDeferredExpansion ().get () ==
@@ -983,9 +946,8 @@ ASTScopeImpl *ASTScopeImpl::expandAndBeCurrent(ScopeCreator &scopeCreator) {
983
946
" accurate before expansion, the insertion point before "
984
947
" expansion must be the same as after expansion." );
985
948
986
- replaceASTAncestorScopes (astAncestorScopes);
987
949
setWasExpanded ();
988
- beCurrent ();
950
+
989
951
ASTScopeAssert (checkSourceRangeAfterExpansion (scopeCreator.getASTContext ()),
990
952
" Bad range." );
991
953
return insertionPoint;
@@ -1675,79 +1637,6 @@ IterableTypeBodyPortion::insertionPointForDeferredExpansion(
1675
1637
return s->getParent ().get ();
1676
1638
}
1677
1639
1678
- bool ASTScopeImpl::isExpansionNeeded (const ScopeCreator &scopeCreator) const {
1679
- return !isCurrent () ||
1680
- scopeCreator.getASTContext ().LangOpts .StressASTScopeLookup ;
1681
- }
1682
-
1683
- bool ASTScopeImpl::isCurrent () const {
1684
- return getWasExpanded () && isCurrentIfWasExpanded ();
1685
- }
1686
-
1687
- void ASTScopeImpl::beCurrent () {}
1688
- bool ASTScopeImpl::isCurrentIfWasExpanded () const { return true ; }
1689
-
1690
- #pragma mark getParentOfASTAncestorScopesToBeRescued
1691
- NullablePtr<ASTScopeImpl>
1692
- ASTScopeImpl::getParentOfASTAncestorScopesToBeRescued () {
1693
- return this ;
1694
- }
1695
- NullablePtr<ASTScopeImpl>
1696
- AbstractFunctionBodyScope::getParentOfASTAncestorScopesToBeRescued () {
1697
- // Reexpansion always creates a new body as the first child
1698
- // That body contains the scopes to be rescued.
1699
- return getChildren ().empty () ? nullptr : getChildren ().front ();
1700
- }
1701
- NullablePtr<ASTScopeImpl>
1702
- TopLevelCodeScope::getParentOfASTAncestorScopesToBeRescued () {
1703
- // Reexpansion always creates a new body as the first child
1704
- // That body contains the scopes to be rescued.
1705
- return getChildren ().empty () ? nullptr : getChildren ().front ();
1706
- }
1707
-
1708
- #pragma mark rescuing & reusing
1709
- std::vector<ASTScopeImpl *>
1710
- ASTScopeImpl::rescueASTAncestorScopesForReuseFromMeOrDescendants () {
1711
- if (auto *p = getParentOfASTAncestorScopesToBeRescued ().getPtrOrNull ()) {
1712
- return p->rescueASTAncestorScopesForReuseFromMe ();
1713
- }
1714
- ASTScopeAssert (
1715
- getASTAncestorScopeCount () == 0 ,
1716
- " If receives ASTAncestor scopes, must know where to find parent" );
1717
- return {};
1718
- }
1719
-
1720
- void ASTScopeImpl::replaceASTAncestorScopes (
1721
- ArrayRef<ASTScopeImpl *> scopesToAdd) {
1722
- auto *p = getParentOfASTAncestorScopesToBeRescued ().getPtrOrNull ();
1723
- if (!p) {
1724
- ASTScopeAssert (scopesToAdd.empty (), " Non-empty body disappeared?!" );
1725
- return ;
1726
- }
1727
- auto &ctx = getASTContext ();
1728
- for (auto *s : scopesToAdd) {
1729
- p->addChild (s, ctx);
1730
- ASTScopeAssert (s->verifyThatThisNodeComeAfterItsPriorSibling (),
1731
- " Ensure search will work" );
1732
- }
1733
- p->increaseASTAncestorScopeCount (scopesToAdd.size ());
1734
- }
1735
-
1736
- std::vector<ASTScopeImpl *>
1737
- ASTScopeImpl::rescueASTAncestorScopesForReuseFromMe () {
1738
- std::vector<ASTScopeImpl *> astAncestorScopes;
1739
- for (unsigned i = getChildren ().size () - getASTAncestorScopeCount ();
1740
- i < getChildren ().size (); ++i)
1741
- astAncestorScopes.push_back (getChildren ()[i]);
1742
- // So they don't get disowned and children cleared.
1743
- for (unsigned i = 0 ; i < getASTAncestorScopeCount (); ++i) {
1744
- storedChildren.back ()->emancipate ();
1745
- storedChildren.pop_back ();
1746
- }
1747
- resetASTAncestorScopeCount ();
1748
- return astAncestorScopes;
1749
- }
1750
-
1751
1640
#pragma mark verification
1752
1641
1753
1642
namespace {
@@ -1830,8 +1719,7 @@ void ast_scope::simple_display(llvm::raw_ostream &out,
1830
1719
1831
1720
bool ExpandASTScopeRequest::isCached () const {
1832
1721
ASTScopeImpl *scope = std::get<0 >(getStorage ());
1833
- ScopeCreator *scopeCreator = std::get<1 >(getStorage ());
1834
- return !scope->isExpansionNeeded (*scopeCreator);
1722
+ return scope->getWasExpanded ();
1835
1723
}
1836
1724
1837
1725
Optional<ASTScopeImpl *> ExpandASTScopeRequest::getCachedResult () const {
0 commit comments