Swift AST: add some Type APIs

This commit is contained in:
Erik Eckstein
2025-04-17 12:46:14 +02:00
parent 2623c4bdd7
commit 0f485b6efc
3 changed files with 25 additions and 0 deletions

View File

@@ -48,6 +48,8 @@ public struct Type: TypeProperties, CustomStringConvertible, NoReflectionChildre
public var instanceTypeOfMetatype: Type { Type(bridged: bridged.getInstanceTypeOfMetatype()) }
public var staticTypeOfDynamicSelf: Type { Type(bridged: bridged.getStaticTypeOfDynamicSelf()) }
public var superClassType: Type? {
precondition(isClass)
let bridgedSuperClassTy = bridged.getSuperClassType()
@@ -136,10 +138,12 @@ extension TypeProperties {
public var isTuple: Bool { rawType.bridged.isTuple() }
public var isFunction: Bool { rawType.bridged.isFunction() }
public var isArchetype: Bool { rawType.bridged.isArchetype() }
public var isExistentialArchetype: Bool { rawType.bridged.isExistentialArchetype() }
public var isExistentialArchetypeWithError: Bool { rawType.bridged.isExistentialArchetypeWithError() }
public var isExistential: Bool { rawType.bridged.isExistential() }
public var isClassExistential: Bool { rawType.bridged.isClassExistential() }
public var isGenericTypeParameter: Bool { rawType.bridged.isGenericTypeParam() }
public var isUnownedStorageType: Bool { return rawType.bridged.isUnownedStorageType() }
public var isMetatype: Bool { rawType.bridged.isMetatypeType() }
public var isExistentialMetatype: Bool { rawType.bridged.isExistentialMetatypeType() }
@@ -187,6 +191,7 @@ extension TypeProperties {
public var isEscapable: Bool { rawType.bridged.isEscapable() }
public var isNoEscape: Bool { rawType.bridged.isNoEscape() }
public var isBuiltinType: Bool { rawType.bridged.isBuiltinType() }
public var archetypeRequiresClass: Bool { rawType.bridged.archetypeRequiresClass() }
public var representationOfMetatype: AST.`Type`.MetatypeRepresentation {
rawType.bridged.getRepresentationOfMetatype().representation

View File

@@ -3100,11 +3100,14 @@ struct BridgedASTType {
BRIDGED_INLINE bool isGenericAtAnyLevel() const;
BRIDGED_INLINE bool hasTypeParameter() const;
BRIDGED_INLINE bool hasLocalArchetype() const;
BRIDGED_INLINE bool isArchetype() const;
BRIDGED_INLINE bool archetypeRequiresClass() const;
BRIDGED_INLINE bool isExistentialArchetype() const;
BRIDGED_INLINE bool isExistentialArchetypeWithError() const;
BRIDGED_INLINE bool isExistential() const;
BRIDGED_INLINE bool isDynamicSelf() const;
BRIDGED_INLINE bool isClassExistential() const;
BRIDGED_INLINE bool isGenericTypeParam() const;
BRIDGED_INLINE bool isEscapable() const;
BRIDGED_INLINE bool isNoEscape() const;
BRIDGED_INLINE bool isInteger() const;
@@ -3129,6 +3132,7 @@ struct BridgedASTType {
BRIDGED_INLINE TraitResult canBeClass() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getAnyNominal() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getInstanceTypeOfMetatype() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getStaticTypeOfDynamicSelf() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getSuperClassType() const;
BRIDGED_INLINE MetatypeRepresentation getRepresentationOfMetatype() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap getContextSubstitutionMap() const;

View File

@@ -423,6 +423,14 @@ bool BridgedASTType::hasLocalArchetype() const {
return unbridged()->hasLocalArchetype();
}
bool BridgedASTType::isArchetype() const {
return unbridged()->is<swift::ArchetypeType>();
}
bool BridgedASTType::archetypeRequiresClass() const {
return unbridged()->castTo<swift::ArchetypeType>()->requiresClass();
}
bool BridgedASTType::isExistentialArchetype() const {
return unbridged()->is<swift::ExistentialArchetypeType>();
}
@@ -443,6 +451,10 @@ bool BridgedASTType::isClassExistential() const {
return unbridged()->isClassExistentialType();
}
bool BridgedASTType::isGenericTypeParam() const {
return unbridged()->is<swift::GenericTypeParamType>();
}
bool BridgedASTType::isEscapable() const {
return unbridged()->isEscapable();
}
@@ -551,6 +563,10 @@ BridgedASTType BridgedASTType::getInstanceTypeOfMetatype() const {
return {unbridged()->getAs<swift::AnyMetatypeType>()->getInstanceType().getPointer()};
}
BridgedASTType BridgedASTType::getStaticTypeOfDynamicSelf() const {
return {unbridged()->getAs<swift::DynamicSelfType>()->getSelfType().getPointer()};
}
BridgedASTType BridgedASTType::getSuperClassType() const {
return {unbridged()->getSuperclass().getPointer()};
}