Skip to content

Commit b2456ed

Browse files
authored
Merge pull request #3416 from tautschnig/vs-shadow-cpp
Avoid shadowing of variables (several instances, part 2) [blocks: #2310]
2 parents 3dd4be0 + 2d87022 commit b2456ed

11 files changed

+90
-96
lines changed

src/cpp/cpp_is_pod.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ bool cpp_typecheckt::cpp_is_pod(const typet &type) const
4949
if(c.get_bool(ID_is_virtual))
5050
return false;
5151

52-
const typet &return_type=to_code_type(sub_type).return_type();
52+
const typet &comp_return_type = to_code_type(sub_type).return_type();
5353

54-
if(return_type.id()==ID_constructor ||
55-
return_type.id()==ID_destructor)
54+
if(
55+
comp_return_type.id() == ID_constructor ||
56+
comp_return_type.id() == ID_destructor)
57+
{
5658
return false;
59+
}
5760
}
5861
else if(c.get(ID_access) != ID_public && !c.get_bool(ID_is_static))
5962
return false;

src/cpp/cpp_scope.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,22 @@ std::ostream &operator << (std::ostream &out, cpp_scopet::lookup_kindt kind)
2727
}
2828

2929
void cpp_scopet::lookup_rec(
30-
const irep_idt &base_name,
30+
const irep_idt &base_name_to_lookup,
3131
lookup_kindt kind,
3232
id_sett &id_set)
3333
{
34-
cpp_id_mapt::iterator
35-
lower_it=sub.lower_bound(base_name);
34+
cpp_id_mapt::iterator lower_it = sub.lower_bound(base_name_to_lookup);
3635

3736
if(lower_it!=sub.end())
3837
{
39-
cpp_id_mapt::iterator
40-
upper_it=sub.upper_bound(base_name);
38+
cpp_id_mapt::iterator upper_it = sub.upper_bound(base_name_to_lookup);
4139

4240
for(cpp_id_mapt::iterator n_it=lower_it;
4341
n_it!=upper_it; n_it++)
4442
id_set.insert(&n_it->second);
4543
}
4644

47-
if(this->base_name==base_name)
45+
if(base_name == base_name_to_lookup)
4846
id_set.insert(this);
4947

5048
if(kind==SCOPE_ONLY)
@@ -57,7 +55,7 @@ void cpp_scopet::lookup_rec(
5755

5856
// Recursive call.
5957
// Note the different kind!
60-
other_scope.lookup_rec(base_name, QUALIFIED, id_set);
58+
other_scope.lookup_rec(base_name_to_lookup, QUALIFIED, id_set);
6159
}
6260

6361
if(!id_set.empty())
@@ -70,7 +68,7 @@ void cpp_scopet::lookup_rec(
7068

7169
// Recursive call.
7270
// Note the different kind!
73-
other_scope.lookup_rec(base_name, QUALIFIED, id_set);
71+
other_scope.lookup_rec(base_name_to_lookup, QUALIFIED, id_set);
7472
}
7573

7674
if(kind==QUALIFIED)
@@ -81,44 +79,41 @@ void cpp_scopet::lookup_rec(
8179

8280
// ask parent, recursive call
8381
if(!is_root_scope())
84-
get_parent().lookup_rec(base_name, kind, id_set);
82+
get_parent().lookup_rec(base_name_to_lookup, kind, id_set);
8583
}
8684

8785
void cpp_scopet::lookup_rec(
88-
const irep_idt &base_name,
86+
const irep_idt &base_name_to_lookup,
8987
lookup_kindt kind,
90-
cpp_idt::id_classt id_class,
88+
cpp_idt::id_classt identifier_class,
9189
id_sett &id_set)
9290
{
9391
// we have a hack to do full search in case we
9492
// are looking for templates!
9593

9694
#if 0
97-
std::cout << "B: " << base_name << '\n';
95+
std::cout << "B: " << base_name_to_lookup << '\n';
9896
std::cout << "K: " << kind << '\n';
99-
std::cout << "I: " << id_class << '\n';
100-
std::cout << "THIS: " << this->base_name << " " << this->id_class
97+
std::cout << "I: " << identifier_class << '\n';
98+
std::cout << "THIS: " << base_name << " " << identifier_class
10199
<< " " << this->identifier << '\n';
102100
#endif
103101

104-
cpp_id_mapt::iterator
105-
lower_it=sub.lower_bound(base_name);
102+
cpp_id_mapt::iterator lower_it = sub.lower_bound(base_name_to_lookup);
106103

107104
if(lower_it!=sub.end())
108105
{
109-
cpp_id_mapt::iterator
110-
upper_it=sub.upper_bound(base_name);
106+
cpp_id_mapt::iterator upper_it = sub.upper_bound(base_name_to_lookup);
111107

112108
for(cpp_id_mapt::iterator n_it=lower_it;
113109
n_it!=upper_it; n_it++)
114110
{
115-
if(n_it->second.id_class == id_class)
111+
if(n_it->second.id_class == identifier_class)
116112
id_set.insert(&n_it->second);
117113
}
118114
}
119115

120-
if(this->base_name == base_name &&
121-
this->id_class == id_class)
116+
if(base_name == base_name_to_lookup && id_class == identifier_class)
122117
id_set.insert(this);
123118

124119
if(kind==SCOPE_ONLY)
@@ -131,10 +126,11 @@ void cpp_scopet::lookup_rec(
131126

132127
// Recursive call.
133128
// Note the different kind!
134-
other_scope.lookup_rec(base_name, QUALIFIED, id_class, id_set);
129+
other_scope.lookup_rec(
130+
base_name_to_lookup, QUALIFIED, identifier_class, id_set);
135131
}
136132

137-
if(!id_set.empty() && id_class != id_classt::TEMPLATE)
133+
if(!id_set.empty() && identifier_class != id_classt::TEMPLATE)
138134
return; // done, upwards scopes are hidden
139135

140136
// secondary scopes
@@ -144,44 +140,48 @@ void cpp_scopet::lookup_rec(
144140

145141
// Recursive call.
146142
// Note the different kind!
147-
other_scope.lookup_rec(base_name, QUALIFIED, id_class, id_set);
143+
other_scope.lookup_rec(
144+
base_name_to_lookup, QUALIFIED, identifier_class, id_set);
148145
}
149146

150147
if(kind==QUALIFIED)
151148
return; // done
152149

153-
if(!id_set.empty() &&
154-
id_class!=id_classt::TEMPLATE) return; // done, upwards scopes are hidden
150+
if(!id_set.empty() && identifier_class != id_classt::TEMPLATE)
151+
return; // done, upwards scopes are hidden
155152

156153
// ask parent, recursive call
157154
if(!is_root_scope())
158-
get_parent().lookup_rec(base_name, kind, id_class, id_set);
155+
get_parent().lookup_rec(
156+
base_name_to_lookup, kind, identifier_class, id_set);
159157
}
160158

161159
cpp_scopet::id_sett cpp_scopet::lookup_identifier(
162-
const irep_idt &identifier,
163-
cpp_idt::id_classt id_class)
160+
const irep_idt &id,
161+
cpp_idt::id_classt identifier_class)
164162
{
165163
id_sett id_set;
166164

167165
for(cpp_id_mapt::iterator n_it=sub.begin();
168166
n_it!=sub.end(); n_it++)
169167
{
170-
if(n_it->second.identifier == identifier
171-
&& n_it->second.id_class == id_class)
172-
id_set.insert(&n_it->second);
168+
if(
169+
n_it->second.identifier == id &&
170+
n_it->second.id_class == identifier_class)
171+
{
172+
id_set.insert(&n_it->second);
173+
}
173174
}
174175

175-
if(this->identifier == identifier
176-
&& this->id_class == id_class)
176+
if(identifier == id && id_class == identifier_class)
177177
id_set.insert(this);
178178

179179
#if 0
180180
for(std::size_t i=0; i<parents_size(); i++)
181181
{
182182
cpp_idt &parent= get_parent(i);
183-
if(parent.identifier == identifier
184-
&& parent.id_class == id_class)
183+
if(parent.identifier == id
184+
&& parent.id_class == identifier_class)
185185
id_set.insert(&parent);
186186
}
187187
#endif
@@ -200,7 +200,7 @@ cpp_scopet &cpp_scopet::new_scope(const irep_idt &new_scope_name)
200200
return (cpp_scopet &)id;
201201
}
202202

