cprover
validate_code.cpp
Go to the documentation of this file.
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 #include "validate_helpers.h"
19 
20 #define CALL_ON_CODE(code_type) \
21  C<codet, code_type>()(code, std::forward<Args>(args)...)
22 
23 template <template <typename, typename> class C, typename... Args>
24 void call_on_code(const codet &code, Args &&... args)
25 {
26  if(code.get_statement() == ID_assign)
27  {
29  }
30  else if(code.get_statement() == ID_decl)
31  {
33  }
34  else if(code.get_statement() == ID_dead)
35  {
37  }
38  else if(code.get_statement() == ID_function_call)
39  {
41  }
42  else if(code.get_statement() == ID_return)
43  {
45  }
46  else
47  {
48 #ifdef REPORT_UNIMPLEMENTED_CODE_CHECKS
49  std::cerr << "Unimplemented well-formedness check for code statement with "
50  "id: "
51  << code.get_statement().id_string() << std::endl;
52 #endif
53 
55  }
56 }
57 
66 void check_code(const codet &code, const validation_modet vm)
67 {
68  call_on_code<call_checkt>(code, vm);
69 }
70 
81  const codet &code,
82  const namespacet &ns,
83  const validation_modet vm)
84 {
85  call_on_code<call_validatet>(code, ns, vm);
86 }
87 
97  const codet &code,
98  const namespacet &ns,
99  const validation_modet vm)
100 {
101  call_on_code<call_validate_fullt>(code, ns, vm);
102 }
validate_code
void validate_code(const codet &code, const namespacet &ns, const validation_modet vm)
Check that the given code statement is well-formed, assuming that all its enclosed statements,...
Definition: validate_code.cpp:80
code_declt
A codet representing the declaration of a local variable.
Definition: std_code.h:352
call_on_code
void call_on_code(const codet &code, Args &&... args)
Definition: validate_code.cpp:24
namespace.h
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:93
code_function_callt
codet representation of a function call statement.
Definition: std_code.h:1036
validate_full_code
void validate_full_code(const codet &code, const namespacet &ns, const validation_modet vm)
Check that the given code statement is well-formed (full check, including checks of all subexpression...
Definition: validate_code.cpp:96
validation_modet
validation_modet
Definition: validation_mode.h:12
code_deadt
A codet representing the removal of a local variable going out of scope.
Definition: std_code.h:424
std_code.h
code_returnt
codet representation of a "return from a function" statement.
Definition: std_code.h:1191
check_code
void check_code(const codet &code, const validation_modet vm)
Check that the given code statement is well-formed (shallow checks only, i.e., enclosed statements,...
Definition: validate_code.cpp:66
validate_helpers.h
CALL_ON_CODE
#define CALL_ON_CODE(code_type)
Definition: validate_code.cpp:20
validate.h
validate_code.h
code_assignt
A codet representing an assignment in the program.
Definition: std_code.h:256
codet::get_statement
const irep_idt & get_statement() const
Definition: std_code.h:56
codet
Data structure for representing an arbitrary statement in a program.
Definition: std_code.h:34