Skip to content

[Frontend] Add some printing/vistation options to swift-synthesize-interface. #77574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,15 @@ def omit_extension_block_symbols: Flag<["-"], "omit-extension-block-symbols">,
NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
HelpText<"Directly associate members and conformances with the extended nominal when generating symbol graphs instead of emitting 'swift.extension' symbols for extensions to external types">;

// swift-synthesize-interface-only options
def include_submodules : Flag<["-"], "include-submodules">,
Flags<[NoDriverOption, SwiftSynthesizeInterfaceOption]>,
HelpText<"Also print the declarations synthesized for any Clang submodules">;

def print_fully_qualified_types : Flag<["-"], "print-fully-qualified-types">,
Flags<[NoDriverOption, SwiftSynthesizeInterfaceOption]>,
HelpText<"Always print fully qualified type names">;

// swift-symbolgraph-extract-only options
def output_dir : Separate<["-"], "output-dir">,
Flags<[NoDriverOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption,
Expand Down
14 changes: 11 additions & 3 deletions lib/DriverTool/swift_synthesize_interface_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,19 @@ int swift_synthesize_interface_main(ArrayRef<const char *> Args,
return EXIT_FAILURE;
}

StreamPrinter printer(fs);
PrintOptions printOpts =
PrintOptions::printModuleInterface(/*printFullConvention=*/true);
ide::printModuleInterface(M, /*GroupNames=*/{},
/*TraversalOptions=*/std::nullopt, printer,
if (ParsedArgs.hasArg(OPT_print_fully_qualified_types)) {
printOpts.FullyQualifiedTypes = true;
}

swift::OptionSet<swift::ide::ModuleTraversal> traversalOpts = std::nullopt;
if (ParsedArgs.hasArg(OPT_include_submodules)) {
traversalOpts = swift::ide::ModuleTraversal::VisitSubmodules;
}

StreamPrinter printer(fs);
ide::printModuleInterface(M, /*GroupNames=*/{}, traversalOpts, printer,
printOpts, /*PrintSynthesizedExtensions=*/false);

return EXIT_SUCCESS;
Expand Down
3 changes: 3 additions & 0 deletions test/SynthesizeInterfaceTool/Inputs/ExplicitSubmodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct ExplicitSubmoduleStruct {
int value;
};
3 changes: 3 additions & 0 deletions test/SynthesizeInterfaceTool/Inputs/ImplicitSubmodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct ImplicitSubmoduleStruct {
int value;
};
3 changes: 3 additions & 0 deletions test/SynthesizeInterfaceTool/Inputs/TopLevelModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct TopLevelModuleStruct {
int value;
};
12 changes: 12 additions & 0 deletions test/SynthesizeInterfaceTool/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ module mcxx {
requires cplusplus
header "mcxx.h"
}

module TopLevelModule {
header "TopLevelModule.h"

module ImplicitSubmodule {
header "ImplicitSubmodule.h"
}

explicit module ExplicitSubmodule {
header "ExplicitSubmodule.h"
}
}
10 changes: 10 additions & 0 deletions test/SynthesizeInterfaceTool/fully-qualified-types.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-swift-synthesize-interface -module-name m1 -print-fully-qualified-types -I %S/Inputs -o - | %FileCheck %s

// CHECK: public struct MyStruct {
// CHECK-DAG: public init()
// CHECK-DAG: public init(value: Swift.Int32)
// CHECK-DAG: public var value: Swift.Int32
// CHECK-DAG: }
// CHECK-DAG: extension m1.MyStruct {
// CHECK-DAG: public func printValue()
// CHECK-DAG: }
39 changes: 39 additions & 0 deletions test/SynthesizeInterfaceTool/include-submodules.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %target-swift-synthesize-interface -module-name TopLevelModule -I %S/Inputs -o - | %FileCheck %s
// RUN: %target-swift-synthesize-interface -module-name TopLevelModule -include-submodules -I %S/Inputs -o - | %FileCheck %s --check-prefix=IMPLICIT
// RUN: %target-swift-synthesize-interface -module-name TopLevelModule.ExplicitSubmodule -I %S/Inputs -o - | %FileCheck %s --check-prefix=EXPLICIT

// CHECK: import TopLevelModule.ExplicitSubmodule
// CHECK-DAG: import TopLevelModule.ImplicitSubmodule
// CHECK-DAG: public struct TopLevelModuleStruct {
// CHECK-DAG: public init()
// CHECK-DAG: public init(value: Int32)
// CHECK-DAG: public var value: Int32
// CHECK-DAG: }

// CHECK-NOT: ImplicitModuleStruct
// CHECK-NOT: ExplicitModuleStruct

// IMPLICIT: import TopLevelModule.ExplicitSubmodule
// IMPLICIT-DAG: import TopLevelModule.ImplicitSubmodule
// IMPLICIT-DAG: public struct TopLevelModuleStruct {
// IMPLICIT-DAG: public init()
// IMPLICIT-DAG: public init(value: Int32)
// IMPLICIT-DAG: public var value: Int32
// IMPLICIT-DAG: }
// IMPLICIT-DAG: public struct ImplicitSubmoduleStruct {
// IMPLICIT-DAG: public init()
// IMPLICIT-DAG: public init(value: Int32)
// IMPLICIT-DAG: public var value: Int32
// IMPLICIT-DAG: }

// IMPLICIT-NOT: ExplicitSubmoduleStruct

// EXPLICIT: public struct ExplicitSubmoduleStruct {
// EXPLICIT-DAG: public init()
// EXPLICIT-DAG: public init(value: Int32)
// EXPLICIT-DAG: public var value: Int32
// EXPLICIT-DAG: }

// EXPLICIT-NOT: import TopLevelModule{{.*}}
// EXPLICIT-NOT: TopLevelModuleStruct
// EXPLICIT-NOT: ImplicitModuleStruct