Jlm
Loading...
Searching...
No Matches
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
13namespace jlm::rvsdg
14{
15
21enum class TypeKind
22{
29 Value,
37 State
38};
39
40class Type
41{
42public:
43 virtual ~Type() noexcept;
44
48
49public:
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
69
75};
76
78static inline bool
79is(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
88template<class T>
89static inline bool
90is(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
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