Skip to content

Commit 24b2947

Browse files
committed
rename op1/op2 to index/new_value in convert_with
This replaces op1/op2 by identifiers that clearly state the purpose of the operand.
1 parent e18fead commit 24b2947

File tree

2 files changed

+68
-58
lines changed

2 files changed

+68
-58
lines changed

src/solvers/flattening/boolbv.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,34 +198,34 @@ class boolbvt:public arrayst
198198

199199
void convert_with(
200200
const typet &type,
201-
const exprt &op1,
202-
const exprt &op2,
201+
const exprt &where,
202+
const exprt &new_value,
203203
const bvt &prev_bv,
204204
bvt &next_bv);
205205

206206
void convert_with_bv(
207-
const exprt &op1,
208-
const exprt &op2,
207+
const exprt &index,
208+
const exprt &new_value,
209209
const bvt &prev_bv,
210210
bvt &next_bv);
211211

212212
void convert_with_array(
213213
const array_typet &type,
214-
const exprt &op1,
215-
const exprt &op2,
214+
const exprt &index,
215+
const exprt &new_value,
216216
const bvt &prev_bv,
217217
bvt &next_bv);
218218

219219
void convert_with_union(
220220
const union_typet &type,
221-
const exprt &op2,
221+
const exprt &new_value,
222222
const bvt &prev_bv,
223223
bvt &next_bv);
224224

225225
void convert_with_struct(
226226
const struct_typet &type,
227-
const exprt &op1,
228-
const exprt &op2,
227+
const exprt &where,
228+
const exprt &new_value,
229229
const bvt &prev_bv,
230230
bvt &next_bv);
231231

src/solvers/flattening/boolbv_with.cpp

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ bvt boolbvt::convert_with(const with_exprt &expr)
4747

4848
void boolbvt::convert_with(
4949
const typet &type,
50-
const exprt &op1,
51-
const exprt &op2,
50+
const exprt &where,
51+
const exprt &new_value,
5252
const bvt &prev_bv,
5353
bvt &next_bv)
5454
{
@@ -57,31 +57,40 @@ void boolbvt::convert_with(
5757
next_bv.resize(prev_bv.size());
5858

5959
if(type.id()==ID_array)
60-
return convert_with_array(to_array_type(type), op1, op2, prev_bv, next_bv);
60+
return convert_with_array(
61+
to_array_type(type), where, new_value, prev_bv, next_bv);
6162
else if(type.id()==ID_bv ||
6263
type.id()==ID_unsignedbv ||
6364
type.id()==ID_signedbv)
64-
return convert_with_bv(op1, op2, prev_bv, next_bv);
65+
return convert_with_bv(where, new_value, prev_bv, next_bv);
6566
else if(type.id()==ID_struct)
66-
return
67-
convert_with_struct(to_struct_type(type), op1, op2, prev_bv, next_bv);
67+
return convert_with_struct(
68+
to_struct_type(type), where, new_value, prev_bv, next_bv);
6869
else if(type.id() == ID_struct_tag)
6970
return convert_with(
70-
ns.follow_tag(to_struct_tag_type(type)), op1, op2, prev_bv, next_bv);
71+
ns.follow_tag(to_struct_tag_type(type)),
72+
where,
73+
new_value,
74+
prev_bv,
75+
next_bv);
7176
else if(type.id()==ID_union)
72-
return convert_with_union(to_union_type(type), op2, prev_bv, next_bv);
77+
return convert_with_union(to_union_type(type), new_value, prev_bv, next_bv);
7378
else if(type.id() == ID_union_tag)
7479
return convert_with(
75-
ns.follow_tag(to_union_tag_type(type)), op1, op2, prev_bv, next_bv);
80+
ns.follow_tag(to_union_tag_type(type)),
81+
where,
82+
new_value,
83+
prev_bv,
84+
next_bv);
7685

