Skip to content

Commit 246879e

Browse files
authored
Merge pull request #3026 from tautschnig/no-id_type
Use type() instead of find(ID_type) or get(ID_type)
2 parents db3784f + 325db27 commit 246879e

6 files changed

+19
-40
lines changed

src/cpp/cpp_template_parameter.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ struct template_parametert:public exprt
4343
{
4444
return set(ID_identifier, identifier);
4545
}
46-
47-
// the type of expression parameters
48-
typet &type()
49-
{
50-
return static_cast<typet &>(add(ID_type));
51-
}
52-
53-
const typet &type() const
54-
{
55-
return static_cast<const typet &>(find(ID_type));
56-
}
5746
#endif
5847

5948
exprt &default_argument()

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,8 @@ void cpp_typecheckt::typecheck_compound_declarator(
476476
component.set(ID_is_inline, declaration.member_spec().is_inline());
477477

478478
// the 'virtual' name of the function
479-
std::string virtual_name =
480-
id2string(component.get_base_name()) +
481-
id2string(
482-
function_identifier(
483-
static_cast<const typet &>(component.find(ID_type))));
479+
std::string virtual_name = id2string(component.get_base_name()) +
480+
id2string(function_identifier(component.type()));
484481

485482
if(has_const(method_qualifier))
486483
virtual_name+="$const";

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,16 @@ void cpp_typecheckt::default_assignop_value(
462462
if(
463463
c.get_bool(ID_from_base) || c.get_bool(ID_is_type) ||
464464
c.get_bool(ID_is_static) || c.get_bool(ID_is_vtptr) ||
465-
c.get(ID_type) == ID_code)
465+
c.type().id() == ID_code)
466466
{
467467
continue;
468468
}
469469

470470
const irep_idt &mem_name = c.get_base_name();
471471

472-
if(c.get(ID_type) == ID_array)
472+
if(c.type().id() == ID_array)
473473
{
474-
const exprt &size_expr = to_array_type((typet &)c.find(ID_type)).size();
474+
const exprt &size_expr = to_array_type(c.type()).size();
475475

476476
if(size_expr.id()==ID_infinity)
477477
{
@@ -570,7 +570,7 @@ void cpp_typecheckt::check_member_initializers(
570570
// Data member
571571
if(
572572
!c.get_bool(ID_from_base) && !c.get_bool(ID_is_static) &&
573-
c.get(ID_type) != ID_code)
573+
c.type().id() != ID_code)
574574
{
575575
ok=true;
576576
break;
@@ -579,11 +579,10 @@ void cpp_typecheckt::check_member_initializers(
579579
// Maybe it is a parent constructor?
580580
if(c.get_bool(ID_is_type))
581581
{
582-
typet type = static_cast<const typet &>(c.find(ID_type));
583-
if(type.id() != ID_symbol_type)
582+
if(c.type().id() != ID_symbol_type)
584583
continue;
585584

586-
const symbolt &symb=lookup(type.get(ID_identifier));
585+
const symbolt &symb = lookup(to_symbol_type(c.type()).get_identifier());
587586
if(symb.type.id()!=ID_struct)
588587
break;
589588

@@ -741,7 +740,7 @@ void cpp_typecheckt::full_member_initialization(
741740
for(const auto &c : components)
742741
{
743742
if(
744-
c.get_base_name() == base_name && c.get(ID_type) != ID_code &&
743+
c.get_base_name() == base_name && c.type().id() != ID_code &&
745744
!c.get_bool(ID_is_type))
746745
{
747746
is_data=true;
@@ -881,8 +880,8 @@ void cpp_typecheckt::full_member_initialization(
881880
// If the data member is a reference, it must be explicitly
882881
// initialized
883882
if(
884-
!found && c.find(ID_type).id() == ID_pointer &&
885-
c.find(ID_type).get_bool(ID_C_reference))
883+
!found && c.type().id() == ID_pointer &&
884+
c.type().get_bool(ID_C_reference))
886885
{
887886
error().source_location = c.source_location();
888887
error() << "reference must be explicitly initialized" << eom;
@@ -891,7 +890,7 @@ void cpp_typecheckt::full_member_initialization(
891890

892891
// If the data member is not POD and is not explicitly initialized,
893892
// then its default constructor is called.
894-
if(!found && !cpp_is_pod((const typet &)(c.find(ID_type))))
893+
if(!found && !cpp_is_pod(c.type()))
895894
{
896895
irept name(ID_name);
897896
name.set(ID_identifier, mem_name);

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
921921
if(component.get_bool(ID_is_explicit))
922922
continue;
923923

924-
const typet &comp_type =
925-
static_cast<const typet&>(component.find(ID_type));
924+
const typet &comp_type = component.type();
926925

927926
if(comp_type.id() !=ID_code)
928927
continue;
@@ -1058,22 +1057,17 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
10581057
bool found=false;
10591058
for(const auto &component : to_struct_type(from).components())
10601059
{
1061-
const typet comp_type=static_cast<const typet&>(component.find(ID_type));
1062-
10631060
if(component.get_bool(ID_from_base))
10641061
continue;
10651062

10661063
if(!component.get_bool(ID_is_cast_operator))
10671064
continue;
10681065

1069-
assert(component.get(ID_type)==ID_code &&
1070-
component.find(ID_type).find(ID_parameters).get_sub().size()==1);
1066+
const code_typet &comp_type = to_code_type(component.type());
1067+
DATA_INVARIANT(
1068+
comp_type.parameters().size() == 1, "expected exactly one parameter");
10711069

1072-
typet this_type =
1073-
static_cast<const typet&>(comp_type.find(ID_parameters)
1074-
.get_sub()
1075-
.front()
1076-
.find(ID_type));
1070+
typet this_type = comp_type.parameters().front().type();
10771071
this_type.set(ID_C_reference, true);
10781072

10791073
exprt this_expr(expr);

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ void cpp_typecheck_resolvet::filter_for_named_scopes(
23142314
cpp_typecheck.lookup(id.identifier);
23152315

23162316
// Template struct? Really needs arguments to be a scope!
2317-
if(symbol.type.get(ID_type)==ID_struct)
2317+
if(symbol.type.id() == ID_struct)
23182318
{
23192319
id.print(std::cout);
23202320
assert(id.is_scope);

src/cpp/template_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void template_mapt::apply(typet &type) const
3333
{
3434
for(auto &c : to_struct_union_type(type).components())
3535
{
36-
typet &subtype = static_cast<typet &>(c.add(ID_type));
36+
typet &subtype = c.type();
3737
apply(subtype);
3838
}
3939
}

0 commit comments

Comments
 (0)