Skip to content

Commit 14384b7

Browse files
committed
Swift: switch back to references
1 parent 6419af3 commit 14384b7

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

swift/extractor/SwiftExtractor.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
using namespace codeql;
2020

21-
static void archiveFile(const SwiftExtractorConfiguration& config, swift::SourceFile* file) {
21+
static void archiveFile(const SwiftExtractorConfiguration& config, swift::SourceFile& file) {
2222
if (std::error_code ec = llvm::sys::fs::create_directories(config.trapDir)) {
2323
std::cerr << "Cannot create TRAP directory: " << ec.message() << "\n";
2424
return;
@@ -29,7 +29,7 @@ static void archiveFile(const SwiftExtractorConfiguration& config, swift::Source
2929
return;
3030
}
3131

32-
llvm::SmallString<PATH_MAX> srcFilePath(file->getFilename());
32+
llvm::SmallString<PATH_MAX> srcFilePath(file.getFilename());
3333
llvm::sys::fs::make_absolute(srcFilePath);
3434

3535
llvm::SmallString<PATH_MAX> dstFilePath(config.sourceArchiveDir);
@@ -51,12 +51,12 @@ static void archiveFile(const SwiftExtractorConfiguration& config, swift::Source
5151

5252
static void extractFile(const SwiftExtractorConfiguration& config,
5353
swift::CompilerInstance& compiler,
54-
swift::SourceFile* file) {
54+
swift::SourceFile& file) {
5555
// The extractor can be called several times from different processes with
5656
// the same input file(s)
5757
// We are using PID to avoid concurrent access
5858
// TODO: find a more robust approach to avoid collisions?
59-
std::string tempTrapName = file->getFilename().str() + '.' + std::to_string(getpid()) + ".trap";
59+
std::string tempTrapName = file.getFilename().str() + '.' + std::to_string(getpid()) + ".trap";
6060
llvm::SmallString<PATH_MAX> tempTrapPath(config.trapDir);
6161
llvm::sys::path::append(tempTrapPath, tempTrapName);
6262

@@ -87,19 +87,19 @@ static void extractFile(const SwiftExtractorConfiguration& config,
8787
// In the case of emtpy files, the dispatcher is not called, but we still want to 'record' the
8888
// fact that the file was extracted
8989
// TODO: to be moved elsewhere
90-
llvm::SmallString<PATH_MAX> srcFilePath(file->getFilename());
90+
llvm::SmallString<PATH_MAX> srcFilePath(file.getFilename());
9191
llvm::sys::fs::make_absolute(srcFilePath);
9292
auto fileLabel = arena.allocateLabel<FileTag>();
9393
trap.assignKey(fileLabel, srcFilePath.str().str());
9494
trap.emit(FilesTrap{fileLabel, srcFilePath.str().str()});
9595

9696
SwiftVisitor visitor(compiler.getSourceMgr(), arena, trap);
97-
for (swift::Decl* decl : file->getTopLevelDecls()) {
97+
for (swift::Decl* decl : file.getTopLevelDecls()) {
9898
visitor.extract(decl);
9999
}
100100

101101
// TODO: Pick a better name to avoid collisions
102-
std::string trapName = file->getFilename().str() + ".trap";
102+
std::string trapName = file.getFilename().str() + ".trap";
103103
llvm::SmallString<PATH_MAX> trapPath(config.trapDir);
104104
llvm::sys::path::append(trapPath, trapName);
105105

@@ -112,8 +112,10 @@ static void extractFile(const SwiftExtractorConfiguration& config,
112112

113113
void codeql::extractSwiftFiles(const SwiftExtractorConfiguration& config,
114114
swift::CompilerInstance& compiler) {
115+
// The extraction will only work if one (or more) `-primary-file` CLI option is provided, which
116+
// is what always happen in case of `swift build` and `xcodebuild`
115117
for (auto s : compiler.getPrimarySourceFiles()) {
116-
archiveFile(config, s);
117-
extractFile(config, compiler, s);
118+
archiveFile(config, *s);
119+
extractFile(config, compiler, *s);
118120
}
119121
}

0 commit comments

Comments
 (0)