@@ -89,15 +89,16 @@ class SourceLoc {
8989 return SourceLoc::getFromPointer (Pointer + ByteOffset);
9090 }
9191
92- // Not imported into Swift in pure bridging mode.
93- #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
94-
92+ SWIFT_UNAVAILABLE (" Unavailable in Swift" )
9593 SourceLoc getAdvancedLocOrInvalid (int ByteOffset) const {
9694 if (isValid ())
9795 return getAdvancedLoc (ByteOffset);
9896 return SourceLoc ();
9997 }
10098
99+ // Not imported into Swift in pure bridging mode.
100+ #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
101+
101102 // / An explicit bool operator so one can check if a SourceLoc is valid in an
102103 // / if statement:
103104 // /
@@ -226,9 +227,6 @@ class SourceRange {
226227#endif // #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
227228};
228229
229- // Not imported into Swift in pure bridging mode.
230- #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
231-
232230// / A half-open character-based source range.
233231class CharSourceRange {
234232 SourceLoc Start;
@@ -238,29 +236,40 @@ class CharSourceRange {
238236 // / Constructs an invalid range.
239237 CharSourceRange () = default ;
240238
239+ SWIFT_NAME (" init(start:byteLength:)" )
241240 CharSourceRange (SourceLoc Start, unsigned ByteLength)
242241 : Start(Start), ByteLength(ByteLength) {}
243242
243+ // Not imported into Swift in pure bridging mode.
244+ #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
245+
244246 // / Constructs a character range which starts and ends at the
245247 // / specified character locations.
246248 CharSourceRange (const SourceManager &SM, SourceLoc Start, SourceLoc End);
247249
248250 // / Use Lexer::getCharSourceRangeFromSourceRange() instead.
249251 CharSourceRange (const SourceManager &SM, SourceRange Range) = delete;
250252
253+ #endif // #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
254+
251255 bool isValid () const { return Start.isValid (); }
252256 bool isInvalid () const { return !isValid (); }
253257
254- bool operator ==(const CharSourceRange &other) const {
255- return Start == other.Start && ByteLength == other.ByteLength ;
256- }
257- bool operator !=(const CharSourceRange &other) const {
258- return !operator ==(other);
259- }
260-
258+ SWIFT_COMPUTED_PROPERTY
261259 SourceLoc getStart () const { return Start; }
260+ SWIFT_COMPUTED_PROPERTY
262261 SourceLoc getEnd () const { return Start.getAdvancedLocOrInvalid (ByteLength); }
263262
263+ // / Return the length of this valid range in bytes. Can be zero.
264+ SWIFT_COMPUTED_PROPERTY
265+ unsigned getByteLength () const {
266+ assert (isValid () && " length does not make sense for an invalid range" );
267+ return ByteLength;
268+ }
269+
270+ // Not imported into Swift in pure bridging mode.
271+ #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
272+
264273 // / Returns true if the given source location is contained in the range.
265274 bool contains (SourceLoc loc) const {
266275 auto less = std::less<const char *>();
@@ -296,12 +305,13 @@ class CharSourceRange {
296305
297306 StringRef str () const { return StringRef (Start.Pointer , ByteLength); }
298307
299- // / Return the length of this valid range in bytes. Can be zero.
300- unsigned getByteLength () const {
301- assert (isValid () && " length does not make sense for an invalid range" );
302- return ByteLength;
308+ bool operator ==(const CharSourceRange &other) const {
309+ return Start == other.Start && ByteLength == other.ByteLength ;
303310 }
304-
311+ bool operator !=(const CharSourceRange &other) const {
312+ return !operator ==(other);
313+ }
314+
305315 // / Print out the CharSourceRange. If the locations are in the same buffer
306316 // / as specified by LastBufferID, then we don't print the filename. If not,
307317 // / we do print the filename, and then update LastBufferID with the BufferID
@@ -314,11 +324,11 @@ class CharSourceRange {
314324 unsigned Tmp = ~0U ;
315325 print (OS, SM, Tmp, PrintText);
316326 }
317-
327+
318328 SWIFT_DEBUG_DUMPER (dump(const SourceManager &SM));
319- };
320329
321330#endif // #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
331+ };
322332
323333} // end namespace swift
324334
0 commit comments