Skip to content

Disable printing of #ifs from the AST #76334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,6 @@ struct PrintOptions {
/// Print all decls that have at least this level of access.
AccessLevel AccessFilter = AccessLevel::Private;

/// Print IfConfigDecls.
bool PrintIfConfig = true;

/// Whether we are printing for sil.
bool PrintForSIL = false;

Expand Down Expand Up @@ -661,7 +658,6 @@ struct PrintOptions {
result.ExcludeAttrList.push_back(DeclAttrKind::Rethrows);
result.PrintOverrideKeyword = false;
result.AccessFilter = accessFilter;
result.PrintIfConfig = false;
result.ShouldQualifyNestedDeclarations =
QualifyNestedDeclarations::TypesOnly;
result.PrintDocumentationComments = false;
Expand Down
21 changes: 3 additions & 18 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
result.IsForSwiftInterface = true;
result.PrintLongAttrsOnSeparateLines = true;
result.TypeDefinitions = true;
result.PrintIfConfig = false;
result.CurrentModule = ModuleToPrint;
result.FullyQualifiedTypes = true;
result.FullyQualifiedTypesIfAmbiguous = true;
Expand Down Expand Up @@ -2281,7 +2280,7 @@ bool ShouldPrintChecker::shouldPrint(const Decl *D,
}

if (isa<IfConfigDecl>(D)) {
return Options.PrintIfConfig;
return false;
}

return true;
Expand Down Expand Up @@ -3360,21 +3359,7 @@ void PrintAST::visitTopLevelCodeDecl(TopLevelCodeDecl *decl) {
}

void PrintAST::visitIfConfigDecl(IfConfigDecl *ICD) {
if (!Options.PrintIfConfig)
return;

for (auto &Clause : ICD->getClauses()) {
if (&Clause == &*ICD->getClauses().begin())
Printer << tok::pound_if << " /* condition */"; // FIXME: print condition
else if (Clause.Cond)
Printer << tok::pound_elseif << " /* condition */"; // FIXME: print condition
else
Printer << tok::pound_else;
printASTNodes(Clause.Elements);
Printer.printNewline();
indent();
}
Printer << tok::pound_endif;
// Never printed
}

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

if (isa<IfConfigDecl>(this)) {
return PO.PrintIfConfig;
return false;
}

// Print everything else.
Expand Down
1 change: 0 additions & 1 deletion lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4591,7 +4591,6 @@ PrintOptions PrintOptions::printSIL(const SILPrintContext *ctx) {
result.PrintForSIL = true;
result.PrintInSILBody = true;
result.PreferTypeRepr = false;
result.PrintIfConfig = false;
result.OpaqueReturnTypePrinting =
OpaqueReturnTypePrintingMode::StableReference;
if (ctx && ctx->printFullConvention())
Expand Down
11 changes: 1 addition & 10 deletions test/IDE/print_ast_non_typechecked.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,4 @@ func baz() {}
func qux() {}
#endif

// CHECK1: {{^}}#if /* condition */
// CHECK1: {{^}} func bar() {
// CHECK1: {{^}} }
// CHECK1: {{^}}#elseif /* condition */
// CHECK1: {{^}} func baz() {
// CHECK1: {{^}} }
// CHECK1: {{^}}#else
// CHECK1: {{^}} func qux() {
// CHECK1: {{^}} }
// CHECK1: {{^}}#endif
// CHECK1-NOT: #if
5 changes: 1 addition & 4 deletions test/IDE/print_ast_tc_decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1431,10 +1431,7 @@ protocol ProtocolWithWhereClauseAndAssoc : QuxProtocol where Qux == Int {
#elseif false
#else
#endif
// PASS_PRINT_AST: #if
// PASS_PRINT_AST: #elseif
// PASS_PRINT_AST: #else
// PASS_PRINT_AST: #endif
// PASS_PRINT_AST-NOT: #if

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