Skip to content

Commit 9001ce4

Browse files
committed
Bridging: Bridge swift::SourceRange directly
1 parent 6eb5d7d commit 9001ce4

18 files changed

+329
-369
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 72 additions & 73 deletions
Large diffs are not rendered by default.

include/swift/Basic/BasicBridging.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -317,29 +317,6 @@ class BridgedOStream {
317317

318318
BridgedOStream Bridged_dbgs();
319319

320-
//===----------------------------------------------------------------------===//
321-
// MARK: SourceRange
322-
//===----------------------------------------------------------------------===//
323-
324-
class BridgedSourceRange {
325-
public:
326-
SWIFT_NAME("start")
327-
swift::SourceLoc Start;
328-
329-
SWIFT_NAME("end")
330-
swift::SourceLoc End;
331-
332-
BridgedSourceRange() : Start(), End() {}
333-
334-
SWIFT_NAME("init(start:end:)")
335-
BridgedSourceRange(swift::SourceLoc start, swift::SourceLoc end)
336-
: Start(start), End(end) {}
337-
338-
BRIDGED_INLINE BridgedSourceRange(swift::SourceRange range);
339-
340-
BRIDGED_INLINE swift::SourceRange unbridged() const;
341-
};
342-
343320
//===----------------------------------------------------------------------===//
344321
// MARK: BridgedCharSourceRange
345322
//===----------------------------------------------------------------------===//

include/swift/Basic/BasicBridgingImpl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ llvm::StringRef BridgedStringRef::unbridged() const {
3838

3939
llvm::StringRef BridgedOwnedString::unbridgedRef() const { return llvm::StringRef(Data, Length); }
4040

41-
//===----------------------------------------------------------------------===//
42-
// MARK: BridgedSourceRange
43-
//===----------------------------------------------------------------------===//
44-
45-
BridgedSourceRange::BridgedSourceRange(swift::SourceRange range)
46-
: Start(range.Start), End(range.End) {}
47-
48-
swift::SourceRange BridgedSourceRange::unbridged() const {
49-
return swift::SourceRange(Start, End);
50-
}
51-
5241
//===----------------------------------------------------------------------===//
5342
// MARK: BridgedCharSourceRange
5443
//===----------------------------------------------------------------------===//

include/swift/Basic/SourceLoc.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,24 @@ class SourceLoc {
137137
#endif // #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
138138
};
139139

140-
// Not imported into Swift in pure bridging mode.
141-
#ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
142-
143140
/// SourceRange in swift is a pair of locations. However, note that the end
144141
/// location is the start of the last token in the range, not the last character
145142
/// in the range. This is unlike SMRange, so we use a distinct type to make
146143
/// sure that proper conversions happen where important.
147144
class SourceRange {
148145
public:
149-
SourceLoc Start, End;
146+
SWIFT_NAME("start")
147+
SourceLoc Start;
148+
149+
SWIFT_NAME("end")
150+
SourceLoc End;
150151

151152
SourceRange() {}
153+
154+
SWIFT_NAME("init(start:)")
152155
SourceRange(SourceLoc Loc) : Start(Loc), End(Loc) {}
156+
157+
SWIFT_NAME("init(start:end:)")
153158
SourceRange(SourceLoc Start, SourceLoc End) : Start(Start), End(End) {
154159
assert(Start.isValid() == End.isValid() &&
155160
"Start and end should either both be valid or both be invalid!");
@@ -158,6 +163,9 @@ class SourceRange {
158163
bool isValid() const { return Start.isValid(); }
159164
bool isInvalid() const { return !isValid(); }
160165

166+
// Not imported into Swift in pure bridging mode.
167+
#ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
168+
161169
/// An explicit bool operator so one can check if a SourceRange is valid in an
162170
/// if statement:
163171
///
@@ -215,8 +223,12 @@ class SourceRange {
215223
// Nothing meaningful to print.
216224
}
217225

226+
#endif // #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
218227
};
219228

229+
// Not imported into Swift in pure bridging mode.
230+
#ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
231+
220232
/// A half-open character-based source range.
221233
class CharSourceRange {
222234
SourceLoc Start;

lib/AST/Bridging/AvailabilityBridging.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ BridgedAvailabilitySpec_createWildcard(BridgedASTContext cContext,
6767

6868
BridgedAvailabilitySpec BridgedAvailabilitySpec_createForDomainIdentifier(
6969
BridgedASTContext cContext, Identifier name, SourceLoc loc,
70-
BridgedVersionTuple cVersion, BridgedSourceRange cVersionRange) {
71-
return AvailabilitySpec::createForDomainIdentifier(cContext.unbridged(), name,
72-
loc, cVersion.unbridged(),
73-
cVersionRange.unbridged());
70+
BridgedVersionTuple cVersion, SourceRange versionRange) {
71+
return AvailabilitySpec::createForDomainIdentifier(
72+
cContext.unbridged(), name, loc, cVersion.unbridged(), versionRange);
7473
}
7574

7675
BridgedAvailabilitySpec
@@ -89,7 +88,7 @@ BridgedAvailabilitySpec_getDomainOrIdentifier(BridgedAvailabilitySpec spec) {
8988
return spec.unbridged()->getDomainOrIdentifier();
9089
}
9190

92-
BridgedSourceRange
91+
SourceRange
9392
BridgedAvailabilitySpec_getSourceRange(BridgedAvailabilitySpec spec) {
9493
return spec.unbridged()->getSourceRange();
9594
}
@@ -103,7 +102,7 @@ BridgedAvailabilitySpec_getRawVersion(BridgedAvailabilitySpec spec) {
103102
return spec.unbridged()->getRawVersion();
104103
}
105104

106-
BridgedSourceRange
105+
SourceRange
107106
BridgedAvailabilitySpec_getVersionRange(BridgedAvailabilitySpec spec) {
108107
return spec.unbridged()->getVersionSrcRange();
109108
}

0 commit comments

Comments
 (0)