Skip to content

Commit 7f6fb74

Browse files
committed
SILBridging: move BridgedInstruction.OptionalInt -> BridgedOptionalInt in BasicBridging.h
1 parent a0aad5c commit 7f6fb74

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

include/swift/Basic/BasicBridging.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
#include "swift/Basic/SourceLoc.h"
5252
#include "llvm/ADT/StringRef.h"
53+
#include "llvm/ADT/APInt.h"
5354
#include <string>
5455
#include <vector>
5556
#endif
@@ -273,6 +274,24 @@ BRIDGED_INLINE SwiftInt BridgedOwnedString_count(BridgedOwnedString str);
273274
SWIFT_NAME("getter:BridgedOwnedString.isEmpty(self:)")
274275
BRIDGED_INLINE bool BridgedOwnedString_empty(BridgedOwnedString str);
275276

277+
//===----------------------------------------------------------------------===//
278+
// MARK: BridgedOptionalInt
279+
//===----------------------------------------------------------------------===//
280+
281+
struct BridgedOptionalInt {
282+
SwiftInt value;
283+
bool hasValue;
284+
285+
#ifdef USED_IN_CPP_SOURCE
286+
static BridgedOptionalInt getFromAPInt(llvm::APInt i) {
287+
if (i.getSignificantBits() <= std::min(std::numeric_limits<SwiftInt>::digits, 64)) {
288+
return {(SwiftInt)i.getSExtValue(), true};
289+
}
290+
return {0, false};
291+
}
292+
#endif
293+
};
294+
276295
//===----------------------------------------------------------------------===//
277296
// MARK: OStream
278297
//===----------------------------------------------------------------------===//

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,6 @@ struct BridgedInstruction {
699699
unknown
700700
};
701701

702-
struct OptionalInt {
703-
SwiftInt value;
704-
bool hasValue;
705-
};
706-
707702
enum class MarkDependenceKind {
708703
Unresolved, Escaping, NonEscaping
709704
};
@@ -744,7 +739,7 @@ struct BridgedInstruction {
744739
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGlobalVar GlobalAccessInst_getGlobal() const;
745740
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGlobalVar AllocGlobalInst_getGlobal() const;
746741
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedFunction FunctionRefBaseInst_getReferencedFunction() const;
747-
BRIDGED_INLINE OptionalInt IntegerLiteralInst_getValue() const;
742+
BRIDGED_INLINE BridgedOptionalInt IntegerLiteralInst_getValue() const;
748743
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef StringLiteralInst_getValue() const;
749744
BRIDGED_INLINE int StringLiteralInst_getEncoding() const;
750745
BRIDGED_INLINE SwiftInt TupleExtractInst_fieldIndex() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,12 +1170,9 @@ BridgedFunction BridgedInstruction::FunctionRefBaseInst_getReferencedFunction()
11701170
return {getAs<swift::FunctionRefBaseInst>()->getInitiallyReferencedFunction()};
11711171
}
11721172

1173-
BridgedInstruction::OptionalInt BridgedInstruction::IntegerLiteralInst_getValue() const {
1173+
BridgedOptionalInt BridgedInstruction::IntegerLiteralInst_getValue() const {
11741174
llvm::APInt result = getAs<swift::IntegerLiteralInst>()->getValue();
1175-
if (result.getSignificantBits() <= std::min(std::numeric_limits<SwiftInt>::digits, 64)) {
1176-
return {(SwiftInt)result.getSExtValue(), true};
1177-
}
1178-
return {0, false};
1175+
return BridgedOptionalInt::getFromAPInt(result);
11791176
}
11801177

11811178
BridgedStringRef BridgedInstruction::StringLiteralInst_getValue() const {

0 commit comments

Comments
 (0)