21
21
using namespace swift ;
22
22
using namespace symbolgraphgen ;
23
23
24
+ namespace {
25
+
26
+ // / Compare the two \c ModuleDecl instances to see whether they are the same.
27
+ // /
28
+ // / Pass \c true to the \c ignoreUnderlying argument to consider two modules the same even if
29
+ // / one is a Swift module and the other a non-Swift module. This allows a Swift module and its
30
+ // / underlying Clang module to compare as equal.
31
+ bool areModulesEqual (const ModuleDecl *lhs, const ModuleDecl *rhs, bool ignoreUnderlying = false ) {
32
+ return lhs->getNameStr () == rhs->getNameStr ()
33
+ && (ignoreUnderlying || lhs->isNonSwiftModule () == rhs->isNonSwiftModule ());
34
+ }
35
+
36
+ } // anonymous namespace
37
+
24
38
SymbolGraphASTWalker::SymbolGraphASTWalker (ModuleDecl &M,
25
39
const SmallPtrSet<ModuleDecl *, 4 > ExportedImportedModules,
26
40
const SymbolGraphOptions &Options)
@@ -45,10 +59,10 @@ SymbolGraph *SymbolGraphASTWalker::getModuleSymbolGraph(const Decl *D) {
45
59
}
46
60
}
47
61
48
- if (this ->M . getNameStr (). equals (M-> getNameStr () )) {
62
+ if (areModulesEqual (& this ->M , M, true )) {
49
63
return &MainGraph;
50
64
} else if (MainGraph.DeclaringModule .hasValue () &&
51
- MainGraph.DeclaringModule .getValue ()-> getNameStr (). equals (M-> getNameStr () )) {
65
+ areModulesEqual ( MainGraph.DeclaringModule .getValue (), M, true )) {
52
66
// Cross-import overlay modules already appear as "extensions" of their declaring module; we
53
67
// should put actual extensions of that module into the main graph
54
68
return &MainGraph;
@@ -220,6 +234,6 @@ bool SymbolGraphASTWalker::isFromExportedImportedModule(const Decl* D) const {
220
234
auto *M = D->getModuleContext ();
221
235
222
236
return llvm::any_of (ExportedImportedModules, [&M](const auto *MD) {
223
- return M-> getNameStr (). equals ( MD->getModuleContext ()-> getNameStr ());
237
+ return areModulesEqual (M, MD->getModuleContext ());
224
238
});
225
239
}
0 commit comments