203-
bool cpp_scopet::contains(const irep_idt &base_name)
203+
bool cpp_scopet::contains(const irep_idt &base_name_to_lookup)
204204
{
205-
return !lookup(base_name, SCOPE_ONLY).empty();
205+
return !lookup(base_name_to_lookup, SCOPE_ONLY).empty();
206206
}

src/cpp/cpp_scope.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ class cpp_scopet:public cpp_idt
2929

3030
enum lookup_kindt { SCOPE_ONLY, QUALIFIED, RECURSIVE };
3131

32-
id_sett lookup(const irep_idt &base_name, lookup_kindt kind)
32+
id_sett lookup(const irep_idt &base_name_to_lookup, lookup_kindt kind)
3333
{
3434
id_sett result;
35-
lookup_rec(base_name, kind, result);
35+
lookup_rec(base_name_to_lookup, kind, result);
3636
return result;
3737
}
3838

3939
id_sett lookup(
40-
const irep_idt &base_name,
40+
const irep_idt &base_name_to_lookup,
4141
lookup_kindt kind,
42-
cpp_idt::id_classt id_class)
42+
cpp_idt::id_classt identifier_class)
4343
{
4444
id_sett result;
45-
lookup_rec(base_name, kind, id_class, result);
45+
lookup_rec(base_name_to_lookup, kind, identifier_class, result);
4646
return result;
4747
}
4848

