Skip to content

Commit 6794191

Browse files
committed
Improve symbol table documentation
No functional changes
1 parent d320187 commit 6794191

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/util/symbol_table.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ bool symbol_tablet::add(const symbolt &symbol)
1414
return !insert(symbol).second;
1515
}
1616

17+
/// Move or copy a new symbol to the symbol table
18+
/// \remark: This is a nicer interface than move and achieves the same
19+
/// result as both move and add
20+
/// \param symbol: The symbol to be added to the symbol table - can be
21+
/// moved or copied in
22+
/// \return Returns a reference to the newly inserted symbol or to the
23+
/// existing symbol if a symbol with the same name already exists in the
24+
/// symbol table, along with a bool that is true if a new symbol was inserted.
1725
std::pair<symbolt &, bool> symbol_tablet::insert(symbolt symbol)
1826
{
1927
// Add the symbol to the table or retrieve existing symbol with the same name
@@ -84,6 +92,7 @@ bool symbol_tablet::move(symbolt &symbol, symbolt *&new_symbol)
8492
/// Remove a symbol from the symbol table
8593
/// \param name: The name of the symbol to remove
8694
/// \return Returns a boolean indicating whether the process failed
95+
/// i.e. false if the symbol was removed, or true if it didn't exist.
8796
bool symbol_tablet::remove(const irep_idt &name)
8897
{
8998
symbolst::const_iterator entry=symbols.find(name);
@@ -93,6 +102,8 @@ bool symbol_tablet::remove(const irep_idt &name)
93102
return false;
94103
}
95104

105+
/// Remove a symbol from the symbol table
106+
/// \param entry: an iterator pointing at the symbol to remove
96107
void symbol_tablet::erase(const symbolst::const_iterator &entry)
97108
{
98109
const symbolt &symbol=entry->second;
@@ -137,10 +148,9 @@ void symbol_tablet::show(std::ostream &out) const
137148
out << it->second;
138149
}
139150

140-
/// Find a symbol in the symbol table. Throws a string if no such symbol is
141-
/// found.
151+
/// Find a symbol in the symbol table for read-only access.
142152
/// \param identifier: The name of the symbol to look for
143-
/// \return The symbol in the symbol table with the correct name
153+
/// \return an optional reference, set if found, unset otherwise.
144154
symbol_tablet::opt_const_symbol_reft symbol_tablet::lookup(
145155
const irep_idt &identifier) const
146156
{
@@ -150,9 +160,9 @@ symbol_tablet::opt_const_symbol_reft symbol_tablet::lookup(
150160
return std::ref(it->second);
151161
}
152162

153-
/// Find a symbol in the symbol table.
163+
/// Find a symbol in the symbol table for read-write access.
154164
/// \param identifier: The name of the symbol to look for
155-
/// \return The symbol in the symbol table with the correct name
165+
/// \return an optional reference, set if found, unset otherwise.
156166
symbol_tablet::opt_symbol_reft symbol_tablet::get_writeable(
157167
const irep_idt &identifier)
158168
{

src/util/symbol_table.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,15 @@ class symbol_tablet
100100
{
101101
return symbols.find(name)!=symbols.end();
102102
}
103+
103104
opt_const_symbol_reft lookup(const irep_idt &identifier) const;
105+
104106
opt_symbol_reft get_writeable(const irep_idt &identifier);
105107

106108
bool add(const symbolt &symbol);
107-
/// Move or copy a new symbol to the symbol table
108-
/// \remark: This is a nicer interface than move and achieves the same
109-
/// result as both move and add
110-
/// \param symbol: The symbol to be added to the symbol table - can be
111-
/// moved or copied in
112-
/// \return Returns a reference to the newly inserted symbol or to the
113-
/// existing symbol if a symbol with the same name already exists in the
114-
/// symbol table, along with a bool that is true if a new symbol was inserted.
109+
115110
std::pair<symbolt &, bool> insert(symbolt symbol);
111+
116112
bool move(symbolt &symbol, symbolt *&new_symbol);
117113

118114
void clear()

0 commit comments

Comments
 (0)