Skip to content

Commit 912ee38

Browse files
committed
Improve symbol table style
1 parent 6b1a49d commit 912ee38

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

src/util/recording_symbol_table.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,11 @@ class recording_symbol_tablet:public symbol_tablet
5656
virtual symbolt *get_writeable(const irep_idt &identifier) override
5757
{
5858
symbolt *result=base_symbol_table.get_writeable(identifier);
59-
if(result)
59+
if(result!=nullptr)
6060
on_update(identifier);
6161
return result;
6262
}
6363

64-
virtual symbolt &get_writeable_ref(const irep_idt &identifier) override
65-
{
66-
symbolt &result=base_symbol_table.get_writeable_ref(identifier);
67-
on_update(identifier);
68-
return result;
69-
}
70-
7164
virtual std::pair<symbolt &, bool> insert(symbolt symbol) override
7265
{
7366
std::pair<symbolt &, bool> result=

src/util/symbol_table.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@
77
#include <util/invariant.h>
88

99

10-
/// Find a symbol in the symbol table.
11-
/// \param identifier: The name of the symbol to look for
12-
/// \return Returns an optional reference to the found symbol, without a value
13-
/// if a symbol with the given name does not exist in the symbol table
14-
const symbolt *symbol_tablet::lookup(
15-
const irep_idt &identifier) const
16-
{
17-
symbolst::const_iterator it=symbols.find(identifier);
18-
if(it==symbols.end())
19-
return nullptr;
20-
return &it->second;
21-
}
22-
2310
/// Add a new symbol to the symbol table
2411
/// \param symbol: The symbol to be added to the symbol table
2512
/// \return Returns true if the process failed, which should only happen if
@@ -106,12 +93,7 @@ std::ostream &operator<<(std::ostream &out, const symbol_tablet &symbol_table)
10693
}
10794

10895

109-
/// Find a symbol in the symbol table.
110-
/// \param identifier: The name of the symbol to look for
111-
/// \return Returns an optional reference to the found symbol, without a value
112-
/// if a symbol with the given name does not exist in the symbol table
113-
symbolt *concrete_symbol_tablet::get_writeable(
114-
const irep_idt &identifier)
96+
symbolt *concrete_symbol_tablet::get_writeable(const irep_idt &identifier)
11597
{
11698
symbolst::iterator it=internal_symbols.find(identifier);
11799
if(it==symbols.end())

src/util/symbol_table.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,39 @@ class symbol_tablet
6868
}
6969

7070
/// Find a symbol in the symbol table for read-only access.
71-
/// \param id: The name of the symbol to look for
72-
/// \return an optional reference, set if found, nullptr otherwise.
73-
const symbolt *lookup(const irep_idt &identifier) const;
71+
/// \param identifier: The name of the symbol to look for
72+
/// \return an optional pointer, set if found, nullptr otherwise.
73+
const symbolt *lookup(const irep_idt &identifier) const
74+
{
75+
symbolst::const_iterator it=symbols.find(identifier);
76+
if(it==symbols.end())
77+
return nullptr;
78+
return &it->second;
79+
}
7480

7581
/// Find a symbol in the symbol table for read-write access.
76-
/// \param id: The name of the symbol to look for
77-
/// \return an optional reference, set if found, unset otherwise.
82+
/// \param identifier: The name of the symbol to look for
83+
/// \return an optional pointer, set if found, nullptr otherwise.
7884
virtual symbolt *get_writeable(const irep_idt &identifier)=0;
7985

8086
/// Find a symbol in the symbol table for read-only access.
81-
/// \param id: The name of the symbol to look for
87+
/// \param identifier: The name of the symbol to look for
8288
/// \return A reference to the symbol
8389
/// \throw `std::out_of_range` if no such symbol exists
84-
const symbolt &lookup_ref(const irep_idt &id) const
85-
{ return symbols.at(id); }
90+
const symbolt &lookup_ref(const irep_idt &identifier) const
91+
{ return symbols.at(identifier); }
8692

8793
/// Find a symbol in the symbol table for read-write access.
88-
/// \param id: The name of the symbol to look for
94+
/// \param identifier: The name of the symbol to look for
8995
/// \return A reference to the symbol
9096
/// \throw `std::out_of_range` if no such symbol exists
91-
virtual symbolt &get_writeable_ref(const irep_idt &id)=0;
97+
symbolt &get_writeable_ref(const irep_idt &identifier)
98+
{
99+
symbolt *symbol=get_writeable(identifier);
100+
if(symbol==nullptr)
101+
throw std::out_of_range("identifier not found in symbol_table");
102+
return *symbol;
103+
}
92104

93105
bool add(const symbolt &symbol);
94106
/// Move or copy a new symbol to the symbol table
@@ -103,6 +115,8 @@ class symbol_tablet
103115
bool move(symbolt &symbol, symbolt *&new_symbol);
104116

105117
bool remove(const irep_idt &name);
118+
/// Remove a symbol from the symbol table
119+
/// \param entry: an iterator pointing at the symbol to remove
106120
virtual void erase(const symbolst::const_iterator &entry)=0;
107121
virtual void clear()=0;
108122

@@ -187,8 +201,6 @@ class concrete_symbol_tablet:public symbol_tablet
187201
}
188202

189203
virtual symbolt *get_writeable(const irep_idt &identifier) override;
190-
virtual symbolt &get_writeable_ref(const irep_idt &identifier) override
191-
{ return internal_symbols.at(identifier); }
192204

193205
virtual std::pair<symbolt &, bool> insert(symbolt symbol) override;
194206

0 commit comments

Comments
 (0)