@@ -1331,6 +1331,11 @@ void ModuleDecl::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
13311331 FORWARD (getTopLevelDecls, (Results));
13321332}
13331333
1334+ void ModuleDecl::getTopLevelDeclsWithAuxiliaryDecls (
1335+ SmallVectorImpl<Decl *> &Results) const {
1336+ FORWARD (getTopLevelDeclsWithAuxiliaryDecls, (Results));
1337+ }
1338+
13341339void ModuleDecl::dumpDisplayDecls () const {
13351340 SmallVector<Decl *, 32 > Decls;
13361341 getDisplayDecls (Decls);
@@ -3060,7 +3065,9 @@ void SourceFile::print(raw_ostream &OS, const PrintOptions &PO) {
30603065void SourceFile::print (ASTPrinter &Printer, const PrintOptions &PO) {
30613066 std::set<DeclKind> MajorDeclKinds = {DeclKind::Class, DeclKind::Enum,
30623067 DeclKind::Extension, DeclKind::Protocol, DeclKind::Struct};
3063- for (auto decl : getTopLevelDecls ()) {
3068+ SmallVector<Decl *> topLevelDecls;
3069+ getTopLevelDeclsWithAuxiliaryDecls (topLevelDecls);
3070+ for (auto decl : topLevelDecls) {
30643071 if (!decl->shouldPrintInContext (PO))
30653072 continue ;
30663073 // For a major decl, we print an empty line before it.
@@ -4137,14 +4144,18 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
41374144
41384145void FileUnit::getTopLevelDeclsWithAuxiliaryDecls (
41394146 SmallVectorImpl<Decl*> &results) const {
4147+
4148+ std::function<void (Decl *)> addResult;
4149+ addResult = [&](Decl *decl) {
4150+ results.push_back (decl);
4151+ decl->visitAuxiliaryDecls (addResult);
4152+ };
4153+
41404154 SmallVector<Decl *, 32 > nonExpandedDecls;
41414155 nonExpandedDecls.reserve (results.capacity ());
41424156 getTopLevelDecls (nonExpandedDecls);
41434157 for (auto *decl : nonExpandedDecls) {
4144- decl->visitAuxiliaryDecls ([&](Decl *auxDecl) {
4145- results.push_back (auxDecl);
4146- });
4147- results.push_back (decl);
4158+ addResult (decl);
41484159 }
41494160}
41504161
0 commit comments