Files
swift-mirror/test/SynthesizeInterfaceTool/synthesize-interface-swift.swift
Tony Allevato 2cfcdd8ed1 Add a new driver tool/mode to print the synthesized Swift interface for a module.
This mode is similar to `swift-symbolgraph-extract`; it takes a subset of compiler
flags to configure the invocation for module loading, as well as a module name
whose contents should be extracted. It does not take any other input files. The
output is a single text file specified by `-o` (or `stdout` if not specified).

While the most common use case for this would be viewing the synthesized Swift
interface for a Clang module, since the implementation simply calls
`swift::ide::printModuleInterface` under the hood, it's usable for any module
that Swift can import. Thus, it could also be used to view a synthesized textual
representation of, say, a compiled `.swiftmodule`.

One could imagine that in the future, we might add more flags to
`swift-synthesize-interface` to modify various `PrintOptions` used when
generating the output, if we think those would be useful.
2024-10-10 15:30:41 -04:00

24 lines
695 B
Swift

// Emit the Swift module.
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -module-name MyModule -o %t/MyModule.swiftmodule %s
// Invoke the frontend with the module on the import path.
// RUN: %target-swift-synthesize-interface -module-name MyModule -I %t -o - | %FileCheck %s
public struct MyStruct {
// CHECK: public struct MyStruct {
public private(set) var value: Int
// CHECK-DAG: public private(set) var value: Int { get }
public init(value: Int = 0) {
// CHECK-DAG: public init(value: Int = 0)
self.value = value
}
public func printValue() {
// CHECK-DAG: public func printValue()
print(self.value)
}
}
// CHECK-DAG: }