PrintAsClang: Print @cdecl enums in the compatibility header

Print @cdecl enums in the C section of the compatibility header. Use and
extend the macros to support C compiler clients.

The macro is adapted to the features supported by the client compiler.
It uses an Objective-C style macro with raw type when available and
fallbacks to a simple typedef for C compatibility.
This commit is contained in:
Alexis Laferrière
2025-06-02 13:19:03 -07:00
parent 6d091123f9
commit 138e2daa3e
5 changed files with 217 additions and 11 deletions

View File

@@ -530,6 +530,10 @@ public:
}
void forwardDeclare(const EnumDecl *ED) {
// Don't forward declare C enums.
if (ED->getAttrs().getAttribute<CDeclAttr>())
return;
assert(ED->isObjC() || ED->hasClangNode());
forwardDeclare(ED, [&]{
@@ -864,7 +868,7 @@ public:
SmallVector<ProtocolConformance *, 1> conformances;
auto errorTypeProto = ctx.getProtocol(KnownProtocolKind::Error);
if (outputLangMode != OutputLanguageMode::Cxx
if (outputLangMode == OutputLanguageMode::ObjC
&& ED->lookupConformance(errorTypeProto, conformances)) {
bool hasDomainCase = std::any_of(ED->getAllElements().begin(),
ED->getAllElements().end(),