Skip to content

Commit 506367a

Browse files
Refactor show-points-to-sets in value_set_dereference
Moves the display logic out of the main dereference function into one function to clean up the clutter, this makes it easier to see the logic of what the display does and what the actual function is supposed to do.
1 parent db23173 commit 506367a

File tree

1 file changed

+41
-49
lines changed

1 file changed

+41
-49
lines changed

src/pointer-analysis/value_set_dereference.cpp

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,42 @@ static bool should_use_local_definition_for(const exprt &expr)
6161
return false;
6262
}
6363

64+
static json_objectt value_set_dereference_stats_to_json(
65+
const exprt &pointer,
66+
const std::vector<exprt> &points_to_set,
67+
const std::vector<exprt> &retained_values,
68+
const exprt &value)
69+
{
70+
json_objectt json_result;
71+
json_result["Pointer"] = json_stringt{format_to_string(pointer)};
72+
json_result["PointsToSetSize"] =
73+
json_numbert{std::to_string(points_to_set.size())};
74+
75+
json_arrayt points_to_set_json;
76+
for(const auto &object : points_to_set)
77+
{
78+
points_to_set_json.push_back(json_stringt{format_to_string(object)});
79+
}
80+
81+
json_result["PointsToSet"] = points_to_set_json;
82+
83+
json_result["RetainedValuesSetSize"] =
84+
json_numbert{std::to_string(points_to_set.size())};
85+
86+
json_arrayt retained_values_set_json;
87+
for(auto &retained_value : retained_values)
88+
{
89+
retained_values_set_json.push_back(
90+
json_stringt{format_to_string(retained_value)});
91+
}
92+
93+
json_result["RetainedValuesSet"] = retained_values_set_json;
94+
95+
json_result["Value"] = json_stringt{format_to_string(value)};
96+
97+
return json_result;
98+
}
99+
64100
exprt value_set_dereferencet::dereference(
65101
const exprt &pointer,
66102
bool display_points_to_sets)
@@ -106,14 +142,6 @@ exprt value_set_dereferencet::dereference(
106142
// type of the object
107143
const typet &type=pointer.type().subtype();
108144

109-
json_objectt json_result;
110-
if(display_points_to_sets)
111-
{
112-
std::stringstream ss;
113-
ss << format(pointer);
114-
json_result["Pointer"] = json_stringt(ss.str());
115-
}
116-
117145
#ifdef DEBUG
118146
std::cout << "value_set_dereferencet::dereference pointer=" << format(pointer)
119147
<< '\n';
@@ -123,22 +151,6 @@ exprt value_set_dereferencet::dereference(
123151
const std::vector<exprt> points_to_set =
124152
dereference_callback.get_value_set(pointer);
125153

126-
if(display_points_to_sets)
127-
{
128-
json_result["PointsToSetSize"] =
129-
json_numbert(std::to_string(points_to_set.size()));
130-
131-
json_arrayt points_to_set_json;
132-
for(auto p : points_to_set)
133-
{
134-
std::stringstream ss;
135-
ss << format(p);
136-
points_to_set_json.push_back(json_stringt(ss.str()));
137-
}
138-
139-
json_result["PointsToSet"] = points_to_set_json;
140-
}
141-
142154
#ifdef DEBUG
143155
std::cout << "value_set_dereferencet::dereference points_to_set={";
144156
for(auto p : points_to_set)
@@ -167,22 +179,6 @@ exprt value_set_dereferencet::dereference(
167179
compare_against_pointer = fresh_binder.symbol_expr();
168180
}
169181

170-
if(display_points_to_sets)
171-
{
172-
json_result["RetainedValuesSetSize"] =
173-
json_numbert(std::to_string(points_to_set.size()));
174-
175-
json_arrayt retained_values_set_json;
176-
for(auto &value : retained_values)
177-
{
178-
std::stringstream ss;
179-
ss << format(value);
180-
retained_values_set_json.push_back(json_stringt(ss.str()));
181-
}
182-
183-
json_result["RetainedValuesSet"] = retained_values_set_json;
184-
}
185-
186182
#ifdef DEBUG
187183
std::cout << "value_set_dereferencet::dereference retained_values={";
188184
for(const auto &value : retained_values)
@@ -272,21 +268,17 @@ exprt value_set_dereferencet::dereference(
272268
if(compare_against_pointer != pointer)
273269
value = let_exprt(to_symbol_expr(compare_against_pointer), pointer, value);
274270

275-
if(display_points_to_sets)
276-
{
277-
std::stringstream ss;
278-
ss << format(value);
279-
json_result["Value"] = json_stringt(ss.str());
280-
281-
log.status() << json_result;
282-
}
283-
284271
#ifdef DEBUG
285272
std::cout << "value_set_derefencet::dereference value=" << format(value)
286273
<< '\n'
287274
<< std::flush;
288275
#endif
289276

277+
if(display_points_to_sets)
278+
{
279+
log.status() << value_set_dereference_stats_to_json(
280+
pointer, points_to_set, retained_values, value);
281+
}
290282
return value;
291283
}
292284

0 commit comments

Comments
 (0)