Skip to content

Commit bf8d471

Browse files
committed
move the types used in C programs to c_types.h
The rationale is that types of a particular group (say bitvectors or pointers) are often used together with the expressions that are specific for them. The goal is that std_types.h will only contain the basic types, such as bool_typet.
1 parent d30e826 commit bf8d471

14 files changed

+105
-103
lines changed

src/ansi-c/c_typecheck_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Author: Daniel Kroening, [email protected]
1313
#define CPROVER_ANSI_C_C_TYPECHECK_BASE_H
1414

1515
#include <util/bitvector_expr.h>
16+
#include <util/c_types.h>
1617
#include <util/namespace.h>
1718
#include <util/std_code.h>
1819
#include <util/std_expr.h>
19-
#include <util/std_types.h>
2020
#include <util/symbol_table.h>
2121
#include <util/typecheck.h>
2222

src/ansi-c/padding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <algorithm>
1515

1616
#include <util/arith_tools.h>
17-
#include <util/bitvector_types.h>
17+
#include <util/c_types.h>
1818
#include <util/config.h>
1919
#include <util/pointer_offset_size.h>
2020
#include <util/simplify_expr.h>

src/goto-instrument/dump_c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "dump_c.h"
1313

14-
#include <util/bitvector_types.h>
1514
#include <util/byte_operators.h>
15+
#include <util/c_types.h>
1616
#include <util/config.h>
1717
#include <util/expr_initializer.h>
1818
#include <util/find_symbols.h>

src/goto-programs/interpreter_evaluate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/bitvector_expr.h>
1515
#include <util/byte_operators.h>
16+
#include <util/c_types.h>
1617
#include <util/fixedbv.h>
1718
#include <util/ieee_float.h>
1819
#include <util/pointer_expr.h>

src/goto-programs/json_expr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Peter Schrammel
1212
#include "json_expr.h"
1313

1414
#include <util/arith_tools.h>
15+
#include <util/c_types.h>
1516
#include <util/config.h>
1617
#include <util/expr.h>
1718
#include <util/expr_util.h>

src/goto-programs/xml_expr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening
1414
#include "xml_expr.h"
1515

1616
#include <util/arith_tools.h>
17+
#include <util/c_types.h>
1718
#include <util/config.h>
1819
#include <util/expr.h>
1920
#include <util/fixedbv.h>

src/solvers/flattening/boolbv_width.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111
#include <algorithm>
1212

1313
#include <util/arith_tools.h>
14+
#include <util/c_types.h>
1415
#include <util/exception_utils.h>
1516
#include <util/invariant.h>
1617
#include <util/namespace.h>

src/solvers/flattening/c_bit_field_replacement_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "c_bit_field_replacement_type.h"
1010

11-
#include <util/bitvector_types.h>
11+
#include <util/c_types.h>
1212
#include <util/invariant.h>
1313

