Skip to content

Commit a5a58d3

Browse files
committed
Swift: start with loaded modules for extraction
1 parent 0971ca6 commit a5a58d3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

swift/extractor/SwiftExtractor.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,20 @@ static std::unordered_set<std::string> collectInputFilenames(swift::CompilerInst
180180
return sourceFiles;
181181
}
182182

183+
static std::vector<swift::ModuleDecl*> collectLoadedModules(swift::CompilerInstance& compiler) {
184+
std::vector<swift::ModuleDecl*> ret;
185+
for (const auto& [id, module] : compiler.getASTContext().getLoadedModules()) {
186+
std::ignore = id;
187+
ret.push_back(module);
188+
}
189+
return ret;
190+
}
191+
183192
void codeql::extractSwiftFiles(const SwiftExtractorConfiguration& config,
184193
swift::CompilerInstance& compiler) {
185194
auto inputFiles = collectInputFilenames(compiler);
186-
std::vector<swift::ModuleDecl*> todo = {compiler.getMainModule()};
187-
std::unordered_set<swift::ModuleDecl*> seen = {compiler.getMainModule()};
195+
std::vector<swift::ModuleDecl*> todo = collectLoadedModules(compiler);
196+
std::unordered_set<swift::ModuleDecl*> seen{todo.begin(), todo.end()};
188197

189198
while (!todo.empty()) {
190199
auto module = todo.back();

0 commit comments

Comments
 (0)