Swift: tweak after review comments

This commit is contained in:
Paolo Tranquilli
2023-05-04 15:14:46 +02:00
parent b5c0cd8cac
commit 7ce1189e36
2 changed files with 8 additions and 6 deletions

View File

@@ -45,7 +45,7 @@ std::string SwiftDiagnosticsSource::sourceId() const {
std::replace(ret.begin(), ret.end(), '_', '-');
return ret;
}
void SwiftDiagnosticsSource::inscribeImpl(const SwiftDiagnosticsSource* source) {
void SwiftDiagnosticsSource::registerImpl(const SwiftDiagnosticsSource* source) {
auto [it, inserted] = map().emplace(source->id, source);
CODEQL_ASSERT(inserted, "duplicate diagnostics source detected with id {}", source->id);
}

View File

@@ -23,15 +23,17 @@ struct SwiftDiagnosticsSource {
std::string_view name;
static constexpr std::string_view extractorName = "swift";
std::string_view action;
std::string_view helpLinks; // space separated if more than 1. Not a vector to allow constexpr
// space separated if more than 1. Not a vector to allow constexpr
// TODO(C++20) with vector going constexpr this can be turned to `std::vector<std::string_view>`
std::string_view helpLinks;
// for the moment, we only output errors, so no need to store the severity
// registers a diagnostics source for later retrieval with get, if not done yet
template <const SwiftDiagnosticsSource* Spec>
static void inscribe() {
template <const SwiftDiagnosticsSource* Source>
static void ensureRegistered() {
static std::once_flag once;
std::call_once(once, inscribeImpl, Spec);
std::call_once(once, registerImpl, Source);
}
// gets a previously inscribed SwiftDiagnosticsSource for the given id. Will abort if none exists
@@ -44,7 +46,7 @@ struct SwiftDiagnosticsSource {
void emit(std::ostream& out, std::string_view timestamp, std::string_view message) const;
private:
static void inscribeImpl(const SwiftDiagnosticsSource* Spec);
static void registerImpl(const SwiftDiagnosticsSource* source);
std::string sourceId() const;
using Map = std::unordered_map<std::string, const SwiftDiagnosticsSource*>;