Skip to content

Commit ced655b

Browse files
author
Daniel Kroening
authored
Merge pull request #3168 from diffblue/remove_from_array_expr
clean up string_constantt
2 parents e859483 + 4ea9151 commit ced655b

File tree

1 file changed

+4
-48
lines changed

1 file changed

+4
-48
lines changed

src/util/string_constant.cpp

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -52,56 +52,12 @@ array_exprt string_constantt::to_array_expr() const
5252
int ch=i==string_size-1?0:str[i];
5353

5454
if(char_is_unsigned)
55-
ch=(unsigned char)ch;
55+
ch = (unsigned char)ch;
56+
else
57+
ch = (signed char)ch;
5658

57-
exprt &op=*it;
58-
59-
op=from_integer(ch, char_type);
60-
61-
if(ch>=32 && ch<=126)
62-
{
63-
std::string ch_str="'";
64-
if(ch=='\'' || ch=='\\')
65-
ch_str+='\\';
66-
ch_str+=static_cast<char>(ch);
67-
ch_str+="'";
68-
}
59+
*it = from_integer(ch, char_type);
6960
}
7061

7162
return dest;
7263
}
73-
74-
/// convert array constant into string
75-
/// \return true on error
76-
bool string_constantt::from_array_expr(const array_exprt &src)
77-
{
78-
id(ID_string_constant);
79-
type()=src.type();
80-
81-
const typet &subtype = to_array_type(type()).subtype();
82-
83-
// check subtype
84-
if(subtype!=signed_char_type() &&
85-
subtype!=unsigned_char_type())
86-
return true;
87-
88-
std::string value;
89-
90-
forall_operands(it, src)
91-
{
92-
mp_integer int_value=0;
93-
if(to_integer(*it, int_value))
94-
return true;
95-
unsigned unsigned_value=integer2unsigned(int_value);
96-
value+=static_cast<char>(unsigned_value);
97-
}
98-
99-
// Drop the implicit zero at the end.
100-
// Not clear what the semantics should be if it's not there.
101-
if(!value.empty() && value[value.size()-1]==0)
102-
value.resize(value.size()-1);
103-
104-
set_value(value);
105-
106-
return false;
107-
}

0 commit comments

Comments
 (0)