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.
|
/// Whether to skip printing 'import' declarations.
|
||||||
bool SkipImports = false;
|
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
|
/// Whether to skip printing overrides and witnesses for
|
||||||
/// protocol requirements.
|
/// protocol requirements.
|
||||||
bool SkipOverrides = false;
|
bool SkipOverrides = false;
|
||||||
|
|||||||
@@ -913,10 +913,12 @@ private:
|
|||||||
void printPatternType(const Pattern *P);
|
void printPatternType(const Pattern *P);
|
||||||
void printAccessors(const AbstractStorageDecl *ASD);
|
void printAccessors(const AbstractStorageDecl *ASD);
|
||||||
void printSelfAccessKindModifiersIfNeeded(const FuncDecl *FD);
|
void printSelfAccessKindModifiersIfNeeded(const FuncDecl *FD);
|
||||||
void printMembersOfDecl(Decl * NTD, bool needComma = false,
|
void printMembersOfDecl(Decl *NTD, bool needComma = false,
|
||||||
bool openBracket = true, bool closeBracket = true);
|
bool openBracket = true, bool closeBracket = true,
|
||||||
|
bool doIndent = true);
|
||||||
void printMembers(ArrayRef<Decl *> members, bool needComma = false,
|
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 printGenericDeclGenericParams(GenericContext *decl);
|
||||||
void printDeclGenericRequirements(GenericContext *decl);
|
void printDeclGenericRequirements(GenericContext *decl);
|
||||||
void printPrimaryAssociatedTypes(ProtocolDecl *decl);
|
void printPrimaryAssociatedTypes(ProtocolDecl *decl);
|
||||||
@@ -2378,9 +2380,8 @@ static void addNamespaceMembers(Decl *decl,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAST::printMembersOfDecl(Decl *D, bool needComma,
|
void PrintAST::printMembersOfDecl(Decl *D, bool needComma, bool openBracket,
|
||||||
bool openBracket,
|
bool closeBracket, bool doIndent) {
|
||||||
bool closeBracket) {
|
|
||||||
llvm::SmallVector<Decl *, 16> Members;
|
llvm::SmallVector<Decl *, 16> Members;
|
||||||
auto AddMembers = [&](IterableDeclContext *idc) {
|
auto AddMembers = [&](IterableDeclContext *idc) {
|
||||||
if (Options.PrintCurrentMembersOnly) {
|
if (Options.PrintCurrentMembersOnly) {
|
||||||
@@ -2413,18 +2414,19 @@ void PrintAST::printMembersOfDecl(Decl *D, bool needComma,
|
|||||||
if (isa_and_nonnull<clang::NamespaceDecl>(D->getClangDecl()))
|
if (isa_and_nonnull<clang::NamespaceDecl>(D->getClangDecl()))
|
||||||
addNamespaceMembers(D, Members);
|
addNamespaceMembers(D, Members);
|
||||||
}
|
}
|
||||||
printMembers(Members, needComma, openBracket, closeBracket);
|
printMembers(Members, needComma, openBracket, closeBracket, doIndent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAST::printMembers(ArrayRef<Decl *> members, bool needComma,
|
void PrintAST::printMembers(ArrayRef<Decl *> members, bool needComma,
|
||||||
bool openBracket, bool closeBracket) {
|
bool openBracket, bool closeBracket,
|
||||||
|
bool doIndent) {
|
||||||
if (openBracket) {
|
if (openBracket) {
|
||||||
Printer << " {";
|
Printer << " {";
|
||||||
if (!Options.PrintEmptyMembersOnSameLine || !members.empty())
|
if (!Options.PrintEmptyMembersOnSameLine || !members.empty())
|
||||||
Printer.printNewline();
|
Printer.printNewline();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
IndentRAII indentMore(*this);
|
IndentRAII indentMore(*this, /*DoIndent=*/doIndent);
|
||||||
for (auto i = members.begin(), iEnd = members.end(); i != iEnd; ++i) {
|
for (auto i = members.begin(), iEnd = members.end(); i != iEnd; ++i) {
|
||||||
auto member = *i;
|
auto member = *i;
|
||||||
|
|
||||||
@@ -3713,6 +3715,13 @@ void PrintAST::visitEnumDecl(EnumDecl *decl) {
|
|||||||
if (!Printer.shouldPrintRedeclaredClangDecl(
|
if (!Printer.shouldPrintRedeclaredClangDecl(
|
||||||
namespaceDecl->getOriginalNamespace()))
|
namespaceDecl->getOriginalNamespace()))
|
||||||
return;
|
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);
|
printDocumentationComment(decl);
|
||||||
printAttributes(decl);
|
printAttributes(decl);
|
||||||
@@ -6003,6 +6012,20 @@ public:
|
|||||||
return;
|
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;
|
PrintOptions innerOptions = Options;
|
||||||
innerOptions.SynthesizeSugarOnTypes = false;
|
innerOptions.SynthesizeSugarOnTypes = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1149,6 +1149,7 @@ void swift::ide::printSymbolicSwiftClangModuleInterface(
|
|||||||
PrintOptions::printModuleInterface(/*printFullConvention=*/false);
|
PrintOptions::printModuleInterface(/*printFullConvention=*/false);
|
||||||
popts.PrintDocumentationComments = false;
|
popts.PrintDocumentationComments = false;
|
||||||
popts.PrintRegularClangComments = false;
|
popts.PrintRegularClangComments = false;
|
||||||
|
popts.SkipInlineCXXNamespace = true;
|
||||||
|
|
||||||
auto &SwiftContext = M->getTopLevelModule()->getASTContext();
|
auto &SwiftContext = M->getTopLevelModule()->getASTContext();
|
||||||
auto &Importer =
|
auto &Importer =
|
||||||
|
|||||||
@@ -81,6 +81,15 @@ namespace ns {
|
|||||||
|
|
||||||
InnerTemplate<int> returnsTemplateMethod();
|
InnerTemplate<int> returnsTemplateMethod();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline namespace __1 {
|
||||||
|
struct StructInInlineNamespace {
|
||||||
|
};
|
||||||
|
|
||||||
|
using TypealiasInInlineNamespace = TemplateRecord<StructInInlineNamespace>;
|
||||||
|
}
|
||||||
|
|
||||||
|
using TypealiasOfInlineNamespace = __1::StructInInlineNamespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
using MyType = ns::TemplateRecord<int>;
|
using MyType = ns::TemplateRecord<int>;
|
||||||
@@ -128,6 +137,15 @@ import CxxModule
|
|||||||
// CHECK-EMPTY:
|
// CHECK-EMPTY:
|
||||||
// CHECK-NEXT: mutating func returnsTemplateMethod()
|
// CHECK-NEXT: mutating func returnsTemplateMethod()
|
||||||
// CHECK-NEXT: }
|
// 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-EMPTY:
|
||||||
// CHECK-NEXT: static func freeFunction(_ x: Int32, _ y: Int32) -> Int32
|
// CHECK-NEXT: static func freeFunction(_ x: Int32, _ y: Int32) -> Int32
|
||||||
// CHECK-NEXT: }
|
// CHECK-NEXT: }
|
||||||
|
|||||||
@@ -291,9 +291,12 @@ static bool getModuleInterfaceInfo(ASTContext &Ctx,
|
|||||||
PrintOptions Options = PrintOptions::printModuleInterface(
|
PrintOptions Options = PrintOptions::printModuleInterface(
|
||||||
Ctx.TypeCheckerOpts.PrintFullConvention);
|
Ctx.TypeCheckerOpts.PrintFullConvention);
|
||||||
if (Mod->findUnderlyingClangModule()) {
|
if (Mod->findUnderlyingClangModule()) {
|
||||||
// Show unavailable C++ APIs.
|
if (Ctx.LangOpts.EnableCXXInterop) {
|
||||||
if (Ctx.LangOpts.EnableCXXInterop)
|
// Show unavailable C++ APIs.
|
||||||
Options.SkipUnavailable = false;
|
Options.SkipUnavailable = false;
|
||||||
|
// Skip over inline namespaces.
|
||||||
|
Options.SkipInlineCXXNamespace = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ModuleTraversalOptions TraversalOptions = None; // Don't print submodules.
|
ModuleTraversalOptions TraversalOptions = None; // Don't print submodules.
|
||||||
SmallString<128> Text;
|
SmallString<128> Text;
|
||||||
|
|||||||
Reference in New Issue
Block a user