Skip to content

Move is_class and default_access to struct_union_typet #3002

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 21, 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
3 changes: 1 addition & 2 deletions src/cpp/cpp_typecheck_bases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ void cpp_typecheckt::typecheck_compound_bases(struct_typet &type)
std::set<irep_idt> bases;
std::set<irep_idt> vbases;

irep_idt default_class_access=
type.get_bool(ID_C_class)?ID_private:ID_public;
irep_idt default_class_access = type.default_access();

irept::subt &bases_irep=type.add(ID_bases).get_sub();

Expand Down
6 changes: 2 additions & 4 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
symbol.type.set(ID_name, symbol.name);

// default access
irep_idt access=
type.get_bool(ID_C_class)?ID_private:ID_public;
irep_idt access = type.default_access();

bool found_ctor=false;
bool found_dtor=false;
Expand Down Expand Up @@ -1119,8 +1118,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
}

// Reset the access type
access=
type.get_bool(ID_C_class)?ID_private:ID_public;
access = type.default_access();

// All the data members are now known.
// We now deal with the constructors that we are given.
Expand Down
23 changes: 13 additions & 10 deletions src/util/std_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ class struct_union_typet:public typet

irep_idt get_tag() const { return get(ID_tag); }
void set_tag(const irep_idt &tag) { set(ID_tag, tag); }

/// A struct may be a class, where members may have access restrictions.
bool is_class() const
{
return id() == ID_struct && get_bool(ID_C_class);
}

/// Return the access specification for members where access has not been
/// modified.
irep_idt default_access() const
{
return is_class() ? ID_private : ID_public;
}
};

/// Check whether a reference to a typet is a \ref struct_union_typet.
Expand Down Expand Up @@ -313,16 +326,6 @@ class class_typet:public struct_typet
return (methodst &)(add(ID_methods).get_sub());
}

bool is_class() const
{
return get_bool(ID_C_class);
}

irep_idt default_access() const
{
return is_class()?ID_private:ID_public;
}

class baset:public exprt
{
public:
Expand Down