|
25 | 25 |
|
26 | 26 | #include <stddef.h>
|
27 | 27 | #include <stdint.h>
|
28 |
| -#include <vector> |
29 | 28 | #ifdef USED_IN_CPP_SOURCE
|
30 | 29 | // Workaround to avoid a compiler error because `cas::ObjectRef` is not defined
|
31 | 30 | // when including VirtualFileSystem.h
|
|
35 | 34 | #include "swift/Basic/SourceLoc.h"
|
36 | 35 | #include "llvm/ADT/StringRef.h"
|
37 | 36 | #include <string>
|
| 37 | +#include <vector> |
38 | 38 | #endif
|
39 | 39 |
|
40 | 40 | // FIXME: We ought to be importing '<swift/bridging>' instead.
|
@@ -346,26 +346,36 @@ BridgedCharSourceRange_byteLength(BridgedCharSourceRange range) {
|
346 | 346 | // MARK: std::vector<BridgedCharSourceRange>
|
347 | 347 | //===----------------------------------------------------------------------===//
|
348 | 348 |
|
349 |
| -typedef std::vector<BridgedCharSourceRange> BridgedCharSourceRangeVector; |
350 |
| - |
351 |
| -/// Create an empty `std::vector<ResolvedLoc>`. |
| 349 | +/// An opaque, heap-allocated `std::vector<CharSourceRange>`. |
352 | 350 | ///
|
353 |
| -/// - Note: This can't be imported as an initializer on |
354 |
| -/// `BridgedResolvedLocVector` |
355 |
| -/// because initializers without any arguments aren't imported to Swift |
356 |
| -SWIFT_NAME("BridgedCharSourceRangeVector.empty()") |
357 |
| -BridgedCharSourceRangeVector BridgedCharSourceRangeVector_createEmpty(); |
| 351 | +/// This type is manually memory managed. The creator of the object needs to |
| 352 | +/// ensure that `takeUnbridged` is called to free the memory. |
| 353 | +class BridgedCharSourceRangeVector { |
| 354 | + /// Opaque pointer to `std::vector<CharSourceRange>`. |
| 355 | + void *_Nonnull vector; |
358 | 356 |
|
359 |
| -/// Append the given `BridgedCharSourceRange` to `vector`. |
360 |
| -SWIFT_NAME("BridgedCharSourceRangeVector.push_back(self:_:)") |
361 |
| -void BridgedCharSourceRangeVector_push_back_BridgedCharSourceRange( |
362 |
| - BridgedCharSourceRangeVector &vector, BridgedCharSourceRange range); |
| 357 | +public: |
| 358 | + BridgedCharSourceRangeVector(); |
| 359 | + |
| 360 | + SWIFT_NAME("append(_:)") |
| 361 | + void push_back(BridgedCharSourceRange range); |
363 | 362 |
|
364 | 363 | #ifdef USED_IN_CPP_SOURCE
|
365 |
| -/// Convert the `BridgedCharSourceRange` to a `CharSourceRange`. |
366 |
| -std::vector<swift::CharSourceRange> BridgedCharSourceRangeVector_unbridged( |
367 |
| - const BridgedCharSourceRangeVector &vector); |
| 364 | + /// Returns the `std::vector<swift::CharSourceRange>` that this |
| 365 | + /// `BridgedCharSourceRangeVector` represents and frees the memory owned by |
| 366 | + /// this `BridgedCharSourceRangeVector`. |
| 367 | + /// |
| 368 | + /// No operations should be called on `BridgedCharSourceRangeVector` after |
| 369 | + /// `takeUnbridged` is called. |
| 370 | + std::vector<swift::CharSourceRange> takeUnbridged() { |
| 371 | + auto *vectorPtr = |
| 372 | + static_cast<std::vector<swift::CharSourceRange> *>(vector); |
| 373 | + std::vector<swift::CharSourceRange> unbridged = *vectorPtr; |
| 374 | + delete vectorPtr; |
| 375 | + return unbridged; |
| 376 | + } |
368 | 377 | #endif
|
| 378 | +}; |
369 | 379 |
|
370 | 380 | //===----------------------------------------------------------------------===//
|
371 | 381 | // MARK: Plugins
|
|
0 commit comments