1414
typet c_bit_field_replacement_type(

src/solvers/flattening/c_bit_field_replacement_type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Author: Daniel Kroening, [email protected]
1010
#ifndef CPROVER_SOLVERS_FLATTENING_C_BIT_FIELD_REPLACEMENT_TYPE_H
1111
#define CPROVER_SOLVERS_FLATTENING_C_BIT_FIELD_REPLACEMENT_TYPE_H
1212

13-
#include <util/std_types.h>
13+
#include <util/c_types.h>
1414
#include <util/namespace.h>
1515

1616
typet c_bit_field_replacement_type(

src/util/arith_tools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Author: Daniel Kroening, [email protected]
88

99
#include "arith_tools.h"
1010

11+
#include "c_types.h"
1112
#include "fixedbv.h"
1213
#include "ieee_float.h"
1314
#include "invariant.h"
14-
#include "pointer_expr.h"
1515
#include "std_expr.h"
1616
#include "std_types.h"
1717

src/util/c_types.h

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,99 @@ Author: Daniel Kroening, [email protected]
1111
#define CPROVER_UTIL_C_TYPES_H
1212

1313
#include "pointer_expr.h"
14-
#include "std_types.h"
14+
15+
/// Type for C bit fields
16+
/// These are both 'bitvector_typet' (they have a width)
17+
/// and 'type_with_subtypet' (they have a subtype)
18+
class c_bit_field_typet : public bitvector_typet
19+
{
20+
public:
21+
explicit c_bit_field_typet(typet _subtype, std::size_t width)
22+
: bitvector_typet(ID_c_bit_field, width)
23+
{
24+
subtype().swap(_subtype);
25+
}
26+
27+
// These have a sub-type
28+
};
29+
30+
/// Check whether a reference to a typet is a \ref c_bit_field_typet.
31+
/// \param type: Source type.
32+
/// \return True if \p type is a \ref c_bit_field_typet.
33+
template <>
34+
inline bool can_cast_type<c_bit_field_typet>(const typet &type)
35+
{
36+
return type.id() == ID_c_bit_field;
37+
}
38+
39+
/// \brief Cast a typet to a \ref c_bit_field_typet
40+
///
41+
/// This is an unchecked conversion. \a type must be known to be \ref
42+
/// c_bit_field_typet. Will fail with a precondition violation if type
43+
/// doesn't match.
44+
///
45+
/// \param type: Source type.
46+
/// \return Object of type \ref c_bit_field_typet.
47+
inline const c_bit_field_typet &to_c_bit_field_type(const typet &type)
48+
{
49+
PRECONDITION(can_cast_type<c_bit_field_typet>(type));
50+
return static_cast<const c_bit_field_typet &>(type);
51+
}
52+
53+
/// \copydoc to_c_bit_field_type(const typet &type)
54+
inline c_bit_field_typet &to_c_bit_field_type(typet &type)
55+
{
56+
PRECONDITION(can_cast_type<c_bit_field_typet>(type));
57+
return static_cast<c_bit_field_typet &>(type);
58+
}
59+
60+
/// The C/C++ Booleans
61+
class c_bool_typet : public bitvector_typet
62+
{
63+
public:
64+
explicit c_bool_typet(std::size_t width) : bitvector_typet(ID_c_bool, width)
65+
{
66+
}
67+
68+
static void check(
69+
const typet &type,
70+
const validation_modet vm = validation_modet::INVARIANT)
71+
{
72+
DATA_CHECK(vm, !type.get(ID_width).empty(), "C bool type must have width");
73+
}
74+
};
75+
76+
/// Check whether a reference to a typet is a \ref c_bool_typet.
77+
/// \param type: Source type.
78+
/// \return True if \p type is a \ref c_bool_typet.
79+
template <>
80+
inline bool can_cast_type<c_bool_typet>(const typet &type)
81+
{
82+
return type.id() == ID_c_bool;
83+
}
84+
85+
/// \brief Cast a typet to a \ref c_bool_typet
86+
///
87+
/// This is an unchecked conversion. \a type must be known to be \ref
88+
/// c_bool_typet. Will fail with a precondition violation if type
89+
/// doesn't match.
90+
///
91+
/// \param type: Source type.
92+
/// \return Object of type \ref c_bool_typet.
93+
inline const c_bool_typet &to_c_bool_type(const typet &type)
94+
{
95+
PRECONDITION(can_cast_type<c_bool_typet>(type));
96+
c_bool_typet::check(type);
97+
return static_cast<const c_bool_typet &>(type);
98+
}
99+
100+
/// \copydoc to_c_bool_type(const typet &)
101+
inline c_bool_typet &to_c_bool_type(typet &type)
102+
{
103+
PRECONDITION(can_cast_type<c_bool_typet>(type));
104+
c_bool_typet::check(type);
105+
return static_cast<c_bool_typet &>(type);
106+
}
15107

16108
bitvector_typet index_type();
17109
bitvector_typet enum_constant_type();

src/util/format_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Author: Daniel Kroening, [email protected]
77
\*******************************************************************/
88

99
#include "format_type.h"
10+
#include "c_types.h"
1011
#include "format_expr.h"
1112
#include "pointer_expr.h"
12-
#include "std_types.h"
1313

1414
#include <ostream>
1515

src/util/std_types.h

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,100 +1078,6 @@ inline bool can_cast_type<bitvector_typet>(const typet &type)
10781078
type.id() == ID_c_bool;
10791079
}
10801080

1081-
/// Type for C bit fields
1082-
/// These are both 'bitvector_typet' (they have a width)
1083-
/// and 'type_with_subtypet' (they have a subtype)
1084-
class c_bit_field_typet:public bitvector_typet
1085-
{
1086-
public:
1087-
explicit c_bit_field_typet(typet _subtype, std::size_t width)
1088-
: bitvector_typet(ID_c_bit_field, width)
1089-
{
1090-
subtype().swap(_subtype);
1091-
}
1092-
1093-
// These have a sub-type
1094-
};
1095-
1096-
/// Check whether a reference to a typet is a \ref c_bit_field_typet.
1097-
/// \param type: Source type.
1098-
/// \return True if \p type is a \ref c_bit_field_typet.
1099-
template <>
1100-
inline bool can_cast_type<c_bit_field_typet>(const typet &type)
1101-
{
1102-
return type.id() == ID_c_bit_field;
1103-
}
1104-
1105-
/// \brief Cast a typet to a \ref c_bit_field_typet
1106-
///
1107-
/// This is an unchecked conversion. \a type must be known to be \ref
1108-
/// c_bit_field_typet. Will fail with a precondition violation if type
1109-
/// doesn't match.
1110-
///
1111-
/// \param type: Source type.
1112-
/// \return Object of type \ref c_bit_field_typet.
1113-
inline const c_bit_field_typet &to_c_bit_field_type(const typet &type)
1114-
{
1115-
PRECONDITION(can_cast_type<c_bit_field_typet>(type));
1116-
return static_cast<const c_bit_field_typet &>(type);
1117-
}
1118-
1119-
/// \copydoc to_c_bit_field_type(const typet &type)
1120-
inline c_bit_field_typet &to_c_bit_field_type(typet &type)
1121-
{
1122-
PRECONDITION(can_cast_type<c_bit_field_typet>(type));
1123-
return static_cast<c_bit_field_typet &>(type);
1124-
}
1125-
1126-
/// The C/C++ Booleans
1127-
class c_bool_typet:public bitvector_typet
1128-
{
1129-
public:
1130-
explicit c_bool_typet(std::size_t width):
1131-
bitvector_typet(ID_c_bool, width)
1132-
{
1133-
}
1134-
1135-
static void check(
1136-
const typet &type,
1137-
const validation_modet vm = validation_modet::INVARIANT)
1138-
{
1139-
DATA_CHECK(vm, !type.get(ID_width).empty(), "C bool type must have width");
1140-
}
1141-
};
1142-
1143-
/// Check whether a reference to a typet is a \ref c_bool_typet.
1144-
/// \param type: Source type.
1145-
/// \return True if \p type is a \ref c_bool_typet.
1146-
template <>
1147-
inline bool can_cast_type<c_bool_typet>(const typet &type)
1148-
{
1149-
return type.id() == ID_c_bool;
1150-
}
1151-
1152-
/// \brief Cast a typet to a \ref c_bool_typet
1153-
///
1154-
/// This is an unchecked conversion. \a type must be known to be \ref
1155-
/// c_bool_typet. Will fail with a precondition violation if type
1156-
/// doesn't match.
1157-
///
1158-
/// \param type: Source type.
1159-
/// \return Object of type \ref c_bool_typet.
1160-
inline const c_bool_typet &to_c_bool_type(const typet &type)
1161-
{
1162-
PRECONDITION(can_cast_type<c_bool_typet>(type));
1163-
c_bool_typet::check(type);
1164-
return static_cast<const c_bool_typet &>(type);
1165-
}
1166-
1167-
/// \copydoc to_c_bool_type(const typet &)
1168-
inline c_bool_typet &to_c_bool_type(typet &type)
1169-
{
1170-
PRECONDITION(can_cast_type<c_bool_typet>(type));
1171-
c_bool_typet::check(type);
1172-
return static_cast<c_bool_typet &>(type);
1173-
}
1174-
11751081
/// String type
11761082
///
11771083
/// Represents string constants, such as `@class_identifier`.

src/util/validate_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Author: Daniel Poetzl
1212
#include <iostream>
1313
#endif
1414

15+
#include "c_types.h"
1516
#include "namespace.h"
1617
#include "pointer_expr.h"
17-
#include "type.h"
1818
#include "validate.h"
1919
#include "validate_helpers.h"
2020

0 commit comments

Comments
 (0)