CBMC
refined_string_type.h
Go to the documentation of this file.
1 /********************************************************************\
2 
3 Module: Type for string expressions used by the string solver.
4  These string expressions contain a field `length`, of type
5  `index_type`, a field `content` of type `content_type`.
6  This module also defines functions to recognise the C and java
7  string types.
8 
9 Author: Romain Brenguier, romain.brenguier@diffblue.com
10 
11 \*******************************************************************/
12 
18 
19 #ifndef CPROVER_UTIL_REFINED_STRING_TYPE_H
20 #define CPROVER_UTIL_REFINED_STRING_TYPE_H
21 
22 #include "cprover_prefix.h"
23 #include "std_types.h"
24 
25 class pointer_typet;
26 
27 // Internal type used for string refinement
29 {
30 public:
32  const typet &index_type,
33  const pointer_typet &content_type);
34 
35  // Type for the content (list of characters) of a string
37  {
38  PRECONDITION(components().size()==2);
39  return to_array_type(components()[1].type());
40  }
41 
42  const typet &get_char_type() const
43  {
44  return get_content_type().element_type();
45  }
46 
47  const typet &get_index_type() const
48  {
49  PRECONDITION(components().size()==2);
50  return components()[0].type();
51  }
52 };
53 
54 inline bool is_refined_string_type(const typet &type)
55 {
56  return
57  type.id()==ID_struct &&
58  to_struct_type(type).get_tag()==CPROVER_PREFIX"refined_string_type";
59 }
60 
62  const typet &type)
63 {
65  return static_cast<const refined_string_typet &>(type);
66 }
67 
68 #endif
Arrays with given size.
Definition: std_types.h:807
const typet & element_type() const
The type of the elements of the array.
Definition: std_types.h:827
const irep_idt & id() const
Definition: irep.h:384
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
Definition: pointer_expr.h:24
const typet & get_char_type() const
const typet & get_index_type() const
const array_typet & get_content_type() const
refined_string_typet(const typet &index_type, const pointer_typet &content_type)
Structure type, corresponds to C style structs.
Definition: std_types.h:231
irep_idt get_tag() const
Definition: std_types.h:168
const componentst & components() const
Definition: std_types.h:147
The type of an expression, extends irept.
Definition: type.h:29
#define CPROVER_PREFIX
bool is_refined_string_type(const typet &type)
const refined_string_typet & to_refined_string_type(const typet &type)
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
Pre-defined types.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
Definition: std_types.h:308
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Definition: std_types.h:888