Skip to content

Remove {f,F}orall_named_irep #5786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ ForEachMacros: [
'Forall_expr',
'forall_irep',
'Forall_irep',
'forall_named_irep',
'Forall_named_irep',
'forall_symbol_base_map',
'forall_subtypes',
'Forall_subtypes']
Expand Down
24 changes: 14 additions & 10 deletions src/cpp/cpp_type2name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,37 @@ static std::string irep2name(const irept &irep)
result+='(';
bool first=true;

forall_named_irep(it, irep.get_named_sub())
if(!irept::is_comment(it->first))
for(const auto &named_sub : irep.get_named_sub())
{
if(!irept::is_comment(named_sub.first))
{
if(first)
first = false;
else
result += ',';

result += do_prefix(name2string(it->first));
result += do_prefix(name2string(named_sub.first));

result += '=';
result += irep2name(it->second);
result += irep2name(named_sub.second);
}
}

forall_named_irep(it, irep.get_named_sub())
if(it->first==ID_C_constant ||
it->first==ID_C_volatile ||
it->first==ID_C_restricted)
for(const auto &named_sub : irep.get_named_sub())
{
if(
named_sub.first == ID_C_constant || named_sub.first == ID_C_volatile ||
named_sub.first == ID_C_restricted)
{
if(first)
first=false;
else
result+=',';
result+=do_prefix(name2string(it->first));
result += do_prefix(name2string(named_sub.first));
result+='=';
result += irep2name(it->second);
result += irep2name(named_sub.second);
}
}

forall_irep(it, irep.get_sub())
{
Expand Down
22 changes: 12 additions & 10 deletions src/util/irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,15 @@ std::size_t irept::hash() const

std::size_t number_of_named_ireps = 0;

forall_named_irep(it, named_sub)
if(!is_comment(it->first)) // this variant ignores comments
for(const auto &irep_entry : named_sub)
{
if(!is_comment(irep_entry.first)) // this variant ignores comments
{
result = hash_combine(result, hash_string(it->first));
result = hash_combine(result, it->second.hash());
result = hash_combine(result, hash_string(irep_entry.first));
result = hash_combine(result, irep_entry.second.hash());
number_of_named_ireps++;
}
}

result = hash_finalize(result, sub.size() + number_of_named_ireps);

Expand All @@ -467,10 +469,10 @@ std::size_t irept::full_hash() const
forall_irep(it, sub) result=hash_combine(result, it->full_hash());

// this variant includes all named_sub elements
forall_named_irep(it, named_sub)
for(const auto &irep_entry : named_sub)
{
result=hash_combine(result, hash_string(it->first));
result=hash_combine(result, it->second.full_hash());
result = hash_combine(result, hash_string(irep_entry.first));
result = hash_combine(result, irep_entry.second.full_hash());
}

const std::size_t named_sub_size = named_sub.size();
Expand Down Expand Up @@ -498,16 +500,16 @@ std::string irept::pretty(unsigned indent, unsigned max_indent) const
indent+=2;
}

forall_named_irep(it, get_named_sub())
for(const auto &irep_entry : get_named_sub())
{
result+="\n";
indent_str(result, indent);

result+="* ";
result+=id2string(it->first);
result += id2string(irep_entry.first);
result+=": ";

result+=it->second.pretty(indent+2, max_indent);
result += irep_entry.second.pretty(indent + 2, max_indent);
}

std::size_t count=0;
Expand Down
8 changes: 0 additions & 8 deletions src/util/irep.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ inline const std::string &name2string(const irep_namet &n)
for(irept::subt::iterator it=(irep).begin(); \
it!=(irep).end(); ++it)

#define forall_named_irep(it, irep) \
for(irept::named_subt::const_iterator it=(irep).begin(); \
it!=(irep).end(); ++it)

#define Forall_named_irep(it, irep) \
for(irept::named_subt::iterator it=(irep).begin(); \
it!=(irep).end(); ++it)

#ifdef IREP_DEBUG
#include <iostream>
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/util/irep_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ void irep_serializationt::write_irep(
reference_convert(*it, out);
}

forall_named_irep(it, irep.get_named_sub())
for(const auto &sub_irep_entry : irep.get_named_sub())
{
out.put('N');
write_string_ref(out, it->first);
reference_convert(it->second, out);
write_string_ref(out, sub_irep_entry.first);
reference_convert(sub_irep_entry.second, out);
}

out.put(0); // terminator
Expand Down
6 changes: 3 additions & 3 deletions src/util/lispirep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ void irep2lisp(const irept &src, lispexprt &dest)
dest.push_back(sub);
}

