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

The `-include-submodules` flag causes the synthesized interface to include
implicit Clang submodules of the module being printed. Since these are
automatically made visible when importing the corresponding top-level module,
it's often useful to have them present in the same synthesized Swift
interface instead of having to make separate invocations to get each
submodule separately.

The `-print-fully-qualified-types` causes type names to be printed with
full module qualification. This is useful when using the synthesized
interface for some other kind of analysis, because it ensures that all
type references explicitly indicate which module they came from, instead
of having to guess scoping and import resolution rules to figure out
which module a reference comes from.
This commit is contained in:
Tony Allevato
2024-11-10 12:01:42 -05:00
parent aab880da05
commit 0d7bc4d0f5
8 changed files with 90 additions and 3 deletions

View File

@@ -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;