[cxx-interop][index] emit symbolic interface files for C++ modules

This commit is contained in:
Alex Lorenz
2023-01-31 12:01:09 -08:00
parent f36e5cf641
commit d4aa18ab9f
11 changed files with 469 additions and 1 deletions

View File

@@ -544,6 +544,18 @@ void swift::ide::printModuleInterface(
auto &SwiftContext = TopLevelMod->getASTContext();
auto &Importer =
static_cast<ClangImporter &>(*SwiftContext.getClangModuleLoader());
if (Options.PrintSymbolicCXXDecls)
Importer.enableSymbolicImportFeature(true);
struct SymbolicImportRAII {
bool PrintSymbolicCXXDecls;
ClangImporter &Importer;
SymbolicImportRAII(bool PrintSymbolicCXXDecls, ClangImporter &Importer)
: PrintSymbolicCXXDecls(PrintSymbolicCXXDecls), Importer(Importer) {}
~SymbolicImportRAII() {
if (PrintSymbolicCXXDecls)
Importer.enableSymbolicImportFeature(false);
}
} deferDisableSymbolicImport(Options.PrintSymbolicCXXDecls, Importer);
auto AdjustedOptions = Options;
adjustPrintOptions(AdjustedOptions);
@@ -1134,3 +1146,22 @@ void ClangCommentPrinter::updateLastEntityLine(clang::FileID FID,
if (LineNo > LastEntiyLine)
LastEntiyLine = LineNo;
}
void swift::ide::printSymbolicSwiftClangModuleInterface(
ModuleDecl *M, ASTPrinter &Printer, const clang::Module *clangModule) {
std::string headerComment;
llvm::raw_string_ostream(headerComment)
<< "// Swift interface for " << (clangModule->IsSystem ? "system " : "")
<< "module '" << clangModule->Name << "'\n";
Printer.printText(headerComment);
ModuleTraversalOptions opts;
opts |= ModuleTraversal::VisitSubmodules;
auto popts =
PrintOptions::printModuleInterface(/*printFullConvention=*/false);
popts.PrintSymbolicCXXDecls = true;
popts.PrintDocumentationComments = false;
popts.PrintRegularClangComments = false;
printModuleInterface(M, {}, opts, Printer, popts,
/*SynthesizeExtensions=*/false);
}