@@ -19,45 +19,44 @@ Author: Daniel Kroening
19
19
20
20
#include " static_lifetime_init.h"
21
21
22
- void get_symbols_rec (
22
+ static void get_symbols (
23
23
const namespacet &ns,
24
24
const symbolt &symbol,
25
25
find_symbols_sett &dest)
26
26
{
27
- dest. insert (symbol. name ) ;
27
+ std::vector< const symbolt *> working_set ;
28
28
29
- find_symbols_sett new_symbols ;
29
+ working_set. push_back (&symbol) ;
30
30
31
- find_type_and_expr_symbols (symbol.type , new_symbols);
32
- find_type_and_expr_symbols (symbol.value , new_symbols);
33
-
34
- if (symbol.type .id ()==ID_code)
31
+ while (!working_set.empty ())
35
32
{
36
- const code_typet &code_type=to_code_type (symbol.type );
37
- const code_typet::parameterst ¶meters=code_type.parameters ();
33
+ const symbolt *s = working_set.back ();
34
+ working_set.pop_back ();
35
+ const symbolt &symbol = *s;
38
36
39
- for (code_typet::parameterst::const_iterator
40
- it=parameters.begin ();
41
- it!=parameters.end ();
42
- it++)
43
- {
44
- irep_idt id=it->get_identifier ();
45
- const symbolt *s;
46
- // identifiers for prototypes need not exist
47
- if (!ns.lookup (id, s))
48
- new_symbols.insert (id);
49
- }
50
- }
37
+ if (!dest.insert (symbol.name ).second )
38
+ continue ;
51
39
52
- for (find_symbols_sett::const_iterator
53
- it=new_symbols.begin ();
54
- it!=new_symbols.end ();
55
- it++)
56
- {
57
- if (dest.find (*it)==dest.end ())
40
+ find_symbols_sett new_symbols;
41
+
42
+ find_type_and_expr_symbols (symbol.type , new_symbols);
43
+ find_type_and_expr_symbols (symbol.value , new_symbols);
44
+
45
+ for (const auto &s : new_symbols)
46
+ working_set.push_back (&ns.lookup (s));
47
+
48
+ if (symbol.type .id () == ID_code)
58
49
{
59
- dest.insert (*it);
60
- get_symbols_rec (ns, ns.lookup (*it), dest); // recursive call
50
+ const code_typet &code_type = to_code_type (symbol.type );
51
+ const code_typet::parameterst ¶meters = code_type.parameters ();
52
+
53
+ for (const auto &p : parameters)
54
+ {
55
+ const symbolt *s;
56
+ // identifiers for prototypes need not exist
57
+ if (!ns.lookup (p.get_identifier (), s))
58
+ working_set.push_back (s);
59
+ }
61
60
}
62
61
}
63
62
}
@@ -105,7 +104,7 @@ void remove_internal_symbols(
105
104
106
105
if (special.find (symbol.name )!=special.end ())
107
106
{
108
- get_symbols_rec (ns, symbol, exported);
107
+ get_symbols (ns, symbol, exported);
109
108
continue ;
110
109
}
111
110
@@ -135,7 +134,7 @@ void remove_internal_symbols(
135
134
// body? not local (i.e., "static")?
136
135
if (has_body &&
137
136
(!is_file_local || (config.main ==symbol.name .c_str ())))
138
- get_symbols_rec (ns, symbol, exported);
137
+ get_symbols (ns, symbol, exported);
139
138
}
140
139
else
141
140
{
@@ -144,7 +143,7 @@ void remove_internal_symbols(
144
143
if ((has_initializer || !symbol.is_extern ) &&
145
144
!is_file_local)
146
145
{
147
- get_symbols_rec (ns, symbol, exported);
146
+ get_symbols (ns, symbol, exported);
148
147
}
149
148
}
150
149
}
0 commit comments