Jlm
Loading...
Searching...
No Matches
TestType.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
7#include <jlm/util/common.hpp>
8#include <jlm/util/Hash.hpp>
9#include <jlm/util/strfmt.hpp>
10
11#include <unordered_map>
12
13namespace jlm::rvsdg
14{
15
16static std::string
17ToString(const TypeKind kind)
18{
19 switch (kind)
20 {
21 case TypeKind::Value:
22 return "Value";
23 case TypeKind::State:
24 return "State";
25 default:
26 throw std::logic_error("Unhandled type kind!");
27 }
28}
29
31
32std::string
33TestType::debug_string() const
34{
35 return util::strfmt("TestType[", ToString(kind_), "]");
36}
37
38bool
39TestType::operator==(const Type & other) const noexcept
40{
41 const auto testType = dynamic_cast<const TestType *>(&other);
42 return testType && kind_ == testType->kind_;
43}
44
45std::size_t
47{
48 const auto typeHash = typeid(TestType).hash_code();
49 const auto kindHash = std::hash<TypeKind>()(kind_);
51}
52
55{
56 return kind_;
57}
58
59std::shared_ptr<const TestType>
61{
63 return std::shared_ptr<const TestType>(std::shared_ptr<void>(), &stateType);
64}
65
66std::shared_ptr<const TestType>
68{
70 return std::shared_ptr<const TestType>(std::shared_ptr<void>(), &valueType);
71}
72
73}
~TestType() noexcept override
TypeKind Kind() const noexcept override
Return the kind of this type.
Definition TestType.cpp:54
static std::shared_ptr< const TestType > createStateType()
Definition TestType.cpp:60
static std::shared_ptr< const TestType > createValueType()
Definition TestType.cpp:67
bool operator==(const Type &other) const noexcept override
Definition TestType.cpp:39
std::size_t ComputeHash() const noexcept override
Definition TestType.cpp:46
static std::string ToString(const TypeKind kind)
Definition TestType.cpp:17
TypeKind
The kinds of types supported in rvsdg.
Definition type.hpp:22
@ State
Designate a state type.
@ Value
Designate a value type.
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
static std::string strfmt(Args... args)
Definition strfmt.hpp:35
std::size_t CombineHashes(std::size_t hash, Args... args)
Definition Hash.hpp:63