Skip to content

Commit 15b43ae

Browse files
committed
Move is_class and default_access to struct_typet
A class_typet would always return true for is_class() and ID_private for default_access(). Only when available for both a struct_typet and a class_typet do they enable non-trivial use.
1 parent f611794 commit 15b43ae

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/cpp/cpp_typecheck_bases.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ void cpp_typecheckt::typecheck_compound_bases(struct_typet &type)
1818
std::set<irep_idt> bases;
1919
std::set<irep_idt> vbases;
2020

21-
irep_idt default_class_access=
22-
type.get_bool(ID_C_class)?ID_private:ID_public;
21+
irep_idt default_class_access = type.default_access();
2322

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

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
977977
symbol.type.set(ID_name, symbol.name);
978978

979979
// default access
980-
irep_idt access=
981-
type.get_bool(ID_C_class)?ID_private:ID_public;
980+
irep_idt access = type.default_access();
982981

983982
bool found_ctor=false;
984983
bool found_dtor=false;
@@ -1119,8 +1118,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
11191118
}
11201119

11211120
// Reset the access type
1122-
access=
1123-
type.get_bool(ID_C_class)?ID_private:ID_public;
1121+
access = type.default_access();
11241122

11251123
// All the data members are now known.
11261124
// We now deal with the constructors that we are given.

src/util/std_types.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ class struct_union_typet:public typet
216216

217217
irep_idt get_tag() const { return get(ID_tag); }
218218
void set_tag(const irep_idt &tag) { set(ID_tag, tag); }
219+
220+
/// A struct may be a class, where members may have access restrictions.
221+
bool is_class() const
222+
{
223+
return id() == ID_struct && get_bool(ID_C_class);
224+
}
225+
226+
/// Return the access specification for members where access has not been
227+
/// modified.
228+
irep_idt default_access() const
229+
{
230+
return is_class() ? ID_private : ID_public;
231+
}
219232
};
220233

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

316-
bool is_class() const
317-
{
318-
return get_bool(ID_C_class);
319-
}
320-
321-
irep_idt default_access() const
322-
{
323-
return is_class()?ID_private:ID_public;
324-
}
325-
326329
class baset:public exprt
327330
{
328331
public:

0 commit comments

Comments
 (0)