Skip to content

Commit 25e9cbf

Browse files
committed
[NFC] SwiftCompilerSource: bridge Function.accessorKindName
1 parent 49755bd commit 25e9cbf

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
@@ -221,6 +221,13 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
221221
}
222222
}
223223

224+
public var accessorKindName: String? {
225+
guard bridged.isAccessor() else {
226+
return nil
227+
}
228+
return StringRef(bridged: bridged.getAccessorName()).string
229+
}
230+
224231
/// True, if the function runs with a swift 5.1 runtime.
225232
/// Note that this is function specific, because inlinable functions are de-serialized
226233
/// 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
@@ -395,6 +395,7 @@ struct BridgedDeclObj {
395395
BRIDGED_INLINE bool ProtocolDecl_requiresClass() const;
396396
BRIDGED_INLINE bool AbstractFunction_isOverridden() const;
397397
BRIDGED_INLINE bool Destructor_isIsolated() const;
398+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef AccessorDecl_getKindName() const;
398399
};
399400

400401
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
@@ -465,6 +465,8 @@ struct BridgedFunction {
465465
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
466466
BridgedOwnedString getDebugDescription() const;
467467
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getLocation() const;
468+
BRIDGED_INLINE bool isAccessor() const;
469+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getAccessorName() const;
468470
BRIDGED_INLINE bool hasOwnership() const;
469471
BRIDGED_INLINE bool hasLoweredAddresses() const;
470472
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"
@@ -662,6 +663,18 @@ BridgedLocation BridgedFunction::getLocation() const {
662663
return {swift::SILDebugLocation(getFunction()->getLocation(), getFunction()->getDebugScope())};
663664
}
664665

666+
bool BridgedFunction::isAccessor() const {
667+
if (auto *valDecl = getFunction()->getDeclRef().getDecl()) {
668+
return llvm::isa<swift::AccessorDecl>(valDecl);
669+
}
670+
return false;
671+
}
672+
673+
BridgedStringRef BridgedFunction::getAccessorName() const {
674+
auto *accessorDecl = llvm::cast<swift::AccessorDecl>(getFunction()->getDeclRef().getDecl());
675+
return accessorKindName(accessorDecl->getAccessorKind());
676+
}
677+
665678
bool BridgedFunction::hasOwnership() const { return getFunction()->hasOwnership(); }
666679

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

0 commit comments

Comments
 (0)