CBMC
string_constant.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #ifndef CPROVER_UTIL_STRING_CONSTANT_H
10 #define CPROVER_UTIL_STRING_CONSTANT_H
11 
12 #include "std_expr.h"
13 
15 {
16 public:
17  explicit string_constantt(const irep_idt &);
18 
19  DEPRECATED(SINCE(2023, 10, 31, "use value(...)"))
20  void set_value(const irep_idt &_value)
21  {
22  value(_value);
23  }
24 
25  void value(const irep_idt &);
26 
27  DEPRECATED(SINCE(2023, 10, 31, "use value()"))
28  const irep_idt &get_value() const
29  {
30  return value();
31  }
32 
33  const irep_idt &value() const
34  {
35  return get(ID_value);
36  }
37 
38  array_exprt to_array_expr() const;
39 
40  const typet &char_type() const
41  {
42  return type().element_type();
43  }
44 
45  const array_typet &type() const;
46  array_typet &type();
47 };
48 
49 template <>
50 inline bool can_cast_expr<string_constantt>(const exprt &base)
51 {
52  return base.id() == ID_string_constant;
53 }
54 
55 inline void validate_expr(const string_constantt &expr)
56 {
57  validate_operands(expr, 0, "String constants must not have operands");
58 }
59 
60 inline const string_constantt &to_string_constant(const exprt &expr)
61 {
62  PRECONDITION(expr.id() == ID_string_constant);
63  return static_cast<const string_constantt &>(expr);
64 }
65 
66 inline const string_constantt &to_string_constant(const typet &type)
67 {
68  return to_string_constant((const exprt &)type);
69 }
70 
72 {
73  PRECONDITION(expr.id() == ID_string_constant);
74  return static_cast<string_constantt &>(expr);
75 }
76 
78 {
79  return to_string_constant((exprt &)type);
80 }
81 
82 #endif // CPROVER_ANSI_C_STRING_CONSTANT_H
Array constructor from list of elements.
Definition: std_expr.h:1616
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
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
const irep_idt & get(const irep_idt &name) const
Definition: irep.cpp:44
const irep_idt & id() const
Definition: irep.h:384
An expression without operands.
Definition: std_expr.h:22
const irep_idt & value() const
const array_typet & type() const
const irep_idt & get_value() const
void set_value(const irep_idt &_value)
array_exprt to_array_expr() const
convert string into array constant
string_constantt(const irep_idt &)
const typet & char_type() const
The type of an expression, extends irept.
Definition: type.h:29
#define SINCE(year, month, day, msg)
Definition: deprecate.h:26
#define DEPRECATED(msg)
Definition: deprecate.h:23
void validate_operands(const exprt &value, exprt::operandst::size_type number, const char *message, bool allow_more=false)
Definition: expr_cast.h:250
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
API to expression classes.
const string_constantt & to_string_constant(const exprt &expr)
void validate_expr(const string_constantt &expr)
bool can_cast_expr< string_constantt >(const exprt &base)