Skip to content

Commit beb1353

Browse files
mww-awsfeliperodri
authored andcommitted
Adds support for function calls within contracts
Contracts definitions often makes use of elaborate predicates, which could be written on a separate functions. Therefore, function contracts should be able to accept functions as part of their specifications. Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent fa12ca7 commit beb1353

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/linking/remove_internal_symbols.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ static void get_symbols(
5757
if(!ns.lookup(p.get_identifier(), s))
5858
working_set.push_back(s);
5959
}
60+
61+
// check for contract definitions
62+
const exprt ensures =
63+
static_cast<const exprt &>(code_type.find(ID_C_spec_ensures));
64+
const exprt requires =
65+
static_cast<const exprt &>(code_type.find(ID_C_spec_requires));
66+
67+
find_symbols_sett new_symbols;
68+
find_type_and_expr_symbols(ensures, new_symbols);
69+
find_type_and_expr_symbols(requires, new_symbols);
70+
71+
for(const auto &s : new_symbols)
72+
{
73+
// keep functions called in contracts within scope.
74+
// should we keep local variables from the contract as well?
75+
const symbolt *new_symbol = nullptr;
76+
if(!ns.lookup(s, new_symbol))
77+
{
78+
if(new_symbol->type.id() == ID_code)
79+
{
80+
working_set.push_back(new_symbol);
81+
}
82+
}
83+
}
6084
}
6185
}
6286
}

0 commit comments

Comments
 (0)