Skip to content

Commit df2638c

Browse files
author
Thomas Kiley
authored
Merge pull request #5375 from thk123/vsd/util
Util changes needed for VSD
2 parents 7d02492 + 6196338 commit df2638c

7 files changed

+69
-18
lines changed

src/util/journalling_symbol_table.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ class journalling_symbol_tablet : public symbol_table_baset
140140
base_symbol_table.end(), [this](const irep_idt &id) { on_update(id); });
141141
}
142142

143+
using symbol_table_baset::begin;
144+
using symbol_table_baset::end;
145+
143146
const changesett &get_inserted() const
144147
{
145148
return inserted;

src/util/symbol_table.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,8 @@ class symbol_tablet : public symbol_table_baset
120120
return iteratort(internal_symbols.end());
121121
}
122122

123-
typedef symbolst::const_iterator const_iteratort;
124-
125-
virtual const_iteratort begin() const
126-
{
127-
return internal_symbols.begin();
128-
}
129-
130-
virtual const_iteratort end() const
131-
{
132-
return internal_symbols.end();
133-
}
123+
using symbol_table_baset::begin;
124+
using symbol_table_baset::end;
134125

135126
/// Check that the symbol table is well-formed
136127
void validate(const validation_modet vm = validation_modet::INVARIANT) const;

src/util/symbol_table_base.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ void symbol_table_baset::show(std::ostream &out) const
6060
out << symbols.at(name);
6161
}
6262

63+
symbol_table_baset::const_iteratort symbol_table_baset::end() const
64+
{
65+
return symbols.end();
66+
}
67+
68+
symbol_table_baset::const_iteratort symbol_table_baset::begin() const
69+
{
70+
return symbols.begin();
71+
}
72+
6373
/// Print the contents of the symbol table.
6474
/// \param out: The ostream to direct output to
6575
/// \param symbol_table: The symbol table to print out

src/util/symbol_table_base.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ class symbol_table_baset
234234

235235
virtual iteratort begin() = 0;
236236
virtual iteratort end() = 0;
237+
238+
using const_iteratort = symbolst::const_iterator;
239+
240+
virtual const_iteratort begin() const;
241+
virtual const_iteratort end() const;
237242
};
238243

239244
std::ostream &

src/util/symbol_table_builder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class symbol_table_buildert : public symbol_table_baset
8585
return base_symbol_table.end();
8686
}
8787

88+
using symbol_table_baset::begin;
89+
using symbol_table_baset::end;
90+
8891
/// Try to find the next free identity for the passed-in prefix in
8992
/// this symbol table.
9093
/// \remark

unit/util/irep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SCENARIO("irept_memory", "[core][utils][irept]")
2222
const std::size_t ref_count_size = 0;
2323
#endif
2424

25-
#ifndef USE_STRING
25+
#ifndef USE_STD_STRING
2626
const std::size_t data_size = sizeof(dstringt);
2727
REQUIRE(sizeof(dstringt) == sizeof(unsigned));
2828
#else

unit/util/symbol_table.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,53 @@ TEST_CASE("Iterating through a symbol table", "[core][utils][symbol_tablet]")
1717

1818
symbol_table.insert(symbol);
1919

20-
int counter = 0;
21-
for(auto &entry : symbol_table)
20+
SECTION("Non const iterator")
2221
{
23-
(void)entry; // we are just testing iteration here
24-
++counter;
22+
int counter = 0;
23+
for(auto &entry : symbol_table)
24+
{
25+
(void)entry; // we are just testing iteration here
26+
++counter;
27+
}
28+
REQUIRE(counter == 1);
29+
}
30+
SECTION("Const iterator")
31+
{
32+
int counter = 0;
33+
for(const auto &entry : symbol_table)
34+
{
35+
(void)entry; // we are just testing iteration here
36+
++counter;
37+
}
38+
REQUIRE(counter == 1);
39+
}
40+
SECTION("Polymorphic access")
41+
{
42+
SECTION("Non-const iterator")
43+
{
44+
symbol_table_baset &base_st = symbol_table;
45+
REQUIRE(std::distance(base_st.begin(), base_st.end()) == 1);
46+
int counter = 0;
47+
for(auto &entry : base_st)
48+
{
49+
(void)entry; // we are just testing iteration here
50+
++counter;
51+
}
52+
REQUIRE(counter == 1);
53+
}
54+
SECTION("Const iterator")
55+
{
56+
const symbol_table_baset &base_st = symbol_table;
57+
REQUIRE(std::distance(base_st.begin(), base_st.end()) == 1);
58+
int counter = 0;
59+
for(const auto &entry : base_st)
60+
{
61+
(void)entry; // we are just testing iteration here
62+
++counter;
63+
}
64+
REQUIRE(counter == 1);
65+
}
2566
}
26-
27-
REQUIRE(counter == 1);
2867
}
2968

3069
SCENARIO(

0 commit comments

Comments
 (0)