PerceMon
tqtl.hpp
1#pragma once
2
3#ifndef __PERCEMON_AST_TQTL_HPP__
4#define __PERCEMON_AST_TQTL_HPP__
5
6#include "percemon/ast/ast.hpp"
7
8#include <stdexcept>
9
10namespace percemon::ast {
11
15struct Pin {
16 std::optional<Var_x> x;
17 std::optional<Var_f> f;
18
19 Expr phi = Expr{Const{false}};
20
21 Pin(const std::optional<Var_x>& x_, const std::optional<Var_f>& f_) : x{x_}, f{f_} {
22 if (!x_.has_value() and !f_.has_value()) {
23 throw std::invalid_argument(
24 "Either time variable or frame variable must be specified when a frame is pinned.");
25 }
26 };
27
28 Pin(const std::optional<Var_x>& x_) : Pin{x_, {}} {};
29 Pin(const std::optional<Var_f>& f_) : Pin{{}, f_} {};
30
31 Pin(const Pin&) = default;
32 Pin& operator=(const Pin&) = default;
33 Pin(Pin&&) = default;
34 Pin& operator=(Pin&&) = default;
35
36 PinPtr dot(const Expr& e) {
37 auto ret = std::make_shared<Pin>(x, f);
38 ret->phi = e;
39 return ret;
40 };
41};
42
46struct Exists {
47 std::vector<Var_id> ids;
48 std::optional<Pin> pinned_at = {};
49 std::optional<Expr> phi = {};
50
51 Exists(std::vector<Var_id> id_list) : ids{std::move(id_list)}, pinned_at{}, phi{} {};
52
53 ExistsPtr at(const Pin& pin) {
54 auto ret = std::make_shared<Exists>(ids);
55 ret->pinned_at = pin;
56 return ret;
57 };
58
59 ExistsPtr at(Pin&& pin) {
60 auto ret = std::make_shared<Exists>(ids);
61 ret->pinned_at = std::move(pin);
62 return ret;
63 };
64
65 ExistsPtr dot(const Expr& e) {
66 auto ret = std::make_shared<Exists>(ids);
67 if (auto& pin = this->pinned_at) {
68 ret->pinned_at = pin;
69 ret->pinned_at->phi = e;
70 } else {
71 ret->phi = e;
72 }
73 return ret;
74 };
75};
76
80struct Forall {
81 std::vector<Var_id> ids;
82 std::optional<Pin> pinned_at = {};
83 std::optional<Expr> phi = {};
84
85 Forall(std::vector<Var_id> id_list) : ids{std::move(id_list)}, pinned_at{}, phi{} {};
86
87 ForallPtr at(const Pin& pin) {
88 auto ret = std::make_shared<Forall>(ids);
89 ret->pinned_at = pin;
90 return ret;
91 };
92
93 ForallPtr at(Pin&& pin) {
94 auto ret = std::make_shared<Forall>(ids);
95 ret->pinned_at = std::move(pin);
96 return ret;
97 };
98
99 ForallPtr dot(const Expr& e) {
100 auto ret = std::make_shared<Forall>(ids);
101 if (auto& pin = this->pinned_at) {
102 ret->pinned_at = pin;
103 ret->pinned_at->phi = e;
104 } else {
105 ret->phi = e;
106 }
107 return ret;
108 };
109};
110
111struct Not {
112 Expr arg;
113
114 Not() = delete;
115 Not(Expr arg_) : arg{std::move(arg_)} {};
116};
117
118struct And {
119 std::vector<Expr> args;
120 std::vector<TemporalBoundExpr> temporal_bound_args;
121
122 And() = delete;
123 And(const std::vector<Expr>& args_) {
124 if (args_.size() < 2) {
125 throw std::invalid_argument(
126 "It doesn't make sense to have an And operator with < 2 operands");
127 }
128 for (auto&& e : args_) {
129 if (auto tb_ptr = std::get_if<TimeBound>(&e)) {
130 temporal_bound_args.emplace_back(*tb_ptr);
131 } else if (auto fb_ptr = std::get_if<FrameBound>(&e)) {
132 temporal_bound_args.emplace_back(*fb_ptr);
133 } else {
134 args.push_back(e);
135 }
136 }
137 };
138};
139
140struct Or {
141 std::vector<Expr> args;
142 std::vector<TemporalBoundExpr> temporal_bound_args;
143
144 Or() = delete;
145 Or(const std::vector<Expr>& args_) {
146 if (args_.size() < 2) {
147 throw std::invalid_argument(
148 "It doesn't make sense to have an Or operator with < 2 operands");
149 }
150 for (auto&& e : args_) {
151 if (auto tb_ptr = std::get_if<TimeBound>(&e)) {
152 temporal_bound_args.emplace_back(*tb_ptr);
153 } else if (auto fb_ptr = std::get_if<FrameBound>(&e)) {
154 temporal_bound_args.emplace_back(*fb_ptr);
155 } else {
156 args.push_back(e);
157 }
158 }
159 };
160};
161
162struct Previous {
163 Expr arg;
164
165 Previous() = delete;
166 Previous(Expr arg_) : arg{std::move(arg_)} {};
167};
168
169struct Always {
170 Expr arg;
171
172 Always() = delete;
173 Always(Expr arg_) : arg{std::move(arg_)} {};
174};
175
176struct Sometimes {
177 Expr arg;
178
179 Sometimes() = delete;
180 Sometimes(Expr arg_) : arg{std::move(arg_)} {};
181};
182
183struct Since {
184 std::pair<Expr, Expr> args;
185
186 Since() = delete;
187 Since(const Expr& arg0, const Expr& arg1) : args{std::make_pair(arg0, arg1)} {};
188};
189
190struct BackTo {
191 std::pair<Expr, Expr> args;
192
193 BackTo() = delete;
194 BackTo(const Expr& arg0, const Expr& arg1) : args{std::make_pair(arg0, arg1)} {};
195};
196
197} // namespace percemon::ast
198
199#endif /* end of include guard: __PERCEMON_AST_TQTL_HPP__ */
Definition: tqtl.hpp:169
Definition: tqtl.hpp:118
Definition: tqtl.hpp:190
Definition: tqtl.hpp:46
Definition: tqtl.hpp:80
Definition: tqtl.hpp:111
Definition: tqtl.hpp:140
Definition: tqtl.hpp:15
Definition: tqtl.hpp:162
Definition: tqtl.hpp:183
Definition: tqtl.hpp:176
Definition: primitives.hpp:21