diff --git a/jbmc/src/java_bytecode/expr2java.cpp b/jbmc/src/java_bytecode/expr2java.cpp index f042e15ff2a..271d48111ba 100644 --- a/jbmc/src/java_bytecode/expr2java.cpp +++ b/jbmc/src/java_bytecode/expr2java.cpp @@ -127,15 +127,9 @@ std::string expr2javat::convert_struct( bool first=true; size_t last_size=0; - for(struct_typet::componentst::const_iterator - c_it=components.begin(); - c_it!=components.end(); - c_it++) + for(const auto &c : components) { - if(c_it->type().id()==ID_code) - { - } - else + if(c.type().id() != ID_code) { std::string tmp=convert(*o_it); std::string sep; @@ -155,7 +149,7 @@ std::string expr2javat::convert_struct( dest+=sep; dest+='.'; - dest+=c_it->get_string(ID_pretty_name); + dest += id2string(c.get_pretty_name()); dest+='='; dest+=tmp; } diff --git a/src/ansi-c/c_typecheck_code.cpp b/src/ansi-c/c_typecheck_code.cpp index d578ec33724..bbdc4326384 100644 --- a/src/ansi-c/c_typecheck_code.cpp +++ b/src/ansi-c/c_typecheck_code.cpp @@ -372,13 +372,8 @@ bool c_typecheck_baset::is_complete_type(const typet &type) const } else if(type.id()==ID_struct || type.id()==ID_union) { - const struct_union_typet::componentst &components= - to_struct_union_type(type).components(); - for(struct_union_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) - if(!is_complete_type(it->type())) + for(const auto &c : to_struct_union_type(type).components()) + if(!is_complete_type(c.type())) return false; } else if(type.id()==ID_vector) diff --git a/src/ansi-c/c_typecheck_expr.cpp b/src/ansi-c/c_typecheck_expr.cpp index 90328c90af8..e78e2be4135 100644 --- a/src/ansi-c/c_typecheck_expr.cpp +++ b/src/ansi-c/c_typecheck_expr.cpp @@ -619,28 +619,20 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr) else { // maybe anonymous? - - const struct_union_typet::componentst &components= - struct_union_type.components(); - bool found2=false; - for(struct_union_typet::componentst::const_iterator - c_it=components.begin(); - c_it!=components.end(); - c_it++) + for(const auto &c : struct_union_type.components()) { - if(c_it->get_anonymous() && - (follow(c_it->type()).id()==ID_struct || - follow(c_it->type()).id()==ID_union)) + if( + c.get_anonymous() && (follow(c.type()).id() == ID_struct || + follow(c.type()).id() == ID_union)) { - if(has_component_rec(c_it->type(), component_name, *this)) + if(has_component_rec(c.type(), component_name, *this)) { if(type.id()==ID_struct) { - exprt o= - member_offset_expr( - to_struct_type(type), c_it->get_name(), *this); + exprt o = member_offset_expr( + to_struct_type(type), c.get_name(), *this); if(o.is_nil()) { @@ -656,7 +648,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr) result=plus_exprt(result, o); } - typet tmp=follow(c_it->type()); + typet tmp = follow(c.type()); type=tmp; assert(type.id()==ID_union || type.id()==ID_struct); found2=true; @@ -1097,21 +1089,15 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr) op.make_typecast(signed_int_type()); // we need to find a member with the right type - const union_typet &union_type=to_union_type(expr_type); - const union_typet::componentst &components=union_type.components(); - - for(union_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) + for(const auto &c : to_union_type(expr_type).components()) { - if(base_type_eq(it->type(), op.type(), *this)) + if(base_type_eq(c.type(), op.type(), *this)) { // found! build union constructor union_exprt union_expr(expr.type()); union_expr.add_source_location()=expr.source_location(); union_expr.op()=op; - union_expr.set_component_name(it->get_name()); + union_expr.set_component_name(c.get_name()); expr=union_expr; expr.set(ID_C_lvalue, true); return; diff --git a/src/ansi-c/c_typecheck_initializer.cpp b/src/ansi-c/c_typecheck_initializer.cpp index ad1be10fe07..485ab675f57 100644 --- a/src/ansi-c/c_typecheck_initializer.cpp +++ b/src/ansi-c/c_typecheck_initializer.cpp @@ -268,15 +268,11 @@ void c_typecheck_baset::designator_enter( // only a top-level struct may end with a variable-length array entry.vla_permitted=designator.empty(); - for(struct_typet::componentst::const_iterator - it=struct_type.components().begin(); - it!=struct_type.components().end(); - ++it) + for(const auto &c : struct_type.components()) { - if(it->type().id()!=ID_code && - !it->get_is_padding()) + if(c.type().id() != ID_code && !c.get_is_padding()) { - entry.subtype=it->type(); + entry.subtype = c.type(); break; } @@ -758,38 +754,36 @@ designatort c_typecheck_baset::make_designator( do { repeat=false; - unsigned number=0; + std::size_t number = 0; const struct_union_typet::componentst &components= to_struct_union_type(follow(tmp_type)).components(); - for(struct_union_typet::componentst::const_iterator - c_it=components.begin(); - c_it!=components.end(); - c_it++, number++) + for(const auto &c : components) { - if(c_it->get_name()==component_name) + if(c.get_name() == component_name) { // done! entry.index=number; entry.size=components.size(); - entry.subtype=components[entry.index].type(); + entry.subtype = c.type(); entry.type=tmp_type; } - else if(c_it->get_anonymous() && - (follow(c_it->type()).id()==ID_struct || - follow(c_it->type()).id()==ID_union) && - has_component_rec( - c_it->type(), component_name, *this)) + else if( + c.get_anonymous() && (follow(c.type()).id() == ID_struct || + follow(c.type()).id() == ID_union) && + has_component_rec(c.type(), component_name, *this)) { entry.index=number; entry.size=components.size(); - entry.subtype=c_it->type(); + entry.subtype = c.type(); entry.type=tmp_type; tmp_type=entry.subtype; designator.push_entry(entry); found=repeat=true; break; } + + ++number; } } while(repeat); diff --git a/src/ansi-c/padding.cpp b/src/ansi-c/padding.cpp index e024fa4b6f9..d1d6e76f9fa 100644 --- a/src/ansi-c/padding.cpp +++ b/src/ansi-c/padding.cpp @@ -56,18 +56,12 @@ mp_integer alignment(const typet &type, const namespacet &ns) result=alignment(type.subtype(), ns); else if(type.id()==ID_struct || type.id()==ID_union) { - const struct_union_typet::componentst &components= - to_struct_union_type(type).components(); - result=1; // get the max // (should really be the smallest common denominator) - for(struct_union_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) - result=std::max(result, alignment(it->type(), ns)); + for(const auto &c : to_struct_union_type(type).components()) + result = std::max(result, alignment(c.type(), ns)); } else if(type.id()==ID_unsignedbv || type.id()==ID_signedbv || diff --git a/src/ansi-c/type2name.cpp b/src/ansi-c/type2name.cpp index 87789b6c457..2bef9136b00 100644 --- a/src/ansi-c/type2name.cpp +++ b/src/ansi-c/type2name.cpp @@ -203,18 +203,17 @@ static std::string type2name( result+="ST"; if(type.id()==ID_union) result+="UN"; - const struct_union_typet &t=to_struct_union_type(type); - const struct_union_typet::componentst &components = t.components(); result+='['; - for(struct_union_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) + bool first = true; + for(const auto &c : to_struct_union_type(type).components()) { - if(it!=components.begin()) + if(!first) result+='|'; - result+=type2name(it->type(), ns, symbol_number); - irep_idt component_name = it->get_name(); + else + first = false; + + result += type2name(c.type(), ns, symbol_number); + const irep_idt &component_name = c.get_name(); CHECK_RETURN(!component_name.empty()); result+="'"+id2string(component_name)+"'"; } diff --git a/src/cpp/cpp_typecheck_constructor.cpp b/src/cpp/cpp_typecheck_constructor.cpp index 86e7d016ce2..f9784bc9a42 100644 --- a/src/cpp/cpp_typecheck_constructor.cpp +++ b/src/cpp/cpp_typecheck_constructor.cpp @@ -789,17 +789,9 @@ void cpp_typecheckt::full_member_initialization( /// \return return true if a copy constructor is found bool cpp_typecheckt::find_cpctor(const symbolt &symbol) const { - const struct_typet &struct_type=to_struct_type(symbol.type); - const struct_typet::componentst &components=struct_type.components(); - - for(struct_typet::componentst::const_iterator - cit=components.begin(); - cit!=components.end(); - cit++) + for(const auto &component : to_struct_type(symbol.type).components()) { // Skip non-ctor - const struct_typet::componentt &component=*cit; - if(component.type().id()!=ID_code || to_code_type(component.type()).return_type().id() !=ID_constructor) continue; diff --git a/src/goto-instrument/dump_c.cpp b/src/goto-instrument/dump_c.cpp index f5d9aa459da..eda4874070e 100644 --- a/src/goto-instrument/dump_c.cpp +++ b/src/goto-instrument/dump_c.cpp @@ -416,12 +416,8 @@ void dump_ct::convert_compound( std::stringstream struct_body; - for(struct_union_typet::componentst::const_iterator - it=type.components().begin(); - it!=type.components().end(); - it++) + for(const auto &comp : type.components()) { - const struct_typet::componentt &comp=*it; const typet &comp_type=ns.follow(comp.type()); if(comp_type.id()==ID_code || @@ -1236,18 +1232,15 @@ void dump_ct::cleanup_expr(exprt &expr) PRECONDITION(old_components.size()==old_ops.size()); exprt::operandst::iterator o_it=old_ops.begin(); - for(struct_union_typet::componentst::const_iterator - it=old_components.begin(); - it!=old_components.end(); - ++it) + for(const auto &old_comp : old_components) { - const bool is_zero_bit_field= - it->type().id()==ID_c_bit_field && - to_c_bit_field_type(it->type()).get_width()==0; + const bool is_zero_bit_field = + old_comp.type().id() == ID_c_bit_field && + to_c_bit_field_type(old_comp.type()).get_width() == 0; - if(!it->get_is_padding() && !is_zero_bit_field) + if(!old_comp.get_is_padding() && !is_zero_bit_field) { - type.components().push_back(*it); + type.components().push_back(old_comp); expr.move_to_operands(*o_it); } ++o_it; diff --git a/src/goto-instrument/goto_program2code.cpp b/src/goto-instrument/goto_program2code.cpp index e01a87fb2cd..7970511b0d4 100644 --- a/src/goto-instrument/goto_program2code.cpp +++ b/src/goto-instrument/goto_program2code.cpp @@ -1439,16 +1439,8 @@ void goto_program2codet::add_local_types(const typet &type) !type_names_set.insert(identifier).second) return; - const struct_union_typet &struct_union_type= - to_struct_union_type(full_type); - const struct_union_typet::componentst &components= - struct_union_type.components(); - - for(struct_union_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - ++it) - add_local_types(it->type()); + for(const auto &c : to_struct_union_type(full_type).components()) + add_local_types(c.type()); assert(!identifier.empty()); type_names.push_back(identifier); diff --git a/src/goto-programs/remove_complex.cpp b/src/goto-programs/remove_complex.cpp index ef5b351f54d..19a475237ac 100644 --- a/src/goto-programs/remove_complex.cpp +++ b/src/goto-programs/remove_complex.cpp @@ -81,13 +81,8 @@ static bool have_to_remove_complex(const typet &type) { if(type.id()==ID_struct || type.id()==ID_union) { - const struct_union_typet &struct_union_type= - to_struct_union_type(type); - for(struct_union_typet::componentst::const_iterator - it=struct_union_type.components().begin(); - it!=struct_union_type.components().end(); - it++) - if(have_to_remove_complex(it->type())) + for(const auto &c : to_struct_union_type(type).components()) + if(have_to_remove_complex(c.type())) return true; } else if(type.id()==ID_pointer || diff --git a/src/goto-programs/remove_vector.cpp b/src/goto-programs/remove_vector.cpp index cabd5100698..15821d0a1ca 100644 --- a/src/goto-programs/remove_vector.cpp +++ b/src/goto-programs/remove_vector.cpp @@ -50,14 +50,8 @@ static bool have_to_remove_vector(const typet &type) { if(type.id()==ID_struct || type.id()==ID_union) { - const struct_union_typet &struct_union_type= - to_struct_union_type(type); - - for(struct_union_typet::componentst::const_iterator - it=struct_union_type.components().begin(); - it!=struct_union_type.components().end(); - it++) - if(have_to_remove_vector(it->type())) + for(const auto &c : to_struct_union_type(type).components()) + if(have_to_remove_vector(c.type())) return true; } else if(type.id()==ID_pointer || diff --git a/src/goto-symex/goto_symex_state.cpp b/src/goto-symex/goto_symex_state.cpp index 40f5054155e..7a7530274dd 100644 --- a/src/goto-symex/goto_symex_state.cpp +++ b/src/goto-symex/goto_symex_state.cpp @@ -206,14 +206,8 @@ static bool check_renaming(const typet &type) type.id()==ID_union || type.id()==ID_class) { - const struct_union_typet &s_u_type=to_struct_union_type(type); - const struct_union_typet::componentst &components=s_u_type.components(); - - for(struct_union_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - ++it) - if(check_renaming(it->type())) + for(const auto &c : to_struct_union_type(type).components()) + if(check_renaming(c.type())) return true; } else if(type.has_subtype()) diff --git a/src/linking/linking.cpp b/src/linking/linking.cpp index e6c72f4deac..0ae91b5cf20 100644 --- a/src/linking/linking.cpp +++ b/src/linking/linking.cpp @@ -72,23 +72,17 @@ std::string linkingt::type_to_string_verbose( result+=" "+tag; result+=" {\n"; - const struct_union_typet::componentst &components= - to_struct_union_type(followed).components(); - - for(struct_union_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) + for(const auto &c : to_struct_union_type(followed).components()) { - const typet &subtype=it->type(); + const typet &subtype = c.type(); result+=" "; result+=type_to_string(ns, symbol.name, subtype); result+=' '; - if(it->get_base_name()!="") - result+=id2string(it->get_base_name()); + if(!c.get_base_name().empty()) + result += id2string(c.get_base_name()); else - result+=id2string(it->get_name()); + result += id2string(c.get_name()); result+=";\n"; } @@ -686,11 +680,8 @@ void linkingt::duplicate_code_symbol( const typet &src_type=t1.id()==ID_union?t2:t1; bool found=false; - for(union_typet::componentst::const_iterator - it=union_type.components().begin(); - !found && it!=union_type.components().end(); - it++) - if(base_type_eq(it->type(), src_type, ns)) + for(const auto &c : union_type.components()) + if(base_type_eq(c.type(), src_type, ns)) { found=true; if(warn_msg.empty()) diff --git a/src/pointer-analysis/value_set.cpp b/src/pointer-analysis/value_set.cpp index 4ae59c806c9..12e931ab3e2 100644 --- a/src/pointer-analysis/value_set.cpp +++ b/src/pointer-analysis/value_set.cpp @@ -886,12 +886,9 @@ void value_sett::get_value_set_rec( { const struct_typet &struct_type=to_struct_type(op0_type); - for(struct_union_typet::componentst::const_iterator - c_it=struct_type.components().begin(); - !found && c_it!=struct_type.components().end(); - c_it++) + for(const auto &c : struct_type.components()) { - const irep_idt &name=c_it->get_name(); + const irep_idt &name = c.get_name(); mp_integer comp_offset=member_offset(struct_type, name, ns); @@ -902,22 +899,19 @@ void value_sett::get_value_set_rec( found=true; - member_exprt member(expr.op0(), *c_it); + member_exprt member(expr.op0(), c); get_value_set_rec(member, dest, suffix, original_type, ns); + break; } } if(op0_type.id()==ID_union) { - const union_typet &union_type=to_union_type(op0_type); - // just collect them all - for(union_typet::componentst::const_iterator - c_it=union_type.components().begin(); - c_it!=union_type.components().end(); c_it++) + for(const auto &c : to_union_type(op0_type).components()) { - const irep_idt &name=c_it->get_name(); - member_exprt member(expr.op0(), name, c_it->type()); + const irep_idt &name = c.get_name(); + member_exprt member(expr.op0(), name, c.type()); get_value_set_rec(member, dest, suffix, original_type, ns); } } @@ -1172,20 +1166,14 @@ void value_sett::assign( if(type.id()==ID_struct || type.id()==ID_union) { - const struct_union_typet &struct_union_type= - to_struct_union_type(type); - - for(struct_union_typet::componentst::const_iterator - c_it=struct_union_type.components().begin(); - c_it!=struct_union_type.components().end(); - c_it++) + for(const auto &c : to_struct_union_type(type).components()) { - const typet &subtype=c_it->type(); - const irep_idt &name = c_it->get_name(); + const typet &subtype = c.type(); + const irep_idt &name = c.get_name(); // ignore methods and padding - if(subtype.id()==ID_code || - c_it->get_is_padding()) continue; + if(subtype.id() == ID_code || c.get_is_padding()) + continue; member_exprt lhs_member(lhs, name, subtype); diff --git a/src/pointer-analysis/value_set_analysis_fi.cpp b/src/pointer-analysis/value_set_analysis_fi.cpp index e3c4a5e8926..9f1bdd69f92 100644 --- a/src/pointer-analysis/value_set_analysis_fi.cpp +++ b/src/pointer-analysis/value_set_analysis_fi.cpp @@ -99,17 +99,10 @@ void value_set_analysis_fit::get_entries_rec( if(t.id()==ID_struct || t.id()==ID_union) { - const struct_union_typet &struct_type=to_struct_union_type(t); - - const struct_typet::componentst &c=struct_type.components(); - - for(struct_typet::componentst::const_iterator - it=c.begin(); - it!=c.end(); - it++) + for(const auto &c : to_struct_union_type(t).components()) { get_entries_rec( - identifier, suffix + "." + id2string(it->get_name()), it->type(), dest); + identifier, suffix + "." + id2string(c.get_name()), c.type(), dest); } } else if(t.id()==ID_array) @@ -189,17 +182,9 @@ bool value_set_analysis_fit::check_type(const typet &type) else if(type.id()==ID_struct || type.id()==ID_union) { - const struct_union_typet &struct_type=to_struct_union_type(type); - - 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_union_type(type).components()) { - if(check_type(it->type())) + if(check_type(c.type())) return true; } } diff --git a/src/pointer-analysis/value_set_analysis_fivr.cpp b/src/pointer-analysis/value_set_analysis_fivr.cpp index 289f24eddd9..d1b6a88ec17 100644 --- a/src/pointer-analysis/value_set_analysis_fivr.cpp +++ b/src/pointer-analysis/value_set_analysis_fivr.cpp @@ -89,17 +89,10 @@ void value_set_analysis_fivrt::get_entries_rec( if(t.id()==ID_struct || t.id()==ID_union) { - const struct_typet &struct_type=to_struct_type(t); - - const struct_typet::componentst &c=struct_type.components(); - - for(struct_typet::componentst::const_iterator - it=c.begin(); - it!=c.end(); - it++) + for(const auto &c : to_struct_union_type(t).components()) { get_entries_rec( - identifier, suffix + "." + id2string(it->get_name()), it->type(), dest); + identifier, suffix + "." + id2string(c.get_name()), c.type(), dest); } } else if(t.id()==ID_array) @@ -179,19 +172,9 @@ bool value_set_analysis_fivrt::check_type(const typet &type) else if(type.id()==ID_struct || type.id()==ID_union) { - const struct_typet &struct_type=to_struct_type(type); - - const struct_typet::componentst &components= - struct_type.components(); - - for(struct_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) - { - if(check_type(it->type())) + for(const auto &c : to_struct_union_type(type).components()) + if(check_type(c.type())) return true; - } } else if(type.id()==ID_array) return check_type(type.subtype()); diff --git a/src/pointer-analysis/value_set_analysis_fivrns.cpp b/src/pointer-analysis/value_set_analysis_fivrns.cpp index bd4458793c2..a08c1768ee4 100644 --- a/src/pointer-analysis/value_set_analysis_fivrns.cpp +++ b/src/pointer-analysis/value_set_analysis_fivrns.cpp @@ -89,17 +89,10 @@ void value_set_analysis_fivrnst::get_entries_rec( if(t.id()==ID_struct || t.id()==ID_union) { - const struct_typet &struct_type=to_struct_type(t); - - const struct_typet::componentst &c=struct_type.components(); - - for(struct_typet::componentst::const_iterator - it=c.begin(); - it!=c.end(); - it++) + for(const auto &c : to_struct_union_type(t).components()) { get_entries_rec( - identifier, suffix + "." + id2string(it->get_name()), it->type(), dest); + identifier, suffix + "." + id2string(c.get_name()), c.type(), dest); } } else if(t.id()==ID_array) @@ -179,19 +172,9 @@ bool value_set_analysis_fivrnst::check_type(const typet &type) else if(type.id()==ID_struct || type.id()==ID_union) { - const struct_typet &struct_type=to_struct_type(type); - - const struct_typet::componentst &components= - struct_type.components(); - - for(struct_typet::componentst::const_iterator - it=components.begin(); - it!=components.end(); - it++) - { - if(check_type(it->type())) + for(const auto &c : to_struct_union_type(type).components()) + if(check_type(c.type())) return true; - } } else if(type.id()==ID_array) return check_type(type.subtype());