Skip to content

Commit 4f03241

Browse files
committed
Bridge Argument.varDecl
1 parent 25cff62 commit 4f03241

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

SwiftCompilerSources/Sources/SIL/Argument.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public class Argument : Value, Hashable {
3030
}
3131

3232
public var isReborrow: Bool { bridged.isReborrow() }
33-
33+
34+
public var varDecl: VarDecl? {
35+
VarDecl(bridged: bridged.getVarDecl())
36+
}
37+
3438
public static func ==(lhs: Argument, rhs: Argument) -> Bool {
3539
lhs === rhs
3640
}

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ struct BridgedArgument {
899899
BRIDGED_INLINE bool isSelf() const;
900900
BRIDGED_INLINE bool isReborrow() const;
901901
BRIDGED_INLINE bool hasResultDependsOn() const;
902+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedNullableVarDecl getVarDecl() const;
902903
};
903904

904905
struct OptionalBridgedArgument {

include/swift/SIL/SILBridgingImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@ bool BridgedArgument::hasResultDependsOn() const {
471471

472472
bool BridgedArgument::isReborrow() const { return getArgument()->isReborrow(); }
473473

474+
BridgedNullableVarDecl BridgedArgument::getVarDecl() const {
475+
// TODO: why does AST bridging force a non-const pointer?
476+
return {llvm::dyn_cast_or_null<swift::VarDecl>(
477+
const_cast<swift::ValueDecl*>(getArgument()->getDecl()))};
478+
}
479+
474480
//===----------------------------------------------------------------------===//
475481
// BridgedSubstitutionMap
476482
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)