@@ -151,8 +151,7 @@ static void extractDeclarations(const SwiftExtractorConfiguration& config,
151
151
}
152
152
}
153
153
154
- void codeql::extractSwiftFiles (const SwiftExtractorConfiguration& config,
155
- swift::CompilerInstance& compiler) {
154
+ static std::unordered_set<std::string> collectInputFilenames (swift::CompilerInstance& compiler) {
156
155
// The frontend can be called in many different ways.
157
156
// At each invocation we only extract system and builtin modules and any input source files that
158
157
// have an output associated with them.
@@ -163,7 +162,10 @@ void codeql::extractSwiftFiles(const SwiftExtractorConfiguration& config,
163
162
sourceFiles.insert (input.getFileName ());
164
163
}
165
164
}
165
+ return sourceFiles;
166
+ }
166
167
168
+ static std::unordered_set<swift::ModuleDecl*> collectModules (swift::CompilerInstance& compiler) {
167
169
// getASTContext().getLoadedModules() does not provide all the modules available within the
168
170
// program.
169
171
// We need to iterate over all the imported modules (recursively) to see the whole "universe."
@@ -187,8 +189,15 @@ void codeql::extractSwiftFiles(const SwiftExtractorConfiguration& config,
187
189
}
188
190
}
189
191
}
192
+ return allModules;
193
+ }
194
+
195
+ void codeql::extractSwiftFiles (const SwiftExtractorConfiguration& config,
196
+ swift::CompilerInstance& compiler) {
197
+ auto inputFiles = collectInputFilenames (compiler);
198
+ auto modules = collectModules (compiler);
190
199
191
- for (auto & module : allModules ) {
200
+ for (auto & module : modules ) {
192
201
// We only extract system and builtin modules here as the other "user" modules can be built
193
202
// during the build process and then re-used at a later stage. In this case, we extract the
194
203
// user code twice: once during the module build in a form of a source file, and then as
@@ -201,7 +210,7 @@ void codeql::extractSwiftFiles(const SwiftExtractorConfiguration& config,
201
210
} else {
202
211
for (auto file : module ->getFiles ()) {
203
212
auto sourceFile = llvm::dyn_cast<swift::SourceFile>(file);
204
- if (!sourceFile || sourceFiles .count (sourceFile->getFilename ().str ()) == 0 ) {
213
+ if (!sourceFile || inputFiles .count (sourceFile->getFilename ().str ()) == 0 ) {
205
214
continue ;
206
215
}
207
216
archiveFile (config, *sourceFile);
0 commit comments