Skip to content

Commit d025e9f

Browse files
committed
SIL: add var Argument.decl: ValueDecl?
1 parent d526a2f commit d025e9f

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,9 @@ extension OptionalBridgedDeclObj {
157157
public var decl: Decl? { obj.getAs(Decl.self) }
158158
public func getAs<T: Decl>(_ declType: T.Type) -> T? { obj.getAs(T.self) }
159159
}
160+
161+
extension Optional where Wrapped == Decl {
162+
public var bridged: OptionalBridgedDeclObj {
163+
OptionalBridgedDeclObj(self?.bridged.obj)
164+
}
165+
}

SwiftCompilerSources/Sources/SIL/Argument.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ public class Argument : Value, Hashable {
3434

3535
public var isLexical: Bool { false }
3636

37+
public var decl: ValueDecl? { bridged.getDecl().getAs(ValueDecl.self) }
38+
3739
public func findVarDecl() -> VarDecl? {
38-
if let varDecl = bridged.getVarDecl().getAs(VarDecl.self) {
40+
if let varDecl = decl as? VarDecl {
3941
return varDecl
4042
}
4143
return findVarDeclFromDebugUsers()

include/swift/AST/ASTBridging.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,16 @@ void registerBridgedDecl(BridgedStringRef bridgedClassName, SwiftMetatype metaty
370370

371371
struct OptionalBridgedDeclObj {
372372
OptionalSwiftObject obj;
373+
374+
OptionalBridgedDeclObj(OptionalSwiftObject obj) : obj(obj) {}
375+
376+
#ifdef USED_IN_CPP_SOURCE
377+
template <class D> D *_Nullable getAs() const {
378+
if (obj)
379+
return llvm::cast<D>(static_cast<swift::Decl *>(obj));
380+
return nullptr;
381+
}
382+
#endif
373383
};
374384

375385
struct BridgedDeclObj {

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ struct BridgedArgument {
903903
BRIDGED_INLINE bool FunctionArgument_isLexical() const;
904904
BRIDGED_INLINE bool FunctionArgument_isClosureCapture() const;
905905
BRIDGED_INLINE void setReborrow(bool reborrow) const;
906-
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getVarDecl() const;
906+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getDecl() const;
907907
BRIDGED_INLINE void copyFlags(BridgedArgument fromArgument) const;
908908
};
909909

include/swift/SIL/SILBridgingImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ bool BridgedArgument::FunctionArgument_isClosureCapture() const {
593593
getArgument())->isClosureCapture();
594594
}
595595

596-
OptionalBridgedDeclObj BridgedArgument::getVarDecl() const {
597-
return {llvm::dyn_cast_or_null<swift::VarDecl>(getArgument()->getDecl())};
596+
OptionalBridgedDeclObj BridgedArgument::getDecl() const {
597+
return {getArgument()->getDecl()};
598598
}
599599

600600
void BridgedArgument::copyFlags(BridgedArgument fromArgument) const {

0 commit comments

Comments
 (0)