Skip to content

clean up string_constantt #3168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 4 additions & 48 deletions src/util/string_constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,56 +52,12 @@ array_exprt string_constantt::to_array_expr() const
int ch=i==string_size-1?0:str[i];

if(char_is_unsigned)
ch=(unsigned char)ch;
ch = (unsigned char)ch;
else
ch = (signed char)ch;

exprt &op=*it;

op=from_integer(ch, char_type);

if(ch>=32 && ch<=126)
{
std::string ch_str="'";
if(ch=='\'' || ch=='\\')
ch_str+='\\';
ch_str+=static_cast<char>(ch);
ch_str+="'";
}
*it = from_integer(ch, char_type);
}

return dest;
}

/// convert array constant into string
/// \return true on error
bool string_constantt::from_array_expr(const array_exprt &src)
{
id(ID_string_constant);
type()=src.type();

const typet &subtype = to_array_type(type()).subtype();

// check subtype
if(subtype!=signed_char_type() &&
subtype!=unsigned_char_type())
return true;

std::string value;

forall_operands(it, src)
{
mp_integer int_value=0;
if(to_integer(*it, int_value))
return true;
unsigned unsigned_value=integer2unsigned(int_value);
value+=static_cast<char>(unsigned_value);
}

// Drop the implicit zero at the end.
// Not clear what the semantics should be if it's not there.
if(!value.empty() && value[value.size()-1]==0)
value.resize(value.size()-1);

set_value(value);

return false;
}