Skip to content

Commit 9d9e213

Browse files
authored
Merge pull request #6587 from diffblue/remove_ID_size_usage
array_typet and vector_typet APIs
2 parents 195458a + a7e039b commit 9d9e213

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+180
-153
lines changed

src/analyses/goto_rw.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,15 @@ void rw_range_sett::get_objects_index(
262262
{
263263
const vector_typet &vector_type=to_vector_type(type);
264264

265-
auto subtype_bits = pointer_offset_bits(vector_type.subtype(), ns);
265+
auto subtype_bits = pointer_offset_bits(vector_type.element_type(), ns);
266266

267267
sub_size = subtype_bits.has_value() ? to_range_spect(*subtype_bits) : -1;
268268
}
269269
else if(type.id()==ID_array)
270270
{
271271
const array_typet &array_type=to_array_type(type);
272272

273-
auto subtype_bits = pointer_offset_bits(array_type.subtype(), ns);
273+
auto subtype_bits = pointer_offset_bits(array_type.element_type(), ns);
274274

275275
sub_size = subtype_bits.has_value() ? to_range_spect(*subtype_bits) : -1;
276276
}
@@ -301,7 +301,7 @@ void rw_range_sett::get_objects_array(
301301
{
302302
const array_typet &array_type = expr.type();
303303

304-
auto subtype_bits = pointer_offset_bits(array_type.subtype(), ns);
304+
auto subtype_bits = pointer_offset_bits(array_type.element_type(), ns);
305305

306306
range_spect sub_size;
307307

@@ -608,7 +608,7 @@ void rw_range_sett::get_objects_rec(const typet &type)
608608
if(type.id()==ID_array)
609609
{
610610
const auto &array_type = to_array_type(type);
611-
get_objects_rec(array_type.subtype());
611+
get_objects_rec(array_type.element_type());
612612
get_objects_rec(get_modet::READ, array_type.size());
613613
}
614614
}

src/analyses/variable-sensitivity/abstract_aggregate_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct array_aggregate_typet
164164
static typet read_type(const typet &, const typet &object_type)
165165
{
166166
array_typet array_type(to_array_type(object_type));
167-
return array_type.subtype();
167+
return array_type.element_type();
168168
}
169169

170170
static void get_statistics(

src/ansi-c/c_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ shuffle_vector_exprt::shuffle_vector_exprt(
2323
op1() = std::move(*vector2);
2424

2525
const vector_typet &vt = to_vector_type(op0().type());
26-
type() =
27-
vector_typet{vt.subtype(), from_integer(indices.size(), vt.size().type())};
26+
type() = vector_typet{vt.element_type(),
27+
from_integer(indices.size(), vt.size().type())};
2828

2929
op2().operands().swap(indices);
3030
}

src/ansi-c/c_typecast.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ bool check_c_implicit_typecast(
223223
}
224224
}
225225

226-
if(dest_type.id()==ID_array &&
227-
src_type.subtype()==dest_type.subtype())
226+
if(
227+
dest_type.id() == ID_array &&
228+
src_type.subtype() == to_array_type(dest_type).element_type())
228229
return false;
229230

230231
if(dest_type.id()==ID_bool ||

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,15 +3389,16 @@ bool c_typecheck_baset::gcc_vector_types_compatible(
33893389
return false;
33903390

33913391
// compare subtype
3392-
if((type0.subtype().id()==ID_signedbv ||
3393-
type0.subtype().id()==ID_unsignedbv) &&
3394-
(type1.subtype().id()==ID_signedbv ||
3395-
type1.subtype().id()==ID_unsignedbv) &&
3396-
to_bitvector_type(type0.subtype()).get_width()==
3397-
to_bitvector_type(type1.subtype()).get_width())
3392+
if(
3393+
(type0.element_type().id() == ID_signedbv ||
3394+
type0.element_type().id() == ID_unsignedbv) &&
3395+
(type1.element_type().id() == ID_signedbv ||
3396+
type1.element_type().id() == ID_unsignedbv) &&
3397+
to_bitvector_type(type0.element_type()).get_width() ==
3398+
to_bitvector_type(type1.element_type()).get_width())
33983399
return true;
33993400

3400-
return type0.subtype()==type1.subtype();
3401+
return type0.element_type() == type1.element_type();
34013402
}
34023403

34033404
void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr)

src/ansi-c/c_typecheck_gcc_polymorphic_builtins.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,8 @@ exprt c_typecheck_baset::typecheck_shuffle_vector(
14401440
CHECK_RETURN(input_size.has_value());
14411441
if(arg1.has_value())
14421442
input_size = *input_size * 2;
1443-
constant_exprt size = from_integer(*input_size, indices_type.subtype());
1443+
constant_exprt size =
1444+
from_integer(*input_size, indices_type.element_type());
14441445

14451446
for(std::size_t i = 0; i < indices_size; ++i)
14461447
{

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void c_typecheck_baset::designator_enter(
318318
if(array_type.size().is_nil())
319319
{
320320
entry.size=0;
321-
entry.subtype=array_type.subtype();
321+
entry.subtype = array_type.element_type();
322322
}
323323
else
324324
{
@@ -332,7 +332,7 @@ void c_typecheck_baset::designator_enter(
332332
}
333333

334334
entry.size = numeric_cast_v<std::size_t>(*array_size);
335-
entry.subtype=array_type.subtype();
335+
entry.subtype = array_type.element_type();
336336
}
337337
}
338338
else if(full_type.id()==ID_vector)
@@ -350,7 +350,7 @@ void c_typecheck_baset::designator_enter(
350350
}
351351

352352
entry.size = numeric_cast_v<std::size_t>(*vector_size);
353-
entry.subtype=vector_type.subtype();
353+
entry.subtype = vector_type.element_type();
354354
}
355355
else
356356
UNREACHABLE;

src/ansi-c/c_typecheck_type.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,18 +526,18 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
526526
const source_locationt size_source_location = size.find_source_location();
527527

528528
// check subtype
529-
typecheck_type(type.subtype());
529+
typecheck_type(type.element_type());
530530

531531
// we don't allow void as subtype
532-
if(type.subtype().id() == ID_empty)
532+
if(type.element_type().id() == ID_empty)
533533
{
534534
error().source_location=type.source_location();
535535
error() << "array of voids" << eom;
536536
throw 0;
537537
}
538538

539539
// we don't allow incomplete structs or unions as subtype
540-
const typet &followed_subtype = follow(type.subtype());
540+
const typet &followed_subtype = follow(type.element_type());
541541

542542
if(
543543
(followed_subtype.id() == ID_struct || followed_subtype.id() == ID_union) &&
@@ -550,7 +550,7 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
550550
}
551551

552552
// we don't allow functions as subtype
553-
if(type.subtype().id() == ID_code)
553+
if(type.element_type().id() == ID_code)
554554
{
555555
// ISO/IEC 9899 6.7.5.2
556556
error().source_location = type.source_location();

src/ansi-c/expr2c.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ std::string expr2ct::convert_rec(
587587
const mp_integer size_int = numeric_cast_v<mp_integer>(vector_type.size());
588588
std::string dest="__gcc_v"+integer2string(size_int);
589589

590-
std::string tmp=convert(vector_type.subtype());
590+
std::string tmp = convert(vector_type.element_type());
591591

592592
if(tmp=="signed char" || tmp=="char")
593593
dest+="qi";
@@ -603,7 +603,7 @@ std::string expr2ct::convert_rec(
603603
dest+="df";
604604
else
605605
{
606-
const std::string subtype=convert(vector_type.subtype());
606+
const std::string subtype = convert(vector_type.element_type());
607607
dest=subtype;
608608
dest+=" __attribute__((vector_size (";
609609
dest+=convert(vector_type.size());

src/cpp/cpp_declarator_converter.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@ void cpp_declarator_convertert::combine_types(
313313
}
314314
else if(symbol.type==decl_type)
315315
return; // ok
316-
else if(symbol.type.id()==ID_array &&
317-
symbol.type.find(ID_size).is_nil() &&
318-
decl_type.id()==ID_array &&
319-
symbol.type.subtype()==decl_type.subtype())
316+
else if(
317+
symbol.type.id() == ID_array &&
318+
to_array_type(symbol.type).size().is_nil() && decl_type.id() == ID_array &&
319+
to_array_type(symbol.type).element_type() ==
320+
to_array_type(decl_type).element_type())
320321
{
321322
symbol.type = decl_type;
322323
return; // ok

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ void cpp_typecheckt::check_fixed_size_array(typet &type)
794794
}
795795

796796
// recursive call for multi-dimensional arrays
797-
check_fixed_size_array(array_type.subtype());
797+
check_fixed_size_array(array_type.element_type());
798798
}
799799
}
800800

src/cpp/cpp_typecheck_initializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ void cpp_typecheckt::zero_initializer(
244244
for(mp_integer i=0; i<size; ++i)
245245
{
246246
index_exprt index(
247-
object, from_integer(i, c_index_type()), array_type.subtype());
248-
zero_initializer(index, array_type.subtype(), source_location, ops);
247+
object, from_integer(i, c_index_type()), array_type.element_type());
248+
zero_initializer(index, array_type.element_type(), source_location, ops);
249249
}
250250
}
251251
else if(final_type.id()==ID_union)

src/cpp/template_map.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ void template_mapt::apply(typet &type) const
2323
{
2424
if(type.id()==ID_array)
2525
{
26-
apply(type.subtype());
27-
apply(static_cast<exprt &>(type.add(ID_size)));
26+
apply(to_array_type(type).element_type());
27+
apply(to_array_type(type).size());
2828
}
2929
else if(type.id()==ID_pointer)
3030
{

src/goto-programs/graphml_witness.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ std::string graphml_witnesst::convert_assign_rec(
109109
forall_operands(it, assign.rhs())
110110
{
111111
index_exprt index(
112-
assign.lhs(), from_integer(i++, c_index_type()), type.subtype());
112+
assign.lhs(), from_integer(i++, c_index_type()), type.element_type());
113113
if(!result.empty())
114114
result+=' ';
115115
result+=convert_assign_rec(identifier, code_assignt(index, *it));

src/goto-programs/interpreter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ exprt interpretert::get_value(
487487
{
488488
// Get size of array
489489
array_exprt result({}, to_array_type(real_type));
490-
const exprt &size_expr=static_cast<const exprt &>(type.find(ID_size));
490+
const exprt &size_expr = to_array_type(type).size();
491491
mp_integer subtype_size=get_size(type.subtype());
492492
mp_integer count;
493493
if(size_expr.id()!=ID_constant)
@@ -553,7 +553,7 @@ exprt interpretert::get_value(
553553
else if(real_type.id()==ID_array)
554554
{
555555
array_exprt result({}, to_array_type(real_type));
556-
const exprt &size_expr=static_cast<const exprt &>(type.find(ID_size));
556+
const exprt &size_expr = to_array_type(real_type).size();
557557

558558
// Get size of array
559559
mp_integer subtype_size=get_size(type.subtype());
@@ -888,7 +888,7 @@ typet interpretert::concretize_type(const typet &type)
888888
{
889889
if(type.id()==ID_array)
890890
{
891-
const exprt &size_expr=static_cast<const exprt &>(type.find(ID_size));
891+
const exprt &size_expr = to_array_type(type).size();
892892
mp_vectort computed_size = evaluate(size_expr);
893893
if(computed_size.size()==1 &&
894894
computed_size[0]>=0)
@@ -1006,7 +1006,7 @@ mp_integer interpretert::get_size(const typet &type)
10061006
}
10071007
else if(type.id()==ID_array)
10081008
{
1009-
const exprt &size_expr=static_cast<const exprt &>(type.find(ID_size));
1009+
const exprt &size_expr = to_array_type(type).size();
10101010

10111011
mp_integer subtype_size=get_size(type.subtype());
10121012

src/goto-programs/interpreter_evaluate.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool interpretert::count_type_leaves(const typet &ty, mp_integer &result)
136136
if(array_size_vec.size()!=1)
137137
return true;
138138
mp_integer subtype_count;
139-
if(count_type_leaves(at.subtype(), subtype_count))
139+
if(count_type_leaves(at.element_type(), subtype_count))
140140
return true;
141141
result=array_size_vec[0]*subtype_count;
142142
return false;
@@ -205,12 +205,12 @@ bool interpretert::byte_offset_to_memory_offset(
205205
return true;
206206

207207
mp_integer array_size=array_size_vec[0];
208-
auto elem_size_bytes = pointer_offset_size(at.subtype(), ns);
208+
auto elem_size_bytes = pointer_offset_size(at.element_type(), ns);
209209
if(!elem_size_bytes.has_value() || *elem_size_bytes == 0)
210210
return true;
211211

212212
mp_integer elem_size_leaves;
213-
if(count_type_leaves(at.subtype(), elem_size_leaves))
213+
if(count_type_leaves(at.element_type(), elem_size_leaves))
214214
return true;
215215

216216
mp_integer this_idx = offset / (*elem_size_bytes);
@@ -219,7 +219,7 @@ bool interpretert::byte_offset_to_memory_offset(
219219

220220
mp_integer subtype_result;
221221
bool ret = byte_offset_to_memory_offset(
222-
at.subtype(), offset % (*elem_size_bytes), subtype_result);
222+
at.element_type(), offset % (*elem_size_bytes), subtype_result);
223223

224224
result=subtype_result+(elem_size_leaves*this_idx);
225225
return ret;
@@ -280,24 +280,21 @@ bool interpretert::memory_offset_to_byte_offset(
280280
if(array_size_vec.size()!=1)
281281
return true;
282282

283-
auto elem_size = pointer_offset_size(at.subtype(), ns);
283+
auto elem_size = pointer_offset_size(at.element_type(), ns);
284284
if(!elem_size.has_value())
285285
return true;
286286

287287
mp_integer elem_count;
288-
if(count_type_leaves(at.subtype(), elem_count))
288+
if(count_type_leaves(at.element_type(), elem_count))
289289
return true;
290290

291291
mp_integer this_idx=full_cell_offset/elem_count;
292292
if(this_idx>=array_size_vec[0])
293293
return true;
294294

295295
mp_integer subtype_result;
296-
bool ret=
297-
memory_offset_to_byte_offset(
298-
at.subtype(),
299-
full_cell_offset%elem_count,
300-
subtype_result);
296+
bool ret = memory_offset_to_byte_offset(
297+
at.element_type(), full_cell_offset % elem_count, subtype_result);
301298
result = subtype_result + ((*elem_size) * this_idx);
302299
return ret;
303300
}

src/goto-programs/json_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ json_objectt json(const typet &type, const namespacet &ns, const irep_idt &mode)
154154
else if(type.id() == ID_array)
155155
{
156156
result["name"] = json_stringt("array");
157-
result["subtype"] = json(to_array_type(type).subtype(), ns, mode);
157+
result["subtype"] = json(to_array_type(type).element_type(), ns, mode);
158158
result["size"] = json(to_array_type(type).size(), ns, mode);
159159
}
160160
else if(type.id() == ID_vector)
161161
{
162162
result["name"] = json_stringt("vector");
163-
result["subtype"] = json(to_vector_type(type).subtype(), ns, mode);
163+
result["subtype"] = json(to_vector_type(type).element_type(), ns, mode);
164164
result["size"] = json(to_vector_type(type).size(), ns, mode);
165165
}
166166
else if(type.id() == ID_struct)

src/goto-programs/remove_vector.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void remove_vector(exprt &expr)
116116
const mp_integer dimension =
117117
numeric_cast_v<mp_integer>(to_constant_expr(array_type.size()));
118118

119-
const typet subtype=array_type.subtype();
119+
const typet subtype = array_type.element_type();
120120
// do component-wise:
121121
// x+y -> vector(x[0]+y[0],x[1]+y[1],...)
122122
array_exprt array_expr({}, array_type);
@@ -144,7 +144,7 @@ static void remove_vector(exprt &expr)
144144
const mp_integer dimension =
145145
numeric_cast_v<mp_integer>(to_constant_expr(array_type.size()));
146146

147-
const typet subtype=array_type.subtype();
147+
const typet subtype = array_type.element_type();
148148
// do component-wise:
149149
// -x -> vector(-x[0],-x[1],...)
150150
array_exprt array_expr({}, array_type);
@@ -173,7 +173,7 @@ static void remove_vector(exprt &expr)
173173
const vector_typet &vector_type = to_vector_type(expr.type());
174174
const auto dimension = numeric_cast_v<std::size_t>(vector_type.size());
175175

176-
const typet &subtype = vector_type.subtype();
176+
const typet &subtype = vector_type.element_type();
177177
PRECONDITION(subtype.id() == ID_signedbv);
178178
exprt minus_one = from_integer(-1, subtype);
179179
exprt zero = from_integer(0, subtype);
@@ -237,7 +237,7 @@ static void remove_vector(exprt &expr)
237237
const auto dimension =
238238
numeric_cast_v<std::size_t>(to_constant_expr(array_type.size()));
239239
exprt casted_op =
240-
typecast_exprt::conditional_cast(op, array_type.subtype());
240+
typecast_exprt::conditional_cast(op, array_type.element_type());
241241
source_locationt source_location = expr.source_location();
242242
expr = array_exprt(exprt::operandst(dimension, casted_op), array_type);
243243
expr.add_source_location() = std::move(source_location);
@@ -285,10 +285,10 @@ static void remove_vector(typet &type)
285285
{
286286
vector_typet &vector_type=to_vector_type(type);
287287

288-
remove_vector(type.subtype());
288+
remove_vector(vector_type.element_type());
289289

290290
// Replace by an array with appropriate number of members.
291-
array_typet array_type(vector_type.subtype(), vector_type.size());
291+
array_typet array_type(vector_type.element_type(), vector_type.size());
292292
array_type.add_source_location()=type.source_location();
293293
type=array_type;
294294
}

0 commit comments

Comments
 (0)