Skip to content

Commit ca16944

Browse files
committed
[Dependency Scanning] Export opaque types as pointers to C structs instead of void* for better type-safety and cleaner code
1 parent 108e9da commit ca16944

File tree

4 files changed

+96
-188
lines changed

4 files changed

+96
-188
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ typedef enum {
4242
} swiftscan_dependency_info_kind_t;
4343

4444
/// Opaque container of the details specific to a given module dependency.
45-
typedef void *swiftscan_module_details_t;
45+
typedef struct swiftscan_module_details_s *swiftscan_module_details_t;
4646

4747
/// Opaque container to a dependency info of a given module.
48-
typedef void *swiftscan_dependency_info_t;
48+
typedef struct swiftscan_dependency_info_s *swiftscan_dependency_info_t;
4949

5050
/// Opaque container to an overall result of a dependency scan.
51-
typedef void *swiftscan_dependency_result_t;
51+
typedef struct swiftscan_dependency_result_s *swiftscan_dependency_result_t;
5252

5353
/// Opaque container to contain the result of a dependency prescan.
54-
typedef void *swiftscan_prescan_result_t;
54+
typedef struct swiftscan_prescan_result_s *swiftscan_prescan_result_t;
5555

5656
/// Full Dependency Graph (Result)
5757
typedef struct {
@@ -62,7 +62,7 @@ typedef struct {
6262
//=== Batch Scan Input Specification --------------------------------------===//
6363

6464
/// Opaque container to a container of batch scan entry information.
65-
typedef void *swiftscan_batch_scan_entry_t;
65+
typedef struct swiftscan_batch_scan_entry_s *swiftscan_batch_scan_entry_t;
6666

6767
typedef struct {
6868
int count;
@@ -78,7 +78,7 @@ typedef struct {
7878

7979
/// Opaque container of all relevant context required to launch a dependency
8080
/// scan (command line arguments, working directory, etc.)
81-
typedef void *swiftscan_scan_invocation_t;
81+
typedef struct swiftscan_scan_invocation_s *swiftscan_scan_invocation_t;
8282

8383
//=== Dependency Result Functions -----------------------------------------===//
8484

include/swift/DependencyScan/DependencyScanImpl.h

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

22-
typedef struct {
22+
struct swiftscan_dependency_result_s {
2323
/// The name of the main module for this dependency graph (root node)
2424
swiftscan_string_t main_module_name;
2525

2626
/// The complete list of modules discovered
2727
swiftscan_dependency_set_t *module_set;
28-
} swiftscan_impl_dependency_result_t;
28+
};
2929

30-
typedef struct {
30+
struct swiftscan_dependency_info_s {
3131
/// The module's name
3232
/// The format is:
3333
/// `<module-kind>:<module-name>`
@@ -53,7 +53,7 @@ typedef struct {
5353

5454
/// Specific details of a particular kind of module.
5555
swiftscan_module_details_t details;
56-
} swiftscan_impl_dependency_info_t;
56+
};
5757

5858
/// Swift modules to be built from a module interface, may have a bridging
5959
/// header.
@@ -125,31 +125,31 @@ typedef struct {
125125
swiftscan_string_set_t *command_line;
126126
} swiftscan_clang_details_t;
127127

128-
typedef struct {
128+
struct swiftscan_module_details_s {
129129
swiftscan_dependency_info_kind_t kind;
130130
union {
131131
swiftscan_swift_textual_details_t swift_textual_details;
132132
swiftscan_swift_binary_details_t swift_binary_details;
133133
swiftscan_swift_placeholder_details_t swift_placeholder_details;
134134
swiftscan_clang_details_t clang_details;
135135
};
136-
} swiftscan_impl_module_details_t;
136+
} ;
137137

138-
typedef struct {
138+
struct swiftscan_batch_scan_entry_s {
139139
swiftscan_string_t module_name;
140140
swiftscan_string_t arguments;
141141
bool is_swift;
142-
} swiftscan_impl_batch_scan_entry_t;
142+
};
143143

144-
typedef struct {
144+
struct swiftscan_prescan_result_s {
145145
/// The complete list of imports discovered
146146
swiftscan_string_set_t *import_set;
147-
} swiftscan_impl_prescan_result_t;
147+
};
148148

149-
typedef struct {
149+
struct swiftscan_scan_invocation_s {
150150
swiftscan_string_t working_directory;
151151
swiftscan_string_set_t *argv;
152-
} swiftscan_impl_scan_invocation_t;
152+
};
153153

154154
inline swift::dependencies::DependencyScanningTool *
155155
unwrap_scanner(swiftscan_scanner_t P) {
@@ -162,70 +162,4 @@ wrap_scanner(const swift::dependencies::DependencyScanningTool *P) {
162162
const_cast<swift::dependencies::DependencyScanningTool *>(P));
163163
}
164164

165-
inline swiftscan_impl_module_details_t *
166-
unwrap_details(swiftscan_module_details_t P) {
167-
return reinterpret_cast<swiftscan_impl_module_details_t *>(P);
168-
}
169-
170-
inline swiftscan_module_details_t
171-
wrap_details(const swiftscan_impl_module_details_t *P) {
172-
return reinterpret_cast<swiftscan_module_details_t>(
173-
const_cast<swiftscan_impl_module_details_t *>(P));
174-
}
175-
176-
inline swiftscan_impl_dependency_info_t *
177-
unwrap_info(swiftscan_dependency_info_t P) {
178-
return reinterpret_cast<swiftscan_impl_dependency_info_t *>(P);
179-
}
180-
181-
inline swiftscan_dependency_info_t
182-
wrap_info(const swiftscan_impl_dependency_info_t *P) {
183-
return reinterpret_cast<swiftscan_dependency_info_t>(
184-
const_cast<swiftscan_impl_dependency_info_t *>(P));
185-
}
186-
187-
inline swiftscan_impl_dependency_result_t *
188-
unwrap_result(swiftscan_dependency_result_t P) {
189-
return reinterpret_cast<swiftscan_impl_dependency_result_t *>(P);
190-
}
191-
192-
inline swiftscan_dependency_result_t
193-
wrap_result(const swiftscan_impl_dependency_result_t *P) {
194-
return reinterpret_cast<swiftscan_dependency_result_t>(
195-
const_cast<swiftscan_impl_dependency_result_t *>(P));
196-
}
197-
198-
inline swiftscan_impl_prescan_result_t *
199-
unwrap_prescan_result(swiftscan_prescan_result_t P) {
200-
return reinterpret_cast<swiftscan_impl_prescan_result_t *>(P);
201-
}
202-
203-
inline swiftscan_prescan_result_t
204-
wrap_prescan_result(const swiftscan_impl_prescan_result_t *P) {
205-
return reinterpret_cast<swiftscan_prescan_result_t>(
206-
const_cast<swiftscan_impl_prescan_result_t *>(P));
207-
}
208-
209-
inline swiftscan_impl_batch_scan_entry_t *
210-
unwrap_batch_entry(swiftscan_batch_scan_entry_t P) {
211-
return reinterpret_cast<swiftscan_impl_batch_scan_entry_t *>(P);
212-
}
213-
214-
inline swiftscan_batch_scan_entry_t
215-
wrap_batch_entry(const swiftscan_impl_batch_scan_entry_t *P) {
216-
return reinterpret_cast<swiftscan_batch_scan_entry_t>(
217-
const_cast<swiftscan_impl_batch_scan_entry_t *>(P));
218-
}
219-
220-
inline swiftscan_impl_scan_invocation_t *
221-
unwrap_scan_invocation(swiftscan_scan_invocation_t P) {
222-
return reinterpret_cast<swiftscan_impl_scan_invocation_t *>(P);
223-
}
224-
225-
inline swiftscan_batch_scan_entry_t
226-
wrap_scan_invocation(const swiftscan_impl_scan_invocation_t *P) {
227-
return reinterpret_cast<swiftscan_scan_invocation_t>(
228-
const_cast<swiftscan_impl_scan_invocation_t *>(P));
229-
}
230-
231165
#endif // SWIFT_C_DEPENDENCY_SCAN_IMPL_H

0 commit comments

Comments
 (0)