diff --git a/src/analyses/constant_propagator.cpp b/src/analyses/constant_propagator.cpp index 0af715a88bf..8223bab00c9 100644 --- a/src/analyses/constant_propagator.cpp +++ b/src/analyses/constant_propagator.cpp @@ -192,8 +192,7 @@ void constant_propagator_domaint::transform( } else if(from->is_function_call()) { - const auto &function_call = from->get_function_call(); - const exprt &function=function_call.function(); + const exprt &function = from->call_function(); if(function.id()==ID_symbol) { @@ -231,8 +230,8 @@ void constant_propagator_domaint::transform( const code_typet &code_type=to_code_type(symbol.type); const code_typet::parameterst ¶meters=code_type.parameters(); - const code_function_callt::argumentst &arguments= - function_call.arguments(); + const code_function_callt::argumentst &arguments = + from->call_arguments(); code_typet::parameterst::const_iterator p_it=parameters.begin(); for(const auto &arg : arguments) @@ -777,22 +776,11 @@ void constant_propagator_ait::replace( } else if(it->is_function_call()) { - auto call = it->get_function_call(); + constant_propagator_domaint::partial_evaluate( + d.values, it->call_function(), ns); - bool call_changed = false; - - if(!constant_propagator_domaint::partial_evaluate( - d.values, call.function(), ns)) - { - call_changed = true; - } - - for(auto &arg : call.arguments()) - if(!constant_propagator_domaint::partial_evaluate(d.values, arg, ns)) - call_changed = true; - - if(call_changed) - it->set_function_call(call); + for(auto &arg : it->call_arguments()) + constant_propagator_domaint::partial_evaluate(d.values, arg, ns); } else if(it->is_other()) { diff --git a/src/goto-programs/cfg.h b/src/goto-programs/cfg.h index 83247e9b9fa..94e9d488141 100644 --- a/src/goto-programs/cfg.h +++ b/src/goto-programs/cfg.h @@ -391,7 +391,7 @@ void cfg_baset::compute_edges_function_call( goto_programt::const_targett next_PC, entryt &entry) { - const exprt &function = instruction.get_function_call().function(); + const exprt &function = instruction.call_function(); if(function.id()!=ID_symbol) return; @@ -441,7 +441,7 @@ void procedure_local_cfg_baset::compute_edges_function_call( goto_programt::const_targett next_PC, typename cfg_baset::entryt &entry) { - const exprt &function = instruction.get_function_call().function(); + const exprt &function = instruction.call_function(); if(function.id()!=ID_symbol) return; diff --git a/src/goto-programs/goto_inline_class.cpp b/src/goto-programs/goto_inline_class.cpp index 880bca1f446..670888a6202 100644 --- a/src/goto-programs/goto_inline_class.cpp +++ b/src/goto-programs/goto_inline_class.cpp @@ -436,11 +436,9 @@ void goto_inlinet::get_call( { PRECONDITION(it->is_function_call()); - const code_function_callt &call = it->get_function_call(); - - lhs=call.lhs(); - function=call.function(); - arguments=call.arguments(); + lhs = it->call_lhs(); + function = it->call_function(); + arguments = it->call_arguments(); } /// Inline all of the given call locations. diff --git a/src/goto-programs/goto_program.cpp b/src/goto-programs/goto_program.cpp index 22b9059b4aa..000cc827785 100644 --- a/src/goto-programs/goto_program.cpp +++ b/src/goto-programs/goto_program.cpp @@ -329,14 +329,11 @@ std::list expressions_read( break; case FUNCTION_CALL: - { - const code_function_callt &function_call = instruction.get_function_call(); - for(const auto &argument : function_call.arguments()) + for(const auto &argument : instruction.call_arguments()) dest.push_back(argument); - if(function_call.lhs().is_not_nil()) - parse_lhs_read(function_call.lhs(), dest); + if(instruction.call_lhs().is_not_nil()) + parse_lhs_read(instruction.call_lhs(), dest); break; - } case ASSIGN: dest.push_back(instruction.assign_rhs()); @@ -371,12 +368,8 @@ std::list expressions_written( switch(instruction.type) { case FUNCTION_CALL: - { - const code_function_callt &function_call = - instruction.get_function_call(); - if(function_call.lhs().is_not_nil()) - dest.push_back(function_call.lhs()); - } + if(instruction.call_lhs().is_not_nil()) + dest.push_back(instruction.call_lhs()); break; case ASSIGN: @@ -999,35 +992,20 @@ void goto_programt::instructiont::transform( case FUNCTION_CALL: { - auto new_call = get_function_call(); - bool change = false; - - auto new_lhs = f(new_call.lhs()); + auto new_lhs = f(call_lhs()); if(new_lhs.has_value()) - { - new_call.lhs() = *new_lhs; - change = true; - } + call_lhs() = *new_lhs; - auto new_function = f(new_call.function()); - if(new_function.has_value()) - { - new_call.function() = *new_function; - change = true; - } + auto new_call_function = f(call_function()); + if(new_call_function.has_value()) + call_function() = *new_call_function; - for(auto &a : new_call.arguments()) + for(auto &a : call_arguments()) { auto new_a = f(a); if(new_a.has_value()) - { a = *new_a; - change = true; - } } - - if(change) - set_function_call(new_call); } break; @@ -1082,13 +1060,10 @@ void goto_programt::instructiont::apply( break; case FUNCTION_CALL: - { - const auto &call = get_function_call(); - f(call.lhs()); - for(auto &a : call.arguments()) + f(call_lhs()); + for(auto &a : call_arguments()) f(a); - } - break; + break; case GOTO: case ASSUME: diff --git a/src/goto-programs/goto_program.h b/src/goto-programs/goto_program.h index 81168c0c823..e6661ef0a13 100644 --- a/src/goto-programs/goto_program.h +++ b/src/goto-programs/goto_program.h @@ -344,18 +344,74 @@ class goto_programt } /// Get the function call for FUNCTION_CALL +#if 1 + DEPRECATED(SINCE( + 2021, + 2, + 24, + "Use call_function(), call_lhs(), call_arguments() instead")) const code_function_callt &get_function_call() const { PRECONDITION(is_function_call()); return to_code_function_call(code); } +#endif + + /// Get the function that is called for FUNCTION_CALL + const exprt &call_function() const + { + PRECONDITION(is_function_call()); + return to_code_function_call(code).function(); + } + + /// Get the function that is called for FUNCTION_CALL + exprt &call_function() + { + PRECONDITION(is_function_call()); + return to_code_function_call(code).function(); + } + + /// Get the lhs of a FUNCTION_CALL (may be nil) + const exprt &call_lhs() const + { + PRECONDITION(is_function_call()); + return to_code_function_call(code).lhs(); + } + + /// Get the lhs of a FUNCTION_CALL (may be nil) + exprt &call_lhs() + { + PRECONDITION(is_function_call()); + return to_code_function_call(code).lhs(); + } + + /// Get the arguments of a FUNCTION_CALL + const exprt::operandst &call_arguments() const + { + PRECONDITION(is_function_call()); + return to_code_function_call(code).arguments(); + } + + /// Get the arguments of a FUNCTION_CALL + exprt::operandst &call_arguments() + { + PRECONDITION(is_function_call()); + return to_code_function_call(code).arguments(); + } /// Set the function call for FUNCTION_CALL +#if 1 + DEPRECATED(SINCE( + 2021, + 2, + 24, + "Use call_function(), call_lhs(), call_arguments() instead")) void set_function_call(code_function_callt c) { PRECONDITION(is_function_call()); code = std::move(c); } +#endif /// Get the statement for OTHER const codet &get_other() const diff --git a/src/goto-programs/instrument_preconditions.cpp b/src/goto-programs/instrument_preconditions.cpp index a6799b7aadd..a6cd919941c 100644 --- a/src/goto-programs/instrument_preconditions.cpp +++ b/src/goto-programs/instrument_preconditions.cpp @@ -64,14 +64,14 @@ void remove_preconditions(goto_programt &goto_program) } replace_symbolt actuals_replace_map( - const code_function_callt &call, + const goto_programt::instructiont &call, const namespacet &ns) { - PRECONDITION(call.function().id()==ID_symbol); - const symbolt &s=ns.lookup(to_symbol_expr(call.function())); + PRECONDITION(call.call_function().id() == ID_symbol); + const symbolt &s = ns.lookup(to_symbol_expr(call.call_function())); const auto &code_type=to_code_type(s.type); const auto ¶meters=code_type.parameters(); - const auto &arguments=call.arguments(); + const auto &arguments = call.call_arguments(); replace_symbolt result; std::size_t count=0; @@ -102,17 +102,16 @@ void instrument_preconditions( if(it->is_function_call()) { // does the function we call have preconditions? - const auto &call = it->get_function_call(); + const auto &called_function = it->call_function(); - if(call.function().id()==ID_symbol) + if(called_function.id() == ID_symbol) { - auto preconditions= - get_preconditions(to_symbol_expr(call.function()), - goto_model.goto_functions); + auto preconditions = get_preconditions( + to_symbol_expr(called_function), goto_model.goto_functions); source_locationt source_location=it->source_location; - replace_symbolt r=actuals_replace_map(call, ns); + replace_symbolt r = actuals_replace_map(*it, ns); // add before the call, with location of the call for(const auto &p : preconditions) diff --git a/src/goto-programs/interpreter.cpp b/src/goto-programs/interpreter.cpp index cf76fe390d5..dbeeadc5fa9 100644 --- a/src/goto-programs/interpreter.cpp +++ b/src/goto-programs/interpreter.cpp @@ -739,10 +739,12 @@ void interpretert::execute_assert() void interpretert::execute_function_call() { - const code_function_callt &function_call = pc->get_function_call(); + const auto &call_lhs = pc->call_lhs(); + const auto &call_function = pc->call_function(); + const auto &call_arguments = pc->call_arguments(); // function to be called - mp_integer address=evaluate_address(function_call.function()); + mp_integer address = evaluate_address(call_function); if(address==0) throw "function call to NULL"; @@ -767,19 +769,18 @@ void interpretert::execute_function_call() // return value mp_integer return_value_address; - if(function_call.lhs().is_not_nil()) - return_value_address= - evaluate_address(function_call.lhs()); + if(call_lhs.is_not_nil()) + return_value_address = evaluate_address(call_lhs); else return_value_address=0; // values of the arguments std::vector argument_values; - argument_values.resize(function_call.arguments().size()); + argument_values.resize(call_arguments.size()); - for(std::size_t i=0; iis_function_call() && can_cast_expr( - it->get_function_call().function()); + return it->is_function_call() && + can_cast_expr(it->call_function()); }, [&](goto_programt::targett &it) { - auto const &function_call = it->get_function_call(); auto const &function_pointer_dereference = - to_dereference_expr(function_call.function()); - auto const &source_location = function_call.source_location(); + to_dereference_expr(it->call_function()); + auto const &source_location = it->source_location; auto const &goto_function_symbol_mode = goto_model.symbol_table.lookup_ref(goto_function.first).mode; @@ -43,7 +42,7 @@ void label_function_pointer_call_sites(goto_modelt &goto_model) function_call_site_symbol.pretty_name = call_site_symbol_name; function_call_site_symbol.type = function_pointer_dereference.pointer().type(); - function_call_site_symbol.location = function_call.source_location(); + function_call_site_symbol.location = source_location; function_call_site_symbol.is_lvalue = true; function_call_site_symbol.mode = goto_function_symbol_mode; return function_call_site_symbol; diff --git a/src/goto-programs/parameter_assignments.cpp b/src/goto-programs/parameter_assignments.cpp index dbb3128b20e..ff2656e7ba5 100644 --- a/src/goto-programs/parameter_assignments.cpp +++ b/src/goto-programs/parameter_assignments.cpp @@ -44,14 +44,12 @@ void parameter_assignmentst::do_function_calls( { if(i_it->is_function_call()) { - const code_function_callt &function_call = i_it->get_function_call(); - // add x=y for f(y) where x is the parameter - PRECONDITION(function_call.function().id() == ID_symbol); + PRECONDITION(i_it->call_function().id() == ID_symbol); - const irep_idt &identifier= - to_symbol_expr(function_call.function()).get_identifier(); + const irep_idt &identifier = + to_symbol_expr(i_it->call_function()).get_identifier(); // see if we have it const namespacet ns(symbol_table); @@ -67,12 +65,12 @@ void parameter_assignmentst::do_function_calls( if(p_identifier.empty()) continue; - if(nrcall_arguments().size()) { const symbolt &lhs_symbol=ns.lookup(p_identifier); symbol_exprt lhs=lhs_symbol.symbol_expr(); exprt rhs = typecast_exprt::conditional_cast( - function_call.arguments()[nr], lhs.type()); + i_it->call_arguments()[nr], lhs.type()); tmp.add(goto_programt::make_assignment( code_assignt(lhs, rhs), i_it->source_location)); } diff --git a/src/goto-programs/remove_calls_no_body.cpp b/src/goto-programs/remove_calls_no_body.cpp index 59c47013039..1445f7ccd0a 100644 --- a/src/goto-programs/remove_calls_no_body.cpp +++ b/src/goto-programs/remove_calls_no_body.cpp @@ -69,8 +69,7 @@ bool remove_calls_no_bodyt::is_opaque_function_call( if(!target->is_function_call()) return false; - const code_function_callt &cfc = target->get_function_call(); - const exprt &f = cfc.function(); + const exprt &f = target->call_function(); if(f.id() != ID_symbol) return false; @@ -103,8 +102,8 @@ operator()(goto_programt &goto_program, const goto_functionst &goto_functions) { if(is_opaque_function_call(it, goto_functions)) { - const code_function_callt &cfc = it->get_function_call(); - remove_call_no_body(goto_program, it, cfc.lhs(), cfc.arguments()); + remove_call_no_body( + goto_program, it, it->call_lhs(), it->call_arguments()); } else { diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index 537ecc9b9da..d4093532382 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -270,9 +270,7 @@ void remove_function_pointerst::remove_function_pointer( const irep_idt &function_id, goto_programt::targett target) { - const code_function_callt &code = target->get_function_call(); - - const auto &function = to_dereference_expr(code.function()); + const auto &function = to_dereference_expr(target->call_function()); // this better have the right type code_typet call_type=to_code_type(function.type()); @@ -282,7 +280,7 @@ void remove_function_pointerst::remove_function_pointer( call_type.parameters().empty()) { call_type.remove_ellipsis(); - for(const auto &argument : code.arguments()) + for(const auto &argument : target->call_arguments()) { call_type.parameters().push_back(code_typet::parametert(argument.type())); } @@ -317,9 +315,7 @@ void remove_function_pointerst::remove_function_pointer( if(functions.size()==1) { - auto call = target->get_function_call(); - call.function() = *functions.cbegin(); - target->set_function_call(call); + target->call_function() = *functions.cbegin(); return; } } @@ -337,7 +333,7 @@ void remove_function_pointerst::remove_function_pointer( return; } - bool return_value_used=code.lhs().is_not_nil(); + bool return_value_used = target->call_lhs().is_not_nil(); // get all type-compatible functions // whose address is ever taken @@ -368,9 +364,7 @@ void remove_function_pointerst::remove_function_pointer( goto_programt::targett target, const functionst &functions) { - const code_function_callt &code = target->get_function_call(); - - const exprt &function = code.function(); + const exprt &function = target->call_function(); const exprt &pointer = to_dereference_expr(function).pointer(); // the final target is a skip @@ -386,8 +380,8 @@ void remove_function_pointerst::remove_function_pointer( for(const auto &fun : functions) { // call function - auto new_call = code; - new_call.function() = fun; + auto new_call = + code_function_callt(target->call_lhs(), fun, target->call_arguments()); // the signature of the function might not match precisely fix_argument_types(new_call); @@ -487,9 +481,7 @@ bool remove_function_pointerst::remove_function_pointers( Forall_goto_program_instructions(target, goto_program) if(target->is_function_call()) { - const code_function_callt &code = target->get_function_call(); - - if(code.function().id()==ID_dereference) + if(target->call_function().id() == ID_dereference) { remove_function_pointer(goto_program, function_id, target); did_something=true; diff --git a/src/goto-programs/validate_goto_model.cpp b/src/goto-programs/validate_goto_model.cpp index ac2fe9b229b..8f5418ae546 100644 --- a/src/goto-programs/validate_goto_model.cpp +++ b/src/goto-programs/validate_goto_model.cpp @@ -170,9 +170,8 @@ void validate_goto_modelt::check_called_functions() // check functions that are called if(instr.is_function_call()) { - const auto &function_call = instr.get_function_call(); const irep_idt &identifier = - to_symbol_expr(function_call.function()).get_identifier(); + to_symbol_expr(instr.call_function()).get_identifier(); DATA_CHECK( vm,