5#ifndef INCLUDE_CPPGC_TAGGED_MEMBER_H_
6#define INCLUDE_CPPGC_TAGGED_MEMBER_H_
31template <
typename Po
intee,
typename Tag1,
typename Tag2>
36 "The tag must live in the alignment bits of the pointer.");
41 : ptr_(reinterpret_cast<Pointee*>(reinterpret_cast<uintptr_t>(ptr) |
44 template <
typename Tag>
46 auto* raw = ptr_.Get();
47 if constexpr (std::same_as<Tag, Tag1>) {
51 static_assert(std::same_as<Tag, Tag2>);
57 template <
typename Tag>
59 auto* raw = ptr_.Get();
60 if constexpr (std::same_as<Tag, Tag1>) {
61 return (
reinterpret_cast<uintptr_t
>(raw) &
kTagBit) ?
nullptr : raw;
63 static_assert(std::same_as<Tag, Tag2>);
64 return (
reinterpret_cast<uintptr_t
>(raw) &
kTagBit)
65 ?
reinterpret_cast<Pointee*
>(
reinterpret_cast<uintptr_t
>(raw) &
72 return reinterpret_cast<Pointee*
>(
reinterpret_cast<uintptr_t
>(ptr_.Get()) &
76 template <
typename Tag>
78 if constexpr (std::same_as<Tag, Tag1>) {
81 static_assert(std::same_as<Tag, Tag2>);
82 ptr_ =
reinterpret_cast<Pointee*
>(
reinterpret_cast<uintptr_t
>(pointee) |
87 template <
typename Tag>
89 const bool tag_set =
reinterpret_cast<uintptr_t
>(ptr_.Get()) &
kTagBit;
90 if constexpr (std::same_as<Tag, Tag1>) {
93 static_assert(std::same_as<Tag, Tag2>);
102 auto* untagged =
reinterpret_cast<Pointee*
>(
103 reinterpret_cast<uintptr_t
>(ptr_.GetRawAtomic()) & ~
kTagBit);
void Trace(const Member< T > &member)
Definition: visitor.h:93
Definition: tagged-member.h:32
Pointee * GetUntagged() const
Definition: tagged-member.h:71
Pointee * GetAs() const
Definition: tagged-member.h:45
void Trace(Visitor *v) const
Definition: tagged-member.h:98
TaggedUncompressedMember(Tag2, Pointee *ptr)
Definition: tagged-member.h:40
bool Is() const
Definition: tagged-member.h:88
void SetAs(Pointee *pointee)
Definition: tagged-member.h:77
static constexpr uintptr_t kTagBit
Definition: tagged-member.h:34
TaggedUncompressedMember(Tag1, Pointee *ptr)
Definition: tagged-member.h:39
Pointee * TryGetAs() const
Definition: tagged-member.h:58
#define CPPGC_DCHECK(condition)
Definition: logging.h:36
#define CPPGC_PLUGIN_IGNORE(bug_or_reason)
Definition: macros.h:46
#define CPPGC_DISALLOW_NEW()
Definition: macros.h:14
constexpr size_t kAllocationGranularity
Definition: api-constants.h:65
Definition: cross-thread-persistent.h:431