4949
id_sett
50-
lookup_identifier(const irep_idt &identifier, cpp_idt::id_classt id_class);
50+
lookup_identifier(const irep_idt &id, cpp_idt::id_classt identifier_class);
5151

5252
cpp_idt &insert(const irep_idt &_base_name)
5353
{
@@ -72,7 +72,7 @@ class cpp_scopet:public cpp_idt
7272
return it->second;
7373
}
7474

75-
bool contains(const irep_idt &base_name);
75+
bool contains(const irep_idt &base_name_to_lookup);
7676

7777
bool is_root_scope() const
7878
{

src/cpp/cpp_typecheck_code.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@ void cpp_typecheckt::typecheck_try_catch(codet &code)
6060
else
6161
{
6262
// This is (one of) the catch clauses.
63-
codet &code = to_code_block(to_code(op));
63+
code_blockt &catch_block = to_code_block(to_code(op));
6464

6565
// look at the catch operand
66-
assert(!code.operands().empty());
66+
auto &statements = catch_block.statements();
67+
PRECONDITION(!statements.empty());
6768

68-
if(to_code(code.op0()).get_statement()==ID_ellipsis)
69+
if(statements.front().get_statement() == ID_ellipsis)
6970
{
70-
code.operands().erase(code.operands().begin());
71+
statements.erase(statements.begin());
7172

7273
// do body
73-
typecheck_code(code);
74+
typecheck_code(catch_block);
7475
}
7576
else
7677
{
7778
// turn references into non-references
7879
{
79-
assert(to_code(code.op0()).get_statement()==ID_decl);
80-
cpp_declarationt &cpp_declaration=
81-
to_cpp_declaration(to_code_decl(to_code(code.op0())).symbol());
80+
code_declt &decl = to_code_decl(statements.front());
81+
cpp_declarationt &cpp_declaration = to_cpp_declaration(decl.symbol());
8282

8383
assert(cpp_declaration.declarators().size()==1);
8484
cpp_declaratort &declarator=cpp_declaration.declarators().front();
@@ -88,16 +88,16 @@ void cpp_typecheckt::typecheck_try_catch(codet &code)
8888
}
8989

9090
// typecheck the body
91-
typecheck_code(code);
91+
typecheck_code(catch_block);
9292

9393
// the declaration is now in a decl_block
94-
95-
assert(!code.operands().empty());
96-
assert(to_code(code.op0()).get_statement()==ID_decl_block);
94+
CHECK_RETURN(!catch_block.statements().empty());
95+
CHECK_RETURN(
96+
catch_block.statements().front().get_statement() == ID_decl_block);
9797

9898
// get the declaration
99-
const code_declt &code_decl=
100-
to_code_decl(to_code(code.op0().op0()));
99+
const code_declt &code_decl =
100+
to_code_decl(to_code(catch_block.statements().front().op0()));
101101

102102
// get the type
103103
const typet &type = code_decl.symbol().type();
@@ -267,18 +267,18 @@ void cpp_typecheckt::typecheck_member_initializer(codet &code)
267267
{
268268
// maybe the name of the member collides with a parameter of the
269269
// constructor
270-
symbol_expr.make_nil();
271-
cpp_typecheck_fargst fargs;
272270
exprt dereference(
273271
ID_dereference, cpp_scopes.current_scope().this_expr.type().subtype());
274272
dereference.copy_to_operands(cpp_scopes.current_scope().this_expr);
275-
fargs.add_object(dereference);
273+
cpp_typecheck_fargst deref_fargs;
274+
deref_fargs.add_object(dereference);
276275

277276
{
278277
cpp_save_scopet cpp_saved_scope(cpp_scopes);
279278
cpp_scopes.go_to(
280279
*(cpp_scopes.id_map[cpp_scopes.current_scope().class_identifier]));
281-
symbol_expr=resolve(member, cpp_typecheck_resolvet::wantt::VAR, fargs);
280+
symbol_expr =
281+
resolve(member, cpp_typecheck_resolvet::wantt::VAR, deref_fargs);
282282
}
283283

284284
if(

0 commit comments

Comments
 (0)