Skip to content

Commit f61d33d

Browse files
authored
Merge pull request #4303 from tautschnig/deprecate-link_to_library
Deprecate link_to_library(goto_functions, symbol_table, ...) [blocks: #4296]
2 parents ca54005 + 2a2f98c commit f61d33d

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

src/goto-programs/link_to_library.cpp

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,62 @@ void link_to_library(
2828
void(const std::set<irep_idt> &, symbol_tablet &, message_handlert &)>
2929
&library)
3030
{
31-
link_to_library(
32-
goto_model.symbol_table,
33-
goto_model.goto_functions,
34-
message_handler,
35-
library);
31+
// this needs a fixedpoint, as library functions
32+
// may depend on other library functions
33+
34+
std::set<irep_idt> added_functions;
35+
36+
while(true)
37+
{
38+
std::unordered_set<irep_idt> called_functions =
39+
compute_called_functions(goto_model.goto_functions);
40+
41+
// eliminate those for which we already have a body
42+
43+
std::set<irep_idt> missing_functions;
44+
45+
for(const auto &id : called_functions)
46+
{
47+
goto_functionst::function_mapt::const_iterator f_it =
48+
goto_model.goto_functions.function_map.find(id);
49+
50+
if(
51+
f_it != goto_model.goto_functions.function_map.end() &&
52+
f_it->second.body_available())
53+
{
54+
// it's overridden!
55+
}
56+
else if(added_functions.find(id) != added_functions.end())
57+
{
58+
// already added
59+
}
60+
else
61+
missing_functions.insert(id);
62+
}
63+
64+
// done?
65+
if(missing_functions.empty())
66+
break;
67+
68+
library(missing_functions, goto_model.symbol_table, message_handler);
69+
70+
// convert to CFG
71+
for(const auto &id : missing_functions)
72+
{
73+
if(
74+
goto_model.symbol_table.symbols.find(id) !=
75+
goto_model.symbol_table.symbols.end())
76+
{
77+
goto_convert(
78+
id,
79+
goto_model.symbol_table,
80+
goto_model.goto_functions,
81+
message_handler);
82+
}
83+
84+
added_functions.insert(id);
85+
}
86+
}
3687
}
3788

3889
/// Complete missing function definitions using the \p library.

src/goto-programs/link_to_library.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ Author: Daniel Kroening, [email protected]
1515
#include <functional>
1616
#include <set>
1717

18+
#include <util/deprecate.h>
1819
#include <util/irep.h>
1920

2021
class goto_functionst;
2122
class goto_modelt;
2223
class message_handlert;
2324
class symbol_tablet;
2425

26+
DEPRECATED("Use link_to_library(goto_model, ...) instead")
2527
void link_to_library(
2628
symbol_tablet &,
2729
goto_functionst &,

0 commit comments

Comments
 (0)