mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[interop] do not print inline C++ namespaces when printing module interface
This commit is contained in:
@@ -276,6 +276,10 @@ struct PrintOptions {
|
||||
/// Whether to skip printing 'import' declarations.
|
||||
bool SkipImports = false;
|
||||
|
||||
/// Whether to skip over the C++ inline namespace when printing its members or
|
||||
/// when printing it out as a qualifier.
|
||||
bool SkipInlineCXXNamespace = false;
|
||||
|
||||
/// Whether to skip printing overrides and witnesses for
|
||||
/// protocol requirements.
|
||||
bool SkipOverrides = false;
|
||||
|
||||
@@ -913,10 +913,12 @@ private:
|
||||
void printPatternType(const Pattern *P);
|
||||
void printAccessors(const AbstractStorageDecl *ASD);
|
||||
void printSelfAccessKindModifiersIfNeeded(const FuncDecl *FD);
|
||||
void printMembersOfDecl(Decl * NTD, bool needComma = false,
|
||||
bool openBracket = true, bool closeBracket = true);
|
||||
void printMembersOfDecl(Decl *NTD, bool needComma = false,
|
||||
bool openBracket = true, bool closeBracket = true,
|
||||
bool doIndent = true);
|
||||
void printMembers(ArrayRef<Decl *> members, bool needComma = false,
|
||||
bool openBracket = true, bool closeBracket = true);
|
||||
bool openBracket = true, bool closeBracket = true,
|
||||
bool doIndent = true);
|
||||
void printGenericDeclGenericParams(GenericContext *decl);
|
||||
void printDeclGenericRequirements(GenericContext *decl);
|
||||
void printPrimaryAssociatedTypes(ProtocolDecl *decl);
|
||||
@@ -2378,9 +2380,8 @@ static void addNamespaceMembers(Decl *decl,
|
||||
}
|
||||
}
|
||||
|
||||
void PrintAST::printMembersOfDecl(Decl *D, bool needComma,
|
||||
bool openBracket,
|
||||
bool closeBracket) {
|
||||
void PrintAST::printMembersOfDecl(Decl *D, bool needComma, bool openBracket,
|
||||
bool closeBracket, bool doIndent) {
|
||||
llvm::SmallVector<Decl *, 16> Members;
|
||||
auto AddMembers = [&](IterableDeclContext *idc) {
|
||||
if (Options.PrintCurrentMembersOnly) {
|
||||
@@ -2413,18 +2414,19 @@ void PrintAST::printMembersOfDecl(Decl *D, bool needComma,
|
||||
if (isa_and_nonnull<clang::NamespaceDecl>(D->getClangDecl()))
|
||||
addNamespaceMembers(D, Members);
|
||||
}
|
||||
printMembers(Members, needComma, openBracket, closeBracket);
|
||||
printMembers(Members, needComma, openBracket, closeBracket, doIndent);
|
||||
}
|
||||
|
||||
void PrintAST::printMembers(ArrayRef<Decl *> members, bool needComma,
|
||||
bool openBracket, bool closeBracket) {
|
||||
bool openBracket, bool closeBracket,
|
||||
bool doIndent) {
|
||||
if (openBracket) {
|
||||
Printer << " {";
|
||||
if (!Options.PrintEmptyMembersOnSameLine || !members.empty())
|
||||
Printer.printNewline();
|
||||
}
|
||||
{
|
||||
IndentRAII indentMore(*this);
|
||||
IndentRAII indentMore(*this, /*DoIndent=*/doIndent);
|
||||
for (auto i = members.begin(), iEnd = members.end(); i != iEnd; ++i) {
|
||||
auto member = *i;
|
||||
|
||||
@@ -3713,6 +3715,13 @@ void PrintAST::visitEnumDecl(EnumDecl *decl) {
|
||||
if (!Printer.shouldPrintRedeclaredClangDecl(
|
||||
namespaceDecl->getOriginalNamespace()))
|
||||
return;
|
||||
|
||||
if (Options.SkipInlineCXXNamespace && namespaceDecl->isInline()) {
|
||||
// Print members directly if this is an inline namespace.
|
||||
printMembersOfDecl(decl, false, /*openBracket=*/false,
|
||||
/*closeBracket=*/false, /*doIndent=*/false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
printDocumentationComment(decl);
|
||||
printAttributes(decl);
|
||||
@@ -6003,6 +6012,20 @@ public:
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Options.SkipInlineCXXNamespace) {
|
||||
// Don't print the parent type if it's a reference to an inline C++
|
||||
// namespace.
|
||||
if (auto *enumTy = T->getAs<EnumType>()) {
|
||||
if (const auto *namespaceDecl = dyn_cast_or_null<clang::NamespaceDecl>(
|
||||
enumTy->getDecl()->getClangDecl())) {
|
||||
if (namespaceDecl->isInline()) {
|
||||
if (auto parent = enumTy->getParent())
|
||||
visitParentType(parent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PrintOptions innerOptions = Options;
|
||||
innerOptions.SynthesizeSugarOnTypes = false;
|
||||
|
||||
|
||||
@@ -1149,6 +1149,7 @@ void swift::ide::printSymbolicSwiftClangModuleInterface(
|
||||
PrintOptions::printModuleInterface(/*printFullConvention=*/false);
|
||||
popts.PrintDocumentationComments = false;
|
||||
popts.PrintRegularClangComments = false;
|
||||
popts.SkipInlineCXXNamespace = true;
|
||||
|
||||
auto &SwiftContext = M->getTopLevelModule()->getASTContext();
|
||||
auto &Importer =
|
||||
|
||||
@@ -81,6 +81,15 @@ namespace ns {
|
||||
|
||||
InnerTemplate<int> returnsTemplateMethod();
|
||||
};
|
||||
|
||||
inline namespace __1 {
|
||||
struct StructInInlineNamespace {
|
||||
};
|
||||
|
||||
using TypealiasInInlineNamespace = TemplateRecord<StructInInlineNamespace>;
|
||||
}
|
||||
|
||||
using TypealiasOfInlineNamespace = __1::StructInInlineNamespace;
|
||||
}
|
||||
|
||||
using MyType = ns::TemplateRecord<int>;
|
||||
@@ -128,6 +137,15 @@ import CxxModule
|
||||
// CHECK-EMPTY:
|
||||
// CHECK-NEXT: mutating func returnsTemplateMethod()
|
||||
// CHECK-NEXT: }
|
||||
// CHECK: public struct StructInInlineNamespace {
|
||||
// CHECK-EMPTY:
|
||||
// CHECK-NEXT: public init()
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-EMPTY:
|
||||
// CHECK-NEXT: public typealias TypealiasInInlineNamespace = ns.TemplateRecord
|
||||
// CHECK-EMPTY:
|
||||
// CHECK-EMPTY:
|
||||
// CHECK-NEXT: public typealias TypealiasOfInlineNamespace = ns.StructInInlineNamespace
|
||||
// CHECK-EMPTY:
|
||||
// CHECK-NEXT: static func freeFunction(_ x: Int32, _ y: Int32) -> Int32
|
||||
// CHECK-NEXT: }
|
||||
|
||||
@@ -291,9 +291,12 @@ static bool getModuleInterfaceInfo(ASTContext &Ctx,
|
||||
PrintOptions Options = PrintOptions::printModuleInterface(
|
||||
Ctx.TypeCheckerOpts.PrintFullConvention);
|
||||
if (Mod->findUnderlyingClangModule()) {
|
||||
// Show unavailable C++ APIs.
|
||||
if (Ctx.LangOpts.EnableCXXInterop)
|
||||
if (Ctx.LangOpts.EnableCXXInterop) {
|
||||
// Show unavailable C++ APIs.
|
||||
Options.SkipUnavailable = false;
|
||||
// Skip over inline namespaces.
|
||||
Options.SkipInlineCXXNamespace = true;
|
||||
}
|
||||
}
|
||||
ModuleTraversalOptions TraversalOptions = None; // Don't print submodules.
|
||||
SmallString<128> Text;
|
||||
|
||||
Reference in New Issue
Block a user