Loading...
Searching...
No Matches
trace-trait.h
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_CPPGC_TRACE_TRAIT_H_
6#define INCLUDE_CPPGC_TRACE_TRAIT_H_
7
8#include <type_traits>
9
10#include "cppgc/type-traits.h"
11#include "v8config.h" // NOLINT(build/include_directory)
12
13namespace cppgc {
14
15class Visitor;
16
17namespace internal {
18
19class RootVisitor;
20
21using TraceRootCallback = void (*)(RootVisitor&, const void* object);
22
23// Implementation of the default TraceTrait handling GarbageCollected and
24// GarbageCollectedMixin.
25template <typename T,
26 bool =
27 IsGarbageCollectedMixinTypeV<typename std::remove_const<T>::type>>
29
30} // namespace internal
31
38using TraceCallback = void (*)(Visitor* visitor, const void* object);
39
54};
55
62using TraceDescriptorCallback = TraceDescriptor (*)(const void* address);
63
64namespace internal {
65
67 static TraceDescriptor GetTraceDescriptor(const void* address);
68};
69
76template <typename T>
78 static_assert(internal::IsTraceableV<T>, "T must have a Trace() method");
79
86 static TraceDescriptor GetTraceDescriptor(const void* self) {
88 static_cast<const T*>(self));
89 }
90
97 static void Trace(Visitor* visitor, const void* self) {
98 static_cast<const T*>(self)->Trace(visitor);
99 }
100};
101
102} // namespace internal
103
104template <typename T>
106
107namespace internal {
108
109template <typename T>
110struct TraceTraitImpl<T, false> {
111 static_assert(IsGarbageCollectedTypeV<T>,
112 "T must be of type GarbageCollected or GarbageCollectedMixin");
113 static TraceDescriptor GetTraceDescriptor(const void* self) {
114 return {self, TraceTrait<T>::Trace};
115 }
116};
117
118template <typename T>
119struct TraceTraitImpl<T, true> {
120 static TraceDescriptor GetTraceDescriptor(const void* self) {
122 }
123};
124
125} // namespace internal
126} // namespace cppgc
127
128#endif // INCLUDE_CPPGC_TRACE_TRAIT_H_
Definition: visitor.h:56
Definition: visitor.h:441
void(*)(RootVisitor &, const void *object) TraceRootCallback
Definition: trace-trait.h:21
Definition: allocation.h:38
void(*)(Visitor *visitor, const void *object) TraceCallback
Definition: trace-trait.h:38
TraceDescriptor(*)(const void *address) TraceDescriptorCallback
Definition: trace-trait.h:62
Definition: trace-trait.h:44
const void * base_object_payload
Definition: trace-trait.h:49
TraceCallback callback
Definition: trace-trait.h:53
Definition: trace-trait.h:105
Definition: trace-trait.h:77
static TraceDescriptor GetTraceDescriptor(const void *self)
Definition: trace-trait.h:86
static void Trace(Visitor *visitor, const void *self)
Definition: trace-trait.h:97
static TraceDescriptor GetTraceDescriptor(const void *address)
static TraceDescriptor GetTraceDescriptor(const void *self)
Definition: trace-trait.h:113
static TraceDescriptor GetTraceDescriptor(const void *self)
Definition: trace-trait.h:120
Definition: trace-trait.h:28
#define V8_EXPORT
Definition: v8config.h:793