Skip to content

Commit 3b27b76

Browse files
committed
remove usage of typet::subtype()
This commit replaces invocations of typet::subtype() by the appropriate methods offered by the more specific types, e.g., pointer_typet, array_typet, and so on.
1 parent 59155f9 commit 3b27b76

File tree

98 files changed

+742
-483
lines changed

Some content is hidden

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

98 files changed

+742
-483
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,8 +2431,8 @@ void java_bytecode_convert_methodt::convert_athrow(
24312431
{
24322432
if(
24332433
assert_no_exceptions_thrown ||
2434-
((uncaught_exceptions_domaint::get_exception_type(op[0].type()) ==
2435-
"java::java.lang.AssertionError") &&
2434+
((uncaught_exceptions_domaint::get_exception_type(
2435+
to_reference_type(op[0].type())) == "java::java.lang.AssertionError") &&
24362436
!throw_assertion_error))
24372437
{
24382438
// we translate athrow into

jbmc/src/java_bytecode/java_types.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,8 @@ class java_generic_parametert : public reference_typet
809809
template <>
810810
inline bool can_cast_type<java_generic_parametert>(const typet &base)
811811
{
812-
return is_reference(base) && is_java_generic_parameter_tag(base.subtype());
812+
return is_reference(base) &&
813+
is_java_generic_parameter_tag(to_reference_type(base).base_type());
813814
}
814815

815816
/// Checks whether the type is a java generic parameter/variable, e.g., `T` in
@@ -937,7 +938,8 @@ class java_generic_typet:public reference_typet
937938
template <>
938939
inline bool can_cast_type<java_generic_typet>(const typet &type)
939940
{
940-
return is_reference(type) && is_java_generic_struct_tag_type(type.subtype());
941+
return is_reference(type) &&
942+
is_java_generic_struct_tag_type(to_reference_type(type).base_type());
941943
}
942944

943945
/// \param type: the type to check

jbmc/unit/java_bytecode/java_bytecode_convert_class/convert_java_annotations.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ SCENARIO(
3737
REQUIRE(annotations.size() == 1);
3838
const auto &annotation = annotations.front();
3939
const auto &identifier =
40-
to_struct_tag_type(annotation.type.subtype()).get_identifier();
40+
to_struct_tag_type(to_reference_type(annotation.type).base_type())
41+
.get_identifier();
4142
REQUIRE(id2string(identifier) == "java::MyClassAnnotation");
4243
const auto &element_value_pair = annotation.element_value_pairs.front();
4344
const auto &element_name = element_value_pair.element_name;
@@ -64,7 +65,8 @@ SCENARIO(
6465
REQUIRE(annotations.size() == 1);
6566
const auto &annotation = annotations.front();
6667
const auto &identifier =
67-
to_struct_tag_type(annotation.type.subtype()).get_identifier();
68+
to_struct_tag_type(to_reference_type(annotation.type).base_type())
69+
.get_identifier();
6870
REQUIRE(id2string(identifier) == "java::MyMethodAnnotation");
6971
const auto &element_value_pair = annotation.element_value_pairs.front();
7072
const auto &element_name = element_value_pair.element_name;

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_annotations.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ SCENARIO(
9393
const auto &id =
9494
to_symbol_expr(element_value_pair.value).get_identifier();
9595
const auto &java_type = java_type_from_string(id2string(id));
96-
const std::string &class_name =
97-
id2string(to_struct_tag_type(java_type->subtype()).get_identifier());
96+
const std::string &class_name = id2string(
97+
to_struct_tag_type(to_reference_type(*java_type).base_type())
98+
.get_identifier());
9899
REQUIRE(id2string(class_name) == "java::java.lang.String");
99100
}
100101
}

jbmc/unit/java_bytecode/java_trace_validation/java_trace_validation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ TEST_CASE("java trace validation", "[core][java_trace_validation]")
3030
member_exprt(plain_expr, "member", java_int_type());
3131
const constant_exprt invalid_constant = constant_exprt("", java_int_type());
3232
const constant_exprt valid_constant = constant_exprt("0", java_int_type());
33-
const index_exprt valid_index =
34-
index_exprt(valid_symbol_expr, valid_constant);
35-
const index_exprt index_plain = index_exprt(exprt(), exprt());
33+
const index_exprt valid_index = index_exprt(
34+
symbol_exprt("id", array_typet(typet(), nil_exprt())), valid_constant);
35+
const index_exprt index_plain =
36+
index_exprt(exprt(ID_nil, array_typet(typet(), nil_exprt())), exprt());
3637
const byte_extract_exprt byte_little_endian = byte_extract_exprt(
3738
ID_byte_extract_little_endian, exprt(), exprt(), typet());
3839
const byte_extract_exprt byte_big_endian =

src/analyses/does_remove_const.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ Author: Diffblue Ltd.
1212
#include "does_remove_const.h"
1313

1414
#include <goto-programs/goto_program.h>
15-
#include <util/type.h>
16-
#include <util/std_code.h>
15+
1716
#include <util/base_type.h>
17+
#include <util/pointer_expr.h>
18+
#include <util/std_code.h>
1819

1920
/// A naive analysis to look for casts that remove const-ness from pointers.
2021
/// \param goto_program: the goto program to check
@@ -122,16 +123,20 @@ bool does_remove_constt::does_type_preserve_const_correctness(
122123
{
123124
while(target_type->id()==ID_pointer)
124125
{
125-
bool direct_subtypes_at_least_as_const=
126-
is_type_at_least_as_const_as(
127-
target_type->subtype(), source_type->subtype());
126+
PRECONDITION(source_type->id() == ID_pointer);
127+
128+
const auto &target_pointer_type = to_pointer_type(*target_type);
129+
const auto &source_pointer_type = to_pointer_type(*source_type);
130+
131+
bool direct_subtypes_at_least_as_const = is_type_at_least_as_const_as(
132+
target_pointer_type.base_type(), source_pointer_type.base_type());
128133
// We have a pointer to something, but the thing it is pointing to can't be
129134
// modified normally, but can through this pointer
130135
if(!direct_subtypes_at_least_as_const)
131136
return false;
132137
// Check the subtypes if they are pointers
133-
target_type=&target_type->subtype();
134-
source_type=&source_type->subtype();
138+
target_type = &target_pointer_type.base_type();
139+
source_type = &source_pointer_type.base_type();
135140
}
136141
return true;
137142
}

src/analyses/goto_check_c.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,8 @@ void goto_check_ct::pointer_primitive_check(
13521352
return;
13531353
}
13541354

1355-
const auto size_of_expr_opt = size_of_expr(pointer.type().subtype(), ns);
1355+
const auto size_of_expr_opt =
1356+
size_of_expr(to_pointer_type(pointer.type()).base_type(), ns);
13561357

13571358
const exprt size = !size_of_expr_opt.has_value()
13581359
? from_integer(1, size_type())

src/analyses/goto_rw.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ void rw_range_sett::get_objects_complex_imag(
9898
{
9999
const exprt &op = expr.op();
100100

101-
auto subtype_bits = pointer_offset_bits(op.type().subtype(), ns);
101+
auto subtype_bits =
102+
pointer_offset_bits(to_complex_type(op.type()).subtype(), ns);
102103
CHECK_RETURN(subtype_bits.has_value());
103104

104105
range_spect sub_size = to_range_spect(*subtype_bits);

src/analyses/uncaught_exceptions_analysis.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ Author: Cristina David
1515
#include "uncaught_exceptions_analysis.h"
1616

1717
#include <util/namespace.h>
18+
#include <util/pointer_expr.h>
1819
#include <util/symbol_table.h>
1920

2021
#include <goto-programs/goto_functions.h>
2122

2223
/// Returns the compile type of an exception
23-
irep_idt uncaught_exceptions_domaint::get_exception_type(const typet &type)
24+
irep_idt
25+
uncaught_exceptions_domaint::get_exception_type(const pointer_typet &type)
2426
{
25-
PRECONDITION(type.id()==ID_pointer);
26-
27-
if(type.subtype().id() == ID_struct_tag)
28-
return to_struct_tag_type(type.subtype()).get_identifier();
27+
if(type.base_type().id() == ID_struct_tag)
28+
return to_struct_tag_type(type.base_type()).get_identifier();
2929
else
3030
return ID_empty;
3131
}
@@ -73,7 +73,8 @@ void uncaught_exceptions_domaint::transform(
7373
{
7474
const exprt &exc_symbol = get_exception_symbol(instruction.get_code());
7575
// retrieve the static type of the thrown exception
76-
const irep_idt &type_id=get_exception_type(exc_symbol.type());
76+
const irep_idt &type_id =
77+
get_exception_type(to_pointer_type(exc_symbol.type()));
7778
join(type_id);
7879
// we must consider all the subtypes given that
7980
// the runtime type is a subtype of the static type

src/analyses/uncaught_exceptions_analysis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Cristina David
2020

2121
class goto_functionst;
2222
class namespacet;
23+
class pointer_typet;
2324

2425
/// defines the domain used by the uncaught exceptions analysis
2526
class uncaught_exceptions_analysist;
@@ -41,7 +42,7 @@ class uncaught_exceptions_domaint
4142
stack_caught.clear();
4243
}
4344

44-
static irep_idt get_exception_type(const typet &type);
45+
static irep_idt get_exception_type(const pointer_typet &);
4546

4647
static exprt get_exception_symbol(const exprt &exor);
4748

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ void ansi_c_convert_typet::read_rec(const typet &type)
5353
c_storage_spec.asm_label =
5454
to_string_constant(type_with_subtypes.subtypes()[0]).get_value();
5555
}
56-
else if(type.id()==ID_section &&
57-
type.has_subtype() &&
58-
type.subtype().id()==ID_string_constant)
56+
else if(
57+
type.id() == ID_section && type.has_subtype() &&
58+
to_type_with_subtype(type).subtype().id() == ID_string_constant)
5959
{
60-
c_storage_spec.section = to_string_constant(type.subtype()).get_value();
60+
c_storage_spec.section =
61+
to_string_constant(to_type_with_subtype(type).subtype()).get_value();
6162
}
6263
else if(type.id()==ID_const)
6364
c_qualifiers.is_constant=true;
@@ -69,7 +70,7 @@ void ansi_c_convert_typet::read_rec(const typet &type)
6970
{
7071
// this gets turned into the qualifier, uh
7172
c_qualifiers.is_atomic=true;
72-
read_rec(type.subtype());
73+
read_rec(to_type_with_subtype(type).subtype());
7374
}
7475
else if(type.id()==ID_char)
7576
char_cnt++;
@@ -228,18 +229,20 @@ void ansi_c_convert_typet::read_rec(const typet &type)
228229
constructor=true;
229230
else if(type.id()==ID_destructor)
230231
destructor=true;
231-
else if(type.id()==ID_alias &&
232-
type.has_subtype() &&
233-
type.subtype().id()==ID_string_constant)
232+
else if(
233+
type.id() == ID_alias && type.has_subtype() &&
234+
to_type_with_subtype(type).subtype().id() == ID_string_constant)
234235
{
235-
c_storage_spec.alias = to_string_constant(type.subtype()).get_value();
236+
c_storage_spec.alias =
237+
to_string_constant(to_type_with_subtype(type).subtype()).get_value();
236238
}
237239
else if(type.id()==ID_frontend_pointer)
238240
{
239241
// We turn ID_frontend_pointer to ID_pointer
240242
// Pointers have a width, much like integers,
241243
// which is added here.
242-
pointer_typet tmp(type.subtype(), config.ansi_c.pointer_width);
244+
pointer_typet tmp(
245+
to_type_with_subtype(type).subtype(), config.ansi_c.pointer_width);
243246
tmp.add_source_location()=type.source_location();
244247
const irep_idt typedef_identifier=type.get(ID_C_typedef);
245248
if(!typedef_identifier.empty())

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ bool generate_ansi_c_start_function(
405405
{
406406
// assign argv[argc] to NULL
407407
const null_pointer_exprt null(
408-
to_pointer_type(argv_symbol.type.subtype()));
408+
to_pointer_type(to_array_type(argv_symbol.type).element_type()));
409409

410410
index_exprt index_expr(
411411
argv_symbol.symbol_expr(), argc_symbol.symbol_expr());
@@ -422,7 +422,8 @@ bool generate_ansi_c_start_function(
422422
const symbolt &envp_size_symbol=ns.lookup("envp_size'");
423423

424424
// assume envp[envp_size] is NULL
425-
null_pointer_exprt null(to_pointer_type(envp_symbol.type.subtype()));
425+
null_pointer_exprt null(
426+
to_pointer_type(to_array_type(envp_symbol.type).element_type()));
426427

427428
index_exprt index_expr(
428429
envp_symbol.symbol_expr(), envp_size_symbol.symbol_expr());

src/ansi-c/ansi_c_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ ansi_c_id_classt ansi_c_parsert::get_class(const typet &type)
171171
}
172172
}
173173
else if(type.has_subtype())
174-
return get_class(type.subtype());
174+
return get_class(to_type_with_subtype(type).subtype());
175175

176176
return ansi_c_id_classt::ANSI_C_SYMBOL;
177177
}

src/ansi-c/c_storage_spec.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ void c_storage_spect::read(const typet &type)
4646
if(it->id()==ID_thread)
4747
is_thread_local=true;
4848
}
49-
else if(type.id()==ID_alias &&
50-
type.has_subtype() &&
51-
type.subtype().id()==ID_string_constant)
49+
else if(
50+
type.id() == ID_alias && type.has_subtype() &&
51+
to_type_with_subtype(type).subtype().id() == ID_string_constant)
5252
{
53-
alias = to_string_constant(type.subtype()).get_value();
53+
alias =
54+
to_string_constant(to_type_with_subtype(type).subtype()).get_value();
5455
}
5556
else if(
5657
type.id() == ID_asm && !to_type_with_subtypes(type).subtypes().empty() &&
@@ -59,10 +60,11 @@ void c_storage_spect::read(const typet &type)
5960
asm_label =
6061
to_string_constant(to_type_with_subtypes(type).subtypes()[0]).get_value();
6162
}
62-
else if(type.id()==ID_section &&
63-
type.has_subtype() &&
64-
type.subtype().id()==ID_string_constant)
63+
else if(
64+
type.id() == ID_section && type.has_subtype() &&
65+
to_type_with_subtype(type).subtype().id() == ID_string_constant)
6566
{
66-
section = to_string_constant(type.subtype()).get_value();
67+
section =
68+
to_string_constant(to_type_with_subtype(type).subtype()).get_value();
6769
}
6870
}

0 commit comments

Comments
 (0)