Skip to content

Commit 9aa61e1

Browse files
committed
Swift AST: add some Type APIs
1 parent 2020897 commit 9aa61e1

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public struct Type: TypeProperties, CustomStringConvertible, NoReflectionChildre
4848

4949
public var instanceTypeOfMetatype: Type { Type(bridged: bridged.getInstanceTypeOfMetatype()) }
5050

51+
public var staticTypeOfDynamicSelf: Type { Type(bridged: bridged.getStaticTypeOfDynamicSelf()) }
52+
5153
public var superClassType: Type? {
5254
precondition(isClass)
5355
let bridgedSuperClassTy = bridged.getSuperClassType()
@@ -136,10 +138,12 @@ extension TypeProperties {
136138

137139
public var isTuple: Bool { rawType.bridged.isTuple() }
138140
public var isFunction: Bool { rawType.bridged.isFunction() }
141+
public var isArchetype: Bool { rawType.bridged.isArchetype() }
139142
public var isExistentialArchetype: Bool { rawType.bridged.isExistentialArchetype() }
140143
public var isExistentialArchetypeWithError: Bool { rawType.bridged.isExistentialArchetypeWithError() }
141144
public var isExistential: Bool { rawType.bridged.isExistential() }
142145
public var isClassExistential: Bool { rawType.bridged.isClassExistential() }
146+
public var isGenericTypeParameter: Bool { rawType.bridged.isGenericTypeParam() }
143147
public var isUnownedStorageType: Bool { return rawType.bridged.isUnownedStorageType() }
144148
public var isMetatype: Bool { rawType.bridged.isMetatypeType() }
145149
public var isExistentialMetatype: Bool { rawType.bridged.isExistentialMetatypeType() }
@@ -186,6 +190,7 @@ extension TypeProperties {
186190
public var hasLocalArchetype: Bool { rawType.bridged.hasLocalArchetype() }
187191
public var isEscapable: Bool { rawType.bridged.isEscapable() }
188192
public var isNoEscape: Bool { rawType.bridged.isNoEscape() }
193+
public var archetypeRequiresClass: Bool { rawType.bridged.archetypeRequiresClass() }
189194

190195
public var representationOfMetatype: AST.`Type`.MetatypeRepresentation {
191196
rawType.bridged.getRepresentationOfMetatype().representation

include/swift/AST/ASTBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,11 +3078,14 @@ struct BridgedASTType {
30783078
BRIDGED_INLINE bool isGenericAtAnyLevel() const;
30793079
BRIDGED_INLINE bool hasTypeParameter() const;
30803080
BRIDGED_INLINE bool hasLocalArchetype() const;
3081+
BRIDGED_INLINE bool isArchetype() const;
3082+
BRIDGED_INLINE bool archetypeRequiresClass() const;
30813083
BRIDGED_INLINE bool isExistentialArchetype() const;
30823084
BRIDGED_INLINE bool isExistentialArchetypeWithError() const;
30833085
BRIDGED_INLINE bool isExistential() const;
30843086
BRIDGED_INLINE bool isDynamicSelf() const;
30853087
BRIDGED_INLINE bool isClassExistential() const;
3088+
BRIDGED_INLINE bool isGenericTypeParam() const;
30863089
BRIDGED_INLINE bool isEscapable() const;
30873090
BRIDGED_INLINE bool isNoEscape() const;
30883091
BRIDGED_INLINE bool isInteger() const;
@@ -3106,6 +3109,7 @@ struct BridgedASTType {
31063109
BRIDGED_INLINE TraitResult canBeClass() const;
31073110
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getAnyNominal() const;
31083111
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getInstanceTypeOfMetatype() const;
3112+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getStaticTypeOfDynamicSelf() const;
31093113
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getSuperClassType() const;
31103114
BRIDGED_INLINE MetatypeRepresentation getRepresentationOfMetatype() const;
31113115
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap getContextSubstitutionMap() const;

include/swift/AST/ASTBridgingImpl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ bool BridgedASTType::hasLocalArchetype() const {
435435
return unbridged()->hasLocalArchetype();
436436
}
437437

438+
bool BridgedASTType::isArchetype() const {
439+
return unbridged()->is<swift::ArchetypeType>();
440+
}
441+
442+
bool BridgedASTType::archetypeRequiresClass() const {
443+
return unbridged()->castTo<swift::ArchetypeType>()->requiresClass();
444+
}
445+
438446
bool BridgedASTType::isExistentialArchetype() const {
439447
return unbridged()->is<swift::ExistentialArchetypeType>();
440448
}
@@ -455,6 +463,10 @@ bool BridgedASTType::isClassExistential() const {
455463
return unbridged()->isClassExistentialType();
456464
}
457465

466+
bool BridgedASTType::isGenericTypeParam() const {
467+
return unbridged()->is<swift::GenericTypeParamType>();
468+
}
469+
458470
bool BridgedASTType::isEscapable() const {
459471
return unbridged()->isEscapable();
460472
}
@@ -559,6 +571,10 @@ BridgedASTType BridgedASTType::getInstanceTypeOfMetatype() const {
559571
return {unbridged()->getAs<swift::AnyMetatypeType>()->getInstanceType().getPointer()};
560572
}
561573

574+
BridgedASTType BridgedASTType::getStaticTypeOfDynamicSelf() const {
575+
return {unbridged()->getAs<swift::DynamicSelfType>()->getSelfType().getPointer()};
576+
}
577+
562578
BridgedASTType BridgedASTType::getSuperClassType() const {
563579
return {unbridged()->getSuperclass().getPointer()};
564580
}

0 commit comments

Comments
 (0)