@@ -105,17 +105,14 @@ static exprt make_or(exprt a, exprt b)
105
105
106
106
// / Helper function for \c bddt to \c exprt conversion
107
107
// / \param r: node to convert
108
- // / \param complement: whether we want the negation of the expression
109
- // / represented by r
110
108
// / \param cache: map of already computed values
111
109
exprt bdd_exprt::as_expr (
112
110
const bdd_nodet &r,
113
- bool complement,
114
111
std::unordered_map<bdd_nodet::idt, exprt> &cache) const
115
112
{
116
113
if (r.is_constant ())
117
114
{
118
- if (complement )
115
+ if (r. is_complement () )
119
116
return false_exprt ();
120
117
else
121
118
return true_exprt ();
@@ -129,63 +126,46 @@ exprt bdd_exprt::as_expr(
129
126
auto insert_result = cache.emplace (r.id (), nil_exprt ());
130
127
if (insert_result.second )
131
128
{
132
- insert_result. first -> second = [&]() -> exprt {
129
+ auto result_ignoring_complementation = [&]() -> exprt {
133
130
if (r.else_branch ().is_constant ())
134
131
{
135
132
if (r.then_branch ().is_constant ())
136
133
{
137
- if (r.else_branch ().is_complement () != complement)
134
+ if (r.else_branch ().is_complement ()) // else is false
138
135
return n_expr;
139
- return not_exprt (n_expr);
136
+ return not_exprt (n_expr); // else is true
140
137
}
141
138
else
142
139
{
143
- if (r.else_branch ().is_complement () != complement)
140
+ if (r.else_branch ().is_complement ()) // else is false
144
141
{
145
- return make_and (
146
- n_expr,
147
- as_expr (
148
- r.then_branch (),
149
- complement != r.then_branch ().is_complement (),
150
- cache));
142
+ exprt then_case = as_expr (r.then_branch (), cache);
143
+ return make_and (n_expr, then_case);
151
144
}
152
- return make_or (
153
- not_exprt (n_expr),
154
- as_expr (
155
- r.then_branch (),
156
- complement != r.then_branch ().is_complement (),
157
- cache));
145
+ exprt then_case = as_expr (r.then_branch (), cache);
146
+ return make_or (not_exprt (n_expr), then_case);
158
147
}
159
148
}
160
149
else if (r.then_branch ().is_constant ())
161
150
{
162
- if (r.then_branch ().is_complement () != complement)
151
+ if (r.then_branch ().is_complement ()) // then is false
163
152
{
164
- return make_and (
165
- not_exprt (n_expr),
166
- as_expr (
167
- r.else_branch (),
168
- complement != r.else_branch ().is_complement (),
169
- cache));
153
+ exprt else_case = as_expr (r.else_branch (), cache);
154
+ return make_and (not_exprt (n_expr), else_case);
170
155
}
171
- return make_or (
172
- n_expr,
173
- as_expr (
174
- r.else_branch (),
175
- complement != r.else_branch ().is_complement (),
176
- cache));
156
+ exprt else_case = as_expr (r.else_branch (), cache);
157
+ return make_or (n_expr, else_case);
177
158
}
178
- return if_exprt (
179
- n_expr,
180
- as_expr (
181
- r.then_branch (),
182
- r.then_branch ().is_complement () != complement,
183
- cache),
184
- as_expr (
185
- r.else_branch (),
186
- r.else_branch ().is_complement () != complement,
187
- cache));
159
+
160
+ exprt then_branch = as_expr (r.then_branch (), cache);
161
+ exprt else_branch = as_expr (r.else_branch (), cache);
162
+ return if_exprt (n_expr, then_branch, else_branch);
188
163
}();
164
+
165
+ insert_result.first ->second =
166
+ r.is_complement ()
167
+ ? boolean_negate (std::move (result_ignoring_complementation))
168
+ : result_ignoring_complementation;
189
169
}
190
170
return insert_result.first ->second ;
191
171
}
@@ -194,5 +174,5 @@ exprt bdd_exprt::as_expr(const bddt &root) const
194
174
{
195
175
std::unordered_map<bdd_nodet::idt, exprt> cache;
196
176
bdd_nodet node = bdd_mgr.bdd_node (root);
197
- return as_expr (node, node. is_complement (), cache);
177
+ return as_expr (node, cache);
198
178
}
0 commit comments