|
| 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 | +} |
0 commit comments