Skip to content

Commit 61f747d

Browse files
committed
Use member operators instead of global-scope friends
1 parent 839e84f commit 61f747d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+637
-713
lines changed

src/analyses/local_bitvector_analysis.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,14 @@ class local_bitvector_analysist
167167
}
168168

169169
void print(std::ostream &) const;
170-
};
171-
172-
friend std::ostream & operator << (std::ostream &out, const flagst f)
173-
{
174-
f.print(out);
175-
return out;
176-
}
177170

178-
inline friend flagst operator|(const flagst f1, const flagst f2)
179-
{
180-
flagst result=f1;
181-
result.bits|=f2.bits;
182-
return result;
183-
}
171+
inline flagst operator|(const flagst other) const
172+
{
173+
flagst result(*this);
174+
result.bits|=other.bits;
175+
return result;
176+
}
177+
};
184178

185179
flagst get(
186180
const goto_programt::const_targett t,
@@ -222,4 +216,12 @@ class local_bitvector_analysist
222216
bool is_tracked(const irep_idt &identifier);
223217
};
224218

219+
inline std::ostream &operator<<(
220+
std::ostream &out,
221+
const local_bitvector_analysist::flagst &flags)
222+
{
223+
flags.print(out);
224+
return out;
225+
}
226+
225227
#endif // CPROVER_ANALYSES_LOCAL_BITVECTOR_ANALYSIS_H

src/ansi-c/c_qualifiers.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,21 @@ class c_qualifierst
6868
// is_transparent_union isn't checked
6969
}
7070

71-
friend bool operator == (
72-
const c_qualifierst &a,
73-
const c_qualifierst &b)
71+
bool operator==(const c_qualifierst &other) const
7472
{
75-
return a.is_constant==b.is_constant &&
76-
a.is_volatile==b.is_volatile &&
77-
a.is_restricted==b.is_restricted &&
78-
a.is_atomic==b.is_atomic &&
79-
a.is_ptr32==b.is_ptr32 &&
80-
a.is_ptr64==b.is_ptr64 &&
81-
a.is_transparent_union==b.is_transparent_union &&
82-
a.is_noreturn==b.is_noreturn;
73+
return is_constant==other.is_constant &&
74+
is_volatile==other.is_volatile &&
75+
is_restricted==other.is_restricted &&
76+
is_atomic==other.is_atomic &&
77+
is_ptr32==other.is_ptr32 &&
78+
is_ptr64==other.is_ptr64 &&
79+
is_transparent_union==other.is_transparent_union &&
80+
is_noreturn==other.is_noreturn;
8381
}
8482

85-
friend bool operator != (
86-
const c_qualifierst &a,
87-
const c_qualifierst &b)
83+
bool operator!=(const c_qualifierst &other) const
8884
{
89-
return !(a==b);
85+
return !(*this==other);
9086
}
9187

9288
c_qualifierst &operator += (
@@ -103,10 +99,10 @@ class c_qualifierst
10399
return *this;
104100
}
105101

106-
friend unsigned count(const c_qualifierst &q)
102+
unsigned count() const
107103
{
108-
return q.is_constant+q.is_volatile+q.is_restricted+q.is_atomic+
109-
q.is_ptr32+q.is_ptr64+q.is_noreturn;
104+
return is_constant+is_volatile+is_restricted+is_atomic+
105+
is_ptr32+is_ptr64+is_noreturn;
110106
}
111107
};
112108

src/ansi-c/c_storage_spec.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,42 +49,36 @@ class c_storage_spect
4949
irep_idt asm_label;
5050
irep_idt section;
5151

52-
friend bool operator == (
53-
const c_storage_spect &a,
54-
const c_storage_spect &b)
52+
bool operator==(const c_storage_spect &other) const
5553
{
56-
return a.is_typedef==b.is_typedef &&
57-
a.is_extern==b.is_extern &&
58-
a.is_static==b.is_static &&
59-
a.is_register==b.is_register &&
60-
a.is_thread_local==b.is_thread_local &&
61-
a.is_inline==b.is_inline &&
62-
a.is_weak==b.is_weak &&
63-
a.alias==b.alias &&
64-
a.asm_label==b.asm_label &&
65-
a.section==b.section;
54+
return is_typedef==other.is_typedef &&
55+
is_extern==other.is_extern &&
56+
is_static==other.is_static &&
57+
is_register==other.is_register &&
58+
is_thread_local==other.is_thread_local &&
59+
is_inline==other.is_inline &&
60+
is_weak==other.is_weak &&
61+
alias==other.alias &&
62+
asm_label==other.asm_label &&
63+
section==other.section;
6664
}
6765

