Skip to content

Commit cba7ba8

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#327 from diffblue/owen-jones-diffblue/clang-format-pointer-analysis
Run clang-format on src/pointer-analysis
2 parents 9c4ca28 + c31459d commit cba7ba8

8 files changed

+405
-360
lines changed

src/pointer-analysis/evs_pretty_printer.cpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,30 @@
77

88
std::string evs_pretty_printert::convert(const exprt &src)
99
{
10-
if(src.id()==ID_external_value_set)
10+
if(src.id() == ID_external_value_set)
1111
{
1212
std::ostringstream result;
1313
result << "EXT_VAL_SET(";
14-
const external_value_set_exprt &evs=to_external_value_set(src);
14+
const external_value_set_exprt &evs = to_external_value_set(src);
1515
result << top_pretty_printer->convert(evs.label());
1616
for(const access_path_entry_exprt &entry : evs.access_path_entries())
1717
result << ", " << top_pretty_printer->convert(entry);
1818
result << ")";
1919
if(evs.is_initializer())
2020
result << "<is-initializer>";
21-
result << " ["
22-
<< top_pretty_printer->convert(evs.type())
23-
<< ']';
21+
result << " [" << top_pretty_printer->convert(evs.type()) << ']';
2422
return result.str();
2523
}
26-
else if(src.id()==ID_access_path_entry)
24+
else if(src.id() == ID_access_path_entry)
2725
{
2826
std::ostringstream result;
29-
result << "{ " << src.get(ID_access_path_label) << ", " <<
30-
src.get(ID_access_path_function) << ", " <<
31-
src.get(ID_access_path_loc);
32-
const auto &decl_type=to_access_path_entry(src).declared_on_type();
33-
if(decl_type.id()==ID_struct)
34-
result << " (decl-on-type " << to_struct_type(decl_type).get_tag() << ") }";
27+
result << "{ " << src.get(ID_access_path_label) << ", "
28+
<< src.get(ID_access_path_function) << ", "
29+
<< src.get(ID_access_path_loc);
30+
const auto &decl_type = to_access_path_entry(src).declared_on_type();
31+
if(decl_type.id() == ID_struct)
32+
result << " (decl-on-type " << to_struct_type(decl_type).get_tag()
33+
<< ") }";
3534
return result.str();
3635
}
3736

@@ -40,10 +39,7 @@ std::string evs_pretty_printert::convert(const exprt &src)
4039

4140
void register_evs_pretty_printer()
4241
{
43-
register_global_pretty_printer(
44-
[](const namespacet &ns)
45-
{
46-
return std::unique_ptr<pretty_printert>(new evs_pretty_printert(ns));
47-
}
48-
);
42+
register_global_pretty_printer([](const namespacet &ns) {
43+
return std::unique_ptr<pretty_printert>(new evs_pretty_printert(ns));
44+
});
4945
}

src/pointer-analysis/evs_pretty_printer.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
#include <langapi/pretty_printer.h>
55
#include <util/namespace.h>
66

7-
class evs_pretty_printert:public pretty_printert
7+
class evs_pretty_printert : public pretty_printert
88
{
99
public:
10-
evs_pretty_printert(const namespacet &ns):
11-
ns(ns)
12-
{}
10+
evs_pretty_printert(const namespacet &ns) : ns(ns)
11+
{
12+
}
1313

1414
std::string convert(const exprt &) override;
15-
protected:
15+
16+
protected:
1617
typedef pretty_printert baset;
1718
const namespacet &ns;
1819
};

src/pointer-analysis/external_value_set_expr.h

+72-41
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,51 @@
1313
// was accessed using e.g. member-x--of-dereference (written
1414
// "->x" in C++, ".x" in Java) at function f location
1515
// (instruction offset) z.
16-
class access_path_entry_exprt:public exprt
16+
class access_path_entry_exprt : public exprt
1717
{
18-
public:
19-
access_path_entry_exprt():exprt(ID_access_path_entry) {}
18+
public:
19+
access_path_entry_exprt() : exprt(ID_access_path_entry)
20+
{
21+
}
22+
2023
access_path_entry_exprt(
2124
const irep_idt &label,
2225
const irep_idt &function,
2326
const irep_idt &loc,
2427
const typet &declared_on_type)
25-
:exprt(ID_access_path_entry)
28+
: exprt(ID_access_path_entry)
2629
{
2730
set_label(label);
2831
set(ID_access_path_function, function);
2932
set(ID_access_path_loc, loc);
3033
add(ID_declared_on_type, declared_on_type);
3134
}
3235

33-
irep_idt label() const { return get(ID_access_path_label); }
34-
void set_label(const irep_idt &i) { set(ID_access_path_label, i); }
35-
irep_idt function() const { return get(ID_access_path_function); }
36-
irep_idt loc() const { return get(ID_access_path_loc); }
36+
irep_idt label() const
37+
{
38+
return get(ID_access_path_label);
39+
}
40+
41+
void set_label(const irep_idt &i)
42+
{
43+
set(ID_access_path_label, i);
44+
}
45+
46+
irep_idt function() const
47+
{
48+
return get(ID_access_path_function);
49+
}
50+
51+
irep_idt loc() const
52+
{
53+
return get(ID_access_path_loc);
54+
}
55+
3756
const typet &declared_on_type() const
3857
{
3958
return static_cast<const typet &>(find(ID_declared_on_type));
4059
}
60+
4161
void drop_loc()
4262
{
4363
set(ID_access_path_function, "");
@@ -77,16 +97,16 @@ enum class external_value_set_typet
7797
// Represents an external unknown points-to set that can't be
7898
// directly referenced with a symbol, such as "arg1->x"
7999

80-
class external_value_set_exprt:public exprt
100+
class external_value_set_exprt : public exprt
81101
{
82-
public:
83-
external_value_set_exprt():exprt(ID_external_value_set)
102+
public:
103+
external_value_set_exprt() : exprt(ID_external_value_set)
84104
{
85105
// The default-initalised version of EVS doesn't represent anything sane;
86106
// the caller should set label() before using an instance constructed
87107
// this way.
88108
operands().resize(2);
89-
op0()=constant_exprt();
109+
op0() = constant_exprt();
90110
/// No need to initialise op1(). op1().operands() will hold the vector of
91111
/// access path entries.
92112
}
@@ -95,11 +115,11 @@ class external_value_set_exprt:public exprt
95115
const typet &type,
96116
const constant_exprt &_label,
97117
const external_value_set_typet mode,
98-
bool is_initializer):
99-
exprt(ID_external_value_set, type)
118+
bool is_initializer)
119+
: exprt(ID_external_value_set, type)
100120
{
101121
operands().resize(2);
102-
op0()=_label;
122+
op0() = _label;
103123
/// No need to initialise op1(). op1().operands() will hold the vector of
104124
/// access path entries.
105125
set(ID_lvsa_evs_type, std::to_string(static_cast<int>(mode)));
@@ -140,24 +160,31 @@ class external_value_set_exprt:public exprt
140160

141161
bool can_extend_to_imprecise() const
142162
{
143-
return
144-
get_external_value_set_type()==external_value_set_typet::ROOT_OBJECT ||
145-
get_external_value_set_type()==external_value_set_typet::PER_FIELD;
163+
const external_value_set_typet evs_type = get_external_value_set_type();
164+
return evs_type == external_value_set_typet::ROOT_OBJECT ||
165+
evs_type == external_value_set_typet::PER_FIELD;
146166
}
147167

148168
bool can_extend_to_precise() const
149169
{
150170
#ifdef DO_NOT_USE_PRECISE_EXTERNAL_VALUE_SETS
151171
return false;
152172
#else
153-
return
154-
get_external_value_set_type()==external_value_set_typet::ROOT_OBJECT ||
155-
get_external_value_set_type()==external_value_set_typet::PRECISE;
173+
const external_value_set_typet evs_type = get_external_value_set_type();
174+
return evs_type == external_value_set_typet::ROOT_OBJECT ||
175+
evs_type == external_value_set_typet::PRECISE;
156176
#endif
157177
}
158178

159-
constant_exprt &label() { return to_constant_expr(op0()); }
160-
const constant_exprt &label() const { return to_constant_expr(op0()); }
179+
constant_exprt &label()
180+
{
181+
return to_constant_expr(op0());
182+
}
183+
184+
const constant_exprt &label() const
185+
{
186+
return to_constant_expr(op0());
187+
}
161188

162189
typedef std::vector<access_path_entry_exprt> access_path_entriest;
163190

@@ -173,27 +200,30 @@ class external_value_set_exprt:public exprt
173200

174201
std::string type_to_basename(const typet &type) const
175202
{
176-
if(type.id()!=ID_struct)
203+
if(type.id() != ID_struct)
177204
return "";
178-
std::string tag=id2string(to_struct_type(type).get_tag());
205+
std::string tag = id2string(to_struct_type(type).get_tag());
179206
for(auto &c : tag)
180-
if(c=='.')
181-
c='_';
182-
return '_'+tag;
207+
{
208+
if(c == '.')
209+
c = '_';
210+
}
211+
return '_' + tag;
183212
}
184213

185214
std::string get_access_path_basename(const typet &declared_on_type) const
186215
{
187216
switch(get_external_value_set_type())
188217
{
189218
case external_value_set_typet::PER_FIELD:
190-
return PER_FIELD_EVS_PREFIX+type_to_basename(declared_on_type);
219+
return PER_FIELD_EVS_PREFIX + type_to_basename(declared_on_type);
191220
case external_value_set_typet::PRECISE:
192221
return id2string(label().get_value());
193222
default:
194223
UNREACHABLE;
195224
}
196225
}
226+
197227
std::string get_access_path_suffix() const
198228
{
199229
switch(get_external_value_set_type())
@@ -227,9 +257,10 @@ class external_value_set_exprt:public exprt
227257
/// `external_value_set_typet::PRECISE`. In this case we should delete the
228258
/// external value set.
229259
bool extend_access_path(
230-
const access_path_entry_exprt &newentry, external_value_set_typet evs_type)
260+
const access_path_entry_exprt &newentry,
261+
external_value_set_typet evs_type)
231262
{
232-
PRECONDITION(evs_type!=external_value_set_typet::ROOT_OBJECT);
263+
PRECONDITION(evs_type != external_value_set_typet::ROOT_OBJECT);
233264
set_external_value_set_type(evs_type);
234265
set_non_initializer();
235266

@@ -238,28 +269,28 @@ class external_value_set_exprt:public exprt
238269
case external_value_set_typet::PER_FIELD:
239270
{
240271
// Any attempt to extend a path yields <all-externals>->fieldname
241-
label()=constant_exprt(PER_FIELD_EVS_PREFIX, string_typet());
242-
access_path_entry_exprt toadd=newentry;
272+
label() = constant_exprt(PER_FIELD_EVS_PREFIX, string_typet());
273+
access_path_entry_exprt toadd = newentry;
243274
// In this case entries created at different
244275
// locations are not distinguished:
245276
toadd.drop_loc();
246277
if(access_path_entries().empty())
247278
access_path_entries().push_back(toadd);
248279
else
249-
access_path_entries().back()=toadd;
280+
access_path_entries().back() = toadd;
250281
break;
251282
}
252283
case external_value_set_typet::PRECISE:
253284
{
254285
/// Check if there is a loop, i.e. there is already an access path
255286
/// entry with the same label and loc as the one we are adding
256287
for(const auto &entry : access_path_entries())
257-
if(entry==newentry)
288+
if(entry == newentry)
258289
return true;
259290

260291
if(access_path_entries().empty())
261-
label()=constant_exprt(
262-
PRECISE_EVS_PREFIX+id2string(label().get_value()), string_typet());
292+
label() = constant_exprt(
293+
PRECISE_EVS_PREFIX + id2string(label().get_value()), string_typet());
263294

264295
access_path_entries().push_back(newentry);
265296
break;
@@ -289,7 +320,7 @@ class external_value_set_exprt:public exprt
289320
return *this;
290321
else
291322
{
292-
external_value_set_exprt copy=*this;
323+
external_value_set_exprt copy = *this;
293324
copy.set_non_initializer();
294325
return copy;
295326
}
@@ -323,10 +354,10 @@ inline const external_value_set_exprt &to_external_value_set(const exprt &e)
323354
return static_cast<const external_value_set_exprt &>(e);
324355
}
325356

326-
template<>
327-
inline bool can_cast_expr<external_value_set_exprt >(const exprt &base)
357+
template <>
358+
inline bool can_cast_expr<external_value_set_exprt>(const exprt &base)
328359
{
329-
return base.id()==ID_external_value_set;
360+
return base.id() == ID_external_value_set;
330361
}
331362

332363
#endif

0 commit comments

Comments
 (0)