|
12 | 12 | #include "c_types.h"
|
13 | 13 | #include "std_expr.h"
|
14 | 14 |
|
| 15 | +static array_typet make_type(const irep_idt &value) |
| 16 | +{ |
| 17 | + exprt size_expr = from_integer(value.size() + 1, c_index_type()); |
| 18 | + return array_typet(char_type(), size_expr); |
| 19 | +} |
| 20 | + |
15 | 21 | string_constantt::string_constantt(const irep_idt &_value)
|
16 |
| - : nullary_exprt(ID_string_constant, typet()) |
| 22 | + : nullary_exprt(ID_string_constant, make_type(_value)) |
17 | 23 | {
|
18 |
| - set_value(_value); |
| 24 | + value(_value); |
19 | 25 | }
|
20 | 26 |
|
21 |
| -void string_constantt::set_value(const irep_idt &value) |
| 27 | +void string_constantt::value(const irep_idt &_value) |
22 | 28 | {
|
23 |
| - exprt size_expr = from_integer(value.size() + 1, c_index_type()); |
24 |
| - type()=array_typet(char_type(), size_expr); |
25 |
| - set(ID_value, value); |
| 29 | + exprt::type() = make_type(_value); |
| 30 | + set(ID_value, _value); |
| 31 | +} |
| 32 | + |
| 33 | +const array_typet &string_constantt::type() const |
| 34 | +{ |
| 35 | + return to_array_type(exprt::type()); |
| 36 | +} |
| 37 | + |
| 38 | +array_typet &string_constantt::type() |
| 39 | +{ |
| 40 | + return to_array_type(exprt::type()); |
26 | 41 | }
|
27 | 42 |
|
28 | 43 | /// convert string into array constant
|
29 | 44 | array_exprt string_constantt::to_array_expr() const
|
30 | 45 | {
|
31 | 46 | const std::string &str=get_string(ID_value);
|
32 | 47 | std::size_t string_size=str.size()+1; // we add the zero
|
33 |
| - const typet &char_type = to_array_type(type()).element_type(); |
| 48 | + const typet &char_type = string_constantt::char_type(); |
34 | 49 | bool char_is_unsigned=char_type.id()==ID_unsignedbv;
|
35 | 50 |
|
36 | 51 | exprt size = from_integer(string_size, c_index_type());
|
|
0 commit comments