Skip to content

Commit 753d303

Browse files
committed
ASTScope: Remove expandIfConfigClauses()
We're always guaranteed to visit the elements of the active clause as members of the parent AST node.
1 parent 76802dd commit 753d303

File tree

1 file changed

+5
-43
lines changed

1 file changed

+5
-43
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ class ScopeCreator final {
228228
ASTScopeImpl *const organicInsertionPoint,
229229
ArrayRef<ASTNode> nodesOrDeclsToAdd) {
230230
auto *ip = insertionPoint;
231-
for (auto nd : expandIfConfigClausesThenCullAndSortElementsOrMembers(
232-
nodesOrDeclsToAdd)) {
231+
for (auto nd : sortBySourceRange(cull(nodesOrDeclsToAdd))) {
233232
if (!shouldThisNodeBeScopedWhenFoundInSourceFileBraceStmtOrType(nd)) {
234233
// FIXME: Could the range get lost if the node is ever reexpanded?
235234
ip->widenSourceRangeForIgnoredASTNode(nd);
@@ -494,48 +493,9 @@ class ScopeCreator final {
494493
fn(diffAttr);
495494
}
496495

497-
std::vector<ASTNode> expandIfConfigClausesThenCullAndSortElementsOrMembers(
498-
ArrayRef<ASTNode> input) const {
499-
auto cleanedupNodes = sortBySourceRange(cull(expandIfConfigClauses(input)));
500-
return cleanedupNodes;
501-
}
502-
503496
public:
504497

505498
private:
506-
static std::vector<ASTNode> expandIfConfigClauses(ArrayRef<ASTNode> input) {
507-
std::vector<ASTNode> expansion;
508-
expandIfConfigClausesInto(expansion, input, /*isInAnActiveNode=*/true);
509-
return expansion;
510-
}
511-
512-
static void expandIfConfigClausesInto(std::vector<ASTNode> &expansion,
513-
ArrayRef<ASTNode> input,
514-
const bool isInAnActiveNode) {
515-
for (auto n : input) {
516-
if (!n.isDecl(DeclKind::IfConfig)) {
517-
expansion.push_back(n);
518-
continue;
519-
}
520-
auto *const icd = cast<IfConfigDecl>(n.get<Decl *>());
521-
for (auto &clause : icd->getClauses()) {
522-
if (auto *const cond = clause.Cond)
523-
expansion.push_back(cond);
524-
if (clause.isActive) {
525-
// TODO: Move this check into ASTVerifier
526-
ASTScopeAssert(isInAnActiveNode, "Clause should not be marked active "
527-
"unless it's context is active");
528-
// get inactive nodes that nest in active clauses
529-
for (auto n : clause.Elements) {
530-
if (auto *const d = n.dyn_cast<Decl *>())
531-
if (isa<IfConfigDecl>(d))
532-
expandIfConfigClausesInto(expansion, {d}, true);
533-
}
534-
}
535-
}
536-
}
537-
}
538-
539499
/// Remove VarDecls because we'll find them when we expand the
540500
/// PatternBindingDecls. Remove EnunCases
541501
/// because they overlap EnumElements and AST includes the elements in the
@@ -548,8 +508,10 @@ class ScopeCreator final {
548508
ASTScopeAssert(
549509
!n.isDecl(DeclKind::Accessor),
550510
"Should not find accessors in iterable types or brace statements");
551-
return isLocalizable(n) && !n.isDecl(DeclKind::Var) &&
552-
!n.isDecl(DeclKind::EnumCase);
511+
return isLocalizable(n) &&
512+
!n.isDecl(DeclKind::Var) &&
513+
!n.isDecl(DeclKind::EnumCase) &&
514+
!n.isDecl(DeclKind::IfConfig);
553515
});
554516
return culled;
555517
}

0 commit comments

Comments
 (0)