7786
DATA_INVARIANT_WITH_DIAGNOSTICS(
7887
false, "unexpected with type", irep_pretty_diagnosticst{type});
7988
}
8089

8190
void boolbvt::convert_with_array(
8291
const array_typet &type,
83-
const exprt &op1,
84-
const exprt &op2,
92+
const exprt &index,
93+
const exprt &new_value,
8594
const bvt &prev_bv,
8695
bvt &next_bv)
8796
{
@@ -100,89 +109,90 @@ void boolbvt::convert_with_array(
100109
"convert_with_array expects constant array size",
101110
irep_pretty_diagnosticst{type});
102111

103-
const bvt &op2_bv=convert_bv(op2);
112+
const bvt &new_value_bv = convert_bv(new_value);
104113

105114
DATA_INVARIANT_WITH_DIAGNOSTICS(
106-
*size * op2_bv.size() == prev_bv.size(),
107-
"convert_with_array: unexpected operand 2 width",
115+
*size * new_value_bv.size() == prev_bv.size(),
116+
"convert_with_array: unexpected new_value operand width",
108117
irep_pretty_diagnosticst{type});
109118

110119
// Is the index a constant?
111-
if(const auto op1_value = numeric_cast<mp_integer>(op1))
120+
if(const auto index_value_opt = numeric_cast<mp_integer>(index))
112121
{
113122
// Yes, it is!
114123
next_bv=prev_bv;
115124

116-
if(*op1_value >= 0 && *op1_value < *size) // bounds check
125+
if(*index_value_opt >= 0 && *index_value_opt < *size) // bounds check
117126
{
118127
const std::size_t offset =
119-
numeric_cast_v<std::size_t>(*op1_value * op2_bv.size());
128+
numeric_cast_v<std::size_t>(*index_value_opt * new_value_bv.size());
120129

121-
for(std::size_t j=0; j<op2_bv.size(); j++)
122-
next_bv[offset+j]=op2_bv[j];
130+
for(std::size_t j = 0; j < new_value_bv.size(); j++)
131+
next_bv[offset + j] = new_value_bv[j];
123132
}
124133

125134
return;
126135
}
127136

128-
typet counter_type=op1.type();
137+
typet counter_type = index.type();
129138

130139
for(mp_integer i=0; i<size; i=i+1)
131140
{
132141
exprt counter=from_integer(i, counter_type);
133142

134-
literalt eq_lit=convert(equal_exprt(op1, counter));
143+
literalt eq_lit = convert(equal_exprt(index, counter));
135144

136-
const std::size_t offset = numeric_cast_v<std::size_t>(i * op2_bv.size());
145+
const std::size_t offset =
146+
numeric_cast_v<std::size_t>(i * new_value_bv.size());
137147

138-
for(std::size_t j=0; j<op2_bv.size(); j++)
139-
next_bv[offset+j]=
140-
prop.lselect(eq_lit, op2_bv[j], prev_bv[offset+j]);
148+
for(std::size_t j = 0; j < new_value_bv.size(); j++)
149+
next_bv[offset + j] =
150+
prop.lselect(eq_lit, new_value_bv[j], prev_bv[offset + j]);
141151
}
142152
}
143153

144154
void boolbvt::convert_with_bv(
145-
const exprt &op1,
146-
const exprt &op2,
155+
const exprt &index,
156+
const exprt &new_value,
147157
const bvt &prev_bv,
148158
bvt &next_bv)
149159
{
150-
literalt l=convert(op2);
160+
literalt l = convert(new_value);
151161

152-
if(const auto op1_value = numeric_cast<mp_integer>(op1))
162+
if(const auto index_value_opt = numeric_cast<mp_integer>(index))
153163
{
154164
next_bv=prev_bv;
155165

156-
if(*op1_value < next_bv.size())
157-
next_bv[numeric_cast_v<std::size_t>(*op1_value)] = l;
166+
if(*index_value_opt >= 0 && *index_value_opt < next_bv.size())
167+
next_bv[numeric_cast_v<std::size_t>(*index_value_opt)] = l;
158168

159169
return;
160170
}
161171

162-
typet counter_type=op1.type();
172+
typet counter_type = index.type();
163173

164174
for(std::size_t i=0; i<prev_bv.size(); i++)
165175
{
166176
exprt counter=from_integer(i, counter_type);
167177

168-
literalt eq_lit=convert(equal_exprt(op1, counter));
178+
literalt eq_lit = convert(equal_exprt(index, counter));
169179

170180
next_bv[i]=prop.lselect(eq_lit, l, prev_bv[i]);
171181
}
172182
}
173183

