mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
ModulePrinting: Encapsulate bracket options into a sub-structure of PrintOptions. NFC
This commit is contained in:
@@ -275,11 +275,11 @@ struct PrintOptions {
|
||||
/// \brief The information for converting archetypes to specialized types.
|
||||
std::shared_ptr<ArchetypeTransformContext> TransformContext;
|
||||
|
||||
struct BracketOptions {
|
||||
bool shouldOpenExtension = true;
|
||||
|
||||
bool shouldCloseExtension = true;
|
||||
|
||||
bool shouldCloseNominal = true;
|
||||
} BracketOptions;
|
||||
|
||||
/// Retrieve the set of options for verbose printing to users.
|
||||
static PrintOptions printVerbose() {
|
||||
|
||||
@@ -1991,7 +1991,7 @@ static void printExtendedTypeName(Type ExtendedType, ASTPrinter &Printer,
|
||||
|
||||
void PrintAST::
|
||||
printSynthesizedExtension(NominalTypeDecl* Decl, ExtensionDecl *ExtDecl) {
|
||||
if (Options.shouldOpenExtension) {
|
||||
if (Options.BracketOptions.shouldOpenExtension) {
|
||||
printDocumentationComment(ExtDecl);
|
||||
printAttributes(ExtDecl);
|
||||
Printer << tok::kw_extension << " ";
|
||||
@@ -2011,13 +2011,13 @@ printSynthesizedExtension(NominalTypeDecl* Decl, ExtensionDecl *ExtDecl) {
|
||||
}
|
||||
if (Options.TypeDefinitions) {
|
||||
printMembersOfDecl(ExtDecl, false,
|
||||
Options.shouldOpenExtension,
|
||||
Options.shouldCloseExtension);
|
||||
Options.BracketOptions.shouldOpenExtension,
|
||||
Options.BracketOptions.shouldCloseExtension);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintAST::printExtension(ExtensionDecl* decl) {
|
||||
if (Options.shouldOpenExtension) {
|
||||
if (Options.BracketOptions.shouldOpenExtension) {
|
||||
printDocumentationComment(decl);
|
||||
printAttributes(decl);
|
||||
Printer << "extension ";
|
||||
@@ -2039,8 +2039,8 @@ void PrintAST::printExtension(ExtensionDecl* decl) {
|
||||
}
|
||||
if (Options.TypeDefinitions) {
|
||||
printMembersOfDecl(decl, false,
|
||||
Options.shouldOpenExtension,
|
||||
Options.shouldCloseExtension);
|
||||
Options.BracketOptions.shouldOpenExtension,
|
||||
Options.BracketOptions.shouldCloseExtension);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2186,7 +2186,8 @@ void PrintAST::visitEnumDecl(EnumDecl *decl) {
|
||||
printInherited(decl);
|
||||
}
|
||||
if (Options.TypeDefinitions) {
|
||||
printMembersOfDecl(decl, false, true, Options.shouldCloseNominal);
|
||||
printMembersOfDecl(decl, false, true,
|
||||
Options.BracketOptions.shouldCloseNominal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2211,7 +2212,8 @@ void PrintAST::visitStructDecl(StructDecl *decl) {
|
||||
printInherited(decl);
|
||||
}
|
||||
if (Options.TypeDefinitions) {
|
||||
printMembersOfDecl(decl, false, true, Options.shouldCloseNominal);
|
||||
printMembersOfDecl(decl, false, true,
|
||||
Options.BracketOptions.shouldCloseNominal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2238,7 +2240,8 @@ void PrintAST::visitClassDecl(ClassDecl *decl) {
|
||||
}
|
||||
|
||||
if (Options.TypeDefinitions) {
|
||||
printMembersOfDecl(decl, false, true, Options.shouldCloseNominal);
|
||||
printMembersOfDecl(decl, false, true,
|
||||
Options.BracketOptions.shouldCloseNominal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2280,7 +2283,8 @@ void PrintAST::visitProtocolDecl(ProtocolDecl *decl) {
|
||||
printInherited(decl, explicitClass);
|
||||
}
|
||||
if (Options.TypeDefinitions) {
|
||||
printMembersOfDecl(decl, false, true, Options.shouldCloseNominal);
|
||||
printMembersOfDecl(decl, false, true,
|
||||
Options.BracketOptions.shouldCloseNominal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -435,14 +435,15 @@ void swift::ide::printSubmoduleInterface(
|
||||
if (auto NTD = dyn_cast<NominalTypeDecl>(D)) {
|
||||
if (PrintSynthesizedExtensions) {
|
||||
pAnalyzer.reset(new SynthesizedExtensionAnalyzer(NTD, AdjustedOptions));
|
||||
AdjustedOptions.shouldCloseNominal = !pAnalyzer->hasMergeGroup(
|
||||
SynthesizedExtensionAnalyzer::MergeGroupKind::MergableWithTypeDef);
|
||||
AdjustedOptions.BracketOptions.shouldCloseNominal =
|
||||
!pAnalyzer->hasMergeGroup(SynthesizedExtensionAnalyzer::
|
||||
MergeGroupKind::MergableWithTypeDef);
|
||||
}
|
||||
}
|
||||
if (D->print(Printer, AdjustedOptions)) {
|
||||
if (AdjustedOptions.shouldCloseNominal)
|
||||
if (AdjustedOptions.BracketOptions.shouldCloseNominal)
|
||||
Printer << "\n";
|
||||
AdjustedOptions.shouldCloseNominal = true;
|
||||
AdjustedOptions.BracketOptions.shouldCloseNominal = true;
|
||||
if (auto NTD = dyn_cast<NominalTypeDecl>(D)) {
|
||||
std::queue<NominalTypeDecl *> SubDecls{{NTD}};
|
||||
|
||||
@@ -484,8 +485,8 @@ void swift::ide::printSubmoduleInterface(
|
||||
SynthesizedExtensionAnalyzer::MergeGroupKind::MergableWithTypeDef,
|
||||
[&](ArrayRef<ExtensionAndIsSynthesized> Decls){
|
||||
for (auto ET : Decls) {
|
||||
AdjustedOptions.shouldOpenExtension = false;
|
||||
AdjustedOptions.shouldCloseExtension =
|
||||
AdjustedOptions.BracketOptions.shouldOpenExtension = false;
|
||||
AdjustedOptions.BracketOptions.shouldCloseExtension =
|
||||
Decls.back().first == ET.first;
|
||||
if (ET.second)
|
||||
AdjustedOptions.
|
||||
@@ -495,7 +496,7 @@ void swift::ide::printSubmoduleInterface(
|
||||
if (ET.second)
|
||||
AdjustedOptions.
|
||||
clearArchetypeTransformerForSynthesizedExtensions();
|
||||
if (AdjustedOptions.shouldCloseExtension)
|
||||
if (AdjustedOptions.BracketOptions.shouldCloseExtension)
|
||||
Printer << "\n";
|
||||
}
|
||||
});
|
||||
@@ -515,11 +516,11 @@ void swift::ide::printSubmoduleInterface(
|
||||
SynthesizedExtensionAnalyzer::MergeGroupKind::All,
|
||||
[&](ArrayRef<ExtensionAndIsSynthesized> Decls){
|
||||
for (auto ET : Decls) {
|
||||
AdjustedOptions.shouldOpenExtension =
|
||||
AdjustedOptions.BracketOptions.shouldOpenExtension =
|
||||
Decls.front().first == ET.first;
|
||||
AdjustedOptions.shouldCloseExtension =
|
||||
AdjustedOptions.BracketOptions.shouldCloseExtension =
|
||||
Decls.back().first == ET.first;
|
||||
if (AdjustedOptions.shouldOpenExtension)
|
||||
if (AdjustedOptions.BracketOptions.shouldOpenExtension)
|
||||
Printer << "\n";
|
||||
if (ET.second)
|
||||
AdjustedOptions.
|
||||
@@ -529,7 +530,7 @@ void swift::ide::printSubmoduleInterface(
|
||||
if (ET.second)
|
||||
AdjustedOptions.
|
||||
clearArchetypeTransformerForSynthesizedExtensions();
|
||||
if (AdjustedOptions.shouldCloseExtension)
|
||||
if (AdjustedOptions.BracketOptions.shouldCloseExtension)
|
||||
Printer << "\n";
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user