MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
rule.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
mim/def.h
"
4
5
namespace
mim
{
6
7
/// Type <b>form</b>ation of a <b>re</b>write Rule.
8
/// Currently opaque.
9
class
Reform
:
public
Def,
public
Setters
<Reform> {
10
protected
:
11
Reform
(
const
Def*
type
,
const
Def*
dom
)
12
: Def(
Node
,
type
, {
dom
}, 0) {}
13
14
public
:
15
/// @name dom
16
/// @see @ref proj
17
///@{
18
const
Def*
dom
()
const
{
return
op
(0); }
19
MIM_PROJ
(
dom
,
const
)
20
///@}
21
22
/// @name Setters
23
///@{
24
using
Setters
<
Reform
>::
set
;
25
Reform
*
set
(
size_t
i, const Def* def) {
return
Def::set
(i, def)->as<
Reform
>(); }
26
Reform
*
set
(
Defs
ops
) {
return
Def::set
(
ops
)->as<
Reform
>(); }
27
Reform
*
unset
() {
return
Def::unset
()->as<
Reform
>(); }
28
///@}
29
30
static
const
Def
*
infer
(
const
Def
*
dom
);
31
32
static
constexpr
auto
Node
=
mim::Node::Reform
;
33
static
constexpr
size_t
Num_Ops
= 1;
34
35
private
:
36
friend
class
World
;
37
};
38
39
/// A rewrite rule
40
class
Rule :
public
Def,
public
Setters
<Rule> {
41
private
:
42
Rule(
const
Reform
*
type
,
const
Def*
lhs
,
const
Def*
rhs
,
const
Def*
guard
)
43
: Def(
Node
,
type
, {
lhs
,
rhs
,
guard
}, 0) {}
44
Rule(
const
Reform
*
type
)
45
: Def(
Node
,
type
, 3, 0) {}
46
47
public
:
48
/// @name type
49
/// @see @ref proj
50
///@{
51
const
Reform
*
type
()
const
{
return
Def::type
()->as<
Reform
>(); }
52
const
Def*
dom
()
const
{
return
type
()->dom(); }
53
MIM_PROJ
(
dom
,
const
)
54
///@}
55
56
/// @name ops
57
/// @see @ref proj
58
///@{
59
const Def*
lhs
()
const
{
return
op
(0); }
60
const
Def*
rhs
()
const
{
return
op
(1); }
61
const
Def*
guard
()
const
{
return
op
(2); }
62
MIM_PROJ
(
lhs
,
const
)
63
MIM_PROJ
(
rhs
, const)
64
MIM_PROJ
(
guard
, const)
65
///@}
66
67
/// @name Setters
68
/// @see @ref set_ops "Setting Ops"
69
///@{
70
using
Setters
<
Rule
>::
set
;
71
Rule*
set
(const Def*
lhs
, const Def*
rhs
, const Def*
guard
) {
return
Def::set
({
lhs
,
rhs
,
guard
})->as<Rule>(); }
72
Rule*
set_lhs
(
const
Def*
lhs
) {
return
Def::set
(0,
lhs
)->as<Rule>(); }
73
Rule*
set_rhs
(
const
Def*
rhs
) {
return
Def::set
(1,
rhs
)->as<Rule>(); }
74
Rule*
set_guard
(
const
Def*
guard
) {
return
Def::set
(2,
guard
)->as<Rule>(); }
75
Rule*
unset
() {
return
Def::unset
()->as<Rule>(); }
76
///@}
77
78
/// @name Type checking
79
///@{
80
///@}
81
82
/// @name Rebuild
83
///@{
84
const
Def*
reduce
(
const
Def* arg)
const
{
return
Def::reduce
(arg).front(); }
85
///@}
86
87
/// @name Apply
88
///@{
89
bool
its_a_match
(
const
Def
* expr,
Def2Def
&)
const
;
90
const
Def
*
replace
(
const
Def
* expr,
Def2Def
&)
const
;
91
///@}
92
93
static
bool
is_in_rule
(
const
Def
*);
94
95
static
constexpr
auto
Node
=
mim::Node::Rule
;
96
static
constexpr
size_t
Num_Ops
= 3;
97
98
private
:
99
bool
its_a_match_(
const
Def*
lhs
,
const
Def*
rhs
,
Def2Def
& seen)
const
;
100
friend
class
World
;
101
};
102
}
// namespace mim
mim::Def
Base class for all Defs.
Definition
def.h:273
mim::Def::set
Def * set(size_t i, const Def *)
Successively set from left to right.
Definition
def.cpp:196
mim::Def::ops
constexpr auto ops() const noexcept
Definition
def.h:348
mim::Def::op
const Def * op(size_t i) const noexcept
Definition
def.h:351
mim::Def::type
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition
def.h:1111
mim::Def::unset
Def * unset()
Unsets all Def::ops; works even, if not set at all or only partially set.
Definition
def.cpp:213
mim::Def::reduce
constexpr auto reduce(const Def *arg) const
Definition
def.h:660
mim::Reform
Type formation of a rewrite Rule.
Definition
rule.h:9
mim::Reform::set
Reform * set(Defs ops)
Definition
rule.h:26
mim::Reform::Reform
Reform(const Def *type, const Def *dom)
Definition
rule.h:11
mim::Reform::set
Reform * set(size_t i, const Def *def)
Definition
rule.h:25
mim::Reform::infer
static const Def * infer(const Def *dom)
Definition
check.cpp:432
mim::Reform::dom
const Def * dom() const
Definition
rule.h:18
mim::Reform::World
friend class World
Definition
rule.h:36
mim::Reform::Node
static constexpr auto Node
Definition
rule.h:32
mim::Reform::Num_Ops
static constexpr size_t Num_Ops
Definition
rule.h:33
mim::Reform::unset
Reform * unset()
Definition
rule.h:27
mim::Rule
A rewrite rule.
Definition
rule.h:40
mim::Rule::set_rhs
Rule * set_rhs(const Def *rhs)
Definition
rule.h:73
mim::Rule::set_lhs
Rule * set_lhs(const Def *lhs)
Definition
rule.h:72
mim::Rule::dom
const Def * dom() const
Definition
rule.h:52
mim::Rule::lhs
const Def * lhs() const
Definition
rule.h:59
mim::Rule::set_guard
Rule * set_guard(const Def *guard)
Definition
rule.h:74
mim::Rule::its_a_match
bool its_a_match(const Def *expr, Def2Def &) const
Definition
rule.cpp:49
mim::Rule::guard
const Def * guard() const
Definition
rule.h:61
mim::Rule::World
friend class World
Definition
rule.h:100
mim::Rule::Num_Ops
static constexpr size_t Num_Ops
Definition
rule.h:96
mim::Rule::replace
const Def * replace(const Def *expr, Def2Def &) const
Definition
rule.cpp:116
mim::Rule::set
Rule * set(const Def *lhs, const Def *rhs, const Def *guard)
Definition
rule.h:71
mim::Rule::is_in_rule
static bool is_in_rule(const Def *)
Definition
rule.cpp:38
mim::Rule::unset
Rule * unset()
Definition
rule.h:75
mim::Rule::rhs
const Def * rhs() const
Definition
rule.h:60
mim::Rule::reduce
const Def * reduce(const Def *arg) const
Definition
rule.h:84
mim::Rule::Node
static constexpr auto Node
Definition
rule.h:95
mim::Rule::type
const Reform * type() const
Definition
rule.h:51
mim::Setters
CRTP-based mixin to declare setters for Def::loc & Def::name using a covariant return type.
Definition
def.h:209
def.h
MIM_PROJ
#define MIM_PROJ(NAME, CONST)
Use as mixin to wrap all kind of Def::proj and Def::projs variants.
Definition
def.h:175
mim
Definition
ast.h:16
mim::Def2Def
DefMap< const Def * > Def2Def
Definition
def.h:90
mim::Defs
fe::View< const Def * > Defs
Definition
def.h:91
mim::Node::Reform
@ Reform
Definition
def.h:122
mim::Node::Rule
@ Rule
Definition
def.h:122
include
mim
rule.h
Generated by
1.18.0