Skip to content

Commit 8035397

Browse files
Style improvements
1 parent 6dae8e8 commit 8035397

File tree

2 files changed

+51
-41
lines changed

2 files changed

+51
-41
lines changed

src/util/symbol_table.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016-2017 DiffBlue Limited. All Rights Reserved.
1+
// Copyright 2016-2017 Diffblue Limited. All Rights Reserved.
22

33
#include "symbol_table.h"
44

@@ -56,7 +56,7 @@ std::pair<symbolt &, bool> symbol_tablet::insert(symbolt symbol)
5656
/// Move a symbol into the symbol table. If there is already a symbol with the
5757
/// same name then symbol is unchanged, new_symbol points to the symbol with the
5858
/// same name and true is returned. Otherwise, the symbol is moved into the
59-
/// symbol table, symbol is set to be empty, new_symbol points to its new
59+
/// symbol table, symbol is destroyed, new_symbol points to its new
6060
/// location in the symbol table and false is returned
6161
/// \param symbol: The symbol to be added to the symbol table
6262
/// \param new_symbol: Pointer which the function will set to either point to
@@ -151,7 +151,7 @@ void symbol_tablet::show(std::ostream &out) const
151151
/// Print the contents of the symbol table
152152
/// \param out: The ostream to direct output to
153153
/// \param symbol_table: The symbol table to print out
154-
std::ostream &operator << (std::ostream &out, const symbol_tablet &symbol_table)
154+
std::ostream &operator<<(std::ostream &out, const symbol_tablet &symbol_table)
155155
{
156156
symbol_table.show(out);
157157
return out;

src/util/symbol_table.h

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016-2017 DiffBlue Limited. All Rights Reserved.
1+
// Copyright 2016-2017 Diffblue Limited. All Rights Reserved.
22

33
/// \file
44
/// Symbol table
@@ -52,6 +52,7 @@ class symbol_tablet
5252
const symbol_base_mapt &symbol_base_map;
5353
const symbol_module_mapt &symbol_module_map;
5454

55+
public:
5556
symbol_tablet()
5657
: symbols(internal_symbols),
5758
symbol_base_map(internal_symbol_base_map),
@@ -93,79 +94,88 @@ class symbol_tablet
9394
return *this;
9495
}
9596

97+
void swap(symbol_tablet &other)
98+
{
99+
internal_symbols.swap(other.internal_symbols);
100+
internal_symbol_base_map.swap(other.internal_symbol_base_map);
101+
internal_symbol_module_map.swap(other.internal_symbol_module_map);
102+
}
103+
104+
public:
96105
bool has_symbol(const irep_idt &name) const
97106
{
98107
return symbols.find(name)!=symbols.end();
99108
}
100109

101110
/// Find a symbol in the symbol table for read-only access.
102-
/// \param id: The name of the symbol to look for
103-
/// \return an optional reference, set if found, nullptr otherwise.
104-
const symbolt *lookup(const irep_idt &id) const { return lookup_impl(id); }
105-
106-
/// Find a symbol in the symbol table for read-write access.
107-
/// \param id: The name of the symbol to look for
108-
/// \return an optional reference, set if found, unset otherwise.
109-
symbolt *get_writeable(const irep_idt &id) { return lookup_impl(id); }
111+
/// \param name: The name of the symbol to look for
112+
/// \return a pointer to the found symbol if it exists, nullptr otherwise.
113+
const symbolt *lookup(const irep_idt &name) const
114+
{
115+
return lookup_impl(name);
116+
}
110117

111118
/// Find a symbol in the symbol table for read-only access.
112-
/// \param id: The name of the symbol to look for
119+
/// \param name: The name of the symbol to look for
113120
/// \return A reference to the symbol
114121
/// \throw `std::out_of_range` if no such symbol exists
115-
const symbolt &lookup_ref(const irep_idt &id) const
116-
{ return internal_symbols.at(id); }
122+
const symbolt &lookup_ref(const irep_idt &name) const
123+
{
124+
return symbols.at(name);
125+
}
126+
127+
/// Find a symbol in the symbol table for read-write access.
128+
/// \param name: The name of the symbol to look for
129+
/// \return a pointer to the found symbol if it exists, nullptr otherwise.
130+
symbolt *get_writeable(const irep_idt &name)
131+
{
132+
return lookup_impl(name);
133+
}
117134

118135
/// Find a symbol in the symbol table for read-write access.
119-
/// \param id: The name of the symbol to look for
136+
/// \param name: The name of the symbol to look for
120137
/// \return A reference to the symbol
121138
/// \throw `std::out_of_range` if no such symbol exists
122-
symbolt &get_writeable_ref(const irep_idt &id)
123-
{ return internal_symbols.at(id); }
139+
symbolt &get_writeable_ref(const irep_idt &name)
140+
{
141+
return internal_symbols.at(name);
142+
}
124143

125144
bool add(const symbolt &symbol);
126-
127145
std::pair<symbolt &, bool> insert(symbolt symbol);
128-
129146
bool move(symbolt &symbol, symbolt *&new_symbol);
130147

148+
bool remove(const irep_idt &name);
149+
void erase(const symbolst::const_iterator &entry);
131150
void clear()
132151
{
133152
internal_symbols.clear();
134153
internal_symbol_base_map.clear();
135154
internal_symbol_module_map.clear();
136155
}
137156

138-
bool remove(const irep_idt &name);
139-
140-
void erase(const symbolst::const_iterator &entry);
141-
142157
void show(std::ostream &out) const;
143158

144-
void swap(symbol_tablet &other)
159+
private:
160+
const symbolt *lookup_impl(const irep_idt &name) const
145161
{
146-
internal_symbols.swap(other.internal_symbols);
147-
internal_symbol_base_map.swap(other.internal_symbol_base_map);
148-
internal_symbol_module_map.swap(other.internal_symbol_module_map);
162+
return lookup_impl(*this, name);
149163
}
150164

151-
private:
152-
const symbolt *lookup_impl(const irep_idt &id) const
153-
{ return lookup_impl(*this, id); }
154-
155-
symbolt *lookup_impl(const irep_idt &id)
156-
{ return lookup_impl(*this, id); }
165+
symbolt *lookup_impl(const irep_idt &name)
166+
{
167+
return lookup_impl(*this, name);
168+
}
157169

158-
template<typename T>
159-
static auto lookup_impl(T &t, const irep_idt &id)
160-
-> decltype(std::declval<T>().lookup_impl(id))
170+
template <typename T>
171+
static auto lookup_impl(T &t, const irep_idt &name)
172+
-> decltype(std::declval<T>().lookup_impl(name))
161173
{
162-
const auto it=t.internal_symbols.find(id);
174+
const auto it = t.internal_symbols.find(name);
163175
return it==t.internal_symbols.end()?nullptr:&it->second;
164176
}
165177
};
166178

167-
std::ostream &operator << (
168-
std::ostream &out,
169-
const symbol_tablet &symbol_table);
179+
std::ostream &operator<<(std::ostream &out, const symbol_tablet &symbol_table);
170180

171181
#endif // CPROVER_UTIL_SYMBOL_TABLE_H

0 commit comments

Comments
 (0)