AST: Support @cdecl enums without an explicit C name

Accept `@cdecl` enums without an explicit C name. The C name defaults to
the Swift one. It is printed using the `SWIFT_ENUM` macro instead of
`SWIFT_ENUM_NAMED`.
This commit is contained in:
Alexis Laferrière
2025-06-10 14:35:47 -07:00
parent dcc7e38ca7
commit beb980b1f3
4 changed files with 9 additions and 6 deletions

View File

@@ -50,7 +50,8 @@ getNameForObjC(const ValueDecl *VD, CustomNamesOnly_t customNamesOnly) {
}
if (auto cdeclAttr = VD->getAttrs().getAttribute<CDeclAttr>())
return cdeclAttr->Name;
if (!customNamesOnly || !cdeclAttr->Name.empty())
return VD->getCDeclName();
if (customNamesOnly)
return StringRef();

View File

@@ -31,18 +31,18 @@ import Foundation
// CHECK-NEXT: ObjcEnumNamedHelloDolly = 4,
// CHECK-NEXT: };
@cdecl("ObjcEnumNamed") enum EnumNamed: Int {
@cdecl(ObjcEnumNamed) enum EnumNamed: Int {
case A, B, C, d, helloDolly
}
// CHECK-LABEL: typedef SWIFT_ENUM_NAMED(unsigned int, ExplicitValues, "ExplicitValues", closed) {
// CHECK-LABEL: typedef SWIFT_ENUM(unsigned int, ExplicitValues, closed) {
// CHECK-NEXT: ExplicitValuesZim = 0,
// CHECK-NEXT: ExplicitValuesZang = 219,
// CHECK-NEXT: ExplicitValuesZung = 220,
// CHECK-NEXT: };
// NEGATIVE-NOT: ExplicitValuesDomain
@cdecl("ExplicitValues") enum ExplicitValues: CUnsignedInt {
@cdecl enum ExplicitValues: CUnsignedInt {
case Zim, Zang = 219, Zung
func methodNotExportedToC() {}

View File

@@ -28,7 +28,7 @@
// CHECK: #endif
// CHECK: /// Enums
// CHECK: typedef SWIFT_ENUM_NAMED(int, CEnum, "CEnum", closed) {
// CHECK: typedef SWIFT_ENUM(int, CEnum, closed) {
// CHECK: CEnumA = 0,
// CHECK: CEnumB = 1,
// CHECK: };
@@ -84,7 +84,7 @@ func g_nullablePointers(_ x: UnsafeMutableRawPointer,
/// Enums
@cdecl("CEnum")
@cdecl
enum CEnum: CInt { case A, B }
@cdecl("CEnumRenamed_CName")

View File

@@ -49,6 +49,8 @@ enum SwiftEnum { case A, B }
@cdecl("CEnum") enum CEnum: Int { case A, B }
#endif
@cdecl enum CEnumDefaultName: CInt { case A, B }
@cdecl("CEnumNoRawType") enum CEnumNoRawType { case A, B }
// expected-error @-1 {{'@cdecl' enum must declare an integer raw type}}