|
14 | 14 |
|
15 | 15 | using namespace codeql;
|
16 | 16 |
|
17 |
| -SwiftExtractor::SwiftExtractor(const SwiftExtractorConfiguration& config, |
18 |
| - swift::CompilerInstance& instance) |
19 |
| - : config{config}, compiler{instance} {} |
20 |
| - |
21 |
| -void SwiftExtractor::extract() { |
22 |
| - // Swift frontend can be called in several different modes, we are interested |
23 |
| - // only in the cases when either a primary or a main source file is present |
24 |
| - if (compiler.getPrimarySourceFiles().empty()) { |
25 |
| - swift::ModuleDecl* module = compiler.getMainModule(); |
26 |
| - if (!module->getFiles().empty() && |
27 |
| - module->getFiles().front()->getKind() == swift::FileUnitKind::Source) { |
28 |
| - // We can only call getMainSourceFile if the first file is of a Source kind |
29 |
| - swift::SourceFile& file = module->getMainSourceFile(); |
30 |
| - extractFile(file); |
31 |
| - } |
32 |
| - } else { |
33 |
| - for (auto s : compiler.getPrimarySourceFiles()) { |
34 |
| - extractFile(*s); |
35 |
| - } |
36 |
| - } |
37 |
| -} |
38 |
| - |
39 |
| -void SwiftExtractor::extractFile(swift::SourceFile& file) { |
| 17 | +static void extractFile(const SwiftExtractorConfiguration& config, swift::SourceFile& file) { |
40 | 18 | if (std::error_code ec = llvm::sys::fs::create_directories(config.trapDir)) {
|
41 | 19 | std::cerr << "Cannot create TRAP directory: " << ec.message() << "\n";
|
42 | 20 | return;
|
@@ -103,3 +81,22 @@ void SwiftExtractor::extractFile(swift::SourceFile& file) {
|
103 | 81 | << trapPath.str().str() << "': " << ec.message() << "\n";
|
104 | 82 | }
|
105 | 83 | }
|
| 84 | + |
| 85 | +void codeql::extractSwiftFiles(const SwiftExtractorConfiguration& config, |
| 86 | + swift::CompilerInstance& compiler) { |
| 87 | + // Swift frontend can be called in several different modes, we are interested |
| 88 | + // only in the cases when either a primary or a main source file is present |
| 89 | + if (compiler.getPrimarySourceFiles().empty()) { |
| 90 | + swift::ModuleDecl* module = compiler.getMainModule(); |
| 91 | + if (!module->getFiles().empty() && |
| 92 | + module->getFiles().front()->getKind() == swift::FileUnitKind::Source) { |
| 93 | + // We can only call getMainSourceFile if the first file is of a Source kind |
| 94 | + swift::SourceFile& file = module->getMainSourceFile(); |
| 95 | + extractFile(config, file); |
| 96 | + } |
| 97 | + } else { |
| 98 | + for (auto s : compiler.getPrimarySourceFiles()) { |
| 99 | + extractFile(config, *s); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments