Skip to content

Commit 5811370

Browse files
Merge pull request diffblue#94 from diffblue/nathan/feature/virtual_map-const_iterator
Nathan/feature/virtual map const iterator
2 parents 23d8fe8 + a54827e commit 5811370

File tree

4 files changed

+121
-54
lines changed

4 files changed

+121
-54
lines changed

src/taint-slicer/search_for_rule_applications.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ explicit propagation rules were applied.
2020
#include <vector>
2121

2222
void taint_search_for_rule_applications(
23-
const taint_summaryt::dbt * const orig_summaries,
23+
const taint_summaryt::dbt * const summaries,
2424
taint_map_from_rules_to_their_application_sitest &result)
2525
{
26-
taint_summaryt::dbt * const summaries=
27-
const_cast<taint_summaryt::dbt *>(orig_summaries);
28-
for(auto it=summaries->begin(); it!=summaries->end(); ++it)
26+
for(taint_summaryt::dbt::const_reference summary : *summaries)
2927
{
30-
for(const auto &iit_props : it->second->get_transition_props())
28+
for(const auto &iit_props : summary.second->get_transition_props())
3129
{
3230
switch(iit_props.second.get_applied_transition_type())
3331
{
@@ -36,8 +34,8 @@ void taint_search_for_rule_applications(
3634
case taint_transition_property_typet::APPLICATION_OF_SINK_RULE:
3735
case
3836
taint_transition_property_typet::CONDITIONAL_APPLICATION_OF_SINK_RULE:
39-
result[iit_props.second.get_rule_id()][as_string(it->first)].push_back(
40-
iit_props.first);
37+
result[iit_props.second.get_rule_id()][as_string(summary.first)]
38+
.push_back(iit_props.first);
4139
break;
4240
default:
4341
break;

src/util/json_map_serializer.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class json_map_serializert:public map_serializert<keyt, valuet>
135135
This function checks the existence on disc of each item in the map.
136136
137137
\*******************************************************************/
138-
virtual std::size_t size() override
138+
virtual std::size_t size() const override
139139
{
140140
return boost::size(keys());
141141
}
@@ -156,7 +156,7 @@ class json_map_serializert:public map_serializert<keyt, valuet>
156156
This function checks the existence on disc of each item in the map.
157157
158158
\*******************************************************************/
159-
virtual typename json_map_serializert::keys_ranget keys() override
159+
virtual typename json_map_serializert::keys_ranget keys() const override
160160
{
161161
// For a key to be in the set it must exist both in the index and on disc
162162
return index.left
@@ -183,7 +183,7 @@ class json_map_serializert:public map_serializert<keyt, valuet>
183183
Checks whether a given key exists in the map.
184184
185185
\*******************************************************************/
186-
virtual bool contains(const keyt &key) override
186+
virtual bool contains(const keyt &key) const override
187187
{
188188
return index_contains(key) && fileutl_file_exists(get_existing_path(key));
189189
}
@@ -202,7 +202,7 @@ class json_map_serializert:public map_serializert<keyt, valuet>
202202
Gets the value corresponding to a given key.
203203
204204
\*******************************************************************/
205-
virtual valuet at(const keyt &key) override
205+
virtual valuet at(const keyt &key) const override
206206
{
207207
if(!index_contains(key))
208208
throw std::out_of_range("Element not found in map");
@@ -322,12 +322,12 @@ class json_map_serializert:public map_serializert<keyt, valuet>
322322
}
323323

324324
private:
325-
bool index_contains(const keyt &key)
325+
bool index_contains(const keyt &key) const
326326
{
327327
return index.left.count(key) != 0;
328328
}
329329

330-
std::string get_existing_path(const keyt &key)
330+
std::string get_existing_path(const keyt &key) const
331331
{
332332
return get_path_for_filename(index.left.at(key));
333333
}
@@ -339,7 +339,7 @@ class json_map_serializert:public map_serializert<keyt, valuet>
339339
return uniqueness == 0 ? base : base + '_' + std::to_string(uniqueness);
340340
}
341341

342-
std::string get_path_for_filename(const std::string &file_name)
342+
std::string get_path_for_filename(const std::string &file_name) const
343343
{
344344
return concat_dir_file(base_folder, file_name + suffix);
345345
}

src/util/map_serializer.h

+21-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ template<typename keyt, typename valuet>
3131
class map_serializert
3232
{
3333
public:
34+
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
35+
typedef keyt key_type;
36+
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
37+
typedef valuet mapped_type;
38+
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
39+
typedef std::pair<const keyt, valuet> value_type;
40+
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
41+
typedef value_type & reference;
42+
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
43+
typedef const value_type & const_reference;
44+
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
45+
typedef value_type * pointer;
46+
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
47+
typedef const value_type * const_pointer;
48+
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
49+
typedef std::size_t size_type;
50+
3451
// The type of ranges of map keys
3552
typedef
3653
boost::any_range<
@@ -56,7 +73,7 @@ class map_serializert
5673
Returns the size of the map.
5774
5875
\*******************************************************************/
59-
virtual std::size_t size()=0;
76+
virtual size_type size() const=0;
6077

6178
/*******************************************************************\
6279
@@ -71,7 +88,7 @@ class map_serializert
7188
Returns all the keys in the map, which could be large.
7289
7390
\*******************************************************************/
74-
virtual keys_ranget keys()=0;
91+
virtual keys_ranget keys() const=0;
7592

7693
/*******************************************************************\
7794
@@ -87,7 +104,7 @@ class map_serializert
87104
Checks whether a given key exists in the map.
88105
89106
\*******************************************************************/
90-
virtual bool contains(const keyt &key)=0;
107+
virtual bool contains(const keyt &key) const=0;
91108

92109
/*******************************************************************\
93110
@@ -103,7 +120,7 @@ class map_serializert
103120
Gets the value corresponding to a given key.
104121
105122
\*******************************************************************/
106-
virtual valuet at(const keyt &key)=0;
123+
virtual valuet at(const keyt &key) const=0;
107124

108125
/*******************************************************************\
109126

0 commit comments

Comments
 (0)