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 {
48744874 return getAttrs ().hasAttribute <IndirectAttr>();
48754875 }
48764876
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+
48774887 // / True if the enum can be exhaustively switched within \p useDC.
48784888 // /
48794889 // / 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) {
654654 return convert (Context.TheEmptyTupleType );
655655
656656 auto ED = type->getDecl ();
657- if (!ED->isObjC () && !ED-> getAttrs (). hasAttribute <CDeclAttr> ())
657+ if (!ED->isCCompatibleEnum ())
658658 // Can't translate something not marked with @objc or @cdecl.
659659 return clang::QualType ();
660660
Original file line number Diff line number Diff line change @@ -2408,7 +2408,7 @@ class DeclAndTypePrinter::Implementation
24082408 void maybePrintTagKeyword (const TypeDecl *NTD) {
24092409 auto *ED = dyn_cast<EnumDecl>(NTD);
24102410 if (ED && !NTD->hasClangNode ()) {
2411- if (ED->getAttrs (). hasAttribute <CDeclAttr> ()) {
2411+ if (ED->isCDeclEnum ()) {
24122412 // We should be able to use the tag macro for all printed enums but
24132413 // for now restrict it to @cdecl to guard it behind the feature flag.
24142414 os << " SWIFT_ENUM_TAG " ;
Original file line number Diff line number Diff line change @@ -538,8 +538,7 @@ class ModuleWriter {
538538 }
539539
540540 void forwardDeclare (const EnumDecl *ED) {
541- assert (ED->isObjC () || ED->getAttrs ().getAttribute <CDeclAttr>() ||
542- ED->hasClangNode ());
541+ assert (ED->isCCompatibleEnum () || ED->hasClangNode ());
543542
544543 forwardDeclare (ED, [&]{
545544 if (ED->getASTContext ().LangOpts .hasFeature (Feature::CDecl)) {
You can’t perform that action at this time.
0 commit comments