Skip to content

Move class_typet::baset to struct_typet #3027

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
Sep 25, 2018
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
10 changes: 3 additions & 7 deletions src/cpp/cpp_declarator_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,16 @@ symbolt &cpp_declarator_convertert::convert(

irep_idt identifier=symbol_expr.type().get(ID_identifier);
const symbolt &symb=cpp_typecheck.lookup(identifier);
const typet &type = symb.type;
assert(type.id()==ID_struct);
const struct_typet &type = to_struct_type(symb.type);

if(declarator.find(ID_member_initializers).is_nil())
declarator.set(ID_member_initializers, ID_member_initializers);

cpp_typecheck.check_member_initializers(
type.find(ID_bases),
to_struct_type(type).components(),
declarator.member_initializers());
type.bases(), type.components(), declarator.member_initializers());

cpp_typecheck.full_member_initialization(
to_struct_type(type),
declarator.member_initializers());
type, declarator.member_initializers());
}

if(!storage_spec.is_extern())
Expand Down
10 changes: 3 additions & 7 deletions src/cpp/cpp_exception_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
#include "cpp_exception_id.h"

#include <util/invariant.h>
#include <util/std_types.h>

/// turns a type into a list of relevant exception IDs
void cpp_exception_list_rec(
Expand Down Expand Up @@ -48,13 +49,8 @@ void cpp_exception_list_rec(
dest.push_back("struct_"+src.get_string(ID_tag));

// now do any bases, recursively
const irept::subt &bases=src.find(ID_bases).get_sub();

forall_irep(it, bases)
{
const typet &type=static_cast<const typet &>(it->find(ID_type));
cpp_exception_list_rec(type, ns, suffix, dest);
}
for(const auto &b : to_struct_type(src).bases())
cpp_exception_list_rec(b.type(), ns, suffix, dest);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_typecheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class cpp_typecheckt:public c_typecheck_baset
codet dtor(const symbolt &symb);

void check_member_initializers(
const irept &bases,
const struct_typet::basest &bases,
const struct_typet::componentst &components,
const irept &initializers);

Expand Down
9 changes: 4 additions & 5 deletions src/cpp/cpp_typecheck_bases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,18 @@ void cpp_typecheckt::add_base_components(
vbases.insert(from_name);

// look at the the parents of the base type
forall_irep(it, from.find(ID_bases).get_sub())
for(const auto &b : from.bases())
{
irep_idt sub_access=it->get(ID_access);
irep_idt sub_access = b.get(ID_access);

if(access==ID_private)
sub_access=ID_private;
else if(access==ID_protected && sub_access!=ID_private)
sub_access=ID_protected;

const symbolt &symb=
lookup(it->find(ID_type).get(ID_identifier));
const symbolt &symb = lookup(to_symbol_type(b.type()).get_identifier());

bool is_virtual=it->get_bool(ID_virtual);
const bool is_virtual = b.get_bool(ID_virtual);

// recursive call
add_base_components(
Expand Down
40 changes: 21 additions & 19 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,10 +1135,18 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
if(declarator.find(ID_member_initializers).is_nil())
declarator.set(ID_member_initializers, ID_member_initializers);

check_member_initializers(
type.add(ID_bases),
type.components(),
declarator.member_initializers());
if(type.id() == ID_union)
{
check_member_initializers(
{}, type.components(), declarator.member_initializers());
}
else
{
check_member_initializers(
to_struct_type(type).bases(),
type.components(),
declarator.member_initializers());
}

full_member_initialization(
type,
Expand Down Expand Up @@ -1634,15 +1642,12 @@ void cpp_typecheckt::get_bases(
const struct_typet &type,
std::set<irep_idt> &set_bases) const
{
const irept::subt &bases=type.find(ID_bases).get_sub();

forall_irep(it, bases)
for(const auto &b : type.bases())
{
assert(it->id()==ID_base);
assert(it->get(ID_type) == ID_symbol_type);
DATA_INVARIANT(b.id() == ID_base, "base class expression expected");

const struct_typet &base=
to_struct_type(lookup(it->find(ID_type).get(ID_identifier)).type);
const struct_typet &base =
to_struct_type(lookup(to_symbol_type(b.type()).get_identifier()).type);

set_bases.insert(base.get(ID_name));
get_bases(base, set_bases);
Expand All @@ -1656,17 +1661,14 @@ void cpp_typecheckt::get_virtual_bases(
if(std::find(vbases.begin(), vbases.end(), type.get(ID_name))!=vbases.end())
return;

const irept::subt &bases=type.find(ID_bases).get_sub();

forall_irep(it, bases)
for(const auto &b : type.bases())
{
assert(it->id()==ID_base);
assert(it->get(ID_type) == ID_symbol_type);
DATA_INVARIANT(b.id() == ID_base, "base class expression expected");

const struct_typet &base=
to_struct_type(lookup(it->find(ID_type).get(ID_identifier)).type);
const struct_typet &base =
to_struct_type(lookup(to_symbol_type(b.type()).get_identifier()).type);

if(it->get_bool(ID_virtual))
if(b.get_bool(ID_virtual))
vbases.push_back(base.get(ID_name));

get_virtual_bases(base, vbases);
Expand Down
62 changes: 25 additions & 37 deletions src/cpp/cpp_typecheck_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,11 @@ void cpp_typecheckt::default_cpctor(
exprt &block=declarator.value();

// First, we need to call the parent copy constructors
const irept &bases=symbol.type.find(ID_bases);
forall_irep(parent_it, bases.get_sub())
for(const auto &b : to_struct_type(symbol.type).bases())
{
assert(parent_it->id()==ID_base);
assert(parent_it->get(ID_type) == ID_symbol_type);
DATA_INVARIANT(b.id() == ID_base, "base class expression expected");

const symbolt &parsymb=
lookup(parent_it->find(ID_type).get(ID_identifier));
const symbolt &parsymb = lookup(to_symbol_type(b.type()).get_identifier());

if(cpp_is_pod(parsymb.type))
copy_parent(source_location, parsymb.base_name, param_identifier, block);
Expand Down Expand Up @@ -358,15 +355,11 @@ void cpp_typecheckt::default_assignop_value(
std::string arg_name("ref");

// First, we copy the parents
const irept &bases=symbol.type.find(ID_bases);

forall_irep(parent_it, bases.get_sub())
for(const auto &b : to_struct_type(symbol.type).bases())
{
assert(parent_it->id()==ID_base);
assert(parent_it->get(ID_type) == ID_symbol_type);
DATA_INVARIANT(b.id() == ID_base, "base class expression expected");

const symbolt &symb=
lookup(parent_it->find(ID_type).get(ID_identifier));
const symbolt &symb = lookup(to_symbol_type(b.type()).get_identifier());

copy_parent(source_location, symb.base_name, arg_name, block);
}
Expand Down Expand Up @@ -426,7 +419,7 @@ void cpp_typecheckt::default_assignop_value(
/// \return If an invalid initializer is found, then the method outputs an error
/// message and throws a 0 exception.
void cpp_typecheckt::check_member_initializers(
const irept &bases,
const struct_typet::basest &bases,
const struct_typet::componentst &components,
const irept &initializers)
{
Expand All @@ -450,12 +443,11 @@ void cpp_typecheckt::check_member_initializers(

// check for a direct parent
bool ok=false;
forall_irep(parent_it, bases.get_sub())
for(const auto &b : bases)
{
assert(parent_it->get(ID_type) == ID_symbol_type);

if(member_type.get(ID_identifier)
==parent_it->find(ID_type).get(ID_identifier))
if(
to_symbol_type(member_type).get_identifier() ==
to_symbol_type(b.type()).get_identifier())
{
ok=true;
break;
Expand Down Expand Up @@ -500,10 +492,9 @@ void cpp_typecheckt::check_member_initializers(
break;

// check for a direct parent
forall_irep(parent_it, bases.get_sub())
for(const auto &b : bases)
{
assert(parent_it->get(ID_type) == ID_symbol_type);
if(symb.name==parent_it->find(ID_type).get(ID_identifier))
if(symb.name == to_symbol_type(b.type()).get_identifier())
{
ok=true;
break;
Expand All @@ -522,12 +513,11 @@ void cpp_typecheckt::check_member_initializers(
typecheck_type(member_type);

// check for a direct parent
forall_irep(parent_it, bases.get_sub())
for(const auto &b : bases)
{
assert(parent_it->get(ID_type) == ID_symbol_type);

if(member_type.get(ID_identifier)==
parent_it->find(ID_type).get(ID_identifier))
if(
member_type.get(ID_identifier) ==
to_symbol_type(b.type()).get_identifier())
{
ok=true;
break;
Expand Down Expand Up @@ -600,16 +590,13 @@ void cpp_typecheckt::full_member_initialization(
final_initializers.move_to_sub(cond);
}

const irept &bases=struct_union_type.find(ID_bases);

// Subsequently, we need to call the non-POD parent constructors
forall_irep(parent_it, bases.get_sub())
for(const auto &b : to_struct_type(struct_union_type).bases())
{
assert(parent_it->id()==ID_base);
assert(parent_it->get(ID_type) == ID_symbol_type);
DATA_INVARIANT(b.id() == ID_base, "base class expression expected");

const symbolt &ctorsymb=
lookup(parent_it->find(ID_type).get(ID_identifier));
const symbolt &ctorsymb =
lookup(to_symbol_type(b.type()).get_identifier());

if(cpp_is_pod(ctorsymb.type))
continue;
Expand Down Expand Up @@ -659,8 +646,9 @@ void cpp_typecheckt::full_member_initialization(
if(member_type.id() != ID_symbol_type)
break;

if(parent_it->find(ID_type).get(ID_identifier)==
member_type.get(ID_identifier))
if(
to_symbol_type(b.type()).get_identifier() ==
to_symbol_type(member_type).get_identifier())
{
final_initializers.move_to_sub(initializer);
found=true;
Expand All @@ -678,7 +666,7 @@ void cpp_typecheckt::full_member_initialization(
final_initializers.move_to_sub(mem_init);
}

if(parent_it->get_bool(ID_virtual))
if(b.get_bool(ID_virtual))
{
// TODO(tautschnig): this code doesn't seem to make much sense as the
// ifthenelse only gets to have two operands (instead of three)
Expand Down
15 changes: 8 additions & 7 deletions src/cpp/cpp_typecheck_destructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,18 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
block.move_to_operands(dtor_code.value());
}

const irept::subt &bases=symbol.type.find(ID_bases).get_sub();
if(symbol.type.id() == ID_union)
return block;

const auto &bases = to_struct_type(symbol.type).bases();

// call the base destructors in the reverse order
for(irept::subt::const_reverse_iterator
bit=bases.rbegin();
bit!=bases.rend();
for(class_typet::basest::const_reverse_iterator bit = bases.rbegin();
bit != bases.rend();
bit++)
{
assert(bit->id()==ID_base);
assert(bit->find(ID_type).id() == ID_symbol_type);
const symbolt &psymb = lookup(bit->find(ID_type).get(ID_identifier));
DATA_INVARIANT(bit->id() == ID_base, "base class expression expected");
const symbolt &psymb = lookup(to_symbol_type(bit->type()).get_identifier());

symbol_exprt this_ptr(ID_this, pointer_type(symbol.type));
dereference_exprt object(this_ptr, psymb.type);
Expand Down
7 changes: 4 additions & 3 deletions src/cpp/cpp_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ bool cpp_typecheckt::find_parent(
const irep_idt &base_name,
irep_idt &identifier)
{
forall_irep(bit, symb.type.find(ID_bases).get_sub())
for(const auto &b : to_struct_type(symb.type).bases())
{
if(lookup(bit->find(ID_type).get(ID_identifier)).base_name == base_name)
const irep_idt &id = to_symbol_type(b.type()).get_identifier();
if(lookup(id).base_name == base_name)
{
identifier=bit->find(ID_type).get(ID_identifier);
identifier = id;
return true;
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/goto-programs/class_hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ void class_hierarchy_grapht::populate(const symbol_tablet &symbol_table)
{
if(symbol_pair.second.is_type && symbol_pair.second.type.id() == ID_struct)
{
const class_typet &class_type = to_class_type(symbol_pair.second.type);
const struct_typet &struct_type = to_struct_type(symbol_pair.second.type);

for(const auto &base : class_type.bases())
for(const auto &base : struct_type.bases())
{
const irep_idt &parent = to_symbol_type(base.type()).get_identifier();
if(!parent.empty())
Expand Down Expand Up @@ -157,11 +157,9 @@ void class_hierarchyt::operator()(const symbol_tablet &symbol_table)
class_map[symbol_pair.first].is_abstract =
struct_type.get_bool(ID_abstract);

const irept::subt &bases = struct_type.find(ID_bases).get_sub();

for(const auto &base : bases)
for(const auto &base : struct_type.bases())
{
irep_idt parent = base.find(ID_type).get(ID_identifier);
const irep_idt &parent = to_symbol_type(base.type()).get_identifier();
if(parent.empty())
continue;

Expand Down
Loading