|
| 1 | +#include "namespace_utils.h" |
| 2 | +#include "symbol.h" |
| 3 | +#include <goto-programs/remove_returns.h> |
| 4 | + |
| 5 | + |
| 6 | +/*******************************************************************\ |
| 7 | + Function: namespace_utils_baset::does_symbol_match |
| 8 | +
|
| 9 | + Purpose: |
| 10 | + Checks whether an exprt is actually a symbolt matching a predicate |
| 11 | +
|
| 12 | + Inputs: |
| 13 | + lvalue: |
| 14 | + An exprt to be tested |
| 15 | + predicate: |
| 16 | + The predicate to test for |
| 17 | +
|
| 18 | + Outputs: |
| 19 | + Whether the exprt was actually a symbolt matching a predicate |
| 20 | +
|
| 21 | +\*******************************************************************/ |
| 22 | +bool namespace_utils_baset::does_symbol_match( |
| 23 | + const exprt &lvalue, |
| 24 | + std::function<bool(symbolt)> predicate) const |
| 25 | +{ |
| 26 | + if(lvalue.id()!=ID_symbol) |
| 27 | + return false; |
| 28 | + const symbolt *symbol; |
| 29 | + if(lookup(lvalue.get(ID_identifier), symbol)) |
| 30 | + return false; |
| 31 | + return predicate(*symbol); |
| 32 | +} |
| 33 | + |
| 34 | +/*******************************************************************\ |
| 35 | + Function: namespace_utils_baset::is_parameter |
| 36 | +
|
| 37 | + Purpose: |
| 38 | + Checks whether an exprt is actually a parameter symbol |
| 39 | +
|
| 40 | + Inputs: |
| 41 | + lvalue: |
| 42 | + An exprt to be tested |
| 43 | +
|
| 44 | + Outputs: |
| 45 | + Whether the exprt was actually a parameter symbol |
| 46 | +
|
| 47 | +\*******************************************************************/ |
| 48 | +bool namespace_utils_baset::is_parameter(const exprt &lvalue) const |
| 49 | +{ |
| 50 | + return does_symbol_match( |
| 51 | + lvalue, |
| 52 | + [] (symbolt symbol) { return symbol.is_parameter; }); |
| 53 | +} |
| 54 | + |
| 55 | +/*******************************************************************\ |
| 56 | + Function: namespace_utils_baset::is_static |
| 57 | +
|
| 58 | + Purpose: |
| 59 | + Checks whether an exprt is actually a static symbol |
| 60 | +
|
| 61 | + Inputs: |
| 62 | + lvalue: |
| 63 | + An exprt to be tested |
| 64 | +
|
| 65 | + Outputs: |
| 66 | + Whether the exprt was actually a static symbol |
| 67 | +
|
| 68 | +\*******************************************************************/ |
| 69 | +bool namespace_utils_baset::is_static(const exprt &lvalue) const |
| 70 | +{ |
| 71 | + // TODO: Also check for static member accesses |
| 72 | + return does_symbol_match( |
| 73 | + lvalue, |
| 74 | + [] (symbolt symbol) { return symbol.is_static_lifetime; }); |
| 75 | +} |
| 76 | + |
| 77 | +/*******************************************************************\ |
| 78 | + Function: namespace_utils_baset::is_auxiliary_variable |
| 79 | +
|
| 80 | + Purpose: |
| 81 | + Checks whether an exprt is actually an auxiliary variable symbol |
| 82 | +
|
| 83 | + Inputs: |
| 84 | + lvalue: |
| 85 | + An exprt to be tested |
| 86 | +
|
| 87 | + Outputs: |
| 88 | + Whether the exprt was actually an auxiliary variable symbol |
| 89 | +
|
| 90 | +\*******************************************************************/ |
| 91 | +bool namespace_utils_baset::is_auxiliary_variable(const exprt &lvalue) const |
| 92 | +{ |
| 93 | + return does_symbol_match( |
| 94 | + lvalue, |
| 95 | + [] (symbolt symbol) { return symbol.is_auxiliary; }); |
| 96 | +} |
| 97 | + |
| 98 | +/*******************************************************************\ |
| 99 | + Function: namespace_utils_baset::is_return_value_auxiliary |
| 100 | +
|
| 101 | + Purpose: |
| 102 | + Checks whether an exprt is actually an auxiliary return value symbol |
| 103 | +
|
| 104 | + Inputs: |
| 105 | + lvalue: |
| 106 | + An exprt to be tested |
| 107 | +
|
| 108 | + Outputs: |
| 109 | + Whether the exprt was actually an auxiliary return value symbol |
| 110 | +
|
| 111 | +\*******************************************************************/ |
| 112 | +bool namespace_utils_baset::is_return_value_auxiliary(const exprt &lvalue) const |
| 113 | +{ |
| 114 | + return |
| 115 | + does_symbol_match( |
| 116 | + lvalue, |
| 117 | + [] (symbolt symbol) |
| 118 | + { |
| 119 | + return |
| 120 | + symbol.is_static_lifetime |
| 121 | + && symbol.is_auxiliary |
| 122 | + && symbol.is_file_local |
| 123 | + && symbol.is_thread_local; |
| 124 | + }) |
| 125 | + && as_string(lvalue.get(ID_identifier)).find(RETURN_VALUE_SUFFIX) |
| 126 | + != std::string::npos; |
| 127 | +} |
0 commit comments