@@ -89,15 +89,16 @@ class SourceLoc {
89
89
return SourceLoc::getFromPointer (Pointer + ByteOffset);
90
90
}
91
91
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" )
95
93
SourceLoc getAdvancedLocOrInvalid (int ByteOffset) const {
96
94
if (isValid ())
97
95
return getAdvancedLoc (ByteOffset);
98
96
return SourceLoc ();
99
97
}
100
98
99
+ // Not imported into Swift in pure bridging mode.
100
+ #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
101
+
101
102
// / An explicit bool operator so one can check if a SourceLoc is valid in an
102
103
// / if statement:
103
104
// /
@@ -226,9 +227,6 @@ class SourceRange {
226
227
#endif // #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
227
228
};
228
229
229
- // Not imported into Swift in pure bridging mode.
230
- #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
231
-
232
230
// / A half-open character-based source range.
233
231
class CharSourceRange {
234
232
SourceLoc Start;
@@ -238,29 +236,40 @@ class CharSourceRange {
238
236
// / Constructs an invalid range.
239
237
CharSourceRange () = default ;
240
238
239
+ SWIFT_NAME (" init(start:byteLength:)" )
241
240
CharSourceRange (SourceLoc Start, unsigned ByteLength)
242
241
: Start(Start), ByteLength(ByteLength) {}
243
242
243
+ // Not imported into Swift in pure bridging mode.
244
+ #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
245
+
244
246
// / Constructs a character range which starts and ends at the
245
247
// / specified character locations.
246
248
CharSourceRange (const SourceManager &SM, SourceLoc Start, SourceLoc End);
247
249
248
250
// / Use Lexer::getCharSourceRangeFromSourceRange() instead.
249
251
CharSourceRange (const SourceManager &SM, SourceRange Range) = delete;
250
252
253
+ #endif // #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
254
+
251
255
bool isValid () const { return Start.isValid (); }
252
256
bool isInvalid () const { return !isValid (); }
253
257
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
261
259
SourceLoc getStart () const { return Start; }
260
+ SWIFT_COMPUTED_PROPERTY
262
261
SourceLoc getEnd () const { return Start.getAdvancedLocOrInvalid (ByteLength); }
263
262
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
+
264
273
// / Returns true if the given source location is contained in the range.
265
274
bool contains (SourceLoc loc) const {
266
275
auto less = std::less<const char *>();
@@ -296,12 +305,13 @@ class CharSourceRange {
296
305
297
306
StringRef str () const { return StringRef (Start.Pointer , ByteLength); }
298
307
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 ;
303
310
}
304
-
311
+ bool operator !=(const CharSourceRange &other) const {
312
+ return !operator ==(other);
313
+ }
314
+
305
315
// / Print out the CharSourceRange. If the locations are in the same buffer
306
316
// / as specified by LastBufferID, then we don't print the filename. If not,
307
317
// / we do print the filename, and then update LastBufferID with the BufferID
@@ -314,11 +324,11 @@ class CharSourceRange {
314
324
unsigned Tmp = ~0U ;
315
325
print (OS, SM, Tmp, PrintText);
316
326
}
317
-
327
+
318
328
SWIFT_DEBUG_DUMPER (dump(const SourceManager &SM));
319
- };
320
329
321
330
#endif // #ifdef NOT_COMPILED_WITH_SWIFT_PURE_BRIDGING_MODE
331
+ };
322
332
323
333
} // end namespace swift
324
334
0 commit comments