Skip to content

Commit d11232b

Browse files
committed
[PrintAsObjC] NFC Document and make isEmptyExtensionDecl public
1 parent ea456f7 commit d11232b

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ class DeclAndTypePrinter::Implementation
155155
return owningPrinter.shouldInclude(VD);
156156
}
157157

158+
bool isEmptyExtensionDecl(const ExtensionDecl *ED) {
159+
auto members = ED->getMembers();
160+
auto hasMembers = std::any_of(members.begin(), members.end(),
161+
[this](const Decl *D) -> bool {
162+
if (auto VD = dyn_cast<ValueDecl>(D))
163+
if (shouldInclude(VD))
164+
return true;
165+
return false;
166+
});
167+
168+
auto protocols = ED->getLocalProtocols(ConformanceLookupKind::OnlyExplicit);
169+
auto hasProtocols = std::any_of(protocols.begin(), protocols.end(),
170+
[this](const ProtocolDecl *PD) -> bool {
171+
return shouldInclude(PD);
172+
});
173+
174+
return (!hasMembers && !hasProtocols);
175+
}
176+
158177
private:
159178
/// Prints a protocol adoption list: <code>&lt;NSCoding, NSCopying&gt;</code>
160179
///
@@ -311,25 +330,6 @@ class DeclAndTypePrinter::Implementation
311330
os << "@end\n";
312331
}
313332

314-
bool isEmptyExtensionDecl(ExtensionDecl *ED) {
315-
auto members = ED->getMembers();
316-
auto hasMembers = std::any_of(members.begin(), members.end(),
317-
[this](const Decl *D) -> bool {
318-
if (auto VD = dyn_cast<ValueDecl>(D))
319-
if (shouldInclude(VD))
320-
return true;
321-
return false;
322-
});
323-
324-
auto protocols = ED->getLocalProtocols(ConformanceLookupKind::OnlyExplicit);
325-
auto hasProtocols = std::any_of(protocols.begin(), protocols.end(),
326-
[this](const ProtocolDecl *PD) -> bool {
327-
return shouldInclude(PD);
328-
});
329-
330-
return (!hasMembers && !hasProtocols);
331-
}
332-
333333
void visitExtensionDecl(ExtensionDecl *ED) {
334334
if (isEmptyExtensionDecl(ED))
335335
return;
@@ -2063,6 +2063,10 @@ void DeclAndTypePrinter::printAdHocCategory(
20632063
getImpl().printAdHocCategory(members);
20642064
}
20652065

2066+
bool DeclAndTypePrinter::isEmptyExtensionDecl(const ExtensionDecl *ED) {
2067+
return getImpl().isEmptyExtensionDecl(ED);
2068+
}
2069+
20662070
StringRef
20672071
DeclAndTypePrinter::maybeGetOSObjectBaseName(const clang::NamedDecl *decl) {
20682072
StringRef name = decl->getName();

lib/PrintAsObjC/DeclAndTypePrinter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class DeclAndTypePrinter {
7070
void print(const Decl *D);
7171
void print(Type ty);
7272

73+
/// Is \p ED empty of members and protocol conformances to include?
74+
bool isEmptyExtensionDecl(const ExtensionDecl *ED);
75+
7376
/// Prints a category declaring the given members.
7477
///
7578
/// All members must have the same parent type. The list must not be empty.

0 commit comments

Comments
 (0)