Skip to content

Commit 32e4a06

Browse files
committed
Cleanup and correctly document get_new_name
Remove the unused variant that takes a symbol as first argument. Change the interface to explicitly return a value. Add proper doxygen documentation rather than accepting warnings about wrong documentation.
1 parent 06de9f4 commit 32e4a06

File tree

5 files changed

+19
-33
lines changed

5 files changed

+19
-33
lines changed

scripts/expected_doxygen_warnings.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
template
1515
satcheck_minisat2_baset< Minisat::SimpSolver >::~satcheck_minisat2_baset()
1616

17-
/home/runner/work/cbmc/cbmc/src/util/rename.cpp:27: warning: documented empty return type of get_new_name
18-
/home/runner/work/cbmc/cbmc/src/util/rename.cpp:19: warning: documented empty return type of get_new_name
19-
/home/runner/work/cbmc/cbmc/src/util/rename.h:26: warning: documented empty return type of get_new_name
20-
/home/runner/work/cbmc/cbmc/src/util/rename.h:23: warning: documented empty return type of get_new_name
2117
warning: Include graph for 'goto_instrument_parse_options.cpp' not generated, too many nodes (97), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
2218
warning: Included by graph for 'goto_functions.h' not generated, too many nodes (66), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
2319
warning: Included by graph for 'goto_model.h' not generated, too many nodes (111), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.

src/goto-harness/recursive_initialization.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,8 @@ const symbolt &recursive_initializationt::get_fresh_fun_symbol(
558558
const std::string &fun_name,
559559
const typet &fun_type)
560560
{
561-
irep_idt fresh_name(fun_name);
562-
563-
get_new_name(fresh_name, namespacet{goto_model.symbol_table}, '_');
561+
irep_idt fresh_name =
562+
get_new_name(fun_name, namespacet{goto_model.symbol_table}, '_');
564563

565564
// create the function symbol
566565
symbolt function_symbol{};

src/util/fresh_symbol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ symbolt &get_fresh_aux_symbol(
4545
identifier = name_prefix + "::" + basename_prefix;
4646
prefix_size = name_prefix.size() + 2;
4747
}
48-
get_new_name(identifier, ns, '$');
48+
identifier = get_new_name(identifier, ns, '$');
4949
std::string basename = id2string(identifier).substr(prefix_size);
5050

5151
auxiliary_symbolt new_symbol(basename, type);

src/util/rename.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,16 @@ Author: Daniel Kroening, kroening@kroening.com
1010

1111
#include <string>
1212

13-
#include "symbol.h"
1413
#include "namespace.h"
1514

16-
/// automated variable renaming
17-
/// \par parameters: symbol to be renamed, namespace
18-
/// \return new symbol
19-
void get_new_name(symbolt &symbol, const namespacet &ns)
20-
{
21-
get_new_name(symbol.name, ns);
22-
}
23-
24-
/// automated variable renaming
25-
/// \par parameters: symbol to be renamed, namespace
26-
/// \return new symbol
27-
void get_new_name(irep_idt &new_name, const namespacet &ns, char delimiter)
15+
irep_idt
16+
get_new_name(const irep_idt &name, const namespacet &ns, char delimiter)
2817
{
2918
const symbolt *symbol;
30-
if(ns.lookup(new_name, symbol))
31-
return; // name not taken yet
19+
if(ns.lookup(name, symbol))
20+
return name;
3221

33-
std::string prefix = id2string(new_name) + delimiter;
22+
std::string prefix = id2string(name) + delimiter;
3423

35-
new_name = prefix + std::to_string(ns.smallest_unused_suffix(prefix));
24+
return prefix + std::to_string(ns.smallest_unused_suffix(prefix));
3625
}

src/util/rename.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ Author: Daniel Kroening, kroening@kroening.com
1515
//
1616

1717
#include "irep.h"
18+
#include "nodiscard.h"
1819

1920
class exprt;
2021
class namespacet;
21-
class symbolt;
2222

23-
void get_new_name(symbolt &symbol,
24-
const namespacet &ns);
25-
26-
void get_new_name(
27-
irep_idt &new_name,
28-
const namespacet &ns,
29-
char delimiter = '_');
23+
/// Build and identifier not yet present in the namespace \p ns based on \p
24+
/// name. If \p name is not in the namespace, just returns \p name.
25+
/// \param name: initial candidate identifier
26+
/// \param ns: namespace
27+
/// \param delimiter: character to separate the name and a newly generated
28+
/// suffix
29+
/// \return Identifier that is not yet part of the namespace.
30+
NODISCARD irep_idt
31+
get_new_name(const irep_idt &name, const namespacet &ns, char delimiter = '_');
3032

3133
#endif // CPROVER_UTIL_RENAME_H

0 commit comments

Comments
 (0)