diff --git a/.clang-format b/.clang-format index ba558aa8b07..905f2aaa380 100644 --- a/.clang-format +++ b/.clang-format @@ -38,9 +38,7 @@ ForEachMacros: [ 'Forall_operands', 'forall_expr', 'Forall_expr', - 'forall_symbol_base_map', - 'forall_subtypes', - 'Forall_subtypes'] + 'forall_symbol_base_map'] IndentCaseLabels: 'false' IndentPPDirectives: AfterHash IndentWidth: '2' diff --git a/src/ansi-c/ansi_c_convert_type.cpp b/src/ansi-c/ansi_c_convert_type.cpp index 65e01c5383f..3887da8922c 100644 --- a/src/ansi-c/ansi_c_convert_type.cpp +++ b/src/ansi-c/ansi_c_convert_type.cpp @@ -32,8 +32,8 @@ void ansi_c_convert_typet::read_rec(const typet &type) { if(type.id()==ID_merged_type) { - forall_subtypes(it, type) - read_rec(*it); + for(const typet &subtype : to_type_with_subtypes(type).subtypes()) + read_rec(subtype); } else if(type.id()==ID_signed) signed_cnt++; diff --git a/src/ansi-c/ansi_c_parser.cpp b/src/ansi-c/ansi_c_parser.cpp index 310a7e2bcb1..61d2825e662 100644 --- a/src/ansi-c/ansi_c_parser.cpp +++ b/src/ansi-c/ansi_c_parser.cpp @@ -164,9 +164,11 @@ ansi_c_id_classt ansi_c_parsert::get_class(const typet &type) return ansi_c_id_classt::ANSI_C_TAG; else if(type.id()==ID_merged_type) { - forall_subtypes(it, type) - if(get_class(*it)==ansi_c_id_classt::ANSI_C_TYPEDEF) + for(const typet &subtype : to_type_with_subtypes(type).subtypes()) + { + if(get_class(subtype) == ansi_c_id_classt::ANSI_C_TYPEDEF) return ansi_c_id_classt::ANSI_C_TYPEDEF; + } } else if(type.has_subtype()) return get_class(type.subtype()); diff --git a/src/ansi-c/c_storage_spec.cpp b/src/ansi-c/c_storage_spec.cpp index 668d7e08f32..81fdb3f5235 100644 --- a/src/ansi-c/c_storage_spec.cpp +++ b/src/ansi-c/c_storage_spec.cpp @@ -16,8 +16,8 @@ void c_storage_spect::read(const typet &type) if(type.id()==ID_merged_type || type.id()==ID_code) { - forall_subtypes(it, type) - read(*it); + for(const typet &subtype : to_type_with_subtypes(type).subtypes()) + read(subtype); } else if(type.id()==ID_static) is_static=true; diff --git a/src/ansi-c/type2name.cpp b/src/ansi-c/type2name.cpp index 8fcee0bb37a..314742e5951 100644 --- a/src/ansi-c/type2name.cpp +++ b/src/ansi-c/type2name.cpp @@ -258,9 +258,9 @@ static std::string type2name( if(type.has_subtypes()) { result+='$'; - forall_subtypes(it, type) + for(const typet &subtype : to_type_with_subtypes(type).subtypes()) { - result+=type2name(*it, ns, symbol_number); + result += type2name(subtype, ns, symbol_number); result+='|'; } result[result.size()-1]='$'; diff --git a/src/cpp/cpp_declaration.cpp b/src/cpp/cpp_declaration.cpp index 42fdb2d44c3..71af2797a12 100644 --- a/src/cpp/cpp_declaration.cpp +++ b/src/cpp/cpp_declaration.cpp @@ -57,7 +57,7 @@ void cpp_declarationt::name_anon_struct_union(typet &dest) } else if(dest.id()==ID_merged_type) { - Forall_subtypes(it, dest) - name_anon_struct_union(*it); + for(typet &subtype : to_type_with_subtypes(dest).subtypes()) + name_anon_struct_union(subtype); } } diff --git a/src/cpp/cpp_storage_spec.cpp b/src/cpp/cpp_storage_spec.cpp index f0c15dc7a25..e170d8440ea 100644 --- a/src/cpp/cpp_storage_spec.cpp +++ b/src/cpp/cpp_storage_spec.cpp @@ -12,8 +12,8 @@ void cpp_storage_spect::read(const typet &type) { if(type.id() == ID_merged_type || type.id() == ID_function_type) { - forall_subtypes(it, type) - read(*it); + for(const typet &subtype : to_type_with_subtypes(type).subtypes()) + read(subtype); } else if(type.id() == ID_static) set_static(); diff --git a/src/cpp/cpp_typecheck_compound_type.cpp b/src/cpp/cpp_typecheck_compound_type.cpp index 202396b19bc..561ce491319 100644 --- a/src/cpp/cpp_typecheck_compound_type.cpp +++ b/src/cpp/cpp_typecheck_compound_type.cpp @@ -35,9 +35,11 @@ bool cpp_typecheckt::has_const(const typet &type) return true; else if(type.id()==ID_merged_type) { - forall_subtypes(it, type) - if(has_const(*it)) + for(const typet &subtype : to_type_with_subtypes(type).subtypes()) + { + if(has_const(subtype)) return true; + } return false; } @@ -51,9 +53,11 @@ bool cpp_typecheckt::has_volatile(const typet &type) return true; else if(type.id()==ID_merged_type) { - forall_subtypes(it, type) - if(has_volatile(*it)) + for(const typet &subtype : to_type_with_subtypes(type).subtypes()) + { + if(has_volatile(subtype)) return true; + } return false; } @@ -69,9 +73,11 @@ bool cpp_typecheckt::has_auto(const typet &type) type.id() == ID_merged_type || type.id() == ID_frontend_pointer || type.id() == ID_pointer) { - forall_subtypes(it, type) - if(has_auto(*it)) + for(const typet &subtype : to_type_with_subtypes(type).subtypes()) + { + if(has_auto(subtype)) return true; + } return false; } diff --git a/src/cpp/template_map.cpp b/src/cpp/template_map.cpp index 57638ded149..a683dc48419 100644 --- a/src/cpp/template_map.cpp +++ b/src/cpp/template_map.cpp @@ -62,8 +62,8 @@ void template_mapt::apply(typet &type) const } else if(type.id()==ID_merged_type) { - Forall_subtypes(it, type) - apply(*it); + for(typet &subtype : to_type_with_subtypes(type).subtypes()) + apply(subtype); } } diff --git a/src/goto-instrument/dump_c.cpp b/src/goto-instrument/dump_c.cpp index 247757a1ff5..18d732563a5 100644 --- a/src/goto-instrument/dump_c.cpp +++ b/src/goto-instrument/dump_c.cpp @@ -1475,8 +1475,8 @@ void dump_ct::cleanup_expr(exprt &expr) void dump_ct::cleanup_type(typet &type) { - Forall_subtypes(it, type) - cleanup_type(*it); + for(typet &subtype : to_type_with_subtypes(type).subtypes()) + cleanup_type(subtype); if(type.id()==ID_code) { diff --git a/src/util/find_symbols.cpp b/src/util/find_symbols.cpp index 076cd15a16d..70b3d033931 100644 --- a/src/util/find_symbols.cpp +++ b/src/util/find_symbols.cpp @@ -124,8 +124,8 @@ void find_symbols(kindt kind, const typet &src, find_symbols_sett &dest) if(src.has_subtype()) find_symbols(kind, to_type_with_subtype(src).subtype(), dest); - forall_subtypes(it, src) - find_symbols(kind, *it, dest); + for(const typet &subtype : to_type_with_subtypes(src).subtypes()) + find_symbols(kind, subtype, dest); const irep_idt &typedef_name=src.get(ID_C_typedef); if(!typedef_name.empty()) diff --git a/src/util/rename_symbol.cpp b/src/util/rename_symbol.cpp index 0c312dc4689..cd785b9d4b0 100644 --- a/src/util/rename_symbol.cpp +++ b/src/util/rename_symbol.cpp @@ -129,9 +129,11 @@ bool rename_symbolt::rename(typet &dest) const if(!rename(dest.subtype())) result=false; - Forall_subtypes(it, dest) - if(!rename(*it)) + for(typet &subtype : to_type_with_subtypes(dest).subtypes()) + { + if(!rename(subtype)) result=false; + } if(dest.id()==ID_struct || dest.id()==ID_union) @@ -193,9 +195,11 @@ bool rename_symbolt::have_to_rename(const typet &dest) const if(have_to_rename(dest.subtype())) return true; - forall_subtypes(it, dest) - if(have_to_rename(*it)) + for(const typet &subtype : to_type_with_subtypes(dest).subtypes()) + { + if(have_to_rename(subtype)) return true; + } if(dest.id()==ID_struct || dest.id()==ID_union) diff --git a/src/util/replace_symbol.cpp b/src/util/replace_symbol.cpp index 92ffa53699b..e2f4c306c1a 100644 --- a/src/util/replace_symbol.cpp +++ b/src/util/replace_symbol.cpp @@ -170,9 +170,11 @@ bool replace_symbolt::replace(typet &dest) const if(!replace(dest.subtype())) result=false; - Forall_subtypes(it, dest) - if(!replace(*it)) + for(typet &subtype : to_type_with_subtypes(dest).subtypes()) + { + if(!replace(subtype)) result=false; + } if(dest.id()==ID_struct || dest.id()==ID_union) @@ -212,9 +214,11 @@ bool replace_symbolt::have_to_replace(const typet &dest) const if(have_to_replace(dest.subtype())) return true; - forall_subtypes(it, dest) - if(have_to_replace(*it)) + for(const typet &subtype : to_type_with_subtypes(dest).subtypes()) + { + if(have_to_replace(subtype)) return true; + } if(dest.id()==ID_struct || dest.id()==ID_union) diff --git a/src/util/type.h b/src/util/type.h index 1e711488b2f..d7c153facda 100644 --- a/src/util/type.h +++ b/src/util/type.h @@ -149,14 +149,6 @@ class type_with_subtypet:public typet : typet(std::move(_id), std::move(_subtype)) { } - - #if 0 - const typet &subtype() const - { return (typet &)find(ID_subtype); } - - typet &subtype() - { return (typet &)add(ID_subtype); } - #endif }; inline const type_with_subtypet &to_type_with_subtype(const typet &type) @@ -213,17 +205,6 @@ inline type_with_subtypest &to_type_with_subtypes(typet &type) return static_cast(type); } -#define forall_subtypes(it, type) \ - if((type).has_subtypes()) /* NOLINT(readability/braces) */ \ - for(type_with_subtypest::subtypest::const_iterator it=to_type_with_subtypes(type).subtypes().begin(), \ - it##_end=to_type_with_subtypes(type).subtypes().end(); \ - it!=it##_end; ++it) - -#define Forall_subtypes(it, type) \ - if((type).has_subtypes()) /* NOLINT(readability/braces) */ \ - for(type_with_subtypest::subtypest::iterator it=to_type_with_subtypes(type).subtypes().begin(); \ - it!=to_type_with_subtypes(type).subtypes().end(); ++it) - /// Remove const qualifier from type (if any). /// Returns type as is if there is no const qualifier. typet remove_const(typet type);