@@ -105,7 +105,7 @@ struct saj_tablet
105
105
{ irep_idt (), { irep_idt () }}
106
106
};
107
107
108
- static bool sort_and_join (
108
+ static bool is_associative_and_commutative_for_type (
109
109
const struct saj_tablet &saj_entry,
110
110
const irep_idt &type_id)
111
111
{
@@ -116,42 +116,44 @@ static bool sort_and_join(
116
116
return false ;
117
117
}
118
118
119
- static const struct saj_tablet &sort_and_join (
120
- const irep_idt &id,
121
- const irep_idt &type_id)
119
+ static const struct saj_tablet &
120
+ get_sort_and_join_table_entry (const irep_idt &id, const irep_idt &type_id)
122
121
{
123
122
unsigned i=0 ;
124
123
125
124
for ( ; !saj_table[i].id .empty (); i++)
126
- if (id==saj_table[i].id &&
127
- sort_and_join (saj_table[i], type_id))
125
+ {
126
+ if (
127
+ id == saj_table[i].id &&
128
+ is_associative_and_commutative_for_type (saj_table[i], type_id))
128
129
return saj_table[i];
130
+ }
129
131
130
132
return saj_table[i];
131
133
}
132
134
133
- bool sort_and_join (exprt &expr)
135
+ static bool sort_and_join (exprt &expr, bool do_sort )
134
136
{
135
137
bool no_change = true ;
136
138
137
139
if (!expr.has_operands ())
138
140
return true ;
139
141
140
142
const struct saj_tablet &saj_entry =
141
- sort_and_join (expr.id (), as_const (expr).type ().id ());
143
+ get_sort_and_join_table_entry (expr.id (), as_const (expr).type ().id ());
142
144
if (saj_entry.id .empty ())
143
145
return true ;
144
146
145
147
// check operand types
146
148
147
149
forall_operands (it, expr)
148
- if (!sort_and_join (saj_entry, it->type ().id ()))
150
+ if (!is_associative_and_commutative_for_type (saj_entry, it->type ().id ()))
149
151
return true ;
150
152
151
153
// join expressions
152
154
153
155
exprt::operandst new_ops;
154
- new_ops.reserve (expr.operands ().size ());
156
+ new_ops.reserve (as_const ( expr) .operands ().size ());
155
157
156
158
forall_operands (it, expr)
157
159
{
@@ -169,13 +171,25 @@ bool sort_and_join(exprt &expr)
169
171
}
170
172
171
173
// sort it
174
+ if (do_sort)
175
+ no_change = sort_operands (new_ops) && no_change;
172
176
173
- no_change = sort_operands (new_ops) && no_change;
174
- expr.operands ().swap (new_ops);
177
+ if (! no_change)
178
+ expr.operands ().swap (new_ops);
175
179
176
180
return no_change;
177
181
}
178
182
183
+ bool sort_and_join (exprt &expr)
184
+ {
185
+ return sort_and_join (expr, true );
186
+ }
187
+
188
+ bool join_operands (exprt &expr)
189
+ {
190
+ return sort_and_join (expr, false );
191
+ }
192
+
179
193
optionalt<exprt> bits2expr (
180
194
const std::string &bits,
181
195
const typet &type,
0 commit comments