Skip to content

Commit 9b9a405

Browse files
committed
[NFC] SwiftCompilerSource: bridge Function.accessorKindName
(cherry picked from commit 25e9cbf)
1 parent 8bce9b2 commit 9b9a405

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
219219
}
220220
}
221221

222+
public var accessorKindName: String? {
223+
guard bridged.isAccessor() else {
224+
return nil
225+
}
226+
return StringRef(bridged: bridged.getAccessorName()).string
227+
}
228+
222229
/// True, if the function runs with a swift 5.1 runtime.
223230
/// Note that this is function specific, because inlinable functions are de-serialized
224231
/// in a client module, which might be compiled with a different deployment target.

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ struct BridgedDeclObj {
393393
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj Class_getDestructor() const;
394394
BRIDGED_INLINE bool AbstractFunction_isOverridden() const;
395395
BRIDGED_INLINE bool Destructor_isIsolated() const;
396+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef AccessorDecl_getKindName() const;
396397
};
397398

398399
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedASTNodeKind : uint8_t {

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ struct BridgedFunction {
462462
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
463463
BridgedOwnedString getDebugDescription() const;
464464
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getLocation() const;
465+
BRIDGED_INLINE bool isAccessor() const;
466+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getAccessorName() const;
465467
BRIDGED_INLINE bool hasOwnership() const;
466468
BRIDGED_INLINE bool hasLoweredAddresses() const;
467469
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType getLoweredFunctionTypeInContext() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/Builtins.h"
2424
#include "swift/AST/Decl.h"
2525
#include "swift/AST/SourceFile.h"
26+
#include "swift/AST/StorageImpl.h"
2627
#include "swift/AST/SubstitutionMap.h"
2728
#include "swift/AST/Types.h"
2829
#include "swift/Basic/BasicBridging.h"
@@ -649,6 +650,18 @@ BridgedLocation BridgedFunction::getLocation() const {
649650
return {swift::SILDebugLocation(getFunction()->getLocation(), getFunction()->getDebugScope())};
650651
}
651652

653+
bool BridgedFunction::isAccessor() const {
654+
if (auto *valDecl = getFunction()->getDeclRef().getDecl()) {
655+
return llvm::isa<swift::AccessorDecl>(valDecl);
656+
}
657+
return false;
658+
}
659+
660+
BridgedStringRef BridgedFunction::getAccessorName() const {
661+
auto *accessorDecl = llvm::cast<swift::AccessorDecl>(getFunction()->getDeclRef().getDecl());
662+
return accessorKindName(accessorDecl->getAccessorKind());
663+
}
664+
652665
bool BridgedFunction::hasOwnership() const { return getFunction()->hasOwnership(); }
653666

654667
bool BridgedFunction::hasLoweredAddresses() const { return getFunction()->getModule().useLoweredAddresses(); }

0 commit comments

Comments
 (0)