@@ -229,12 +229,8 @@ class ScopeCreator final {
229229 ArrayRef<ASTNode> nodesOrDeclsToAdd) {
230230 auto *ip = insertionPoint;
231231 for (auto nd : sortBySourceRange (cull (nodesOrDeclsToAdd))) {
232- const unsigned preCount = ip->getChildren ().size ();
233232 auto *const newIP =
234233 addToScopeTreeAndReturnInsertionPoint (nd, ip).getPtrOr (ip);
235- if (ip != organicInsertionPoint)
236- ip->increaseASTAncestorScopeCount (ip->getChildren ().size () -
237- preCount);
238234 ip = newIP;
239235 }
240236 return ip;
@@ -923,20 +919,6 @@ void ASTScopeImpl::addChild(ASTScopeImpl *child, ASTContext &ctx) {
923919 clearCachedSourceRangesOfMeAndAncestors ();
924920}
925921
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-
940922#pragma mark implementations of expansion
941923
942924ASTScopeImpl *
@@ -955,26 +937,7 @@ ExpandASTScopeRequest::evaluate(Evaluator &evaluator, ASTScopeImpl *parent,
955937 return insertionPoint;
956938}
957939
958- bool ASTScopeImpl::doesExpansionOnlyAddNewDeclsAtEnd () const { return false ; }
959- bool ASTSourceFileScope::doesExpansionOnlyAddNewDeclsAtEnd () const {
960- return true ;
961- }
962-
963940ASTScopeImpl *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-
978941 auto *insertionPoint = expandSpecifically (scopeCreator);
979942 ASTScopeAssert (!insertionPointForDeferredExpansion () ||
980943 insertionPointForDeferredExpansion ().get () ==
@@ -983,9 +946,8 @@ ASTScopeImpl *ASTScopeImpl::expandAndBeCurrent(ScopeCreator &scopeCreator) {
983946 " accurate before expansion, the insertion point before "
984947 " expansion must be the same as after expansion." );
985948
986- replaceASTAncestorScopes (astAncestorScopes);
987949 setWasExpanded ();
988- beCurrent ();
950+
989951 ASTScopeAssert (checkSourceRangeAfterExpansion (scopeCreator.getASTContext ()),
990952 " Bad range." );
991953 return insertionPoint;
@@ -1675,79 +1637,6 @@ IterableTypeBodyPortion::insertionPointForDeferredExpansion(
16751637 return s->getParent ().get ();
16761638}
16771639
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-
17511640#pragma mark verification
17521641
17531642namespace {
@@ -1830,8 +1719,7 @@ void ast_scope::simple_display(llvm::raw_ostream &out,
18301719
18311720bool ExpandASTScopeRequest::isCached () const {
18321721 ASTScopeImpl *scope = std::get<0 >(getStorage ());
1833- ScopeCreator *scopeCreator = std::get<1 >(getStorage ());
1834- return !scope->isExpansionNeeded (*scopeCreator);
1722+ return scope->getWasExpanded ();
18351723}
18361724
18371725Optional<ASTScopeImpl *> ExpandASTScopeRequest::getCachedResult () const {
0 commit comments