Skip to content

Commit 0d496b5

Browse files
committed
SwiftCompilerSources: bridge Type.unsafePointerElementType
1 parent 4f25495 commit 0d496b5

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,8 @@ extension TypeProperties {
147147
public var isDynamicSelf: Bool { rawType.bridged.isDynamicSelf()}
148148
public var isBox: Bool { rawType.bridged.isBox() }
149149

150-
/// True if this is the type which represents an integer literal used in a type position.
151-
/// For example `N` in `struct T<let N: Int> {}`
152-
public var isInteger: Bool { rawType.bridged.isInteger() }
153-
154150
public var canBeClass: Type.TraitResult { rawType.bridged.canBeClass().result }
155151

156-
/// True if this the nominal type `Swift.Optional`.
157-
public var isOptional: Bool { rawType.bridged.isOptional() }
158-
159152
/// True if this type is a value type (struct/enum) that defines a `deinit`.
160153
public var isValueTypeWithDeinit: Bool {
161154
if let nominal = nominal, nominal.valueTypeDestructor != nil {
@@ -164,6 +157,34 @@ extension TypeProperties {
164157
return false
165158
}
166159

160+
//===--------------------------------------------------------------------===//
161+
// Checks for stdlib types
162+
//===--------------------------------------------------------------------===//
163+
164+
/// True if this is the type which represents an integer literal used in a type position.
165+
/// For example `N` in `struct T<let N: Int> {}`
166+
public var isInteger: Bool { rawType.bridged.isInteger() }
167+
168+
/// True if this the nominal type `Swift.Optional`.
169+
public var isOptional: Bool { rawType.bridged.isOptional() }
170+
171+
/// A non-nil result type implies isUnsafe[Raw][Mutable]Pointer. A raw
172+
/// pointer has a `void` element type.
173+
public var unsafePointerElementType: Type? {
174+
Type(bridgedOrNil: rawType.bridged.getAnyPointerElementType())
175+
}
176+
177+
public var isAnyUnsafePointer: Bool {
178+
unsafePointerElementType != nil
179+
}
180+
181+
public var isAnyUnsafeBufferPointer: Bool {
182+
rawType.bridged.isUnsafeBufferPointerType()
183+
|| rawType.bridged.isUnsafeMutableBufferPointerType()
184+
|| rawType.bridged.isUnsafeRawBufferPointerType()
185+
|| rawType.bridged.isUnsafeMutableRawBufferPointerType()
186+
}
187+
167188
//===--------------------------------------------------------------------===//
168189
// Properties of lowered `SILFunctionType`s
169190
//===--------------------------------------------------------------------===//

include/swift/AST/ASTBridging.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,6 +2955,11 @@ struct BridgedASTType {
29552955
BRIDGED_INLINE bool isBuiltinFixedWidthInteger(SwiftInt width) const;
29562956
BRIDGED_INLINE bool isOptional() const;
29572957
BRIDGED_INLINE bool isBuiltinType() const;
2958+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getAnyPointerElementType() const;
2959+
BRIDGED_INLINE bool isUnsafeBufferPointerType() const;
2960+
BRIDGED_INLINE bool isUnsafeMutableBufferPointerType() const;
2961+
BRIDGED_INLINE bool isUnsafeRawBufferPointerType() const;
2962+
BRIDGED_INLINE bool isUnsafeMutableRawBufferPointerType() const;
29582963
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getNominalOrBoundGenericNominal() const;
29592964
BRIDGED_INLINE TraitResult canBeClass() const;
29602965
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getAnyNominal() const;

include/swift/AST/ASTBridgingImpl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,26 @@ bool BridgedASTType::isBuiltinType() const {
566566
return unbridged()->isBuiltinType();
567567
}
568568

569+
BridgedASTType BridgedASTType::getAnyPointerElementType() const {
570+
return {unbridged()->getCanonicalType()->getAnyPointerElementType().getPointer()};
571+
}
572+
573+
bool BridgedASTType::isUnsafeBufferPointerType() const {
574+
return unbridged()->isUnsafeBufferPointer();
575+
}
576+
577+
bool BridgedASTType::isUnsafeMutableBufferPointerType() const {
578+
return unbridged()->isUnsafeMutableBufferPointer();
579+
}
580+
581+
bool BridgedASTType::isUnsafeRawBufferPointerType() const {
582+
return unbridged()->isUnsafeRawBufferPointer();
583+
}
584+
585+
bool BridgedASTType::isUnsafeMutableRawBufferPointerType() const {
586+
return unbridged()->isUnsafeMutableRawBufferPointer();
587+
}
588+
569589
OptionalBridgedDeclObj BridgedASTType::getNominalOrBoundGenericNominal() const {
570590
return {unbridged()->getNominalOrBoundGenericNominal()};
571591
}

0 commit comments

Comments
 (0)