Skip to content

Commit c6705ad

Browse files
committed
[Dependency Scanning] Make the batch scan entry container an opaque type
1 parent 409de73 commit c6705ad

File tree

3 files changed

+70
-26
lines changed

3 files changed

+70
-26
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ typedef struct {
6363

6464
//=== Batch Scan Input Specification --------------------------------------===//
6565

66-
typedef struct {
67-
swiftscan_string_t module_name;
68-
swiftscan_string_t arguments;
69-
bool is_swift;
70-
} swiftscan_batch_scan_entry_t;
66+
/// Opaque container to a container of batch scan entry information.
67+
typedef void *swiftscan_batch_scan_entry_t;
7168

7269
typedef struct {
7370
int count;
@@ -186,25 +183,36 @@ swiftscan_clang_detail_get_context_hash(swiftscan_module_details_t details);
186183
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
187184
swiftscan_clang_detail_get_command_line(swiftscan_module_details_t details);
188185

186+
//=== Batch Scan Entry Functions ------------------------------------------===//
187+
188+
SWIFTSCAN_PUBLIC swiftscan_string_t
189+
swiftscan_batch_scan_entry_get_module_name(swiftscan_batch_scan_entry_t entry);
190+
191+
SWIFTSCAN_PUBLIC swiftscan_string_t
192+
swiftscan_batch_scan_entry_get_arguments(swiftscan_batch_scan_entry_t entry);
193+
194+
SWIFTSCAN_PUBLIC bool
195+
swiftscan_batch_scan_entry_get_is_swift(swiftscan_batch_scan_entry_t entry);
196+
189197
//=== Cleanup Functions ---------------------------------------------------===//
190198

191199
SWIFTSCAN_PUBLIC void
192200
swiftscan_dependency_info_details_dispose(swiftscan_module_details_t details);
193201

194202
SWIFTSCAN_PUBLIC void
195-
swiftscan_dependency_info_dispose(swiftscan_dependency_info_t *info);
203+
swiftscan_dependency_info_dispose(swiftscan_dependency_info_t info);
196204

197205
SWIFTSCAN_PUBLIC void
198206
swiftscan_dependency_set_dispose(swiftscan_dependency_set_t *set);
199207

200208
SWIFTSCAN_PUBLIC void
201-
swiftscan_dependency_result_dispose(swiftscan_dependency_result_t *result);
209+
swiftscan_dependency_result_dispose(swiftscan_dependency_result_t result);
202210

203211
SWIFTSCAN_PUBLIC void
204212
swiftscan_prescan_result_dispose(swiftscan_prescan_result_t *result);
205213

206214
SWIFTSCAN_PUBLIC void
207-
swiftscan_batch_scan_entry_dispose(swiftscan_batch_scan_entry_t *entry);
215+
swiftscan_batch_scan_entry_dispose(swiftscan_batch_scan_entry_t entry);
208216

209217
SWIFTSCAN_PUBLIC void
210218
swiftscan_batch_scan_input_dispose(swiftscan_batch_scan_input_t *input);

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ typedef struct {
135135
};
136136
} swiftscan_impl_module_details_t;
137137

138+
typedef struct {
139+
swiftscan_string_t module_name;
140+
swiftscan_string_t arguments;
141+
bool is_swift;
142+
} swiftscan_impl_batch_scan_entry_t;
143+
138144
inline swift::dependencies::DependencyScanningTool *
139145
unwrap_scanner(swiftscan_scanner_t P) {
140146
return reinterpret_cast<swift::dependencies::DependencyScanningTool *>(P);
@@ -179,4 +185,15 @@ wrap_result(const swiftscan_impl_dependency_result_t *P) {
179185
const_cast<swiftscan_impl_dependency_result_t *>(P));
180186
}
181187

188+
inline swiftscan_impl_batch_scan_entry_t *
189+
unwrap_batch_entry(swiftscan_batch_scan_entry_t P) {
190+
return reinterpret_cast<swiftscan_impl_batch_scan_entry_t *>(P);
191+
}
192+
193+
inline swiftscan_batch_scan_entry_t
194+
wrap_batch_entry(const swiftscan_impl_batch_scan_entry_t *P) {
195+
return reinterpret_cast<swiftscan_batch_scan_entry_t>(
196+
const_cast<swiftscan_impl_batch_scan_entry_t *>(P));
197+
}
198+
182199
#endif // SWIFT_C_DEPENDENCY_SCAN_IMPL_H

lib/DependencyScan/DependencyScanImpl.cpp

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ swiftscan_batch_scan_dependencies(swiftscan_scanner_t *scanner,
5757

5858
std::vector<BatchScanInput> BatchInput;
5959
for (int i = 0; i < batch_input->count; ++i) {
60-
swiftscan_batch_scan_entry_t &Entry = batch_input->modules[i];
61-
BatchInput.push_back({swiftscan_get_C_string(Entry.module_name),
62-
swiftscan_get_C_string(Entry.arguments),
63-
/*outputPath*/ "", Entry.is_swift});
60+
swiftscan_impl_batch_scan_entry_t *Entry =
61+
unwrap_batch_entry(batch_input->modules[i]);
62+
BatchInput.push_back({swiftscan_get_C_string(Entry->module_name),
63+
swiftscan_get_C_string(Entry->arguments),
64+
/*outputPath*/ "", Entry->is_swift});
6465
}
6566

6667
// Execute the scan and bridge the result
6768
auto BatchScanResult =
6869
ScanningTool->getDependencies(Compilation, BatchInput, {});
6970
swiftscan_batch_scan_result_t *Result = new swiftscan_batch_scan_result_t;
70-
auto ResultGraphs =
71-
new swiftscan_dependency_result_t[BatchScanResult.size()];
71+
auto ResultGraphs = new swiftscan_dependency_result_t[BatchScanResult.size()];
7272
for (size_t i = 0; i < BatchScanResult.size(); ++i) {
7373
auto &ResultOrErr = BatchScanResult[i];
7474
if (ResultOrErr.getError())
@@ -237,6 +237,23 @@ swiftscan_clang_detail_get_command_line(swiftscan_module_details_t details) {
237237
return unwrap_details(details)->clang_details.command_line;
238238
}
239239

240+
//=== Batch Scan Entry Functions ------------------------------------------===//
241+
242+
swiftscan_string_t
243+
swiftscan_batch_scan_entry_get_module_name(swiftscan_batch_scan_entry_t entry) {
244+
return unwrap_batch_entry(entry)->module_name;
245+
}
246+
247+
swiftscan_string_t
248+
swiftscan_batch_scan_entry_get_arguments(swiftscan_batch_scan_entry_t entry) {
249+
return unwrap_batch_entry(entry)->arguments;
250+
}
251+
252+
bool swiftscan_batch_scan_entry_get_is_swift(
253+
swiftscan_batch_scan_entry_t entry) {
254+
return unwrap_batch_entry(entry)->is_swift;
255+
}
256+
240257
//=== Cleanup Functions ---------------------------------------------------===//
241258

242259
void swiftscan_dependency_info_details_dispose(
@@ -285,12 +302,14 @@ void swiftscan_dependency_info_details_dispose(
285302
delete details_impl;
286303
}
287304

288-
void swiftscan_dependency_info_dispose(swiftscan_dependency_info_t *info) {
289-
swiftscan_string_dispose(unwrap_info(info)->module_name);
290-
swiftscan_string_dispose(unwrap_info(info)->module_path);
291-
swiftscan_string_set_dispose(unwrap_info(info)->source_files);
292-
swiftscan_string_set_dispose(unwrap_info(info)->direct_dependencies);
293-
swiftscan_dependency_info_details_dispose(unwrap_info(info)->details);
305+
void swiftscan_dependency_info_dispose(swiftscan_dependency_info_t info) {
306+
swiftscan_impl_dependency_info_t *info_impl = unwrap_info(info);
307+
swiftscan_string_dispose(info_impl->module_name);
308+
swiftscan_string_dispose(info_impl->module_path);
309+
swiftscan_string_set_dispose(info_impl->source_files);
310+
swiftscan_string_set_dispose(info_impl->direct_dependencies);
311+
swiftscan_dependency_info_details_dispose(info_impl->details);
312+
delete info_impl;
294313
}
295314

296315
void swiftscan_dependency_set_dispose(swiftscan_dependency_set_t *set) {
@@ -301,8 +320,7 @@ void swiftscan_dependency_set_dispose(swiftscan_dependency_set_t *set) {
301320
delete set;
302321
}
303322

304-
void swiftscan_dependency_result_dispose(
305-
swiftscan_dependency_result_t result) {
323+
void swiftscan_dependency_result_dispose(swiftscan_dependency_result_t result) {
306324
swiftscan_impl_dependency_result_t *result_impl = unwrap_result(result);
307325
swiftscan_string_dispose(result_impl->main_module_name);
308326
swiftscan_dependency_set_dispose(result_impl->module_set);
@@ -314,10 +332,11 @@ void swiftscan_prescan_result_dispose(swiftscan_prescan_result_t *result) {
314332
delete result;
315333
}
316334

317-
void swiftscan_batch_scan_entry_dispose(swiftscan_batch_scan_entry_t *entry) {
318-
swiftscan_string_dispose(entry->module_name);
319-
swiftscan_string_dispose(entry->arguments);
320-
delete entry;
335+
void swiftscan_batch_scan_entry_dispose(swiftscan_batch_scan_entry_t entry) {
336+
swiftscan_impl_batch_scan_entry_t *entry_impl = unwrap_batch_entry(entry);
337+
swiftscan_string_dispose(entry_impl->module_name);
338+
swiftscan_string_dispose(entry_impl->arguments);
339+
delete entry_impl;
321340
}
322341

323342
void swiftscan_batch_scan_input_dispose(swiftscan_batch_scan_input_t *input) {

0 commit comments

Comments
 (0)