@@ -91,6 +91,30 @@ bddt bdd_exprt::from_expr(const exprt &expr)
91
91
return from_expr_rec (expr);
92
92
}
93
93
94
+ // / Conjunction of two expressions. If the second is already an `and_exprt`
95
+ // / add to its operands instead of creating a new expression.
96
+ static exprt make_and (exprt a, exprt b)
97
+ {
98
+ if (b.id () == ID_and)
99
+ {
100
+ b.add_to_operands (std::move (a));
101
+ return b;
102
+ }
103
+ return and_exprt{std::move (a), std::move (b)};
104
+ }
105
+
106
+ // / Disjunction of two expressions. If the second is already an `or_exprt`
107
+ // / add to its operands instead of creating a new expression.
108
+ static exprt make_or (exprt a, exprt b)
109
+ {
110
+ if (b.id () == ID_or)
111
+ {
112
+ b.add_to_operands (std::move (a));
113
+ return b;
114
+ }
115
+ return or_exprt{std::move (a), std::move (b)};
116
+ }
117
+
94
118
// / Helper function for \c bddt to \c exprt conversion
95
119
// / \param r: node to convert
96
120
// / \param complement: whether we want the negation of the expression
@@ -130,14 +154,14 @@ exprt bdd_exprt::as_expr(
130
154
{
131
155
if (r.else_branch ().is_complement () != complement)
132
156
{
133
- return and_exprt (
157
+ return make_and (
134
158
n_expr,
135
159
as_expr (
136
160
r.then_branch (),
137
161
complement != r.then_branch ().is_complement (),
138
162
cache));
139
163
}
140
- return or_exprt (
164
+ return make_or (
141
165
not_exprt (n_expr),
142
166
as_expr (
143
167
r.then_branch (),
@@ -149,14 +173,14 @@ exprt bdd_exprt::as_expr(
149
173
{
150
174
if (r.then_branch ().is_complement () != complement)
151
175
{
152
- return and_exprt (
176
+ return make_and (
153
177
not_exprt (n_expr),
154
178
as_expr (
155
179
r.else_branch (),
156
180
complement != r.else_branch ().is_complement (),
157
181
cache));
158
182
}
159
- return or_exprt (
183
+ return make_or (
160
184
n_expr,
161
185
as_expr (
162
186
r.else_branch (),
0 commit comments