Skip to content

Commit 285db29

Browse files
committed
Improve the readability of the refactor
In the get_function_pointer_targets and remove_function_pointer. The previous version followed the original structure of the code to ease reviewing.
1 parent b10d219 commit 285db29

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

src/goto-programs/remove_function_pointers.cpp

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -381,21 +381,14 @@ remove_function_pointerst::get_function_pointer_targets(
381381

382382
try_remove_const_fp(goto_program, functions, function.pointer());
383383

384-
if(does_remove_const_first)
385-
{
386-
}
387-
else
388-
{
389-
if(functions.size() == 1)
390-
return functions;
391-
}
384+
if(!does_remove_const_first && functions.size() == 1)
385+
return functions;
392386

393387
if(!found_functions)
394388
{
395389
if(!only_resolve_const_fps)
396-
{
397390
return functions;
398-
}
391+
399392
// get all type-compatible functions
400393
// whose address is ever taken
401394
for(const auto &type_pair : type_map)
@@ -432,32 +425,23 @@ void remove_function_pointerst::remove_function_pointer(
432425
const auto functions =
433426
get_function_pointer_targets(goto_program, const_target);
434427

435-
if(does_remove_const_first)
428+
if(!does_remove_const_first && functions.size() == 1)
436429
{
437-
}
438-
else
439-
{
440-
if(functions.size() == 1)
441-
{
442-
auto call = target->get_function_call();
443-
call.function() = *functions.cbegin();
444-
target->set_function_call(call);
445-
return;
446-
}
430+
auto call = target->get_function_call();
431+
call.function() = *functions.cbegin();
432+
target->set_function_call(call);
433+
return;
447434
}
448435

449-
if(!found_functions)
436+
if(!found_functions && only_resolve_const_fps)
450437
{
451-
if(only_resolve_const_fps)
452-
{
453-
// If this mode is enabled, we only remove function pointers
454-
// that we can resolve either to an exact function, or an exact subset
455-
// (e.g. a variable index in a constant array).
456-
// Since we haven't found functions, we would now resort to
457-
// replacing the function pointer with any function with a valid signature
458-
// Since we don't want to do that, we abort.
459-
return;
460-
}
438+
// If this mode is enabled, we only remove function pointers
439+
// that we can resolve either to an exact function, or an exact subset
440+
// (e.g. a variable index in a constant array).
441+
// Since we haven't found functions, we would now resort to
442+
// replacing the function pointer with any function with a valid signature
443+
// Since we don't want to do that, we abort.
444+
return;
461445
}
462446

463447
remove_function_pointer(goto_program, function_id, target, functions);

0 commit comments

Comments
 (0)