Skip to content

Commit 42bba8f

Browse files
committed
AST: add some Declaration APIs
* `var Declaration.parentModule` * `var AbstractFunctionDecl.isOverridden`
1 parent e1af31b commit 42bba8f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class Decl: CustomStringConvertible, Hashable {
2020

2121
public var description: String { String(taking: bridged.getDebugDescription()) }
2222

23+
/// The module in which this declaration resides.
24+
public var parentModule: ModuleDecl { bridged.getModuleContext().getAs(ModuleDecl.self) }
25+
2326
// True if this declaration is imported from C/C++/ObjC.
2427
public var hasClangNode: Bool { bridged.hasClangNode() }
2528

@@ -88,7 +91,9 @@ final public class ParamDecl: VarDecl {}
8891

8992
final public class SubscriptDecl: AbstractStorageDecl {}
9093

91-
public class AbstractFunctionDecl: ValueDecl {}
94+
public class AbstractFunctionDecl: ValueDecl {
95+
public var isOverridden: Bool { bridged.AbstractFunction_isOverridden() }
96+
}
9297

9398
final public class ConstructorDecl: AbstractFunctionDecl {}
9499

include/swift/AST/ASTBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ struct BridgedDeclObj {
378378
BridgedDeclObj(SwiftObject obj) : obj(obj) {}
379379
BridgedOwnedString getDebugDescription() const;
380380
BRIDGED_INLINE BridgedSourceLoc getLoc() const;
381+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj getModuleContext() const;
381382
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef Type_getName() const;
382383
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef Value_getUserFacingName() const;
383384
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSourceLoc Value_getNameLoc() const;
@@ -389,6 +390,7 @@ struct BridgedDeclObj {
389390
BRIDGED_INLINE bool Struct_hasUnreferenceableStorage() const;
390391
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType Class_getSuperclass() const;
391392
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj Class_getDestructor() const;
393+
BRIDGED_INLINE bool AbstractFunction_isOverridden() const;
392394
BRIDGED_INLINE bool Destructor_isIsolated() const;
393395
};
394396

include/swift/AST/ASTBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ BridgedSourceLoc BridgedDeclObj::getLoc() const {
176176
return BridgedSourceLoc(sourceLoc.getOpaquePointerValue());
177177
}
178178

179+
BridgedDeclObj BridgedDeclObj::getModuleContext() const {
180+
return {unbridged()->getModuleContext()};
181+
}
182+
179183
BridgedStringRef BridgedDeclObj::Type_getName() const {
180184
return getAs<swift::TypeDecl>()->getName().str();
181185
}
@@ -220,6 +224,10 @@ BridgedDeclObj BridgedDeclObj::Class_getDestructor() const {
220224
return {getAs<swift::ClassDecl>()->getDestructor()};
221225
}
222226

227+
bool BridgedDeclObj::AbstractFunction_isOverridden() const {
228+
return getAs<swift::AbstractFunctionDecl>()->isOverridden();
229+
}
230+
223231
bool BridgedDeclObj::Destructor_isIsolated() const {
224232
auto dd = getAs<swift::DestructorDecl>();
225233
auto ai = swift::getActorIsolation(dd);

0 commit comments

Comments
 (0)