68-
friend bool operator != (
69-
const c_storage_spect &a,
70-
const c_storage_spect &b)
66+
bool operator!=(const c_storage_spect &other) const
7167
{
72-
return !(a==b);
68+
return !(*this==other);
7369
}
7470

75-
friend c_storage_spect &operator |= (
76-
c_storage_spect &a,
77-
const c_storage_spect &b)
71+
c_storage_spect &operator|=(const c_storage_spect &other)
7872
{
79-
a.is_typedef |=b.is_typedef;
80-
a.is_extern |=b.is_extern;
81-
a.is_static |=b.is_static;
82-
a.is_register |=b.is_register;
83-
a.is_inline |=b.is_inline;
84-
a.is_thread_local |=b.is_thread_local;
73+
is_typedef |=other.is_typedef;
74+
is_extern |=other.is_extern;
75+
is_static |=other.is_static;
76+
is_register |=other.is_register;
77+
is_inline |=other.is_inline;
78+
is_thread_local |=other.is_thread_local;
8579
// attributes belong to the declarator, don't replace them
8680

87-
return a;
81+
return *this;
8882
}
8983

9084
void read(const typet &type);

src/ansi-c/c_typecast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ void c_typecastt::implicit_typecast_followed(
620620
// build union constructor
621621
exprt union_expr(ID_union, orig_dest_type);
622622
union_expr.move_to_operands(expr);
623-
if(!full_eq(src_type, src_type_no_const))
623+
if(!src_type.full_eq(src_type_no_const))
624624
do_typecast(union_expr.op0(), src_type_no_const);
625625
union_expr.set(ID_component_name, comp.get_name());
626626
expr=union_expr;

src/ansi-c/string_constant.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ class string_constantt:public exprt
1818
string_constantt();
1919
explicit string_constantt(const irep_idt &value);
2020

21-
friend inline const string_constantt &to_string_constant(const exprt &expr)
22-
{
23-
assert(expr.id()==ID_string_constant);
24-
return static_cast<const string_constantt &>(expr);
25-
}
26-
27-
friend inline string_constantt &to_string_constant(exprt &expr)
28-
{
29-
assert(expr.id()==ID_string_constant);
30-
return static_cast<string_constantt &>(expr);
31-
}
32-
3321
void set_value(const irep_idt &value);
3422

3523
inline const irep_idt &get_value() const
@@ -41,7 +29,16 @@ class string_constantt:public exprt
4129
bool from_array_expr(const array_exprt &);
4230
};
4331

44-
const string_constantt &to_string_constant(const exprt &expr);
45-
string_constantt &to_string_constant(exprt &expr);
32+
inline const string_constantt &to_string_constant(const exprt &expr)
33+
{
34+
assert(expr.id()==ID_string_constant);
35+
return static_cast<const string_constantt &>(expr);
36+
}
37+
38+
inline string_constantt &to_string_constant(exprt &expr)
39+
{
40+
assert(expr.id()==ID_string_constant);
41+
return static_cast<string_constantt &>(expr);
42+
}
4643

4744
#endif // CPROVER_ANSI_C_STRING_CONSTANT_H

src/cpp/cpp_typecheck_resolve.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,12 @@ class cpp_typecheck_resolvet
146146
id(_id)
147147
{
148148
}
149-
};
150-
151-
inline friend bool operator < (const matcht &m1, const matcht &m2)
152-
{
153-
return m1.cost<m2.cost;
154-
}
155149

150+
inline bool operator<(const matcht &other) const
151+
{
152+
return cost<other.cost;
153+
}
154+
};
156155
};
157156

158157
#endif // CPROVER_CPP_CPP_TYPECHECK_RESOLVE_H

src/goto-cc/xml_binaries/xml_irep_hashing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class xml_irep_convertt {
4242
{
4343
bool operator()(const irept &l, const irept &r) const
4444
{
45-
return full_eq(l,r);
45+
return l.full_eq(l,r);
4646
}
4747
};
4848

src/goto-instrument/call_sequences.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ class check_call_sequencet
173173
{
174174
goto_functionst::function_mapt::const_iterator f;
175175
goto_programt::const_targett return_address;
176-
};
177176

178-
friend bool operator==(const call_stack_entryt &e1,
179-
const call_stack_entryt &e2)
180-
{
181-
return e1.f->first==e2.f->first &&
182-
e1.return_address==e2.return_address;
183-
}
177+
bool operator==(const call_stack_entryt &other) const
178+
{
179+
return
180+
f->first==other.f->first &&
181+
return_address==other.return_address;
182+
}
183+
};
184184

