Skip to content

Commit 0f485b6

Browse files
committed
Swift AST: add some Type APIs
1 parent 2623c4b commit 0f485b6

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() }
@@ -187,6 +191,7 @@ extension TypeProperties {
187191
public var isEscapable: Bool { rawType.bridged.isEscapable() }
188192
public var isNoEscape: Bool { rawType.bridged.isNoEscape() }
189193
public var isBuiltinType: Bool { rawType.bridged.isBuiltinType() }
194+
public var archetypeRequiresClass: Bool { rawType.bridged.archetypeRequiresClass() }
190195

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

include/swift/AST/ASTBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,11 +3100,14 @@ struct BridgedASTType {
31003100
BRIDGED_INLINE bool isGenericAtAnyLevel() const;
31013101
BRIDGED_INLINE bool hasTypeParameter() const;
31023102
BRIDGED_INLINE bool hasLocalArchetype() const;
3103+
BRIDGED_INLINE bool isArchetype() const;
3104+
BRIDGED_INLINE bool archetypeRequiresClass() const;
31033105
BRIDGED_INLINE bool isExistentialArchetype() const;
31043106
BRIDGED_INLINE bool isExistentialArchetypeWithError() const;
31053107
BRIDGED_INLINE bool isExistential() const;
31063108
BRIDGED_INLINE bool isDynamicSelf() const;
31073109
BRIDGED_INLINE bool isClassExistential() const;
3110+
BRIDGED_INLINE bool isGenericTypeParam() const;
31083111
BRIDGED_INLINE bool isEscapable() const;
31093112
BRIDGED_INLINE bool isNoEscape() const;
31103113
BRIDGED_INLINE bool isInteger() const;
@@ -3129,6 +3132,7 @@ struct BridgedASTType {
31293132
BRIDGED_INLINE TraitResult canBeClass() const;
31303133
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getAnyNominal() const;
31313134
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getInstanceTypeOfMetatype() const;
3135+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getStaticTypeOfDynamicSelf() const;
31323136
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getSuperClassType() const;
31333137
BRIDGED_INLINE MetatypeRepresentation getRepresentationOfMetatype() const;
31343138
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
@@ -423,6 +423,14 @@ bool BridgedASTType::hasLocalArchetype() const {
423423
return unbridged()->hasLocalArchetype();
424424
}
425425

426+
bool BridgedASTType::isArchetype() const {
427+
return unbridged()->is<swift::ArchetypeType>();
428+
}
429+
430+
bool BridgedASTType::archetypeRequiresClass() const {
431+
return unbridged()->castTo<swift::ArchetypeType>()->requiresClass();
432+
}
433+
426434
bool BridgedASTType::isExistentialArchetype() const {
427435
return unbridged()->is<swift::ExistentialArchetypeType>();
428436
}
@@ -443,6 +451,10 @@ bool BridgedASTType::isClassExistential() const {
443451
return unbridged()->isClassExistentialType();
444452
}
445453

454+
bool BridgedASTType::isGenericTypeParam() const {
455+
return unbridged()->is<swift::GenericTypeParamType>();
456+
}
457+
446458
bool BridgedASTType::isEscapable() const {
447459
return unbridged()->isEscapable();
448460
}
@@ -551,6 +563,10 @@ BridgedASTType BridgedASTType::getInstanceTypeOfMetatype() const {
551563
return {unbridged()->getAs<swift::AnyMetatypeType>()->getInstanceType().getPointer()};
552564
}
553565

566+
BridgedASTType BridgedASTType::getStaticTypeOfDynamicSelf() const {
567+
return {unbridged()->getAs<swift::DynamicSelfType>()->getSelfType().getPointer()};
568+
}
569+
554570
BridgedASTType BridgedASTType::getSuperClassType() const {
555571
return {unbridged()->getSuperclass().getPointer()};
556572
}

0 commit comments

Comments
 (0)