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"
21 using WeakCallback =
void (*)(
const LivenessBroker&,
const void*);
30 void Trace(
const Member<T>& member) {
31 const T* value = member.GetRawAtomic();
37 void Trace(
const WeakMember<T>& weak_member) {
38 static_assert(
sizeof(T),
"T must be fully defined");
40 "T must be GarabgeCollected or GarbageCollectedMixin type");
42 const T* value = weak_member.GetRawAtomic();
52 &HandleWeak<WeakMember<T>>
, &weak_member
);
55 template <
typename Persistent,
56 std::enable_if_t<Persistent::IsStrongPersistent::value>* =
nullptr>
58 using PointeeType =
typename Persistent::PointeeType;
59 static_assert(
sizeof(PointeeType),
60 "Persistent's pointee type must be fully defined");
62 "Persisent's pointee type must be GarabgeCollected or "
63 "GarbageCollectedMixin");
71 typename WeakPersistent,
72 std::enable_if_t<!WeakPersistent::IsStrongPersistent::value>* =
nullptr>
74 using PointeeType =
typename WeakPersistent::PointeeType;
75 static_assert(
sizeof(PointeeType),
76 "Persistent's pointee type must be fully defined");
78 "Persisent's pointee type must be GarabgeCollected or "
79 "GarbageCollectedMixin");
81 &HandleWeak<WeakPersistent>
, &p
);
84 template <
typename T,
void (T::*method)(
const LivenessBroker&)>
94 const void* weak_member) {}
97 const void* weak_root) {}
100 template <
typename T,
void (T::*method)(
const LivenessBroker&)>
101 static void WeakCallbackMethodDelegate(
const LivenessBroker& info,
105 (
const_cast<T*>(
static_cast<
const T*>(self))->*method)(info);
108 template <
typename PointerType>
109 static void HandleWeak(
const LivenessBroker& info,
const void* object) {
110 const PointerType* weak =
static_cast<
const PointerType*>(object);
111 const auto* raw = weak->Get();
112 if (raw && !info.IsHeapObjectAlive(raw)) {
116 const_cast<PointerType*>(weak)->Clear();
122 template <
typename T>
123 void Trace(
const T* t) {
124 static_assert(
sizeof(T),
"T must be fully defined");
126 "T must be GarabgeCollected or GarbageCollectedMixin type");