Skip to content

Fix formatting in cegis-util/type_helper.cpp #867

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
Apr 27, 2017
Merged
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
63 changes: 41 additions & 22 deletions src/cegis/cegis-util/type_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ Author: Daniel Kroening, [email protected]

#include <cegis/cegis-util/type_helper.h>

const typet &replace_struct_by_symbol_type(const symbol_tablet &st,
const typet &type)
const typet &replace_struct_by_symbol_type(
const symbol_tablet &st,
const typet &type)
{
const irep_idt &type_id=type.id();
if(ID_struct != type_id && ID_incomplete_struct != type_id
&& ID_union != type_id && ID_incomplete_union != type_id) return type;
if(type_id!=ID_struct && type_id!=ID_incomplete_struct &&
type_id!=ID_union && type_id!=ID_incomplete_union)
{
return type;
}
std::string tag(TAG_PREFIX);
tag+=id2string(to_struct_union_type(type).get_tag());
return st.lookup(tag).type;
Expand All @@ -31,16 +35,21 @@ namespace
{
bool instanceof(const typet &lhs, const typet &rhs, const namespacet &ns)
{
if(type_eq(lhs, rhs, ns)) return true;
assert(ID_class == lhs.id());
const class_typet &lhs_class=to_class_type(lhs);
const irept::subt &bases=lhs_class.bases();
for(const irept &base : bases)
if(type_eq(lhs, rhs, ns))
{
const typet &type=static_cast<const typet &>(base.find(ID_type));
if(instanceof(ns.follow(type), rhs, ns)) return true;
return true;
}
return false;
assert(ID_class==lhs.id());
const class_typet &lhs_class=to_class_type(lhs);
const irept::subt &bases=lhs_class.bases();
return std::any_of(
std::begin(bases),
std::end(bases),
[&](const irept &base)
{
const typet &type=static_cast<const typet &>(base.find(ID_type));
return instanceof(ns.follow(type), rhs, ns);
});
}
}

Expand All @@ -49,22 +58,32 @@ bool instanceof(const symbol_tablet &st, const typet &lhs, const typet &rhs)
const namespacet ns(st);
const typet &resolved_lhs=ns.follow(lhs);
const typet &resolved_rhs=ns.follow(rhs);
if(ID_class != resolved_lhs.id() || ID_class != resolved_rhs.id())
if(ID_class!=resolved_lhs.id() || ID_class!=resolved_rhs.id())
{
return type_eq(resolved_lhs, resolved_rhs, ns);
}
return instanceof(resolved_lhs, resolved_rhs, ns);
}

instanceof_anyt::instanceof_anyt(const symbol_tablet &st,
const std::set<typet> &types) :
st(st), types(types)
instanceof_anyt::instanceof_anyt(
const symbol_tablet &st,
const std::set<typet> &types) :
st(st),
types(types)
{
}

bool instanceof_anyt::operator ()(const typet &type) const
bool instanceof_anyt::operator()(const typet &type) const
{
if(types.empty()) return true;
return types.end()
!= std::find_if(types.begin(), types.end(),
[this, &type](const typet &rhs)
{ return instanceof(st, type, rhs);});
if(types.empty())
{
return true;
}
return types.end()!=std::find_if(
types.begin(),
types.end(),
[this, &type](const typet &rhs)
{
return instanceof(st, type, rhs);
});
}