@@ -9,6 +9,7 @@ Author: Daniel Kroening, kroening@kroening.com
9
9
#include " symbol_table.h"
10
10
11
11
#include < ostream>
12
+ #include < util/invariant.h>
12
13
13
14
// / Add a new symbol to the symbol table
14
15
// / \param symbol: The symbol to be added to the symbol table
@@ -109,35 +110,39 @@ void symbol_tablet::add_base_and_module(symbolst::iterator added_symbol)
109
110
// / \return Returns a boolean indicating whether the process failed
110
111
bool symbol_tablet::remove (const irep_idt &name)
111
112
{
112
- symbolst::iterator entry=symbols.find (name);
113
-
113
+ symbolst::const_iterator entry=symbols.find (name);
114
114
if (entry==symbols.end ())
115
115
return true ;
116
116
117
- for (symbol_base_mapt::iterator
118
- it=symbol_base_map.lower_bound (entry->second .base_name ),
119
- it_end=symbol_base_map.upper_bound (entry->second .base_name );
120
- it!=it_end;
121
- ++it)
122
- if (it->second ==name)
123
- {
124
- symbol_base_map.erase (it);
125
- break ;
126
- }
127
-
128
- for (symbol_module_mapt::iterator
129
- it=symbol_module_map.lower_bound (entry->second .module ),
130
- it_end=symbol_module_map.upper_bound (entry->second .module );
131
- it!=it_end;
132
- ++it)
133
- if (it->second ==name)
134
- {
135
- symbol_module_map.erase (it);
136
- break ;
137
- }
117
+ const symbolt &symbol=entry->second ;
118
+
119
+ symbol_base_mapt::const_iterator
120
+ base_it=symbol_base_map.lower_bound (entry->second .base_name ),
121
+ base_it_end=symbol_base_map.upper_bound (entry->second .base_name );
122
+ while (base_it!=base_it_end && base_it->second !=name)
123
+ ++base_it;
124
+ INVARIANT (
125
+ base_it!=base_it_end,
126
+ " symbolt::base_name should not be changed "
127
+ " after it is added to the symbol_table "
128
+ " (name: " +id2string (symbol.name )+" , "
129
+ " current base_name: " +id2string (symbol.base_name )+" )" );
130
+ symbol_base_map.erase (base_it);
131
+
132
+ symbol_module_mapt::const_iterator
133
+ module_it=symbol_module_map.lower_bound (entry->second .module ),
134
+ module_it_end=symbol_module_map.upper_bound (entry->second .module );
135
+ while (module_it!=module_it_end && module_it->second !=name)
136
+ ++module_it;
137
+ INVARIANT (
138
+ module_it!=module_it_end,
139
+ " symbolt::module should not be changed "
140
+ " after it is added to the symbol_table "
141
+ " (name: " +id2string (symbol.name )+" , "
142
+ " current module: " +id2string (symbol.module )+" )" );
143
+ symbol_module_map.erase (module_it);
138
144
139
145
symbols.erase (entry);
140
-
141
146
return false ;
142
147
}
143
148
0 commit comments