Swift: replace all usages of std::to_string with absl::StrCat or absl::StrAppend

This commit is contained in:
Paolo Tranquilli
2023-05-10 07:03:06 +02:00
parent 84c017083f
commit ec3c63a2b3
5 changed files with 12 additions and 10 deletions

View File

@@ -5,6 +5,7 @@
#include <swift/AST/SourceFile.h>
#include <swift/Basic/SourceManager.h>
#include <swift/Parse/Token.h>
#include "absl/strings/str_cat.h"
#include "swift/extractor/trap/TrapDomain.h"
#include "swift/extractor/infra/SwiftTagTraits.h"
@@ -83,7 +84,7 @@ class SwiftDispatcher {
valid = false;
}
LOG_ERROR("{} has undefined field {}{}, {}", entry.NAME, field,
index >= 0 ? ('[' + std::to_string(index) + ']') : "", action);
index >= 0 ? absl::StrCat("[", index, "]") : "", action);
}
});
if (valid) {

View File

@@ -1,4 +1,5 @@
#include "swift/extractor/infra/SwiftMangledName.h"
#include "absl/strings/str_cat.h"
namespace codeql {
@@ -8,13 +9,11 @@ void appendPart(std::string& out, const std::string& prefix) {
}
void appendPart(std::string& out, UntypedTrapLabel label) {
out += '{';
out += label.str();
out += '}';
absl::StrAppend(&out, "{", label.str(), "}");
}
void appendPart(std::string& out, unsigned index) {
out += std::to_string(index);
absl::StrAppend(&out, index);
}
} // namespace

View File

@@ -10,6 +10,7 @@
#include <swift/Basic/InitializeSwiftModules.h>
#include "absl/strings/str_join.h"
#include "absl/strings/str_cat.h"
#include "swift/extractor/SwiftExtractor.h"
#include "swift/extractor/infra/TargetDomains.h"
@@ -166,7 +167,7 @@ static void checkWhetherToRunUnderTool(int argc, char* const* argv) {
// compilations, diagnostics, etc.
codeql::TrapDomain invocationTrapDomain(codeql::SwiftExtractorState& state) {
auto timestamp = std::chrono::system_clock::now().time_since_epoch().count();
auto filename = std::to_string(timestamp) + '-' + std::to_string(getpid());
auto filename = absl::StrCat(timestamp, "-", getpid());
auto target = std::filesystem::path("invocations") / std::filesystem::path(filename);
auto maybeDomain = codeql::createTargetTrapDomain(state, target, codeql::TrapType::invocation);
CODEQL_ASSERT(maybeDomain, "Cannot create invocation trap file for {}", target);

View File

@@ -2,6 +2,7 @@
#include <memory>
#include <sstream>
#include "absl/strings/str_cat.h"
#include "swift/extractor/trap/TrapLabel.h"
#include "swift/extractor/infra/file/TargetFile.h"
@@ -27,7 +28,7 @@ class TrapDomain {
e.forEachLabel([&e, this](const char* field, int index, auto& label) {
if (!label.valid()) {
LOG_ERROR("{} has undefined field {}{}", e.NAME, field,
index >= 0 ? ('[' + std::to_string(index) + ']') : "");
index >= 0 ? absl::StrCat("[", index, "]") : "");
}
});
}

View File

@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <optional>
#include <unistd.h>
#include "absl/strings/str_cat.h"
#define LEVEL_REGEX_PATTERN "trace|debug|info|warning|error|critical|no_logs"
@@ -98,9 +99,8 @@ std::vector<std::string> Log::collectLevelRulesAndReturnProblems(const char* env
void Log::configure() {
// as we are configuring logging right now, we collect problems and log them at the end
auto problems = collectLevelRulesAndReturnProblems("CODEQL_EXTRACTOR_SWIFT_LOG_LEVELS");
auto logBaseName = std::to_string(std::chrono::system_clock::now().time_since_epoch().count());
logBaseName += '-';
logBaseName += std::to_string(getpid());
auto timestamp = std::chrono::system_clock::now().time_since_epoch().count();
auto logBaseName = absl::StrCat(timestamp, "-", getpid());
if (text || binary) {
std::filesystem::path logFile = getEnvOr("CODEQL_EXTRACTOR_SWIFT_LOG_DIR", "extractor-out/log");
logFile /= "swift";