diff --git a/src/ansi-c/ansi_c_typecheck.cpp b/src/ansi-c/ansi_c_typecheck.cpp index 50bfe78dffb..02ef8f86de6 100644 --- a/src/ansi-c/ansi_c_typecheck.cpp +++ b/src/ansi-c/ansi_c_typecheck.cpp @@ -14,13 +14,9 @@ Author: Daniel Kroening, kroening@kroening.com void ansi_c_typecheckt::typecheck() { start_typecheck_code(); - for(ansi_c_parse_treet::itemst::iterator - it=parse_tree.items.begin(); - it!=parse_tree.items.end(); - it++) - { - typecheck_declaration(*it); - } + + for(auto &item : parse_tree.items) + typecheck_declaration(item); } bool ansi_c_typecheck( diff --git a/src/ansi-c/c_typecheck_base.cpp b/src/ansi-c/c_typecheck_base.cpp index 03170ca8fbe..b420d88cfe5 100644 --- a/src/ansi-c/c_typecheck_base.cpp +++ b/src/ansi-c/c_typecheck_base.cpp @@ -143,16 +143,14 @@ void c_typecheck_baset::typecheck_new_symbol(symbolt &symbol) { if(symbol.value.is_not_nil() && !symbol.is_macro) + { typecheck_function_body(symbol); + } else { // we don't need the identifiers - code_typet &code_type=to_code_type(symbol.type); - for(code_typet::parameterst::iterator - it=code_type.parameters().begin(); - it!=code_type.parameters().end(); - it++) - it->set_identifier(irep_idt()); + for(auto ¶meter : to_code_type(symbol.type).parameters()) + parameter.set_identifier(irep_idt()); } } else if(!symbol.is_macro) @@ -361,13 +359,9 @@ void c_typecheck_baset::typecheck_redefinition_non_type( old_symbol.is_file_local=new_symbol.is_file_local; // remove parameter declarations to avoid conflicts - const code_typet::parameterst &old_p=old_ct.parameters(); - for(code_typet::parameterst::const_iterator - p_it=old_p.begin(); - p_it!=old_p.end(); - p_it++) + for(const auto &old_parameter : old_ct.parameters()) { - const irep_idt &identifier=p_it->get_identifier(); + const irep_idt &identifier = old_parameter.get_identifier(); symbol_tablet::symbolst::const_iterator p_s_it= symbol_table.symbols.find(identifier); @@ -530,31 +524,27 @@ void c_typecheck_baset::typecheck_function_body(symbolt &symbol) unsigned anon_counter=0; // Add the parameter declarations into the symbol table. - code_typet::parameterst ¶meters=code_type.parameters(); - for(code_typet::parameterst::iterator - p_it=parameters.begin(); - p_it!=parameters.end(); - p_it++) + for(auto &p : code_type.parameters()) { // may be anonymous - if(p_it->get_base_name().empty()) + if(p.get_base_name().empty()) { irep_idt base_name="#anon"+std::to_string(anon_counter++); - p_it->set_base_name(base_name); + p.set_base_name(base_name); } // produce identifier - irep_idt base_name=p_it->get_base_name(); + irep_idt base_name = p.get_base_name(); irep_idt identifier=id2string(symbol.name)+"::"+id2string(base_name); - p_it->set_identifier(identifier); + p.set_identifier(identifier); parameter_symbolt p_symbol; - p_symbol.type=p_it->type(); + p_symbol.type = p.type(); p_symbol.name=identifier; p_symbol.base_name=base_name; - p_symbol.location=p_it->source_location(); + p_symbol.location = p.source_location(); symbolt *new_p_symbol; move_symbol(p_symbol, new_p_symbol); @@ -564,13 +554,12 @@ void c_typecheck_baset::typecheck_function_body(symbolt &symbol) typecheck_code(to_code(symbol.value)); // check the labels - for(std::map::const_iterator - it=labels_used.begin(); it!=labels_used.end(); it++) + for(const auto &label : labels_used) { - if(labels_defined.find(it->first)==labels_defined.end()) + if(labels_defined.find(label.first) == labels_defined.end()) { - error().source_location=it->second; - error() << "branching label `" << it->first + error().source_location = label.second; + error() << "branching label `" << label.first << "' is not defined in function" << eom; throw 0; } @@ -626,12 +615,9 @@ void c_typecheck_baset::apply_asm_label( { const code_typet &code_type=to_code_type(symbol.type); - for(code_typet::parameterst::const_iterator - p_it=code_type.parameters().begin(); - p_it!=code_type.parameters().end(); - ++p_it) + for(const auto &p : code_type.parameters()) { - const irep_idt &p_bn=p_it->get_base_name(); + const irep_idt &p_bn = p.get_base_name(); if(p_bn.empty()) continue; @@ -678,12 +664,9 @@ void c_typecheck_baset::typecheck_declaration( } // Now do declarators, if any. - for(ansi_c_declarationt::declaratorst::iterator - d_it=declaration.declarators().begin(); - d_it!=declaration.declarators().end(); - d_it++) + for(auto &declarator : declaration.declarators()) { - c_storage_spect full_spec(declaration.full_type(*d_it)); + c_storage_spect full_spec(declaration.full_type(declarator)); full_spec|=c_storage_spec; declaration.set_is_inline(full_spec.is_inline); @@ -696,7 +679,7 @@ void c_typecheck_baset::typecheck_declaration( declaration.set_is_used(full_spec.is_used); symbolt symbol; - declaration.to_symbol(*d_it, symbol); + declaration.to_symbol(declarator, symbol); current_symbol=symbol; // now check other half of type @@ -749,7 +732,7 @@ void c_typecheck_baset::typecheck_declaration( } irep_idt identifier=symbol.name; - d_it->set_name(identifier); + declarator.set_name(identifier); typecheck_symbol(symbol); diff --git a/src/ansi-c/c_typecheck_code.cpp b/src/ansi-c/c_typecheck_code.cpp index e885807f3ce..7bad78eb1e7 100644 --- a/src/ansi-c/c_typecheck_code.cpp +++ b/src/ansi-c/c_typecheck_code.cpp @@ -259,12 +259,9 @@ void c_typecheck_baset::typecheck_decl(codet &code) // iterate over declarators - for(ansi_c_declarationt::declaratorst::const_iterator - d_it=declaration.declarators().begin(); - d_it!=declaration.declarators().end(); - d_it++) + for(const auto &d : declaration.declarators()) { - irep_idt identifier=d_it->get_name(); + irep_idt identifier = d.get_name(); // look it up symbol_tablet::symbolst::const_iterator s_it= diff --git a/src/ansi-c/c_typecheck_typecast.cpp b/src/ansi-c/c_typecheck_typecast.cpp index 2ce03d83f18..09c3f055b96 100644 --- a/src/ansi-c/c_typecheck_typecast.cpp +++ b/src/ansi-c/c_typecheck_typecast.cpp @@ -20,33 +20,22 @@ void c_typecheck_baset::implicit_typecast( c_typecast.implicit_typecast(expr, dest_type); - for(std::list::const_iterator - it=c_typecast.errors.begin(); - it!=c_typecast.errors.end(); - it++) + for(const auto &tc_error : c_typecast.errors) { error().source_location=expr.find_source_location(); error() << "in expression `" << to_string(expr) << "':\n" - << "conversion from `" - << to_string(src_type) << "' to `" - << to_string(dest_type) << "': " - << *it << eom; + << "conversion from `" << to_string(src_type) << "' to `" + << to_string(dest_type) << "': " << tc_error << eom; } if(!c_typecast.errors.empty()) throw 0; // give up - for(std::list::const_iterator - it=c_typecast.warnings.begin(); - it!=c_typecast.warnings.end(); - it++) + for(const auto &tc_warning : c_typecast.warnings) { warning().source_location=expr.find_source_location(); - warning() << "warning: conversion from `" - << to_string(src_type) - << "' to `" - << to_string(dest_type) - << "': " << *it << eom; + warning() << "warning: conversion from `" << to_string(src_type) << "' to `" + << to_string(dest_type) << "': " << tc_warning << eom; } } diff --git a/src/ansi-c/expr2c.cpp b/src/ansi-c/expr2c.cpp index 9768e61844d..b4abacc3270 100644 --- a/src/ansi-c/expr2c.cpp +++ b/src/ansi-c/expr2c.cpp @@ -92,13 +92,11 @@ static std::string clean_identifier(const irep_idt &id) dest.erase(0, c_pos+2); else if(c_pos!=std::string::npos) { - for(std::string::iterator it2=dest.begin(); - it2!=dest.end(); - ++it2) - if(*it2==':') - *it2='$'; - else if(*it2=='-') - *it2='_'; + for(char &ch : dest) + if(ch == ':') + ch = '$'; + else if(ch == '-') + ch = '_'; } // rewrite . as used in ELF section names @@ -113,20 +111,17 @@ void expr2ct::get_shorthands(const exprt &expr) find_symbols(expr, symbols); // avoid renaming parameters, if possible - for(find_symbols_sett::const_iterator - it=symbols.begin(); - it!=symbols.end(); - it++) + for(const auto &symbol_id : symbols) { const symbolt *symbol; - bool is_param=!ns.lookup(*it, symbol) && symbol->is_parameter; + bool is_param = !ns.lookup(symbol_id, symbol) && symbol->is_parameter; if(!is_param) continue; - irep_idt sh=id_shorthand(*it); + irep_idt sh = id_shorthand(symbol_id); - std::string func = id2string(*it); + std::string func = id2string(symbol_id); func = func.substr(0, func.rfind("::")); // if there is a global symbol of the same name as the shorthand (even if @@ -137,19 +132,16 @@ void expr2ct::get_shorthands(const exprt &expr) ns_collision[func].insert(sh); - if(!shorthands.insert(std::make_pair(*it, sh)).second) + if(!shorthands.insert(std::make_pair(symbol_id, sh)).second) UNREACHABLE; } - for(find_symbols_sett::const_iterator - it=symbols.begin(); - it!=symbols.end(); - it++) + for(const auto &symbol_id : symbols) { - if(shorthands.find(*it)!=shorthands.end()) + if(shorthands.find(symbol_id) != shorthands.end()) continue; - irep_idt sh=id_shorthand(*it); + irep_idt sh = id_shorthand(symbol_id); bool has_collision= ns_collision[irep_idt()].find(sh)!= @@ -168,16 +160,16 @@ void expr2ct::get_shorthands(const exprt &expr) irep_idt func; const symbolt *symbol; - if(!ns.lookup(*it, symbol)) + if(!ns.lookup(symbol_id, symbol)) func=symbol->location.get_function(); has_collision=!ns_collision[func].insert(sh).second; } if(has_collision) - sh=clean_identifier(*it); + sh = clean_identifier(symbol_id); - shorthands.insert(std::make_pair(*it, sh)); + shorthands.insert(std::make_pair(symbol_id, sh)); } } @@ -1786,13 +1778,10 @@ std::string expr2ct::convert_constant( const c_enum_typet::memberst &members= to_c_enum_type(c_enum_type).members(); - for(c_enum_typet::memberst::const_iterator - it=members.begin(); - it!=members.end(); - it++) + for(const auto &member : members) { - if(it->get_value()==int_value_string) - return "/*enum*/"+id2string(it->get_base_name()); + if(member.get_value() == int_value_string) + return "/*enum*/" + id2string(member.get_base_name()); } // failed...