|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Remove function definition |
| 4 | +
|
| 5 | +Author: Michael Tautschnig |
| 6 | +
|
| 7 | +Date: April 2017 |
| 8 | +
|
| 9 | +\*******************************************************************/ |
| 10 | + |
| 11 | +#include "remove_function.h" |
| 12 | + |
| 13 | +#include <util/message.h> |
| 14 | + |
| 15 | +#include <goto-programs/goto_functions.h> |
| 16 | + |
| 17 | +/*******************************************************************\ |
| 18 | +
|
| 19 | +Function: remove_function |
| 20 | +
|
| 21 | + Inputs: |
| 22 | + symbol_table Input symbol table to be modified |
| 23 | + goto_functions Input functions to be modified |
| 24 | + identifier Function to be removed |
| 25 | + message_handler Error/status output |
| 26 | +
|
| 27 | + Outputs: |
| 28 | +
|
| 29 | + Purpose: Remove the body of function "identifier" such that an |
| 30 | + analysis will treat it as a side-effect free function with |
| 31 | + non-deterministic return value. |
| 32 | +
|
| 33 | +\*******************************************************************/ |
| 34 | + |
| 35 | +void remove_function( |
| 36 | + symbol_tablet &symbol_table, |
| 37 | + goto_functionst &goto_functions, |
| 38 | + const irep_idt &identifier, |
| 39 | + message_handlert &message_handler) |
| 40 | +{ |
| 41 | + messaget message(message_handler); |
| 42 | + |
| 43 | + goto_functionst::function_mapt::iterator entry= |
| 44 | + goto_functions.function_map.find(identifier); |
| 45 | + |
| 46 | + if(entry==goto_functions.function_map.end()) |
| 47 | + { |
| 48 | + message.error() << "No function " << identifier |
| 49 | + << " in goto program" << messaget::eom; |
| 50 | + return; |
| 51 | + } |
| 52 | + else if(entry->second.is_inlined()) |
| 53 | + { |
| 54 | + message.warning() << "Function " << identifier << " is inlined, " |
| 55 | + << "instantiations will not be removed" |
| 56 | + << messaget::eom; |
| 57 | + } |
| 58 | + |
| 59 | + if(entry->second.body_available()) |
| 60 | + { |
| 61 | + message.status() << "Removing body of " << identifier |
| 62 | + << messaget::eom; |
| 63 | + entry->second.clear(); |
| 64 | + symbol_table.lookup(identifier).value.make_nil(); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +/*******************************************************************\ |
| 69 | +
|
| 70 | +Function: remove_functions |
| 71 | +
|
| 72 | + Inputs: |
| 73 | + symbol_table Input symbol table to be modified |
| 74 | + goto_functions Input functions to be modified |
| 75 | + names List of functions to be removed |
| 76 | + message_handler Error/status output |
| 77 | +
|
| 78 | + Outputs: |
| 79 | +
|
| 80 | + Purpose: Remove the body of all functions listed in "names" such that |
| 81 | + an analysis will treat it as a side-effect free function with |
| 82 | + non-deterministic return value. |
| 83 | +
|
| 84 | +\*******************************************************************/ |
| 85 | + |
| 86 | +void remove_functions( |
| 87 | + symbol_tablet &symbol_table, |
| 88 | + goto_functionst &goto_functions, |
| 89 | + const std::list<std::string> &names, |
| 90 | + message_handlert &message_handler) |
| 91 | +{ |
| 92 | + for(const auto &f : names) |
| 93 | + remove_function(symbol_table, goto_functions, f, message_handler); |
| 94 | +} |
0 commit comments