Skip to content

Commit f69fe00

Browse files
authored
Merge pull request #76334 from DougGregor/ast-printed-no-if-config
Disable printing of #ifs from the AST
2 parents 28ac942 + c0fea1f commit f69fe00

File tree

5 files changed

+5
-37
lines changed

5 files changed

+5
-37
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,6 @@ struct PrintOptions {
439439
/// Print all decls that have at least this level of access.
440440
AccessLevel AccessFilter = AccessLevel::Private;
441441

442-
/// Print IfConfigDecls.
443-
bool PrintIfConfig = true;
444-
445442
/// Whether we are printing for sil.
446443
bool PrintForSIL = false;
447444

@@ -661,7 +658,6 @@ struct PrintOptions {
661658
result.ExcludeAttrList.push_back(DeclAttrKind::Rethrows);
662659
result.PrintOverrideKeyword = false;
663660
result.AccessFilter = accessFilter;
664-
result.PrintIfConfig = false;
665661
result.ShouldQualifyNestedDeclarations =
666662
QualifyNestedDeclarations::TypesOnly;
667663
result.PrintDocumentationComments = false;

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
213213
result.IsForSwiftInterface = true;
214214
result.PrintLongAttrsOnSeparateLines = true;
215215
result.TypeDefinitions = true;
216-
result.PrintIfConfig = false;
217216
result.CurrentModule = ModuleToPrint;
218217
result.FullyQualifiedTypes = true;
219218
result.FullyQualifiedTypesIfAmbiguous = true;
@@ -2281,7 +2280,7 @@ bool ShouldPrintChecker::shouldPrint(const Decl *D,
22812280
}
22822281

22832282
if (isa<IfConfigDecl>(D)) {
2284-
return Options.PrintIfConfig;
2283+
return false;
22852284
}
22862285

22872286
return true;
@@ -3360,21 +3359,7 @@ void PrintAST::visitTopLevelCodeDecl(TopLevelCodeDecl *decl) {
33603359
}
33613360

33623361
void PrintAST::visitIfConfigDecl(IfConfigDecl *ICD) {
3363-
if (!Options.PrintIfConfig)
3364-
return;
3365-
3366-
for (auto &Clause : ICD->getClauses()) {
3367-
if (&Clause == &*ICD->getClauses().begin())
3368-
Printer << tok::pound_if << " /* condition */"; // FIXME: print condition
3369-
else if (Clause.Cond)
3370-
Printer << tok::pound_elseif << " /* condition */"; // FIXME: print condition
3371-
else
3372-
Printer << tok::pound_else;
3373-
printASTNodes(Clause.Elements);
3374-
Printer.printNewline();
3375-
indent();
3376-
}
3377-
Printer << tok::pound_endif;
3362+
// Never printed
33783363
}
33793364

33803365
void PrintAST::visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) {
@@ -5603,7 +5588,7 @@ bool Decl::shouldPrintInContext(const PrintOptions &PO) const {
56035588
}
56045589

56055590
if (isa<IfConfigDecl>(this)) {
5606-
return PO.PrintIfConfig;
5591+
return false;
56075592
}
56085593

56095594
// Print everything else.

lib/SIL/IR/SILPrinter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4591,7 +4591,6 @@ PrintOptions PrintOptions::printSIL(const SILPrintContext *ctx) {
45914591
result.PrintForSIL = true;
45924592
result.PrintInSILBody = true;
45934593
result.PreferTypeRepr = false;
4594-
result.PrintIfConfig = false;
45954594
result.OpaqueReturnTypePrinting =
45964595
OpaqueReturnTypePrintingMode::StableReference;
45974596
if (ctx && ctx->printFullConvention())

test/IDE/print_ast_non_typechecked.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,4 @@ func baz() {}
1313
func qux() {}
1414
#endif
1515

16-
// CHECK1: {{^}}#if /* condition */
17-
// CHECK1: {{^}} func bar() {
18-
// CHECK1: {{^}} }
19-
// CHECK1: {{^}}#elseif /* condition */
20-
// CHECK1: {{^}} func baz() {
21-
// CHECK1: {{^}} }
22-
// CHECK1: {{^}}#else
23-
// CHECK1: {{^}} func qux() {
24-
// CHECK1: {{^}} }
25-
// CHECK1: {{^}}#endif
16+
// CHECK1-NOT: #if

test/IDE/print_ast_tc_decls.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,10 +1431,7 @@ protocol ProtocolWithWhereClauseAndAssoc : QuxProtocol where Qux == Int {
14311431
#elseif false
14321432
#else
14331433
#endif
1434-
// PASS_PRINT_AST: #if
1435-
// PASS_PRINT_AST: #elseif
1436-
// PASS_PRINT_AST: #else
1437-
// PASS_PRINT_AST: #endif
1434+
// PASS_PRINT_AST-NOT: #if
14381435

14391436
public struct MyPair<A, B> { var a: A, b: B }
14401437
public typealias MyPairI<B> = MyPair<Int, B>

0 commit comments

Comments
 (0)