5 #ifndef INCLUDE_CPPGC_VISITOR_H_
6 #define INCLUDE_CPPGC_VISITOR_H_
8 #include "cppgc/garbage-collected.h"
9 #include "cppgc/internal/logging.h"
10 #include "cppgc/internal/pointer-policies.h"
11 #include "cppgc/liveness-broker.h"
12 #include "cppgc/member.h"
13 #include "cppgc/source-location.h"
14 #include "cppgc/trace-trait.h"
19 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
20 typename CheckingPolicy>
22 class ConservativeTracingVisitor;
28 using WeakCallback =
void (*)(
const LivenessBroker&,
const void*);
65 void Trace(
const Member<T>& member) {
66 const T* value = member.GetRawAtomic();
77 void Trace(
const WeakMember<T>& weak_member) {
78 static_assert(
sizeof(T),
"Pointee type must be fully defined.");
80 "T must be GarbageCollected or GarbageCollectedMixin type");
82 const T* value = weak_member.GetRawAtomic();
92 &HandleWeak<WeakMember<T>>
, &weak_member
);
101 template <
typename T>
108 CheckObjectNotInConstruction(&object);
119 template <
typename T,
void (T::*method)(
const LivenessBroker&)>
135 const void* weak_member) {}
138 const void* weak_root) {}
141 template <
typename T,
void (T::*method)(
const LivenessBroker&)>
142 static void WeakCallbackMethodDelegate(
const LivenessBroker& info,
146 (
const_cast<T*>(
static_cast<
const T*>(self))->*method)(info);
149 template <
typename PointerType>
150 static void HandleWeak(
const LivenessBroker& info,
const void* object) {
151 const PointerType* weak =
static_cast<
const PointerType*>(object);
154 const auto* raw = weak->Get();
155 if (!info.IsHeapObjectAlive(raw)) {
160 template <
typename Persistent,
161 std::enable_if_t<Persistent::IsStrongPersistent::value>* =
nullptr>
163 using PointeeType =
typename Persistent::PointeeType;
164 static_assert(
sizeof(PointeeType),
165 "Persistent's pointee type must be fully defined");
167 "Persistent's pointee type must be GarbageCollected or "
168 "GarbageCollectedMixin");
176 typename WeakPersistent,
177 std::enable_if_t<!WeakPersistent::IsStrongPersistent::value>* =
nullptr>
178 void TraceRoot(
const WeakPersistent& p,
const SourceLocation& loc) {
179 using PointeeType =
typename WeakPersistent::PointeeType;
180 static_assert(
sizeof(PointeeType),
181 "Persistent's pointee type must be fully defined");
183 "Persistent's pointee type must be GarbageCollected or "
184 "GarbageCollectedMixin");
186 &HandleWeak<WeakPersistent>
, &p
);
189 template <
typename T>
190 void Trace(
const T* t) {
191 static_assert(
sizeof(T),
"Pointee type must be fully defined.");
193 "T must be GarbageCollected or GarbageCollectedMixin type");
204 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
205 typename CheckingPolicy>