Swift: replace assertions and prints in main and SwiftExtractor

This commit is contained in:
Paolo Tranquilli
2023-04-18 12:12:17 +02:00
parent f42975f132
commit dbfd85c505
4 changed files with 36 additions and 32 deletions

View File

@@ -14,18 +14,23 @@
#include "swift/extractor/infra/SwiftLocationExtractor.h"
#include "swift/extractor/infra/SwiftBodyEmissionStrategy.h"
#include "swift/extractor/mangler/SwiftMangler.h"
#include "swift/extractor/infra/log/SwiftAssert.h"
using namespace codeql;
using namespace std::string_literals;
namespace fs = std::filesystem;
Logger& main_logger::logger() {
static Logger ret{"main"};
return ret;
}
using namespace main_logger;
static void ensureDirectory(const char* label, const fs::path& dir) {
std::error_code ec;
fs::create_directories(dir, ec);
if (ec) {
std::cerr << "Cannot create " << label << " directory: " << ec.message() << "\n";
std::abort();
}
CODEQL_ASSERT(!ec, "Cannot create {} directory ({})", label, ec);
}
static void archiveFile(const SwiftExtractorConfiguration& config, swift::SourceFile& file) {
@@ -36,11 +41,7 @@ static void archiveFile(const SwiftExtractorConfiguration& config, swift::Source
std::error_code ec;
fs::copy(source, destination, fs::copy_options::overwrite_existing, ec);
if (ec) {
std::cerr << "Cannot archive source file " << source << " -> " << destination << ": "
<< ec.message() << "\n";
}
CODEQL_ASSERT(!ec, "Cannot archive source file {} -> {} ({})", source, destination, ec);
}
static fs::path getFilename(swift::ModuleDecl& module,
@@ -243,11 +244,9 @@ void codeql::extractExtractLazyDeclarations(SwiftExtractorState& state,
// Just in case
const int upperBound = 100;
int iteration = 0;
while (!state.pendingDeclarations.empty() && iteration++ < upperBound) {
while (!state.pendingDeclarations.empty()) {
CODEQL_ASSERT(iteration++ < upperBound,
"Swift extractor reached upper bound while extracting lazy declarations");
extractLazy(state, compiler);
}
if (iteration >= upperBound) {
std::cerr << "Swift extractor reached upper bound while extracting lazy declarations\n";
abort();
}
}