Skip to content

Commit

Permalink
Merge pull request #7999 from NlightNFotis/cleanup_string_constantt
Browse files Browse the repository at this point in the history
Refactor `string_constantt::get_value` and `string_constantt::set_value` call sites.
  • Loading branch information
kroening authored Dec 15, 2023
2 parents 032a284 + db61a6a commit ab2a26c
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/analyses/custom_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ unsigned custom_bitvector_analysist::get_bit_nr(
else if(string_expr.id()==ID_index)
return get_bit_nr(to_index_expr(string_expr).array());
else if(string_expr.id()==ID_string_constant)
return bits.number(to_string_constant(string_expr).get_value());
return bits.number(to_string_constant(string_expr).value());
else
return bits.number("(unknown)");
}
Expand Down
6 changes: 3 additions & 3 deletions src/ansi-c/ansi_c_convert_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ void ansi_c_convert_typet::read_rec(const typet &type)
!type_with_subtypes.subtypes().empty() &&
type_with_subtypes.subtypes()[0].id() == ID_string_constant)
c_storage_spec.asm_label =
to_string_constant(type_with_subtypes.subtypes()[0]).get_value();
to_string_constant(type_with_subtypes.subtypes()[0]).value();
}
else if(
type.id() == ID_section && type.has_subtype() &&
to_type_with_subtype(type).subtype().id() == ID_string_constant)
{
c_storage_spec.section =
to_string_constant(to_type_with_subtype(type).subtype()).get_value();
to_string_constant(to_type_with_subtype(type).subtype()).value();
}
else if(type.id()==ID_const)
c_qualifiers.is_constant=true;
Expand Down Expand Up @@ -227,7 +227,7 @@ void ansi_c_convert_typet::read_rec(const typet &type)
to_type_with_subtype(type).subtype().id() == ID_string_constant)
{
c_storage_spec.alias =
to_string_constant(to_type_with_subtype(type).subtype()).get_value();
to_string_constant(to_type_with_subtype(type).subtype()).value();
}
else if(type.id()==ID_frontend_pointer)
{
Expand Down
8 changes: 3 additions & 5 deletions src/ansi-c/c_storage_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,19 @@ void c_storage_spect::read(const typet &type)
type.id() == ID_alias && type.has_subtype() &&
to_type_with_subtype(type).subtype().id() == ID_string_constant)
{
alias =
to_string_constant(to_type_with_subtype(type).subtype()).get_value();
alias = to_string_constant(to_type_with_subtype(type).subtype()).value();
}
else if(
type.id() == ID_asm && !to_type_with_subtypes(type).subtypes().empty() &&
to_type_with_subtypes(type).subtypes()[0].id() == ID_string_constant)
{
asm_label =
to_string_constant(to_type_with_subtypes(type).subtypes()[0]).get_value();
to_string_constant(to_type_with_subtypes(type).subtypes()[0]).value();
}
else if(
type.id() == ID_section && type.has_subtype() &&
to_type_with_subtype(type).subtype().id() == ID_string_constant)
{
section =
to_string_constant(to_type_with_subtype(type).subtype()).get_value();
section = to_string_constant(to_type_with_subtype(type).subtype()).value();
}
}
2 changes: 1 addition & 1 deletion src/ansi-c/c_typecheck_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void c_typecheck_baset::typecheck_code(codet &code)
error().source_location = code.find_source_location();
error() << "static assertion failed";
if(code.op1().id() == ID_string_constant)
error() << ": " << to_string_constant(code.op1()).get_value();
error() << ": " << to_string_constant(code.op1()).value();
error() << eom;
throw 0;
}
Expand Down
3 changes: 1 addition & 2 deletions src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3960,8 +3960,7 @@ std::string expr2ct::convert_with_precedence(
}

else if(src.id()==ID_string_constant)
return '"' + MetaString(id2string(to_string_constant(src).get_value())) +
'"';
return '"' + MetaString(id2string(to_string_constant(src).value())) + '"';

