Skip to content

Commit af0761c

Browse files
danpoePetr Bauch
authored and
Petr Bauch
committed
Add functions to validate types
1 parent dd1664b commit af0761c

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

src/util/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ SRC = arith_tools.cpp \
9797
union_find_replace.cpp \
9898
unwrap_nested_exception.cpp \
9999
validate_expressions.cpp \
100+
validate_types.cpp \
100101
version.cpp \
101102
xml.cpp \
102103
xml_expr.cpp \

src/util/validate_types.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*******************************************************************\
2+
3+
Module: Validate types
4+
5+
Author: Daniel Poetzl
6+
7+
\*******************************************************************/
8+
9+
#include "validate_types.h"
10+
11+
#ifdef REPORT_UNIMPLEMENTED_TYPE_CHECKS
12+
#include <iostream>
13+
#endif
14+
15+
#include "namespace.h"
16+
#include "std_types.h"
17+
#include "type.h"
18+
#include "validate.h"
19+
20+
#define CALL_ON_TYPE(type_type) \
21+
C<type_type>()(type, std::forward<Args>(args)...)
22+
23+
template <template <typename> class C, typename... Args>
24+
void call_on_type(const typet &type, Args &&... args)
25+
{
26+
if(type.id() == ID_signedbv)
27+
{
28+
CALL_ON_TYPE(signedbv_typet);
29+
}
30+
else if(type.id() == ID_unsignedbv)
31+
{
32+
CALL_ON_TYPE(unsignedbv_typet);
33+
}
34+
else
35+
{
36+
#ifdef REPORT_UNIMPLEMENTED_TYPE_CHECKS
37+
std::cerr << "Unimplemented well-formedness check for type with id: "
38+
<< type.id_string() << std::endl;
39+
#endif
40+
41+
CALL_ON_TYPE(typet);
42+
}
43+
}
44+
45+
/// Check that the given type is well-formed (shallow checks only, i.e.,
46+
/// subtypes are not checked)
47+
///
48+
/// The function casts the given type to its concrete subtype (as determined by
49+
/// the id() field) and then calls its check() method.
50+
///
51+
/// The validation mode indicates whether well-formedness check failures are
52+
/// reported via DATA_INVARIANT violations or exceptions.
53+
void check_type_pick(const typet &type, const validation_modet vm)
54+
{
55+
call_on_type<call_checkt>(type, vm);
56+
}
57+
58+
/// Check that the given type is well-formed, assuming that its subtypes have
59+
/// already been checked for well-formedness.
60+
///
61+
/// The function casts the given type to its concrete subtype (as determined by
62+
/// the id() field) and then calls its validate() method.
63+
///
64+
/// The validation mode indicates whether well-formedness check failures are
65+
/// reported via DATA_INVARIANT violations or exceptions.
66+
void validate_type_pick(
67+
const typet &type,
68+
const namespacet &ns,
69+
const validation_modet vm)
70+
{
71+
call_on_type<call_validatet>(type, ns, vm);
72+
}
73+
74+
/// Check that the given type is well-formed (full check, including checks of
75+
/// subtypes)
76+
///
77+
/// The function casts the given type to its concrete subtype (as determined by
78+
/// the id() field) and then calls its validate_full() method.
79+
///
80+
/// The validation mode indicates whether well-formedness check failures are
81+
/// reported via DATA_INVARIANT violations or exceptions.
82+
void validate_type_full_pick(
83+
const typet &type,
84+
const namespacet &ns,
85+
const validation_modet vm)
86+
{
87+
call_on_type<call_validate_fullt>(type, ns, vm);
88+
}

src/util/validate_types.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************\
2+
3+
Module: Validate types
4+
5+
Author: Daniel Poetzl
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_UTIL_VALIDATE_TYPES_H
10+
#define CPROVER_UTIL_VALIDATE_TYPES_H
11+
12+
class typet;
13+
class namespacet;
14+
enum class validation_modet;
15+
16+
void check_type_pick(const typet &type, const validation_modet vm);
17+
18+
void validate_type_pick(
19+
const typet &type,
20+
const namespacet &ns,
21+
const validation_modet vm);
22+
23+
void validate_type_full_pick(
24+
const typet &type,
25+
const namespacet &ns,
26+
const validation_modet vm);
27+
28+
#endif /* CPROVER_UTIL_VALIDATE_TYPES_H */

0 commit comments

Comments
 (0)