Jlm
type.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010 2011 2012 Helge Bahmann <hcb@chaoticmind.net>
3  * Copyright 2011 2012 2013 2014 2015 Nico Reißmann <nico.reissmann@gmail.com>
4  * See COPYING for terms of redistribution.
5  */
6 
7 #ifndef JLM_RVSDG_TYPE_HPP
8 #define JLM_RVSDG_TYPE_HPP
9 
10 #include <memory>
11 #include <string>
12 
13 namespace jlm::rvsdg
14 {
15 
21 enum class TypeKind
22 {
29  Value,
37  State
38 };
39 
40 class Type
41 {
42 public:
43  virtual ~Type() noexcept;
44 
45 protected:
46  inline constexpr Type() noexcept
47  {}
48 
49 public:
50  virtual bool
51  operator==(const jlm::rvsdg::Type & other) const noexcept = 0;
52 
53  inline bool
54  operator!=(const jlm::rvsdg::Type & other) const noexcept
55  {
56  return !(*this == other);
57  }
58 
59  [[nodiscard]] virtual std::string
60  debug_string() const = 0;
61 
67  [[nodiscard]] virtual std::size_t
68  ComputeHash() const noexcept = 0;
69 
73  virtual TypeKind
74  Kind() const noexcept = 0;
75 };
76 
77 template<class T>
78 static inline bool
79 is(const jlm::rvsdg::Type & type) noexcept
80 {
81  static_assert(
82  std::is_base_of<jlm::rvsdg::Type, T>::value,
83  "Template parameter T must be derived from jlm::rvsdg::Type.");
84 
85  return dynamic_cast<const T *>(&type) != nullptr;
86 }
87 
88 template<class T>
89 static inline bool
90 is(const std::shared_ptr<const jlm::rvsdg::Type> & type) noexcept
91 {
92  static_assert(
93  std::is_base_of<jlm::rvsdg::Type, T>::value,
94  "Template parameter T must be derived from jlm::rvsdg::Type.");
95 
96  return dynamic_cast<const T *>(type.get()) != nullptr;
97 }
98 
99 }
100 
101 #endif
virtual std::string debug_string() const =0
virtual TypeKind Kind() const noexcept=0
Return the kind of this type.
virtual bool operator==(const jlm::rvsdg::Type &other) const noexcept=0
bool operator!=(const jlm::rvsdg::Type &other) const noexcept
Definition: type.hpp:54
virtual std::size_t ComputeHash() const noexcept=0
virtual ~Type() noexcept
static bool is(const jlm::rvsdg::Input &input) noexcept
Definition: node.hpp:236
static std::string type(const Node *n)
Definition: view.cpp:255
TypeKind
The kinds of types supported in rvsdg.
Definition: type.hpp:22
@ State
Designate a state type.
@ Value
Designate a value type.