Skip to content

Commit 02a53f7

Browse files
danpoePetr Bauch
authored and
Petr Bauch
committed
Add functions to validate statements
1 parent af0761c commit 02a53f7

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

src/util/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ SRC = arith_tools.cpp \
9696
union_find.cpp \
9797
union_find_replace.cpp \
9898
unwrap_nested_exception.cpp \
99+
validate_code.cpp \
99100
validate_expressions.cpp \
100101
validate_types.cpp \
101102
version.cpp \

src/util/validate_code.cpp

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

src/util/validate_code.h

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

0 commit comments

Comments
 (0)