Skip to content

Commit 1def64c

Browse files
NathanJPhillipssmowton
authored andcommitted
Added INVARIANT to symbol_tablet::remove
1 parent 7798daa commit 1def64c

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

src/util/symbol_table.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
99
#include "symbol_table.h"
1010

1111
#include <ostream>
12+
#include <util/invariant.h>
1213

1314
/// Add a new symbol to the symbol table
1415
/// \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)
109110
/// \return Returns a boolean indicating whether the process failed
110111
bool symbol_tablet::remove(const irep_idt &name)
111112
{
112-
symbolst::iterator entry=symbols.find(name);
113-
113+
symbolst::const_iterator entry=symbols.find(name);
114114
if(entry==symbols.end())
115115
return true;
116116

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);
138144

139145
symbols.erase(entry);
140-
141146
return false;
142147
}
143148

0 commit comments

Comments
 (0)