forall_named_irep(it, src.get_named_sub())
for(const auto &irep_entry : src.get_named_sub())
{
lispexprt name;
name.type=lispexprt::String;
name.value=name2string(it->first);
name.value = name2string(irep_entry.first);
dest.push_back(name);

lispexprt sub;

irep2lisp(it->second, sub);
irep2lisp(irep_entry.second, sub);
dest.push_back(sub);
}

Expand Down
31 changes: 16 additions & 15 deletions src/util/merge_irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ std::size_t to_be_merged_irept::hash() const
forall_irep(it, sub)
result=hash_combine(result, static_cast<const merged_irept &>(*it).hash());

forall_named_irep(it, named_sub)
for(const auto &irep_entry : named_sub)
{
result=hash_combine(result, hash_string(it->first));
result=
hash_combine(
result, static_cast<const merged_irept &>(it->second).hash());
result = hash_combine(result, hash_string(irep_entry.first));
result = hash_combine(
result, static_cast<const merged_irept &>(irep_entry.second).hash());
}

const std::size_t named_sub_size = named_sub.size();
Expand Down Expand Up @@ -108,14 +107,15 @@ const merged_irept &merged_irepst::merged(const irept &irep)
#if NAMED_SUB_IS_FORWARD_LIST
irept::named_subt::iterator before = dest_named_sub.before_begin();
#endif
forall_named_irep(it, src_named_sub)
for(const auto &irep_entry : src_named_sub)
{
#if NAMED_SUB_IS_FORWARD_LIST
dest_named_sub.emplace_after(
before, it->first, merged(it->second)); // recursive call
before, irep_entry.first, merged(irep_entry.second)); // recursive call
++before;
#else
dest_named_sub[it->first]=merged(it->second); // recursive call
dest_named_sub[irep_entry.first] =
merged(irep_entry.second); // recursive call
#endif
}

Expand Down Expand Up @@ -164,12 +164,12 @@ const irept &merge_irept::merged(const irept &irep)
irept::named_subt *dest_named_sub_ptr = nullptr;

std::ptrdiff_t advance_by = 0;
forall_named_irep(it, src_named_sub)
for(const auto &irep_entry : src_named_sub)
{
if(!irept::is_comment(it->first))
if(!irept::is_comment(irep_entry.first))
{
const irept &op = merged(it->second); // recursive call
if(&op.read() != &(it->second.read()))
const irept &op = merged(irep_entry.second); // recursive call
if(&op.read() != &(irep_entry.second.read()))
{
if(!dest_named_sub_ptr)
dest_named_sub_ptr =
Expand Down Expand Up @@ -212,14 +212,15 @@ const irept &merge_full_irept::merged(const irept &irep)
#if NAMED_SUB_IS_FORWARD_LIST
irept::named_subt::iterator before = dest_named_sub.before_begin();
#endif
forall_named_irep(it, src_named_sub)
for(const auto &irep_entry : src_named_sub)
{
#if NAMED_SUB_IS_FORWARD_LIST
dest_named_sub.emplace_after(
before, it->first, merged(it->second)); // recursive call
before, irep_entry.first, merged(irep_entry.second)); // recursive call
++before;
#else
dest_named_sub[it->first]=merged(it->second); // recursive call
dest_named_sub[irep_entry.first] =
merged(irep_entry.second); // recursive call
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions src/util/source_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ std::string source_locationt::as_string(bool print_cwd) const

void source_locationt::merge(const source_locationt &from)
{
forall_named_irep(it, from.get_named_sub())
for(const auto &irep_entry : from.get_named_sub())
{
if(get(it->first).empty())
set(it->first, it->second);
if(get(irep_entry.first).empty())
set(irep_entry.first, irep_entry.second);
}
}

Expand Down
20 changes: 12 additions & 8 deletions src/util/xml_irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ void convert(
convert(*it, x_sub);
}

forall_named_irep(it, irep.get_named_sub())
if(!irept::is_comment(it->first))
for(const auto &irep_entry : irep.get_named_sub())
{
if(!irept::is_comment(irep_entry.first))
{
xmlt &x_nsub = xml.new_element("named_sub");
x_nsub.set_attribute("name", name2string(it->first));
convert(it->second, x_nsub);
x_nsub.set_attribute("name", name2string(irep_entry.first));
convert(irep_entry.second, x_nsub);
}
}

forall_named_irep(it, irep.get_named_sub())
if(!irept::is_comment(it->first))
for(const auto &irep_entry : irep.get_named_sub())
{
if(!irept::is_comment(irep_entry.first))
{
xmlt &x_com = xml.new_element("comment");
x_com.set_attribute("name", name2string(it->first));
convert(it->second, x_com);
x_com.set_attribute("name", name2string(irep_entry.first));
convert(irep_entry.second, x_com);
}
}
}

void convert(
Expand Down