diff --git a/src/cpp/cpp_constructor.cpp b/src/cpp/cpp_constructor.cpp index c358bd06568..61290ea116d 100644 --- a/src/cpp/cpp_constructor.cpp +++ b/src/cpp/cpp_constructor.cpp @@ -125,13 +125,10 @@ optionalt cpp_typecheckt::cpp_constructor( { exprt::operandst operands_tc=operands; - for(exprt::operandst::iterator - it=operands_tc.begin(); - it!=operands_tc.end(); - it++) + for(auto &op : operands_tc) { - typecheck_expr(*it); - add_implicit_dereference(*it); + typecheck_expr(op); + add_implicit_dereference(op); } if(operands_tc.empty()) @@ -167,13 +164,10 @@ optionalt cpp_typecheckt::cpp_constructor( { exprt::operandst operands_tc=operands; - for(exprt::operandst::iterator - it=operands_tc.begin(); - it!=operands_tc.end(); - it++) + for(auto &op : operands_tc) { - typecheck_expr(*it); - add_implicit_dereference(*it); + typecheck_expr(op); + add_implicit_dereference(op); } const struct_typet &struct_type= @@ -228,17 +222,11 @@ optionalt cpp_typecheckt::cpp_constructor( // there is always a constructor for non-PODs assert(constructor_name!=""); - side_effect_expr_function_callt function_call; + side_effect_expr_function_callt function_call( + cpp_namet(constructor_name, source_location).as_expr(), + operands_tc); + function_call.add_source_location()=source_location; - function_call.function() = - cpp_namet(constructor_name, source_location).as_expr(); - function_call.arguments().reserve(operands_tc.size()); - - for(exprt::operandst::iterator - it=operands_tc.begin(); - it!=operands_tc.end(); - it++) - function_call.op1().copy_to_operands(*it); typecheck_side_effect_function_call(function_call); assert(function_call.get(ID_statement)==ID_temporary_object); diff --git a/src/cpp/cpp_declarator_converter.cpp b/src/cpp/cpp_declarator_converter.cpp index 6b773c072e0..28686d5a495 100644 --- a/src/cpp/cpp_declarator_converter.cpp +++ b/src/cpp/cpp_declarator_converter.cpp @@ -501,12 +501,9 @@ symbolt &cpp_declarator_convertert::convert_new_symbol( cpp_typecheck.cpp_scopes.current_scope().lookup( base_name, cpp_scopet::SCOPE_ONLY, id_set); - for(cpp_scopest::id_sett::const_iterator - id_it=id_set.begin(); - id_it!=id_set.end(); - id_it++) + for(const auto &id_ptr : id_set) { - const cpp_idt &id=**id_it; + const cpp_idt &id = *id_ptr; // the name is already in the scope // this is ok if they belong to different categories diff --git a/src/cpp/cpp_id.cpp b/src/cpp/cpp_id.cpp index edcc139ce4f..128c9a2e179 100644 --- a/src/cpp/cpp_id.cpp +++ b/src/cpp/cpp_id.cpp @@ -34,10 +34,8 @@ void cpp_idt::print(std::ostream &out, unsigned indent) const if(!sub.empty()) { - for(cpp_id_mapt::const_iterator it=sub.begin(); - it!=sub.end(); - it++) - it->second.print(out, indent+2); + for(const auto &s : sub) + s.second.print(out, indent + 2); out << '\n'; } @@ -45,43 +43,37 @@ void cpp_idt::print(std::ostream &out, unsigned indent) const void cpp_idt::print_fields(std::ostream &out, unsigned indent) const { - for(unsigned i=0; ifind_source_location(); + error().source_location = expr.find_source_location(); error() << "template argument expression expected to be " << "scalar constant, but got `" << to_string(e) << "'" << eom; @@ -87,17 +83,14 @@ std::string cpp_typecheckt::template_suffix( void cpp_typecheckt::show_instantiation_stack(std::ostream &out) { - for(instantiation_stackt::const_iterator - s_it=instantiation_stack.begin(); - s_it!=instantiation_stack.end(); - s_it++) + for(const auto &e : instantiation_stack) { - const symbolt &symbol=lookup(s_it->identifier); + const symbolt &symbol = lookup(e.identifier); out << "instantiating `" << symbol.pretty_name << "' with <"; - forall_expr(a_it, s_it->full_template_args.arguments()) + forall_expr(a_it, e.full_template_args.arguments()) { - if(a_it!=s_it->full_template_args.arguments().begin()) + if(a_it != e.full_template_args.arguments().begin()) out << ", "; if(a_it->id()==ID_type) @@ -106,7 +99,7 @@ void cpp_typecheckt::show_instantiation_stack(std::ostream &out) out << to_string(*a_it); } - out << "> at " << s_it->source_location << '\n'; + out << "> at " << e.source_location << '\n'; } } diff --git a/src/cpp/cpp_language.cpp b/src/cpp/cpp_language.cpp index c8075f4e9e5..4acd28a3e02 100644 --- a/src/cpp/cpp_language.cpp +++ b/src/cpp/cpp_language.cpp @@ -142,11 +142,8 @@ bool cpp_languaget::generate_support_functions( void cpp_languaget::show_parse(std::ostream &out) { - for(cpp_parse_treet::itemst::const_iterator it= - cpp_parse_tree.items.begin(); - it!=cpp_parse_tree.items.end(); - it++) - show_parse(out, *it); + for(const auto &i : cpp_parse_tree.items) + show_parse(out, i); } void cpp_languaget::show_parse( @@ -160,11 +157,8 @@ void cpp_languaget::show_parse( out << "LINKAGE " << linkage_spec.linkage().get(ID_value) << ":\n"; - for(cpp_linkage_spect::itemst::const_iterator - it=linkage_spec.items().begin(); - it!=linkage_spec.items().end(); - it++) - show_parse(out, *it); + for(const auto &i : linkage_spec.items()) + show_parse(out, i); out << '\n'; } @@ -176,11 +170,8 @@ void cpp_languaget::show_parse( out << "NAMESPACE " << namespace_spec.get_namespace() << ":\n"; - for(cpp_namespace_spect::itemst::const_iterator - it=namespace_spec.items().begin(); - it!=namespace_spec.items().end(); - it++) - show_parse(out, *it); + for(const auto &i : namespace_spec.items()) + show_parse(out, i); out << '\n'; } diff --git a/src/cpp/cpp_scope.cpp b/src/cpp/cpp_scope.cpp index 502fab14e28..98226f94a66 100644 --- a/src/cpp/cpp_scope.cpp +++ b/src/cpp/cpp_scope.cpp @@ -51,12 +51,9 @@ void cpp_scopet::lookup( return; // done // using scopes - for(scope_listt::iterator - it=using_scopes.begin(); - it!=using_scopes.end(); - it++) + for(const auto &s_ptr : using_scopes) { - cpp_scopet &other_scope=static_cast(**it); + cpp_scopet &other_scope = static_cast(*s_ptr); // Recursive call. // Note the different kind! @@ -67,12 +64,9 @@ void cpp_scopet::lookup( return; // done, upwards scopes are hidden // secondary scopes - for(scope_listt::iterator - it=secondary_scopes.begin(); - it!=secondary_scopes.end(); - it++) + for(const auto &s_ptr : secondary_scopes) { - cpp_scopet &other_scope=static_cast(**it); + cpp_scopet &other_scope = static_cast(*s_ptr); // Recursive call. // Note the different kind! @@ -130,12 +124,9 @@ void cpp_scopet::lookup( return; // done // using scopes - for(scope_listt::iterator - it=using_scopes.begin(); - it!=using_scopes.end(); - it++) + for(const auto &s_ptr : using_scopes) { - cpp_scopet &other_scope=static_cast(**it); + cpp_scopet &other_scope = static_cast(*s_ptr); // Recursive call. // Note the different kind! @@ -146,12 +137,9 @@ void cpp_scopet::lookup( return; // done, upwards scopes are hidden // secondary scopes - for(scope_listt::iterator - it=secondary_scopes.begin(); - it!=secondary_scopes.end(); - it++) + for(const auto &s_ptr : secondary_scopes) { - cpp_scopet &other_scope=static_cast(**it); + cpp_scopet &other_scope = static_cast(*s_ptr); // Recursive call. // Note the different kind! diff --git a/src/cpp/cpp_typecheck_code.cpp b/src/cpp/cpp_typecheck_code.cpp index 7e0a51ebc30..be71f110fa0 100644 --- a/src/cpp/cpp_typecheck_code.cpp +++ b/src/cpp/cpp_typecheck_code.cpp @@ -47,22 +47,20 @@ void cpp_typecheckt::typecheck_code(codet &code) void cpp_typecheckt::typecheck_try_catch(codet &code) { - codet::operandst &operands=code.operands(); + bool first = true; - for(codet::operandst::iterator - it=operands.begin(); - it!=operands.end(); - it++) + for(auto &op : code.operands()) { - if(it==operands.begin()) + if(first) { // this is the 'try' - typecheck_code(to_code(*it)); + typecheck_code(to_code(op)); + first = false; } else { // This is (one of) the catch clauses. - codet &code=to_code_block(to_code(*it)); + codet &code = to_code_block(to_code(op)); // look at the catch operand assert(!code.operands().empty()); @@ -105,7 +103,7 @@ void cpp_typecheckt::typecheck_try_catch(codet &code) const typet &type=code_decl.op0().type(); // annotate exception ID - it->set(ID_exception_id, cpp_exception_id(type, *this)); + op.set(ID_exception_id, cpp_exception_id(type, *this)); } } } diff --git a/src/cpp/cpp_typecheck_fargs.cpp b/src/cpp/cpp_typecheck_fargs.cpp index b4ca6915ab0..95bda450f8a 100644 --- a/src/cpp/cpp_typecheck_fargs.cpp +++ b/src/cpp/cpp_typecheck_fargs.cpp @@ -21,11 +21,9 @@ Author: Daniel Kroening, kroening@cs.cmu.edu bool cpp_typecheck_fargst::has_class_type() const { - for(exprt::operandst::const_iterator it=operands.begin(); - it!=operands.end(); - it++) + for(const auto &op : operands) { - if(it->type().id()==ID_struct) + if(op.type().id() == ID_struct) return true; } @@ -36,12 +34,7 @@ void cpp_typecheck_fargst::build( const side_effect_expr_function_callt &function_call) { in_use=true; - - operands.clear(); - operands.reserve(function_call.op1().operands().size()); - - for(std::size_t i=0; itype()).get_bool(ID_is_template)) - identifiers.push_back(*it); + if(!cpp_typecheck.follow(old_id.type()).get_bool(ID_is_template)) + identifiers.push_back(old_id); } } @@ -166,27 +154,24 @@ void cpp_typecheck_resolvet::remove_duplicates( std::set ids; std::set other; - for(resolve_identifierst::const_iterator - it=old_identifiers.begin(); - it!=old_identifiers.end(); - it++) + for(const auto &old_id : old_identifiers) { irep_idt id; - if(it->id()==ID_symbol) - id = to_symbol_expr(*it).get_identifier(); - else if(it->id() == ID_type && it->type().id() == ID_symbol_type) - id = to_symbol_type(it->type()).get_identifier(); + if(old_id.id() == ID_symbol) + id = to_symbol_expr(old_id).get_identifier(); + else if(old_id.id() == ID_type && old_id.type().id() == ID_symbol_type) + id = to_symbol_type(old_id.type()).get_identifier(); if(id=="") { - if(other.insert(*it).second) - identifiers.push_back(*it); + if(other.insert(old_id).second) + identifiers.push_back(old_id); } else { if(ids.insert(id).second) - identifiers.push_back(*it); + identifiers.push_back(old_id); } } } @@ -396,21 +381,18 @@ void cpp_typecheck_resolvet::filter( resolve_identifierst old_identifiers; old_identifiers.swap(identifiers); - for(resolve_identifierst::const_iterator - it=old_identifiers.begin(); - it!=old_identifiers.end(); - it++) + for(const auto &old_id : old_identifiers) { bool match=false; switch(want) { case wantt::TYPE: - match=(it->id()==ID_type); + match = (old_id.id() == ID_type); break; case wantt::VAR: - match=(it->id()!=ID_type); + match = (old_id.id() != ID_type); break; case wantt::BOTH: @@ -422,7 +404,7 @@ void cpp_typecheck_resolvet::filter( } if(match) - identifiers.push_back(*it); + identifiers.push_back(old_id); } } @@ -439,15 +421,12 @@ void cpp_typecheck_resolvet::exact_match_functions( identifiers.clear(); // put in the ones that match precisely - for(resolve_identifierst::const_iterator - it=old_identifiers.begin(); - it!=old_identifiers.end(); - it++) + for(const auto &old_id : old_identifiers) { unsigned distance; - if(disambiguate_functions(*it, distance, fargs)) + if(disambiguate_functions(old_id, distance, fargs)) if(distance<=0) - identifiers.push_back(*it); + identifiers.push_back(old_id); } } @@ -461,20 +440,20 @@ void cpp_typecheck_resolvet::disambiguate_functions( // sort according to distance std::multimap distance_map; - for(resolve_identifierst::const_iterator - it=old_identifiers.begin(); - it!=old_identifiers.end(); - it++) + for(const auto &old_id : old_identifiers) { unsigned args_distance; - if(disambiguate_functions(*it, args_distance, fargs)) + if(disambiguate_functions(old_id, args_distance, fargs)) { std::size_t template_distance=0; - if(it->type().get(ID_C_template)!="") - template_distance=it->type(). - find(ID_C_template_arguments).find(ID_arguments).get_sub().size(); + if(old_id.type().get(ID_C_template) != "") + template_distance = old_id.type() + .find(ID_C_template_arguments) + .find(ID_arguments) + .get_sub() + .size(); // we give strong preference to functions that have // fewer template arguments @@ -482,8 +461,7 @@ void cpp_typecheck_resolvet::disambiguate_functions( // NOLINTNEXTLINE(whitespace/operators) 1000*template_distance+args_distance; - distance_map.insert( - std::pair(total_distance, *it)); + distance_map.insert({total_distance, old_id}); } } @@ -601,20 +579,16 @@ void cpp_typecheck_resolvet::make_constructors( { resolve_identifierst new_identifiers; - for(resolve_identifierst::iterator - it=identifiers.begin(); - it!=identifiers.end(); - it++) + for(const auto &identifier : identifiers) { - if(it->id()!=ID_type) + if(identifier.id() != ID_type) { // already an expression - new_identifiers.push_back(*it); + new_identifiers.push_back(identifier); continue; } - const typet &symbol_type= - cpp_typecheck.follow(it->type()); + const typet &symbol_type = cpp_typecheck.follow(identifier.type()); // is it a POD? @@ -624,14 +598,15 @@ void cpp_typecheck_resolvet::make_constructors( // 1. no arguments, default initialization { - const code_typet t1({}, it->type()); + const code_typet t1({}, identifier.type()); exprt pod_constructor1(ID_pod_constructor, t1); new_identifiers.push_back(pod_constructor1); } // 2. one argument, copy/conversion { - const code_typet t2({code_typet::parametert(it->type())}, it->type()); + const code_typet t2( + {code_typet::parametert(identifier.type())}, identifier.type()); exprt pod_constructor2(ID_pod_constructor, t2); new_identifiers.push_back(pod_constructor2); } @@ -639,7 +614,8 @@ void cpp_typecheck_resolvet::make_constructors( // enums, in addition, can also be constructed from int if(symbol_type.id()==ID_c_enum_tag) { - const code_typet t3({code_typet::parametert(signed_int_type())}, it->type()); + const code_typet t3( + {code_typet::parametert(signed_int_type())}, identifier.type()); exprt pod_constructor3(ID_pod_constructor, t3); new_identifiers.push_back(pod_constructor3); } @@ -1038,12 +1014,9 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes( std::set primary_templates; - for(cpp_scopest::id_sett::const_iterator - it=id_set.begin(); - it!=id_set.end(); - it++) + for(const auto &id_ptr : id_set) { - const irep_idt id=(*it)->identifier; + const irep_idt id = id_ptr->identifier; const symbolt &s=cpp_typecheck.lookup(id); if(!s.type.get_bool(ID_is_template)) continue; @@ -1098,12 +1071,9 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes( matcht(full_template_args_tc, full_template_args_tc, primary_template_symbol.name)); - for(cpp_scopest::id_sett::const_iterator - it=id_set.begin(); - it!=id_set.end(); - it++) + for(const auto &id_ptr : id_set) { - const irep_idt id=(*it)->identifier; + const irep_idt id = id_ptr->identifier; const symbolt &s=cpp_typecheck.lookup(id); if(s.type.get(ID_specialization_of).empty()) @@ -1296,13 +1266,8 @@ void cpp_typecheck_resolvet::show_identifiers( const resolve_identifierst &identifiers, std::ostream &out) { - for(resolve_identifierst::const_iterator - it=identifiers.begin(); - it!=identifiers.end(); - it++) + for(const auto &id_expr : identifiers) { - const exprt &id_expr=*it; - out << " "; if(id_expr.id()==ID_type) @@ -1347,12 +1312,15 @@ void cpp_typecheck_resolvet::show_identifiers( out << cpp_typecheck.to_string(return_type); out << " " << id << "("; - for(code_typet::parameterst::const_iterator - it=parameters.begin(); it!=parameters.end(); it++) + bool first = true; + + for(const auto ¶meter : parameters) { - const typet ¶meter_type=it->type(); + const typet ¶meter_type = parameter.type(); - if(it!=parameters.begin()) + if(first) + first = false; + else out << ", "; out << cpp_typecheck.to_string(parameter_type); @@ -1508,12 +1476,9 @@ exprt cpp_typecheck_resolvet::resolve( // classes bool have_classes=false, have_methods=false; - for(cpp_scopest::id_sett::const_iterator - it=id_set.begin(); - it!=id_set.end(); - it++) + for(const auto &id_ptr : id_set) { - const irep_idt id=(*it)->identifier; + const irep_idt id = id_ptr->identifier; const symbolt &s=cpp_typecheck.lookup(id); assert(s.type.get_bool(ID_is_template)); if(to_cpp_declaration(s.type).is_class_template()) @@ -1670,14 +1635,10 @@ exprt cpp_typecheck_resolvet::resolve( { cpp_typecheck.error() << "\nargument types:\n"; - for(exprt::operandst::const_iterator - it=fargs.operands.begin(); - it!=fargs.operands.end(); - it++) + for(const auto &op : fargs.operands) { - cpp_typecheck.error() << " " - << cpp_typecheck.to_string(it->type()) - << '\n'; + cpp_typecheck.error() + << " " << cpp_typecheck.to_string(op.type()) << '\n'; } } @@ -1770,11 +1731,9 @@ void cpp_typecheck_resolvet::guess_template_args( base_name, cpp_scopet::RECURSIVE, id_set); // alright, rummage through these - for(cpp_scopest::id_sett::const_iterator it=id_set.begin(); - it!=id_set.end(); - it++) + for(const auto &id_ptr : id_set) { - const cpp_idt &id=**it; + const cpp_idt &id = *id_ptr; // template parameter? if(id.id_class==cpp_idt::id_classt::TEMPLATE_PARAMETER) { @@ -1860,12 +1819,9 @@ void cpp_typecheck_resolvet::guess_template_args( base_name, cpp_scopet::RECURSIVE, id_set); // alright, rummage through these - for(cpp_scopest::id_sett::const_iterator - it=id_set.begin(); - it!=id_set.end(); - it++) + for(const auto &id_ptr : id_set) { - const cpp_idt &id=**it; + const cpp_idt &id = *id_ptr; // template argument? if(id.id_class==cpp_idt::id_classt::TEMPLATE_PARAMETER) @@ -2248,12 +2204,9 @@ void cpp_typecheck_resolvet::filter_for_named_scopes( // std::cout << "FILTER\n"; // We only want scopes! - for(cpp_scopest::id_sett::const_iterator - it=id_set.begin(); - it!=id_set.end(); - it++) + for(const auto &id_ptr : id_set) { - cpp_idt &id=**it; + cpp_idt &id = *id_ptr; if(id.is_class() || id.is_enum() || id.is_namespace()) { diff --git a/src/cpp/template_map.cpp b/src/cpp/template_map.cpp index 2b43ebb4e4a..76f5174d068 100644 --- a/src/cpp/template_map.cpp +++ b/src/cpp/template_map.cpp @@ -132,15 +132,11 @@ exprt template_mapt::lookup_expr(const irep_idt &identifier) const void template_mapt::print(std::ostream &out) const { - for(type_mapt::const_iterator it=type_map.begin(); - it!=type_map.end(); - it++) - out << it->first << " = " << it->second.pretty() << '\n'; - - for(expr_mapt::const_iterator it=expr_map.begin(); - it!=expr_map.end(); - it++) - out << it->first << " = " << it->second.pretty() << '\n'; + for(const auto &mapping : type_map) + out << mapping.first << " = " << mapping.second.pretty() << '\n'; + + for(const auto &mapping : expr_map) + out << mapping.first << " = " << mapping.second.pretty() << '\n'; } void template_mapt::build( @@ -215,16 +211,8 @@ void template_mapt::set( void template_mapt::build_unassigned( const template_typet &template_type) { - const template_typet::template_parameterst &template_parameters= - template_type.template_parameters(); - - for(template_typet::template_parameterst::const_iterator - t_it=template_parameters.begin(); - t_it!=template_parameters.end(); - t_it++) + for(const auto &t : template_type.template_parameters()) { - const template_parametert &t=*t_it; - if(t.id()==ID_type) { typet tmp(ID_unassigned);