Skip to content

Commit 8b91a92

Browse files
committed
Only consider the active clauses of IfConfigDecls in placeholder expansion
This is another step toward the removal of IfConfigDecl
1 parent 8ec800d commit 8b91a92

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

test/SourceKit/CodeExpand/code-expand.swift

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,11 @@ braced2(x: {<#T##() -> Void#>}, y: Int)
147147
// CHECK-NEXT: }, y: Int)
148148

149149
braced3({
150-
#if true
151150
<#T##() -> Int#>
152-
#endif
153151
})
154-
// CHECK: braced3({
155-
// CHECK-NEXT: #if true
156-
// CHECK-NEXT: {
152+
// CHECK: braced3 {
157153
// CHECK-NEXT: <#code#>
158-
// CHECK-NEXT: }
159-
// CHECK-NEXT: #endif
160-
// CHECK-NEXT: })
154+
// CHECK-NEXT: }
161155

162156
func returnTrailing() -> Int {
163157
return withtrail(<#T##() -> ()#>)
@@ -260,17 +254,6 @@ func activeWithTrailing() {
260254
// CHECK: forEach {
261255
// CHECK-NEXT: <#code#>
262256
}
263-
#if false
264-
func inactive() {
265-
foo(<#T##value: Foo##Foo#>)
266-
// CHECK: foo(Foo)
267-
}
268-
func inactiveWithTrailing() {
269-
forEach(<#T##() -> ()#>)
270-
// CHECK: forEach {
271-
// CHECK-NEXT: <#code#>
272-
}
273-
#endif
274257

275258
expandClosureWithInternalParameterNames {
276259
withtrail(<#T##callback: (Int, Int) -> Bool##(_ a: Int, _ b: Int) -> Bool#>)

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,9 +1608,11 @@ class PlaceholderExpansionScanner {
16081608
if (auto *ICD = dyn_cast<IfConfigDecl>(D)) {
16091609
// The base walker assumes the content of active IfConfigDecl clauses
16101610
// has been injected into the parent context and will be walked there.
1611-
// This doesn't hold for pre-typechecked ASTs and we need to find
1612-
// placeholders in inactive clauses anyway, so walk them here.
1611+
// This doesn't hold for pre-typechecked ASTs, so walk them here.
16131612
for (auto Clause: ICD->getClauses()) {
1613+
if (!Clause.isActive)
1614+
continue;
1615+
16141616
for (auto Elem: Clause.Elements) {
16151617
Elem.walk(*this);
16161618
}
@@ -1798,20 +1800,6 @@ class PlaceholderExpansionScanner {
17981800
return Action::Continue(S);
17991801
}
18001802

1801-
PreWalkAction walkToDeclPre(Decl *D) override {
1802-
if (auto *ICD = dyn_cast<IfConfigDecl>(D)) {
1803-
for (auto Clause : ICD->getClauses()) {
1804-
// Active clase elements are visited normally.
1805-
if (Clause.isActive)
1806-
continue;
1807-
for (auto Member : Clause.Elements)
1808-
Member.walk(*this);
1809-
}
1810-
return Action::SkipNode();
1811-
}
1812-
return Action::Continue();
1813-
}
1814-
18151803
ArgumentList *findEnclosingCallArg(SourceFile &SF, SourceLoc SL) {
18161804
EnclosingCallAndArg = {nullptr, nullptr};
18171805
OuterExpr = nullptr;

0 commit comments

Comments
 (0)