type_graph: deduplicate has_node_id

This commit is contained in:
Jake Hillion 2023-07-14 03:22:09 -07:00 committed by Jake Hillion
parent c3fec2624b
commit 011292f2b0
2 changed files with 20 additions and 7 deletions

View File

@ -57,10 +57,7 @@ class TypeGraph {
template <typename T, typename... Args>
T& makeType(NodeId id, Args&&... args) {
static_assert(std::is_same_v<T, Class> || std::is_same_v<T, Container> ||
std::is_same_v<T, Array> || std::is_same_v<T, Typedef> ||
std::is_same_v<T, Pointer>,
"Unnecessary node ID provided");
static_assert(T::has_node_id, "Unnecessary node ID provided");
auto type_unique_ptr = std::make_unique<T>(id, std::forward<Args>(args)...);
auto type_raw_ptr = type_unique_ptr.get();
types_.push_back(std::move(type_unique_ptr));
@ -71,9 +68,7 @@ class TypeGraph {
T& makeType(Args&&... args) {
static_assert(!std::is_same_v<T, Primitive>,
"Primitive singleton override should be used");
if constexpr (std::is_same_v<T, Class> || std::is_same_v<T, Container> ||
std::is_same_v<T, Array> || std::is_same_v<T, Typedef> ||
std::is_same_v<T, Pointer>) {
if constexpr (T::has_node_id) {
// Node ID required
return makeType<T>(next_id_++, std::forward<Args>(args)...);
} else {

View File

@ -202,6 +202,8 @@ class Class : public Type {
: Class(id, kind, name, name, size, virtuality) {
}
static inline constexpr bool has_node_id = true;
DECLARE_ACCEPT
Kind kind() const {
@ -277,6 +279,8 @@ class Container : public Type {
id_(id) {
}
static inline constexpr bool has_node_id = true;
DECLARE_ACCEPT
const std::string& containerName() const {
@ -318,6 +322,8 @@ class Enum : public Type {
: name_(std::move(name)), size_(size) {
}
static inline constexpr bool has_node_id = false;
DECLARE_ACCEPT
virtual std::string name() const override {
@ -351,6 +357,8 @@ class Array : public Type {
: elementType_(elementType), len_(len), id_(id) {
}
static inline constexpr bool has_node_id = true;
DECLARE_ACCEPT
virtual std::string name() const override {
@ -408,6 +416,8 @@ class Primitive : public Type {
explicit Primitive(Kind kind) : kind_(kind) {
}
static inline constexpr bool has_node_id = false;
DECLARE_ACCEPT
virtual std::string name() const override;
@ -429,6 +439,8 @@ class Typedef : public Type {
: name_(std::move(name)), underlyingType_(underlyingType), id_(id) {
}
static inline constexpr bool has_node_id = true;
DECLARE_ACCEPT
virtual std::string name() const override {
@ -467,6 +479,8 @@ class Pointer : public Type {
: pointeeType_(pointeeType), id_(id) {
}
static inline constexpr bool has_node_id = true;
DECLARE_ACCEPT
virtual std::string name() const override {
@ -504,6 +518,8 @@ class Dummy : public Type {
explicit Dummy(size_t size, uint64_t align) : size_(size), align_(align) {
}
static inline constexpr bool has_node_id = false;
DECLARE_ACCEPT
virtual std::string name() const override {
@ -540,6 +556,8 @@ class DummyAllocator : public Type {
: type_(type), size_(size), align_(align) {
}
static inline constexpr bool has_node_id = false;
DECLARE_ACCEPT
virtual std::string name() const override {