mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Swift: make TrapLabelStore store untyped label internally
This commit is contained in:
@@ -13,9 +13,8 @@ class UntypedTrapLabel {
|
||||
uint64_t id_;
|
||||
|
||||
friend class std::hash<UntypedTrapLabel>;
|
||||
|
||||
// we want to have access to the untyped, underlying id
|
||||
friend class TrapLabelStore;
|
||||
template <typename Tag>
|
||||
friend class TrapLabel;
|
||||
|
||||
protected:
|
||||
UntypedTrapLabel() : id_{0xffffffffffffffff} {}
|
||||
@@ -44,6 +43,7 @@ class TrapLabel : public UntypedTrapLabel {
|
||||
|
||||
// The caller is responsible for ensuring ID uniqueness.
|
||||
static TrapLabel unsafeCreateFromExplicitId(uint64_t id) { return {id}; }
|
||||
static TrapLabel unsafeCreateFromUntyped(UntypedTrapLabel label) { return {label.id_}; }
|
||||
|
||||
template <typename OtherTag>
|
||||
TrapLabel(const TrapLabel<OtherTag>& other) : UntypedTrapLabel(other) {
|
||||
|
||||
@@ -41,19 +41,19 @@ class TrapLabelStore {
|
||||
template <typename T>
|
||||
std::optional<TrapLabel<ToTag<T>>> get(const T* e) {
|
||||
if (auto found = store_.find(getCanonicalPtr(e)); found != store_.end()) {
|
||||
return TrapLabel<ToTag<T>>::unsafeCreateFromExplicitId(found->second);
|
||||
return TrapLabel<ToTag<T>>::unsafeCreateFromUntyped(found->second);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void insert(const T* e, TrapLabel<ToTag<T>> l) {
|
||||
auto [_, inserted] = store_.emplace(getCanonicalPtr(e), l.id_);
|
||||
auto [_, inserted] = store_.emplace(getCanonicalPtr(e), l);
|
||||
assert(inserted && "already inserted");
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<const void*, uint64_t> store_;
|
||||
std::unordered_map<const void*, UntypedTrapLabel> store_;
|
||||
};
|
||||
|
||||
} // namespace codeql
|
||||
|
||||
Reference in New Issue
Block a user