Skip to content

Commit dbd0af0

Browse files
committed
AST: add some BuiltinFixedArray and IntegerType APIs
1 parent 7f6fb74 commit dbd0af0

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ public struct Type: TypeProperties, CustomStringConvertible, NoReflectionChildre
6161

6262
public var builtinVectorElementType: Type { Type(bridged: bridged.getBuiltinVectorElementType()) }
6363

64-
public var builtinFixedArrayElementType: Type { Type(bridged: bridged.getBuiltinFixedArrayElementType()) }
65-
6664
public func subst(with substitutionMap: SubstitutionMap) -> Type {
6765
return Type(bridged: bridged.subst(substitutionMap.bridged))
6866
}
@@ -83,8 +81,6 @@ public struct CanonicalType: TypeProperties, CustomStringConvertible, NoReflecti
8381

8482
public var builtinVectorElementType: CanonicalType { rawType.builtinVectorElementType.canonical }
8583

86-
public var builtinFixedArrayElementType: CanonicalType { rawType.builtinFixedArrayElementType.canonical }
87-
8884
public func subst(with substitutionMap: SubstitutionMap) -> CanonicalType {
8985
return rawType.subst(with: substitutionMap).canonical
9086
}
@@ -195,6 +191,23 @@ extension TypeProperties {
195191
rawType.bridged.getRepresentationOfMetatype().representation
196192
}
197193

194+
public var builtinFixedArrayElementType: CanonicalType {
195+
CanonicalType(bridged: rawType.bridged.getBuiltinFixedArrayElementType())
196+
}
197+
public var builtinFixedArraySizeType: CanonicalType {
198+
CanonicalType(bridged: rawType.bridged.getBuiltinFixedArraySizeType())
199+
}
200+
201+
/// Returns the value of an integer value type (see `isInteger`).
202+
/// Returns nil if the value is not representable in an `Int`.
203+
public var valueOfInteger: Int? {
204+
let optionalInt = rawType.bridged.getValueOfIntegerType()
205+
if optionalInt.hasValue {
206+
return optionalInt.value
207+
}
208+
return nil
209+
}
210+
198211
/// Assumes this is a nominal type. Returns a substitution map that sends each
199212
/// generic parameter of the declaration's generic signature to the corresponding
200213
/// generic argument of this nominal type.

include/swift/AST/ASTBridging.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,8 @@ struct BridgedASTType {
31343134
BRIDGED_INLINE bool isBuiltinVector() const;
31353135
BRIDGED_INLINE bool isBuiltinFixedArray() const;
31363136
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getBuiltinVectorElementType() const;
3137-
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getBuiltinFixedArrayElementType() const;
3137+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType getBuiltinFixedArrayElementType() const;
3138+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType getBuiltinFixedArraySizeType() const;
31383139
BRIDGED_INLINE bool isBuiltinFixedWidthInteger(SwiftInt width) const;
31393140
BRIDGED_INLINE bool isOptional() const;
31403141
BRIDGED_INLINE bool isBuiltinType() const;
@@ -3145,6 +3146,7 @@ struct BridgedASTType {
31453146
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getStaticTypeOfDynamicSelf() const;
31463147
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getSuperClassType() const;
31473148
BRIDGED_INLINE MetatypeRepresentation getRepresentationOfMetatype() const;
3149+
BRIDGED_INLINE BridgedOptionalInt getValueOfIntegerType() const;
31483150
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap getContextSubstitutionMap() const;
31493151
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGenericSignature getInvocationGenericSignatureOfFunctionType() const;
31503152
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType subst(BridgedSubstitutionMap substMap) const;

include/swift/AST/ASTBridgingImpl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,12 @@ BridgedASTType BridgedASTType::getBuiltinVectorElementType() const {
550550
return {unbridged()->castTo<swift::BuiltinVectorType>()->getElementType().getPointer()};
551551
}
552552

553-
BridgedASTType BridgedASTType::getBuiltinFixedArrayElementType() const {
554-
return {unbridged()->castTo<swift::BuiltinFixedArrayType>()->getElementType().getPointer()};
553+
BridgedCanType BridgedASTType::getBuiltinFixedArrayElementType() const {
554+
return unbridged()->castTo<swift::BuiltinFixedArrayType>()->getElementType();
555+
}
556+
557+
BridgedCanType BridgedASTType::getBuiltinFixedArraySizeType() const {
558+
return unbridged()->castTo<swift::BuiltinFixedArrayType>()->getSize();
555559
}
556560

557561
bool BridgedASTType::isBuiltinFixedWidthInteger(SwiftInt width) const {
@@ -600,6 +604,10 @@ BridgedASTType::MetatypeRepresentation BridgedASTType::getRepresentationOfMetaty
600604
return MetatypeRepresentation(unbridged()->getAs<swift::AnyMetatypeType>()->getRepresentation());
601605
}
602606

607+
BridgedOptionalInt BridgedASTType::getValueOfIntegerType() const {
608+
return BridgedOptionalInt::getFromAPInt(unbridged()->getAs<swift::IntegerType>()->getValue());
609+
}
610+
603611
BridgedSubstitutionMap BridgedASTType::getContextSubstitutionMap() const {
604612
return unbridged()->getContextSubstitutionMap();
605613
}

0 commit comments

Comments
 (0)