CBMC
validate_types.cpp
Go to the documentation of this file.
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 "bitvector_types.h"
16 #include "c_types.h"
17 #include "pointer_expr.h"
18 #include "validate_helpers.h"
19 
20 #define CALL_ON_TYPE(type_type) \
21  C<typet, type_type>()(type, std::forward<Args>(args)...)
22 
23 template <template <typename, typename> class C, typename... Args>
24 void call_on_type(const typet &type, Args &&... args)
25 {
26  if(type.id() == ID_bv)
27  {
29  }
30  else if(type.id() == ID_unsignedbv)
31  {
33  }
34  else if(type.id() == ID_signedbv)
35  {
37  }
38  else if(type.id() == ID_fixedbv)
39  {
41  }
42  else if(type.id() == ID_floatbv)
43  {
45  }
46  else if(type.id() == ID_pointer)
47  {
48  if(type.get_bool(ID_C_reference))
50  else
52  }
53  else if(type.id() == ID_c_bool)
54  {
56  }
57  else if(type.id() == ID_array)
58  {
60  }
61  else
62  {
63 #ifdef REPORT_UNIMPLEMENTED_TYPE_CHECKS
64  std::cerr << "Unimplemented well-formedness check for type with id: "
65  << type.id_string() << std::endl;
66 #endif
67 
69  }
70 }
71 
80 void check_type(const typet &type, const validation_modet vm)
81 {
82  call_on_type<call_checkt>(type, vm);
83 }
84 
94  const typet &type,
95  const namespacet &ns,
96  const validation_modet vm)
97 {
98  call_on_type<call_validatet>(type, ns, vm);
99 }
100 
110  const typet &type,
111  const namespacet &ns,
112  const validation_modet vm)
113 {
114  call_on_type<call_validate_fullt>(type, ns, vm);
115 }
CALL_ON_TYPE
#define CALL_ON_TYPE(type_type)
Definition: validate_types.cpp:20
validate_full_type
void validate_full_type(const typet &type, const namespacet &ns, const validation_modet vm)
Check that the given type is well-formed (full check, including checks of subtypes)
Definition: validate_types.cpp:109
reference_typet
The reference type.
Definition: pointer_expr.h:106
typet
The type of an expression, extends irept.
Definition: type.h:28
floatbv_typet
Fixed-width bit-vector with IEEE floating-point interpretation.
Definition: bitvector_types.h:321
unsignedbv_typet
Fixed-width bit-vector with unsigned binary interpretation.
Definition: bitvector_types.h:158
c_bool_typet
The C/C++ Booleans.
Definition: c_types.h:74
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
call_on_type
void call_on_type(const typet &type, Args &&... args)
Definition: validate_types.cpp:24
check_type
void check_type(const typet &type, const validation_modet vm)
Check that the given type is well-formed (shallow checks only, i.e., subtypes are not checked)
Definition: validate_types.cpp:80
bitvector_types.h
signedbv_typet
Fixed-width bit-vector with two's complement interpretation.
Definition: bitvector_types.h:207
pointer_expr.h
irept::id_string
const std::string & id_string() const
Definition: irep.h:399
validation_modet
validation_modet
Definition: validation_mode.h:12
irept::id
const irep_idt & id() const
Definition: irep.h:396
fixedbv_typet
Fixed-width bit-vector with signed fixed-point interpretation.
Definition: bitvector_types.h:260
array_typet
Arrays with given size.
Definition: std_types.h:762
validate_type
void validate_type(const typet &type, const namespacet &ns, const validation_modet vm)
Check that the given type is well-formed, assuming that its subtypes have already been checked for we...
Definition: validate_types.cpp:93
validate_helpers.h
pointer_typet
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
Definition: pointer_expr.h:23
validate_types.h
c_types.h
irept::get_bool
bool get_bool(const irep_idt &name) const
Definition: irep.cpp:58
bv_typet
Fixed-width bit-vector without numerical interpretation.
Definition: bitvector_types.h:48