else if(src.id()==ID_struct)
return convert_struct(src, precedence);
Expand Down
4 changes: 2 additions & 2 deletions src/assembler/remove_asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void remove_asmt::process_instruction_gcc(
const code_asm_gcct &code,
goto_programt &dest)
{
const irep_idt &i_str = to_string_constant(code.asm_text()).get_value();
const irep_idt &i_str = to_string_constant(code.asm_text()).value();

std::istringstream str(id2string(i_str));
assembler_parser.clear();
Expand Down Expand Up @@ -396,7 +396,7 @@ void remove_asmt::process_instruction_msc(
const code_asmt &code,
goto_programt &dest)
{
const irep_idt &i_str = to_string_constant(code.op0()).get_value();
const irep_idt &i_str = to_string_constant(code.op0()).value();

std::istringstream str(id2string(i_str));
assembler_parser.clear();
Expand Down
3 changes: 1 addition & 2 deletions src/cpp/cpp_typecheck_static_assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ void cpp_typecheckt::convert(cpp_static_assertt &cpp_static_assert)
error().source_location=cpp_static_assert.source_location();
error() << "static assertion failed";
if(cpp_static_assert.op1().id()==ID_string_constant)
error() << ": "
<< to_string_constant(cpp_static_assert.op1()).get_value();
error() << ": " << to_string_constant(cpp_static_assert.op1()).value();
error() << eom;
throw 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cprover/axioms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void axiomst::object_size()
auto pointers_equal = same_object(a_it->address(), *b_it);
auto size_equal = equal_exprt(
*a_it,
from_integer(string_constant.get_value().size() + 1, a_it->type()));
from_integer(string_constant.value().size() + 1, a_it->type()));
auto implication = implies_exprt(pointers_equal, size_equal);
if(verbose)
std::cout << "OBJECT_SIZE2: " << format(implication) << '\n';
Expand Down
4 changes: 2 additions & 2 deletions src/goto-programs/goto_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ bool goto_convertt::get_string_constant(

if(index_op.id()==ID_string_constant)
{
value = to_string_constant(index_op).get_value();
value = to_string_constant(index_op).value();
return false;
}
else if(index_op.id()==ID_array)
Expand All @@ -1826,7 +1826,7 @@ bool goto_convertt::get_string_constant(

if(expr.id()==ID_string_constant)
{
value = to_string_constant(expr).get_value();
value = to_string_constant(expr).value();
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/goto-programs/string_abstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ bool string_abstractiont::build(const exprt &object, exprt &dest, bool write)
if(object.id()==ID_string_constant)
{
const std::string &str_value =
id2string(to_string_constant(object).get_value());
id2string(to_string_constant(object).value());
// make sure we handle the case of a string constant with string-terminating
// \0 in it
const std::size_t str_len =
Expand Down
4 changes: 2 additions & 2 deletions src/goto-programs/string_instrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void string_instrumentationt::do_format_string_read(
format_token_listt token_list = parse_format_string(id2string(
to_string_constant(
to_index_expr(to_address_of_expr(format_arg).object()).array())
.get_value()));
.value()));

std::size_t args=0;

Expand Down Expand Up @@ -472,7 +472,7 @@ void string_instrumentationt::do_format_string_write(
format_token_listt token_list = parse_format_string(id2string(
to_string_constant(
to_index_expr(to_address_of_expr(format_arg).object()).array())
.get_value()));
.value()));

std::size_t args=0;

Expand Down
2 changes: 1 addition & 1 deletion src/goto-symex/shadow_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void shadow_memoryt::symex_field_static_init_string_constant(

const typet &type = index_expr.array().type();
log.debug() << "Shadow memory: global memory "
<< id2string(to_string_constant(index_expr.array()).get_value())
<< id2string(to_string_constant(index_expr.array()).value())
<< " of type " << from_type(ns, "", type) << messaget::eom;

initialize_shadow_memory(
Expand Down
4 changes: 2 additions & 2 deletions src/goto-symex/symex_builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ static irep_idt get_string_argument_rec(const exprt &src)
index_expr.index().is_zero())
{
const exprt &fmt_str = index_expr.array();
return to_string_constant(fmt_str).get_value();
return to_string_constant(fmt_str).value();
}
}
else if(object.id() == ID_string_constant)
{
return to_string_constant(object).get_value();
return to_string_constant(object).value();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/jsil/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ proc_ident_expr: proc_ident
| TOK_STRING
{
symbol_exprt s = symbol_exprt::typeless(
to_string_constant(parser_stack($$)).get_value());
to_string_constant(parser_stack($$)).value());
parser_stack($$).swap(s);
}
;
Expand Down Expand Up @@ -429,7 +429,7 @@ literal: TOK_IDENTIFIER
| TOK_STRING
{
constant_exprt c(to_string_constant(parser_stack($$))
.get_value(), string_typet());
.value(), string_typet());
parser_stack($$).swap(c);
}
| TOK_BUILTIN_LOC
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/strings/string_constraint_generator_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ string_constraint_generatort::add_axioms_for_char_literal(
{
const string_constantt &s = to_string_constant(
to_binary_expr(to_unary_expr(to_unary_expr(arg).op()).op()).op0());
const std::string &sval = id2string(s.get_value());
const std::string &sval = id2string(s.value());
CHECK_RETURN(sval.size() == 1);
return {from_integer(unsigned(sval[0]), arg.type()), {}};
}
Expand Down
6 changes: 3 additions & 3 deletions src/statement-list/statement_list_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static std::string find_version(const exprt &root)
if(op.get(ID_statement_list_type) == ID_statement_list_version)
{
const string_constantt &constant{to_string_constant(op)};
return id2string(constant.get_value());
return id2string(constant.value());
}
}
UNREACHABLE; // Root expression should always have a version
Expand Down Expand Up @@ -274,10 +274,10 @@ static void find_instructions(
code_token.add_to_operands(*op_it);
}

if(label.get_value() == ID_nil)
if(label.value() == ID_nil)
instruction.add_token(code_token);
else
instruction.add_token(code_labelt{label.get_value(), code_token});
instruction.add_token(code_labelt{label.value(), code_token});

network.add_instruction(instruction);
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/format_constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ std::string format_constantt::operator()(const exprt &expr)
}
}
else if(expr.id()==ID_string_constant)
return id2string(to_string_constant(expr).get_value());
return id2string(to_string_constant(expr).value());

return "(format-constant failed: "+expr.id_string()+")";
}
2 changes: 1 addition & 1 deletion src/util/simplify_expr_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ simplify_exprt::simplify_index(const index_exprt &expr)
{
const auto i = numeric_cast<mp_integer>(index);

const std::string &value = id2string(to_string_constant(array).get_value());
const std::string &value = id2string(to_string_constant(array).value());

if(!i.has_value())
{
Expand Down
2 changes: 1 addition & 1 deletion src/util/simplify_expr_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ simplify_exprt::simplify_object_size(const object_size_exprt &expr)
{
typet type=expr.type();
return from_integer(
to_string_constant(op_object).get_value().size() + 1, type);
to_string_constant(op_object).value().size() + 1, type);
}
}

Expand Down

0 comments on commit ab2a26c

Please sign in to comment.