diff --git a/src/cpp/cpp_constructor.cpp b/src/cpp/cpp_constructor.cpp index a0149204430..7a352c3d86c 100644 --- a/src/cpp/cpp_constructor.cpp +++ b/src/cpp/cpp_constructor.cpp @@ -181,9 +181,8 @@ optionalt cpp_typecheckt::cpp_constructor( // set most-derived bits code_blockt block; - for(std::size_t i=0; i < struct_type.components().size(); i++) + for(const auto &component : struct_type.components()) { - const irept &component=struct_type.components()[i]; if(component.get(ID_base_name)!="@most_derived") continue; diff --git a/src/cpp/cpp_typecheck_constructor.cpp b/src/cpp/cpp_typecheck_constructor.cpp index 1becb2fd7b4..d9bc59117e9 100644 --- a/src/cpp/cpp_typecheck_constructor.cpp +++ b/src/cpp/cpp_typecheck_constructor.cpp @@ -455,23 +455,21 @@ void cpp_typecheckt::default_assignop_value( } // Then, we copy the members - const irept &components=symbol.type.find(ID_components); - - forall_irep(mem_it, components.get_sub()) + for(const auto &c : to_struct_type(symbol.type).components()) { - if(mem_it->get_bool(ID_from_base) || - mem_it->get_bool(ID_is_type) || - mem_it->get_bool(ID_is_static) || - mem_it->get_bool("is_vtptr") || - mem_it->get(ID_type)==ID_code) + if( + c.get_bool(ID_from_base) || c.get_bool(ID_is_type) || + c.get_bool(ID_is_static) || c.get_bool("is_vtptr") || + c.get(ID_type) == ID_code) + { continue; + } - irep_idt mem_name=mem_it->get(ID_base_name); + const irep_idt &mem_name = c.get(ID_base_name); - if(mem_it->get(ID_type)==ID_array) + if(c.get(ID_type) == ID_array) { - const exprt &size_expr= - to_array_type((typet&)mem_it->find(ID_type)).size(); + const exprt &size_expr = to_array_type((typet &)c.find(ID_type)).size(); if(size_expr.id()==ID_infinity) { @@ -811,21 +809,20 @@ void cpp_typecheckt::full_member_initialization( } // Then, we add the member initializers - for(struct_typet::componentst::const_iterator mem_it = - components.begin(); mem_it!=components.end(); mem_it++) + for(const auto &c : components) { // Take care of virtual tables - if(mem_it->get_bool("is_vtptr")) + if(c.get_bool("is_vtptr")) { exprt name(ID_name); - name.set(ID_identifier, mem_it->get(ID_base_name)); - name.add_source_location()=mem_it->source_location(); + name.set(ID_identifier, c.get(ID_base_name)); + name.add_source_location() = c.source_location(); cpp_namet cppname; cppname.move_to_sub(name); const symbolt &virtual_table_symbol_type = - lookup(mem_it->type().subtype().get(ID_identifier)); + lookup(c.type().subtype().get(ID_identifier)); const symbolt &virtual_table_symbol_var = lookup(id2string(virtual_table_symbol_type.name) + "@" + @@ -833,12 +830,12 @@ void cpp_typecheckt::full_member_initialization( exprt var=virtual_table_symbol_var.symbol_expr(); address_of_exprt address(var); - assert(address.type()==mem_it->type()); + assert(address.type() == c.type()); already_typechecked(address); exprt ptrmember(ID_ptrmember); - ptrmember.set(ID_component_name, mem_it->get(ID_name)); + ptrmember.set(ID_component_name, c.get(ID_name)); ptrmember.operands().push_back(exprt("cpp-this")); code_assignt assign(ptrmember, address); @@ -846,13 +843,14 @@ void cpp_typecheckt::full_member_initialization( continue; } - if( mem_it->get_bool(ID_from_base) - || mem_it->type().id()==ID_code - || mem_it->get_bool(ID_is_type) - || mem_it->get_bool(ID_is_static)) - continue; + if( + c.get_bool(ID_from_base) || c.type().id() == ID_code || + c.get_bool(ID_is_type) || c.get_bool(ID_is_static)) + { + continue; + } - irep_idt mem_name=mem_it->get(ID_base_name); + const irep_idt &mem_name = c.get(ID_base_name); // Check if the initialization list of the constructor // explicitly initializes the data member @@ -880,18 +878,18 @@ void cpp_typecheckt::full_member_initialization( // If the data member is a reference, it must be explicitly // initialized - if(!found && - mem_it->find(ID_type).id()==ID_pointer && - mem_it->find(ID_type).get_bool(ID_C_reference)) + if( + !found && c.find(ID_type).id() == ID_pointer && + c.find(ID_type).get_bool(ID_C_reference)) { - error().source_location=mem_it->source_location(); + error().source_location = c.source_location(); error() << "reference must be explicitly initialized" << eom; throw 0; } // If the data member is not POD and is not explicitly initialized, // then its default constructor is called. - if(!found && !cpp_is_pod((const typet &)(mem_it->find(ID_type)))) + if(!found && !cpp_is_pod((const typet &)(c.find(ID_type)))) { irept name(ID_name); name.set(ID_identifier, mem_name); @@ -972,10 +970,8 @@ bool cpp_typecheckt::find_assignop(const symbolt &symbol) const const struct_typet &struct_type=to_struct_type(symbol.type); const struct_typet::componentst &components=struct_type.components(); - for(std::size_t i=0; i < components.size(); i++) + for(const auto &component : components) { - const struct_typet::componentt &component=components[i]; - if(component.get(ID_base_name)!="operator=") continue; diff --git a/src/cpp/cpp_typecheck_conversions.cpp b/src/cpp/cpp_typecheck_conversions.cpp index 432809e4f6e..e48a376c31b 100644 --- a/src/cpp/cpp_typecheck_conversions.cpp +++ b/src/cpp/cpp_typecheck_conversions.cpp @@ -911,17 +911,10 @@ bool cpp_typecheckt::user_defined_conversion_sequence( if(from.id()==ID_struct) from_struct=to_struct_type(from); - struct_typet to_struct=to_struct_type(to); - bool found=false; - for(struct_typet::componentst::const_iterator - it=to_struct.components().begin(); - it != to_struct.components().end(); - it++) + for(const auto &component : to_struct_type(to).components()) { - const irept &component=*it; - if(component.get_bool(ID_from_base)) continue; @@ -1062,14 +1055,9 @@ bool cpp_typecheckt::user_defined_conversion_sequence( // conversion operators if(from.id()==ID_struct) { - struct_typet from_struct=to_struct_type(from); - bool found=false; - for(struct_typet::componentst::const_iterator - it=from_struct.components().begin(); - it != from_struct.components().end(); it++) + for(const auto &component : to_struct_type(from).components()) { - const irept &component=*it; const typet comp_type=static_cast(component.find(ID_type)); if(component.get_bool(ID_from_base)) diff --git a/src/cpp/cpp_typecheck_declaration.cpp b/src/cpp/cpp_typecheck_declaration.cpp index c8cabc9ab11..5edee699602 100644 --- a/src/cpp/cpp_typecheck_declaration.cpp +++ b/src/cpp/cpp_typecheck_declaration.cpp @@ -69,11 +69,10 @@ void cpp_typecheckt::convert_anonymous_union( // do scoping symbolt union_symbol= *symbol_table.get_writeable(follow(symbol.type).get(ID_name)); - const irept::subt &components=union_symbol.type.add(ID_components).get_sub(); - forall_irep(it, components) + for(const auto &c : to_union_type(union_symbol.type).components()) { - if(it->find(ID_type).id()==ID_code) + if(c.type().id() == ID_code) { error().source_location=union_symbol.type.source_location(); error() << "anonymous union `" << union_symbol.base_name @@ -81,7 +80,7 @@ void cpp_typecheckt::convert_anonymous_union( throw 0; } - const irep_idt &base_name=it->get(ID_base_name); + const irep_idt &base_name = c.get(ID_base_name); if(cpp_scopes.current_scope().contains(base_name)) { @@ -93,7 +92,7 @@ void cpp_typecheckt::convert_anonymous_union( cpp_idt &id=cpp_scopes.current_scope().insert(base_name); id.id_class = cpp_idt::id_classt::SYMBOL; - id.identifier=it->get(ID_name); + id.identifier = c.get(ID_name); id.class_identifier=union_symbol.name; id.is_member=true; } diff --git a/src/cpp/cpp_typecheck_destructor.cpp b/src/cpp/cpp_typecheck_destructor.cpp index 0b06b6f95d7..0429c5f9765 100644 --- a/src/cpp/cpp_typecheck_destructor.cpp +++ b/src/cpp/cpp_typecheck_destructor.cpp @@ -15,12 +15,9 @@ Author: Daniel Kroening, kroening@cs.cmu.edu bool cpp_typecheckt::find_dtor(const symbolt &symbol) const { - const irept &components= - symbol.type.find(ID_components); - - forall_irep(cit, components.get_sub()) + for(const auto &c : to_struct_type(symbol.type).components()) { - if(cit->get(ID_base_name)=="~"+id2string(symbol.base_name)) + if(c.get(ID_base_name) == "~" + id2string(symbol.base_name)) return true; } @@ -77,21 +74,18 @@ codet cpp_typecheckt::dtor(const symbolt &symbol) to_struct_union_type(symbol.type).components(); // take care of virtual methods - for(struct_union_typet::componentst::const_iterator - cit=components.begin(); - cit!=components.end(); - cit++) + for(const auto &c : components) { - if(cit->get_bool("is_vtptr")) + if(c.get_bool("is_vtptr")) { exprt name(ID_name); - name.set(ID_identifier, cit->get(ID_base_name)); + name.set(ID_identifier, c.get(ID_base_name)); cpp_namet cppname; cppname.move_to_sub(name); const symbolt &virtual_table_symbol_type = - lookup(cit->type().subtype().get(ID_identifier)); + lookup(c.type().subtype().get(ID_identifier)); const symbolt &virtual_table_symbol_var = lookup( id2string(virtual_table_symbol_type.name) + "@" + @@ -99,12 +93,12 @@ codet cpp_typecheckt::dtor(const symbolt &symbol) exprt var=virtual_table_symbol_var.symbol_expr(); address_of_exprt address(var); - assert(address.type()==cit->type()); + assert(address.type() == c.type()); already_typechecked(address); exprt ptrmember(ID_ptrmember); - ptrmember.set(ID_component_name, cit->get(ID_name)); + ptrmember.set(ID_component_name, c.get(ID_name)); ptrmember.operands().push_back(exprt("cpp-this")); code_assignt assign(ptrmember, address); diff --git a/src/cpp/cpp_typecheck_expr.cpp b/src/cpp/cpp_typecheck_expr.cpp index b6a9803e905..3818bd10fb8 100644 --- a/src/cpp/cpp_typecheck_expr.cpp +++ b/src/cpp/cpp_typecheck_expr.cpp @@ -512,19 +512,9 @@ bool cpp_typecheckt::operator_is_overloaded(exprt &expr) if(t0.id()==ID_struct) { - const struct_typet &struct_type= - to_struct_type(t0); - - const struct_typet::componentst &components= - struct_type.components(); - - for(struct_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) + for(const auto &c : to_struct_type(t0).components()) { - if(!it->get_bool(ID_from_base) && - it->get(ID_base_name) == op_name) + if(!c.get_bool(ID_from_base) && c.get(ID_base_name) == op_name) { found_in_struct=true; break; @@ -2205,18 +2195,15 @@ void cpp_typecheckt::typecheck_side_effect_function_call( const struct_typet::componentst &components= to_struct_type(follow(tmp_object_expr.type())).components(); - for(struct_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) + for(const auto &c : components) { - const typet &type=it->type(); + const typet &type = c.type(); - if(!it->get_bool(ID_from_base) && - type.id()==ID_code && - type.find(ID_return_type).id()==ID_destructor) + if( + !c.get_bool(ID_from_base) && type.id() == ID_code && + type.find(ID_return_type).id() == ID_destructor) { - add_method_body(&symbol_table.get_writeable_ref(it->get(ID_name))); + add_method_body(&symbol_table.get_writeable_ref(c.get(ID_name))); break; } } diff --git a/src/cpp/cpp_typecheck_initializer.cpp b/src/cpp/cpp_typecheck_initializer.cpp index 3ca9dd957e3..6a7121ab5f5 100644 --- a/src/cpp/cpp_typecheck_initializer.cpp +++ b/src/cpp/cpp_typecheck_initializer.cpp @@ -200,10 +200,8 @@ void cpp_typecheckt::zero_initializer( if(final_type.id()==ID_struct) { - forall_irep(cit, final_type.find(ID_components).get_sub()) + for(const auto &component : to_struct_type(final_type).components()) { - const exprt &component=static_cast(*cit); - if(component.type().id()==ID_code) continue; @@ -249,10 +247,8 @@ void cpp_typecheckt::zero_initializer( exprt comp=nil_exprt(); - forall_irep(it, final_type.find(ID_components).get_sub()) + for(const auto &component : to_union_type(final_type).components()) { - const exprt &component=static_cast(*it); - assert(component.type().is_not_nil()); if(component.type().id()==ID_code) diff --git a/src/cpp/cpp_typecheck_virtual_table.cpp b/src/cpp/cpp_typecheck_virtual_table.cpp index f8ffa0dd8c3..d8f2c3636c7 100644 --- a/src/cpp/cpp_typecheck_virtual_table.cpp +++ b/src/cpp/cpp_typecheck_virtual_table.cpp @@ -82,9 +82,8 @@ void cpp_typecheckt::do_virtual_table(const symbolt &symbol) struct_exprt values(symbol_typet(vt_symb_type.name)); - for(std::size_t i=0; i < vt_type.components().size(); i++) + for(const auto &compo : vt_type.components()) { - const struct_typet::componentt &compo=vt_type.components()[i]; std::map::const_iterator cit2 = value_map.find(compo.get("base_name")); assert(cit2!=value_map.end()); diff --git a/src/cpp/template_map.cpp b/src/cpp/template_map.cpp index 28bbb632834..880773dd9c4 100644 --- a/src/cpp/template_map.cpp +++ b/src/cpp/template_map.cpp @@ -31,11 +31,9 @@ void template_mapt::apply(typet &type) const else if(type.id()==ID_struct || type.id()==ID_union) { - irept::subt &components=type.add(ID_components).get_sub(); - - Forall_irep(it, components) + for(auto &c : to_struct_union_type(type).components()) { - typet &subtype=static_cast(it->add(ID_type)); + typet &subtype = static_cast(c.add(ID_type)); apply(subtype); } }