174184
void boolbvt::convert_with_struct(
175185
const struct_typet &type,
176-
const exprt &op1,
177-
const exprt &op2,
186+
const exprt &where,
187+
const exprt &new_value,
178188
const bvt &prev_bv,
179189
bvt &next_bv)
180190
{
181191
next_bv=prev_bv;
182192

183-
const bvt &op2_bv=convert_bv(op2);
193+
const bvt &new_value_bv = convert_bv(new_value);
184194

185-
const irep_idt &component_name=op1.get(ID_component_name);
195+
const irep_idt &component_name = where.get(ID_component_name);
186196
const struct_typet::componentst &components=
187197
type.components();
188198

@@ -197,19 +207,19 @@ void boolbvt::convert_with_struct(
197207
if(c.get_name() == component_name)
198208
{
199209
DATA_INVARIANT_WITH_DIAGNOSTICS(
200-
subtype == op2.type(),
210+
subtype == new_value.type(),
201211
"with/struct: component '" + id2string(component_name) +
202212
"' type does not match",
203213
irep_pretty_diagnosticst{subtype},
204-
irep_pretty_diagnosticst{op2.type()});
214+
irep_pretty_diagnosticst{new_value.type()});
205215

206216
DATA_INVARIANT_WITH_DIAGNOSTICS(
207-
sub_width == op2_bv.size(),
208-
"convert_with_struct: unexpected operand op2 width",
217+
sub_width == new_value_bv.size(),
218+
"convert_with_struct: unexpected new_value operand width",
209219
irep_pretty_diagnosticst{type});
210220

211221
for(std::size_t i=0; i<sub_width; i++)
212-
next_bv[offset+i]=op2_bv[i];
222+
next_bv[offset + i] = new_value_bv[i];
213223

214224
break; // done
215225
}
@@ -220,22 +230,22 @@ void boolbvt::convert_with_struct(
220230

221231
void boolbvt::convert_with_union(
222232
const union_typet &type,
223-
const exprt &op2,
233+
const exprt &new_value,
224234
const bvt &prev_bv,
225235
bvt &next_bv)
226236
{
227237
next_bv=prev_bv;
228238

229-
const bvt &op2_bv=convert_bv(op2);
239+
const bvt &new_value_bv = convert_bv(new_value);
230240

231241
DATA_INVARIANT_WITH_DIAGNOSTICS(
232-
next_bv.size() >= op2_bv.size(),
233-
"convert_with_union: unexpected operand op2 width",
242+
next_bv.size() >= new_value_bv.size(),
243+
"convert_with_union: unexpected new_value operand width",
234244
irep_pretty_diagnosticst{type});
235245

236246
endianness_mapt map_u = endianness_map(type);
237-
endianness_mapt map_op2 = endianness_map(op2.type());
247+
endianness_mapt map_new_value = endianness_map(new_value.type());
238248

239-
for(std::size_t i = 0; i < op2_bv.size(); i++)
240-
next_bv[map_u.map_bit(i)] = op2_bv[map_op2.map_bit(i)];
249+
for(std::size_t i = 0; i < new_value_bv.size(); i++)
250+
next_bv[map_u.map_bit(i)] = new_value_bv[map_new_value.map_bit(i)];
241251
}

0 commit comments

Comments
 (0)