185185
struct statet
186186
{
@@ -189,12 +189,13 @@ class check_call_sequencet
189189
std::vector<call_stack_entryt> call_stack;
190190
unsigned index;
191191

192-
friend bool operator==(const statet &s1, const statet &s2)
192+
bool operator==(const statet &other) const
193193
{
194-
return s1.f->first==s2.f->first &&
195-
s1.pc==s2.pc &&
196-
s1.call_stack==s2.call_stack &&
197-
s1.index==s2.index;
194+
return
195+
f->first==other.f->first &&
196+
pc==other.pc &&
197+
call_stack==other.call_stack &&
198+
index==other.index;
198199
}
199200
};
200201

src/goto-instrument/object_id.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,26 @@ class object_idt
3030
id=identifier;
3131
}
3232

33-
friend std::ostream &operator << (std::ostream &out, const object_idt &x)
33+
inline bool operator<(const object_idt &other) const
3434
{
35-
return out << x.id;
35+
return id < other.id;
3636
}
3737

38-
friend inline bool operator < (const object_idt &a, const object_idt &b)
38+
const irep_idt &get_id() const
3939
{
40-
return a.id < b.id;
40+
return id;
4141
}
4242

4343
protected:
4444
irep_idt id;
4545
};
4646

47-
inline std::ostream &operator << (std::ostream &, const object_idt &);
48-
inline bool operator < (const object_idt &a, const object_idt &b);
47+
inline std::ostream &operator<<(
48+
std::ostream &out,
49+
const object_idt &object_id)
50+
{
51+
return out << object_id.get_id();
52+
}
4953

5054
typedef std::set<object_idt> object_id_sett;
5155

src/goto-instrument/points_to.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ class points_tot
4949

5050
void output(std::ostream &out) const;
5151

52-
inline friend std::ostream &operator << (
53-
std::ostream &out, const points_tot &points_to)
54-
{
55-
points_to.output(out);
56-
return out;
57-
}
58-
5952
protected:
6053
typedef cfg_baset<empty_cfg_nodet> cfgt;
6154
cfgt cfg;
@@ -69,6 +62,12 @@ class points_tot
6962
const object_id_sett empty_set;
7063
};
7164

72-
std::ostream &operator << (std::ostream &, const points_tot &);
65+
inline std::ostream &operator<<(
66+
std::ostream &out,
67+
const points_tot &points_to)
68+
{
69+
points_to.output(out);
70+
return out;
71+
}
7372

7473
#endif // CPROVER_GOTO_INSTRUMENT_POINTS_TO_H

src/goto-instrument/wmm/abstract_event.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ class abstract_eventt:public graph_nodet<empty_edget>
9191
inline bool is_fence() const {
9292
return operation==Fence || operation==Lwfence || operation==ASMfence;}
9393

94-
friend std::ostream& operator<<(std::ostream& s, const abstract_eventt& e)
95-
{
96-
return s << e.get_operation() << e.variable;
97-
}
98-
9994
/* checks the safety of the pair locally (i.e., w/o taking fences
10095
or dependencies into account -- use is_unsafe on the whole
10196
critical cycle for this) */
@@ -152,4 +147,12 @@ class abstract_eventt:public graph_nodet<empty_edget>
152147
return value;
153148
}
154149
};
150+
151+
inline std::ostream& operator<<(
152+
std::ostream& s,
153+
const abstract_eventt &e)
154+
{
155+
return s << e.get_operation() << e.variable;
156+
}
157+
155158
#endif // CPROVER_GOTO_INSTRUMENT_WMM_ABSTRACT_EVENT_H

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,26 @@ class patternt
4141
}
4242

4343
// match with '?'
44-
friend bool operator==(const irep_idt &what, const patternt &pattern)
44+
bool operator==(const irep_idt &what) const
4545
{
4646
for(std::size_t i=0; i<what.size(); i++)
47-
if(pattern.p[i]==0)
47+
if(p[i]==0)
4848
return false;
49-
else if(pattern.p[i]!='?' && pattern.p[i]!=what[i])
49+
else if(p[i]!='?' && p[i]!=what[i])
5050
return false;
5151

52-
return pattern.p[what.size()]==0;
52+
return p[what.size()]==0;
5353
}
5454

5555
protected:
5656
const char *p;
5757
};
5858

59+
static bool operator==(const irep_idt &what, const patternt &pattern)
60+
{
61+
return pattern==what;
62+
}
63+
5964
const size_t SLOTS_PER_INTEGER(1u);
6065
const size_t INTEGER_WIDTH(64u);
6166
static size_t count_slots(

src/java_bytecode/java_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ exprt::operandst java_build_arguments(
220220
to_code_type(function.type).return_type().id()==ID_empty &&
221221
(!to_code_type(function.type).has_this()) &&
222222
parameters.size()==1 &&
223-
full_eq(parameters[0].type(), string_array_type);
223+
parameters[0].type().full_eq(string_array_type);
224224
is_main=(named_main && has_correct_type);
225225
}
226226

0 commit comments

Comments
 (0)