@@ -167,11 +167,13 @@ static bool printModuleInterfaceDecl(Decl *D,
167
167
};
168
168
}
169
169
}
170
- if (!LeadingComment.empty () && Options.shouldPrint (D))
171
- Printer << LeadingComment << " \n " ;
170
+ if (!LeadingComment.empty () && Options.shouldPrint (D)) {
171
+ Printer << LeadingComment;
172
+ Printer.printNewline ();
173
+ }
172
174
if (D->print (Printer, Options)) {
173
175
if (Options.BracketOptions .shouldCloseNominal (D))
174
- Printer << " \n " ;
176
+ Printer. printNewline () ;
175
177
Options.BracketOptions = BracketOptions ();
176
178
if (auto NTD = dyn_cast<NominalTypeDecl>(D)) {
177
179
std::queue<NominalTypeDecl *> SubDecls{{NTD}};
@@ -194,11 +196,13 @@ static bool printModuleInterfaceDecl(Decl *D,
194
196
}
195
197
if (extensionHasClangNode (Ext))
196
198
continue ; // will be printed in its source location, see above.
197
- Printer << " \n " ;
198
- if (!LeadingComment.empty ())
199
- Printer << LeadingComment << " \n " ;
199
+ Printer.printNewline ();
200
+ if (!LeadingComment.empty ()) {
201
+ Printer << LeadingComment;
202
+ Printer.printNewline ();
203
+ }
200
204
Ext->print (Printer, Options);
201
- Printer << " \n " ;
205
+ Printer. printNewline () ;
202
206
}
203
207
for (auto Sub : Ext->getMembers ())
204
208
if (auto N = dyn_cast<NominalTypeDecl>(Sub))
@@ -226,7 +230,7 @@ static bool printModuleInterfaceDecl(Decl *D,
226
230
if (ET.IsSynthesized )
227
231
Options.clearSynthesizedExtension ();
228
232
if (Options.BracketOptions .shouldCloseExtension (ET.Ext ))
229
- Printer << " \n " ;
233
+ Printer. printNewline () ;
230
234
}
231
235
});
232
236
}
@@ -250,9 +254,11 @@ static bool printModuleInterfaceDecl(Decl *D,
250
254
ET.Ext , !Opened, Decls.back ().Ext == ET.Ext , true
251
255
};
252
256
if (Options.BracketOptions .shouldOpenExtension (ET.Ext )) {
253
- Printer << " \n " ;
254
- if (Options.shouldPrint (ET.Ext ) && !LeadingComment.empty ())
255
- Printer << LeadingComment << " \n " ;
257
+ Printer.printNewline ();
258
+ if (Options.shouldPrint (ET.Ext ) && !LeadingComment.empty ()) {
259
+ Printer << LeadingComment;
260
+ Printer.printNewline ();
261
+ }
256
262
}
257
263
if (ET.IsSynthesized ) {
258
264
if (ET.EnablingExt )
@@ -265,7 +271,7 @@ static bool printModuleInterfaceDecl(Decl *D,
265
271
if (ET.IsSynthesized )
266
272
Options.clearSynthesizedExtension ();
267
273
if (Options.BracketOptions .shouldCloseExtension (ET.Ext )) {
268
- Printer << " \n " ;
274
+ Printer. printNewline () ;
269
275
}
270
276
}
271
277
});
@@ -411,18 +417,22 @@ static void printCrossImportOverlays(ModuleDecl *Declaring, ASTContext &Ctx,
411
417
BystanderList += Bystanders[I].str ();
412
418
}
413
419
414
- Printer << " \n // MARK: - " << BystanderList << " Additions\n\n " ;
420
+ Printer.printNewline ();
421
+ Printer << " // MARK: - " << BystanderList << " Additions" ;
422
+ Printer.printNewline ();
423
+ Printer.printNewline ();
415
424
for (auto *Import : DeclLists.first )
416
425
PrintDecl (Import);
417
- Printer << " \n " ;
426
+ if (!DeclLists.first .empty ())
427
+ Printer.printNewline ();
418
428
419
429
std::string PerDeclComment = " // Available when " + BystanderList;
420
430
PerDeclComment += Bystanders.size () == 1 ? " is" : " are" ;
421
431
PerDeclComment += " imported with " + Declaring->getNameStr ().str ();
422
432
423
433
for (auto *D : DeclLists.second ) {
424
- if (PrintDecl (D, PerDeclComment))
425
- Printer << " \n " ;
434
+ if (PrintDecl (D, PerDeclComment) && Options. EmptyLineBetweenDecls )
435
+ Printer. printNewline () ;
426
436
}
427
437
}
428
438
}
@@ -668,7 +678,7 @@ void swift::ide::printModuleInterface(
668
678
if (!TargetMod->isStdlibModule ()) {
669
679
for (auto *D : ImportDecls)
670
680
PrintDecl (D);
671
- Printer << " \n " ;
681
+ Printer. printNewline () ;
672
682
}
673
683
674
684
{
@@ -686,14 +696,15 @@ void swift::ide::printModuleInterface(
686
696
687
697
for (auto CM : ClangModules) {
688
698
for (auto DeclAndLoc : ClangDecls[CM.first ])
689
- PrintDecl (DeclAndLoc.first );
699
+ if (PrintDecl (DeclAndLoc.first ) && Options.EmptyLineBetweenDecls )
700
+ Printer.printNewline ();
690
701
}
691
702
}
692
703
693
704
if (!(TraversalOptions & ModuleTraversal::SkipOverlay) || !TargetClangMod) {
694
705
for (auto *D : SwiftDecls) {
695
- if (PrintDecl (D))
696
- Printer << " \n " ;
706
+ if (PrintDecl (D) && Options. EmptyLineBetweenDecls )
707
+ Printer. printNewline () ;
697
708
}
698
709
699
710
// If we're printing the entire target module (not specific sub-groups),
@@ -704,6 +715,8 @@ void swift::ide::printModuleInterface(
704
715
AdjustedOptions, PrintSynthesizedExtensions);
705
716
}
706
717
}
718
+ // Flush pending newlines.
719
+ Printer.forceNewlines ();
707
720
}
708
721
709
722
static SourceLoc getDeclStartPosition (SourceFile &File) {
@@ -813,8 +826,9 @@ void swift::ide::printHeaderInterface(
813
826
continue ;
814
827
}
815
828
if (D->print (Printer, AdjustedOptions))
816
- Printer << " \n " ;
829
+ Printer. printNewline () ;
817
830
}
831
+ Printer.forceNewlines ();
818
832
}
819
833
820
834
void swift::ide::printSymbolicSwiftClangModuleInterface (
0 commit comments