Skip to content

Commit 9864a22

Browse files
author
Daniel Kroening
authored
Merge pull request #3002 from tautschnig/struct-class
Move is_class and default_access to struct_union_typet
2 parents 0e98e1d + cf07c6c commit 9864a22

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
@@ -976,8 +976,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
976976
symbol.type.set(ID_name, symbol.name);
977977

978978
// default access
979-
irep_idt access=
980-
type.get_bool(ID_C_class)?ID_private:ID_public;
979+
irep_idt access = type.default_access();
981980

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

11201119
// Reset the access type
1121-
access=
1122-
type.get_bool(ID_C_class)?ID_private:ID_public;
1120+
access = type.default_access();
11231121

11241122
// All the data members are now known.
11251123
// 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
@@ -226,6 +226,19 @@ class struct_union_typet:public typet
226226

227227
irep_idt get_tag() const { return get(ID_tag); }
228228
void set_tag(const irep_idt &tag) { set(ID_tag, tag); }
229+
230+
/// A struct may be a class, where members may have access restrictions.
231+
bool is_class() const
232+
{
233+
return id() == ID_struct && get_bool(ID_C_class);
234+
}
235+
236+
/// Return the access specification for members where access has not been
237+
/// modified.
238+
irep_idt default_access() const
239+
{
240+
return is_class() ? ID_private : ID_public;
241+
}
229242
};
230243

231244
/// Check whether a reference to a typet is a \ref struct_union_typet.
@@ -323,16 +336,6 @@ class class_typet:public struct_typet
323336
return (methodst &)(add(ID_methods).get_sub());
324337
}
325338

326-
bool is_class() const
327-
{
328-
return get_bool(ID_C_class);
329-
}
330-
331-
irep_idt default_access() const
332-
{
333-
return is_class()?ID_private:ID_public;
334-
}
335-
336339
class baset:public exprt
337340
{
338341
public:

0 commit comments

Comments
 (0)