Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/util/journalling_symbol_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ class journalling_symbol_tablet : public symbol_table_baset
base_symbol_table.end(), [this](const irep_idt &id) { on_update(id); });
}

using symbol_table_baset::begin;
using symbol_table_baset::end;

const changesett &get_inserted() const
{
return inserted;
Expand Down
13 changes: 2 additions & 11 deletions src/util/symbol_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,8 @@ class symbol_tablet : public symbol_table_baset
return iteratort(internal_symbols.end());
}

typedef symbolst::const_iterator const_iteratort;

virtual const_iteratort begin() const
{
return internal_symbols.begin();
}

virtual const_iteratort end() const
{
return internal_symbols.end();
}
using symbol_table_baset::begin;
using symbol_table_baset::end;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop symbol_table_baset::begin/end are both purely virtual, so can not be used in this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed out of band: more consistent to have both const and non-const iterators be virtual and defined in the base class.


/// Check that the symbol table is well-formed
void validate(const validation_modet vm = validation_modet::INVARIANT) const;
Expand Down
10 changes: 10 additions & 0 deletions src/util/symbol_table_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ void symbol_table_baset::show(std::ostream &out) const
out << symbols.at(name);
}

symbol_table_baset::const_iteratort symbol_table_baset::end() const
{
return symbols.end();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

96bd3ae s/interate/iterate in the commit message.

Also this commit should be removed; Current develop already has begin/end for symbol_tablet.

}

symbol_table_baset::const_iteratort symbol_table_baset::begin() const
{
return symbols.begin();
}

/// Print the contents of the symbol table.
/// \param out: The ostream to direct output to
/// \param symbol_table: The symbol table to print out
Expand Down
5 changes: 5 additions & 0 deletions src/util/symbol_table_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ class symbol_table_baset

virtual iteratort begin() = 0;
virtual iteratort end() = 0;

using const_iteratort = symbolst::const_iterator;

virtual const_iteratort begin() const;
virtual const_iteratort end() const;
};

std::ostream &
Expand Down
3 changes: 3 additions & 0 deletions src/util/symbol_table_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class symbol_table_buildert : public symbol_table_baset
return base_symbol_table.end();
}

using symbol_table_baset::begin;
using symbol_table_baset::end;

/// Try to find the next free identity for the passed-in prefix in
/// this symbol table.
/// \remark
Expand Down
2 changes: 1 addition & 1 deletion unit/util/irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SCENARIO("irept_memory", "[core][utils][irept]")
const std::size_t ref_count_size = 0;
#endif

#ifndef USE_STRING
#ifndef USE_STD_STRING

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I’d really love if we could just get rid of USE_STD_STRING already. I’m not entirely convinced we keep it around for anything other than nostalgia at this point.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the only use case for it is / was debugging problems in the dtringt implementation. I am not sure how many issues it will find that have not already been found.

const std::size_t data_size = sizeof(dstringt);
REQUIRE(sizeof(dstringt) == sizeof(unsigned));
#else
Expand Down
51 changes: 45 additions & 6 deletions unit/util/symbol_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,53 @@ TEST_CASE("Iterating through a symbol table", "[core][utils][symbol_tablet]")

symbol_table.insert(symbol);

int counter = 0;
for(auto &entry : symbol_table)
SECTION("Non const iterator")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit (a9afb9a) can also be removed; symbol table iterators are tested in unit/util/symbol_table.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see a single class to begin() but no call to end. This also tests the correct dispatching when you have a symbol_tablet but the compile time type is symbol_table_baset

{
(void)entry; // we are just testing iteration here
++counter;
int counter = 0;
for(auto &entry : symbol_table)
{
(void)entry; // we are just testing iteration here
++counter;
}
REQUIRE(counter == 1);
}
SECTION("Const iterator")
{
int counter = 0;
for(const auto &entry : symbol_table)
{
(void)entry; // we are just testing iteration here
++counter;
}
REQUIRE(counter == 1);
}
SECTION("Polymorphic access")
{
SECTION("Non-const iterator")
{
symbol_table_baset &base_st = symbol_table;
REQUIRE(std::distance(base_st.begin(), base_st.end()) == 1);
int counter = 0;
for(auto &entry : base_st)
{
(void)entry; // we are just testing iteration here
++counter;
}
REQUIRE(counter == 1);
}
SECTION("Const iterator")
{
const symbol_table_baset &base_st = symbol_table;
REQUIRE(std::distance(base_st.begin(), base_st.end()) == 1);
int counter = 0;
for(const auto &entry : base_st)
{
(void)entry; // we are just testing iteration here
++counter;
}
REQUIRE(counter == 1);
}
}

REQUIRE(counter == 1);
}

SCENARIO(
Expand Down