88#include < swift/AST/SourceFile.h>
99#include < swift/AST/Builtins.h>
1010
11- #include " swift/extractor/trap/TrapDomain.h"
1211#include " swift/extractor/translators/SwiftVisitor.h"
13- #include " swift/extractor/TargetTrapFile .h"
12+ #include " swift/extractor/infra/TargetDomains .h"
1413#include " swift/extractor/SwiftBuiltinSymbols.h"
1514#include " swift/extractor/infra/file/Path.h"
1615
@@ -109,21 +108,24 @@ static llvm::SmallVector<swift::Decl*> getTopLevelDecls(swift::ModuleDecl& modul
109108}
110109
111110static std::unordered_set<swift::ModuleDecl*> extractDeclarations (
112- const SwiftExtractorConfiguration& config ,
111+ SwiftExtractorState& state ,
113112 swift::CompilerInstance& compiler,
114113 swift::ModuleDecl& module ,
115114 swift::SourceFile* primaryFile = nullptr ) {
116115 auto filename = getFilename (module , primaryFile);
116+ if (primaryFile) {
117+ state.sourceFiles .push_back (filename);
118+ }
117119
118120 // The extractor can be called several times from different processes with
119121 // the same input file(s). Using `TargetFile` the first process will win, and the following
120122 // will just skip the work
121- auto trapTarget = createTargetTrapFile (config, filename);
122- if (!trapTarget) {
123+ const auto trapType = primaryFile ? TrapType::source : TrapType::module ;
124+ auto trap = createTargetTrapDomain (state, filename, trapType);
125+ if (!trap) {
123126 // another process arrived first, nothing to do for us
124127 return {};
125128 }
126- TrapDomain trap{*trapTarget};
127129
128130 std::vector<swift::Token> comments;
129131 if (primaryFile && primaryFile->getBufferID ().hasValue ()) {
@@ -137,7 +139,7 @@ static std::unordered_set<swift::ModuleDecl*> extractDeclarations(
137139 }
138140 }
139141
140- SwiftVisitor visitor (compiler.getSourceMgr (), trap, module , primaryFile);
142+ SwiftVisitor visitor (compiler.getSourceMgr (), * trap, module , primaryFile);
141143 auto topLevelDecls = getTopLevelDecls (module , primaryFile);
142144 for (auto decl : topLevelDecls) {
143145 visitor.extract (decl);
@@ -171,11 +173,10 @@ static std::vector<swift::ModuleDecl*> collectLoadedModules(swift::CompilerInsta
171173 return ret;
172174}
173175
174- void codeql::extractSwiftFiles (const SwiftExtractorConfiguration& config,
175- swift::CompilerInstance& compiler) {
176+ void codeql::extractSwiftFiles (SwiftExtractorState& state, swift::CompilerInstance& compiler) {
176177 auto inputFiles = collectInputFilenames (compiler);
177178 std::vector<swift::ModuleDecl*> todo = collectLoadedModules (compiler);
178- std::unordered_set<swift::ModuleDecl*> seen{ todo.begin (), todo.end ()} ;
179+ state. encounteredModules . insert ( todo.begin (), todo.end ()) ;
179180
180181 while (!todo.empty ()) {
181182 auto module = todo.back ();
@@ -191,16 +192,16 @@ void codeql::extractSwiftFiles(const SwiftExtractorConfiguration& config,
191192 if (inputFiles.count (sourceFile->getFilename ().str ()) == 0 ) {
192193 continue ;
193194 }
194- archiveFile (config , *sourceFile);
195- encounteredModules = extractDeclarations (config , compiler, *module , sourceFile);
195+ archiveFile (state. configuration , *sourceFile);
196+ encounteredModules = extractDeclarations (state , compiler, *module , sourceFile);
196197 }
197198 if (!isFromSourceFile) {
198- encounteredModules = extractDeclarations (config , compiler, *module );
199+ encounteredModules = extractDeclarations (state , compiler, *module );
199200 }
200201 for (auto encountered : encounteredModules) {
201- if (seen .count (encountered) == 0 ) {
202+ if (state. encounteredModules .count (encountered) == 0 ) {
202203 todo.push_back (encountered);
203- seen .insert (encountered);
204+ state. encounteredModules .insert (encountered);
204205 }
205206 }
206207 }
0 commit comments