Skip to content

Commit 409de73

Browse files
committed
[Dependency Scanning] Make the overall dependency scan result (inter-module dependency graph) an opaque structure
1 parent 5cacff4 commit 409de73

File tree

7 files changed

+141
-89
lines changed

7 files changed

+141
-89
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,15 @@ typedef void *swiftscan_module_details_t;
4747
/// Opaque container to a dependency info of a given module.
4848
typedef void *swiftscan_dependency_info_t;
4949

50+
/// Opaque container to an overall result of a dependency scan.
51+
typedef void *swiftscan_dependency_result_t;
52+
5053
/// Full Dependency Graph (Result)
5154
typedef struct {
5255
int count;
5356
swiftscan_dependency_info_t *modules;
5457
} swiftscan_dependency_set_t;
5558

56-
typedef struct {
57-
/// The name of the main module for this dependency graph (root node)
58-
swiftscan_string_t main_module_name;
59-
60-
/// The complete list of modules discovered
61-
swiftscan_dependency_set_t *module_set;
62-
} swiftscan_dependency_result_t;
63-
6459
typedef struct {
6560
/// The complete list of imports discovered
6661
swiftscan_string_set_t *import_set;
@@ -81,11 +76,21 @@ typedef struct {
8176

8277
typedef struct {
8378
int count;
84-
swiftscan_dependency_result_t **results;
79+
swiftscan_dependency_result_t *results;
8580
} swiftscan_batch_scan_result_t;
8681

8782
//=== Dependency Result Functions -----------------------------------------===//
8883

84+
SWIFTSCAN_PUBLIC swiftscan_string_t
85+
swiftscan_dependency_result_get_main_module_name(
86+
swiftscan_dependency_result_t result);
87+
88+
SWIFTSCAN_PUBLIC swiftscan_dependency_set_t *
89+
swiftscan_dependency_result_get_module_set(
90+
swiftscan_dependency_result_t result);
91+
92+
//=== Dependency Module Info Functions ------------------------------------===//
93+
8994
SWIFTSCAN_PUBLIC swiftscan_string_t
9095
swiftscan_module_info_get_module_name(swiftscan_dependency_info_t info);
9196

@@ -101,6 +106,8 @@ swiftscan_module_info_get_direct_dependencies(swiftscan_dependency_info_t info);
101106
SWIFTSCAN_PUBLIC swiftscan_module_details_t
102107
swiftscan_module_info_get_details(swiftscan_dependency_info_t info);
103108

109+
//=== Dependency Module Info Details Functions ----------------------------===//
110+
104111
SWIFTSCAN_PUBLIC swiftscan_dependency_info_kind_t
105112
swiftscan_module_detail_get_kind(swiftscan_module_details_t details);
106113

@@ -215,7 +222,7 @@ SWIFTSCAN_PUBLIC swiftscan_scanner_t swiftscan_scanner_create(void);
215222

216223
SWIFTSCAN_PUBLIC void swiftscan_scanner_dispose(swiftscan_scanner_t);
217224

218-
SWIFTSCAN_PUBLIC swiftscan_dependency_result_t *
225+
SWIFTSCAN_PUBLIC swiftscan_dependency_result_t
219226
swiftscan_scan_dependencies(swiftscan_scanner_t *scanner,
220227
const char *working_directory, int argc,
221228
const char *const *argv);

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
#include "swift-c/DependencyScan/DependencyScan.h"
2020
#include "swift/DependencyScan/DependencyScanningTool.h"
2121

22+
typedef struct {
23+
/// The name of the main module for this dependency graph (root node)
24+
swiftscan_string_t main_module_name;
25+
26+
/// The complete list of modules discovered
27+
swiftscan_dependency_set_t *module_set;
28+
} swiftscan_impl_dependency_result_t;
29+
2230
typedef struct {
2331
/// The module's name
2432
/// The format is:
@@ -160,4 +168,15 @@ wrap_info(const swiftscan_impl_dependency_info_t *P) {
160168
const_cast<swiftscan_impl_dependency_info_t *>(P));
161169
}
162170

171+
inline swiftscan_impl_dependency_result_t *
172+
unwrap_result(swiftscan_dependency_result_t P) {
173+
return reinterpret_cast<swiftscan_impl_dependency_result_t *>(P);
174+
}
175+
176+
inline swiftscan_dependency_result_t
177+
wrap_result(const swiftscan_impl_dependency_result_t *P) {
178+
return reinterpret_cast<swiftscan_dependency_result_t>(
179+
const_cast<swiftscan_impl_dependency_result_t *>(P));
180+
}
181+
163182
#endif // SWIFT_C_DEPENDENCY_SCAN_IMPL_H

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DependencyScanningTool {
3636
///
3737
/// \returns a \c StringError with the diagnostic output if errors
3838
/// occurred, \c swiftscan_dependency_result_t otherwise.
39-
llvm::ErrorOr<swiftscan_dependency_result_t*>
39+
llvm::ErrorOr<swiftscan_dependency_result_t>
4040
getDependencies(ArrayRef<const char *> Command,
4141
const llvm::StringSet<> &PlaceholderModules);
4242

@@ -52,7 +52,7 @@ class DependencyScanningTool {
5252
/// BatchScanInput-specified output locations.
5353
///
5454
/// \returns a \c std::error_code if errors occured during scan.
55-
std::vector<llvm::ErrorOr<swiftscan_dependency_result_t*>>
55+
std::vector<llvm::ErrorOr<swiftscan_dependency_result_t>>
5656
getDependencies(ArrayRef<const char *> Command,
5757
const std::vector<BatchScanInput> &BatchInput,
5858
const llvm::StringSet<> &PlaceholderModules);

include/swift/DependencyScan/ScanDependencies.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool batchPrescanDependencies(CompilerInstance &instance,
5454

5555
// MARK: Dependency scanning execution
5656
/// Scans the dependencies of the main module of \c instance.
57-
llvm::ErrorOr<swiftscan_dependency_result_t*>
57+
llvm::ErrorOr<swiftscan_dependency_result_t>
5858
performModuleScan(CompilerInstance &instance,
5959
ModuleDependenciesCache &cache);
6060

@@ -63,7 +63,7 @@ llvm::ErrorOr<swiftscan_prescan_result_t*>
6363
performModulePrescan(CompilerInstance &instance);
6464

6565
/// Batch scan the dependencies for modules specified in \c batchInputFile.
66-
std::vector<llvm::ErrorOr<swiftscan_dependency_result_t*>>
66+
std::vector<llvm::ErrorOr<swiftscan_dependency_result_t>>
6767
performBatchModuleScan(CompilerInstance &instance,
6868
ModuleDependenciesCache &cache, llvm::StringSaver &saver,
6969
const std::vector<BatchScanInput> &BatchInput);

0 commit comments

Comments
 (0)