gc-info.h 1.28 KB
Newer Older
1 2 3 4
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
#define INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
7 8 9

#include <stdint.h>

10
#include "cppgc/internal/finalizer-trait.h"
11
#include "cppgc/trace-trait.h"
12
#include "v8config.h"  // NOLINT(build/include_directory)
13 14 15 16 17 18 19 20 21

namespace cppgc {
namespace internal {

using GCInfoIndex = uint16_t;

class V8_EXPORT RegisteredGCInfoIndex final {
 public:
  RegisteredGCInfoIndex(FinalizationCallback finalization_callback,
22
                        TraceCallback trace_callback, bool has_v_table);
23 24 25 26 27 28 29 30 31 32 33 34 35
  GCInfoIndex GetIndex() const { return index_; }

 private:
  const GCInfoIndex index_;
};

// Trait determines how the garbage collector treats objects wrt. to traversing,
// finalization, and naming.
template <typename T>
struct GCInfoTrait {
  static GCInfoIndex Index() {
    static_assert(sizeof(T), "T must be fully defined");
    static const RegisteredGCInfoIndex registered_index(
36 37
        FinalizerTrait<T>::kCallback, TraceTrait<T>::Trace,
        std::is_polymorphic<T>::value);
38 39 40 41 42 43 44
    return registered_index.GetIndex();
  }
};

}  // namespace internal
}  // namespace cppgc

45
#endif  // INCLUDE_CPPGC_INTERNAL_GC_INFO_H_