File tree Expand file tree Collapse file tree 4 files changed +13
-4
lines changed Expand file tree Collapse file tree 4 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -4874,6 +4874,16 @@ class EnumDecl final : public NominalTypeDecl {
4874
4874
return getAttrs ().hasAttribute <IndirectAttr>();
4875
4875
}
4876
4876
4877
+ // / True if the enum is marked with `@cdecl`.
4878
+ bool isCDeclEnum () const {
4879
+ return getAttrs ().hasAttribute <CDeclAttr>();
4880
+ }
4881
+
4882
+ // / True if the enum is marked with `@cdecl` or `@objc`.
4883
+ bool isCCompatibleEnum () const {
4884
+ return isCDeclEnum () || isObjC ();
4885
+ }
4886
+
4877
4887
// / True if the enum can be exhaustively switched within \p useDC.
4878
4888
// /
4879
4889
// / Note that this property is \e not necessarily true for all children of
Original file line number Diff line number Diff line change @@ -654,7 +654,7 @@ clang::QualType ClangTypeConverter::visitEnumType(EnumType *type) {
654
654
return convert (Context.TheEmptyTupleType );
655
655
656
656
auto ED = type->getDecl ();
657
- if (!ED->isObjC () && !ED-> getAttrs (). hasAttribute <CDeclAttr> ())
657
+ if (!ED->isCCompatibleEnum ())
658
658
// Can't translate something not marked with @objc or @cdecl.
659
659
return clang::QualType ();
660
660
Original file line number Diff line number Diff line change @@ -2408,7 +2408,7 @@ class DeclAndTypePrinter::Implementation
2408
2408
void maybePrintTagKeyword (const TypeDecl *NTD) {
2409
2409
auto *ED = dyn_cast<EnumDecl>(NTD);
2410
2410
if (ED && !NTD->hasClangNode ()) {
2411
- if (ED->getAttrs (). hasAttribute <CDeclAttr> ()) {
2411
+ if (ED->isCDeclEnum ()) {
2412
2412
// We should be able to use the tag macro for all printed enums but
2413
2413
// for now restrict it to @cdecl to guard it behind the feature flag.
2414
2414
os << " SWIFT_ENUM_TAG " ;
Original file line number Diff line number Diff line change @@ -538,8 +538,7 @@ class ModuleWriter {
538
538
}
539
539
540
540
void forwardDeclare (const EnumDecl *ED) {
541
- assert (ED->isObjC () || ED->getAttrs ().getAttribute <CDeclAttr>() ||
542
- ED->hasClangNode ());
541
+ assert (ED->isCCompatibleEnum () || ED->hasClangNode ());
543
542
544
543
forwardDeclare (ED, [&]{
545
544
if (ED->getASTContext ().LangOpts .hasFeature (Feature::CDecl)) {
You can’t perform that action at this time.
0 commit comments