Skip to content

Commit c1304cd

Browse files
committed
Cleanup of operands() accesses
Use iterators instead of indexed access. This may re-enable std::list support (for exprt::operandst) if taken further.
1 parent 2ff33ef commit c1304cd

12 files changed

+80
-66
lines changed

src/cpp/cpp_template_args.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_CPP_CPP_TEMPLATE_ARGS_H
1010
#define CPROVER_CPP_CPP_TEMPLATE_ARGS_H
1111

12-
#include <util/irep.h>
12+
#include <util/expr.h>
1313

1414
// A data structures for template arguments, i.e.,
1515
// a sequence of types/expressions of the form <E1, T2, ...>.
@@ -22,7 +22,7 @@ class cpp_template_args_baset:public irept
2222
{
2323
}
2424

25-
typedef std::vector<exprt> argumentst;
25+
typedef exprt::operandst argumentst;
2626

2727
argumentst &arguments()
2828
{

src/cpp/cpp_typecheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void cpp_typecheckt::do_not_typechecked()
343343
}
344344
else if(symbol.value.operands().size()==1)
345345
{
346-
exprt tmp = symbol.value.operands()[0];
346+
exprt tmp = symbol.value.op0();
347347
symbol.value.swap(tmp);
348348
convert_function(symbol);
349349
cont=true;

src/cpp/cpp_typecheck_expr.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -2577,28 +2577,31 @@ void cpp_typecheckt::typecheck_function_call_arguments(
25772577
}
25782578
}
25792579

2580-
for(std::size_t i=0; i<parameters.size(); i++)
2580+
exprt::operandst::iterator arg_it=expr.arguments().begin();
2581+
for(const auto &parameter : parameters)
25812582
{
2582-
if(parameters[i].get_bool("#call_by_value"))
2583+
if(parameter.get_bool("#call_by_value"))
25832584
{
2584-
assert(is_reference(parameters[i].type()));
2585+
assert(is_reference(parameter.type()));
25852586

2586-
if(expr.arguments()[i].id()!=ID_temporary_object)
2587+
if(arg_it->id()!=ID_temporary_object)
25872588
{
25882589
// create a temporary for the parameter
25892590

25902591
exprt arg("already_typechecked");
2591-
arg.copy_to_operands(expr.arguments()[i]);
2592+
arg.copy_to_operands(*arg_it);
25922593

25932594
exprt temporary;
2594-
new_temporary(expr.arguments()[i].source_location(),
2595-
parameters[i].type().subtype(),
2596-
arg,
2597-
temporary);
2598-
expr.arguments()[i].swap(temporary);
2595+
new_temporary(
2596+
arg_it->source_location(),
2597+
parameter.type().subtype(),
2598+
arg,
2599+
temporary);
2600+
arg_it->swap(temporary);
25992601
}
2600-
26012602
}
2603+
2604+
++arg_it;
26022605
}
26032606

26042607
c_typecheck_baset::typecheck_function_call_arguments(expr);

src/cpp/cpp_typecheck_fargs.cpp

+18-17
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool cpp_typecheck_fargst::match(
8383
{
8484
distance=0;
8585

86-
exprt::operandst ops = operands;
86+
exprt::operandst ops=operands;
8787
const code_typet::parameterst &parameters=code_type.parameters();
8888

8989
if(parameters.size()>ops.size())
@@ -109,7 +109,8 @@ bool cpp_typecheck_fargst::match(
109109
return false;
110110
}
111111

112-
for(std::size_t i=0; i<ops.size(); i++)
112+
exprt::operandst::iterator it=ops.begin();
113+
for(const auto &parameter : parameters)
113114
{
114115
// read
115116
// http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/topic/com.ibm.xlcpp8a.doc/language/ref/implicit_conversion_sequences.htm
@@ -119,16 +120,9 @@ bool cpp_typecheck_fargst::match(
119120
// * User-defined conversion sequences
120121
// * Ellipsis conversion sequences
121122

122-
if(i>=parameters.size())
123-
{
124-
// Ellipsis is the 'worst' of the conversion sequences
125-
distance+=1000;
126-
continue;
127-
}
128-
129-
exprt parameter=parameters[i];
130-
131-
exprt &operand=ops[i];
123+
assert(it!=ops.end());
124+
const exprt &operand=*it;
125+
typet type=parameter.type();
132126

133127
#if 0
134128
// unclear, todo
@@ -140,13 +134,13 @@ bool cpp_typecheck_fargst::match(
140134

141135
// "this" is a special case -- we turn the pointer type
142136
// into a reference type to do the type matching
143-
if(i==0 && parameter.get(ID_C_base_name)==ID_this)
137+
if(it==ops.begin() && parameter.get(ID_C_base_name)==ID_this)
144138
{
145-
parameter.type().set(ID_C_reference, true);
146-
parameter.type().set("#this", true);
139+
type.set(ID_C_reference, true);
140+
type.set("#this", true);
147141
}
148142

149-
unsigned rank = 0;
143+
unsigned rank=0;
150144
exprt new_expr;
151145

152146
#if 0
@@ -156,7 +150,7 @@ bool cpp_typecheck_fargst::match(
156150

157151
// can we do the standard conversion sequence?
158152
if(cpp_typecheck.implicit_conversion_sequence(
159-
operand, parameter.type(), new_expr, rank))
153+
operand, type, new_expr, rank))
160154
{
161155
// ok
162156
distance+=rank;
@@ -171,7 +165,14 @@ bool cpp_typecheck_fargst::match(
171165
#endif
172166
return false; // no conversion possible
173167
}
168+
169+
++it;
174170
}
175171

172+
// we may not have used all operands
173+
for( ; it!=ops.end(); ++it)
174+
// Ellipsis is the 'worst' of the conversion sequences
175+
distance+=1000;
176+
176177
return true;
177178
}

src/cpp/cpp_typecheck_resolve.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ exprt cpp_typecheck_resolvet::convert_identifier(
358358
{
359359
// the object is given to us in fargs
360360
assert(!fargs.operands.empty());
361-
object=fargs.operands[0];
361+
object=fargs.operands.front();
362362
}
363363
else if(this_expr.is_not_nil())
364364
{
@@ -841,7 +841,7 @@ exprt cpp_typecheck_resolvet::do_builtin(
841841
throw 0;
842842
}
843843

844-
const exprt &argument=arguments[0];
844+
const exprt &argument=arguments.front();
845845

846846
if(argument.id()==ID_type)
847847
{
@@ -2193,13 +2193,16 @@ exprt cpp_typecheck_resolvet::guess_function_template_args(
21932193
const irept::subt &parameters=
21942194
function_declarator.type().find(ID_parameters).get_sub();
21952195

2196-
for(std::size_t i=0; i<parameters.size(); i++)
2196+
exprt::operandst::const_iterator it=fargs.operands.begin();
2197+
for(const auto & parameter : parameters)
21972198
{
2198-
if(i<fargs.operands.size() &&
2199-
parameters[i].id()==ID_cpp_declaration)
2199+
if(it==fargs.operands.end())
2200+
break;
2201+
2202+
if(parameter.id()==ID_cpp_declaration)
22002203
{
22012204
const cpp_declarationt &arg_declaration=
2202-
to_cpp_declaration(parameters[i]);
2205+
to_cpp_declaration(parameter);
22032206

22042207
// again, there should be one declarator
22052208
assert(arg_declaration.declarators().size()==1);
@@ -2214,8 +2217,10 @@ exprt cpp_typecheck_resolvet::guess_function_template_args(
22142217
// sorts of trouble.
22152218
cpp_convert_plain_type(arg_type);
22162219

2217-
guess_template_args(arg_type, fargs.operands[i].type());
2220+
guess_template_args(arg_type, it->type());
22182221
}
2222+
2223+
++it;
22192224
}
22202225

22212226
// see if that has worked out
@@ -2633,10 +2638,9 @@ void cpp_typecheck_resolvet::resolve_with_arguments(
26332638
const cpp_typecheck_fargst &fargs)
26342639
{
26352640
// not clear what this is good for
2636-
for(std::size_t i=0; i<fargs.operands.size(); i++)
2641+
for(const auto & arg : fargs.operands)
26372642
{
2638-
const typet &final_type=
2639-
cpp_typecheck.follow(fargs.operands[i].type());
2643+
const typet &final_type=cpp_typecheck.follow(arg.type());
26402644

26412645
if(final_type.id()!=ID_struct && final_type.id()!=ID_union)
26422646
continue;

src/solvers/flattening/boolbv_get.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ exprt boolbvt::bv_get_rec(
213213
{
214214
std::size_t size=width/sub_width;
215215
exprt value(ID_vector, type);
216-
value.operands().resize(size);
216+
value.reserve_operands(size);
217217

218218
for(std::size_t i=0; i<size; i++)
219-
value.operands()[i]=
220-
bv_get_rec(bv, unknown, i*sub_width, subtype);
219+
value.operands().push_back(
220+
bv_get_rec(bv, unknown, i*sub_width, subtype));
221221

222222
return value;
223223
}

src/solvers/flattening/boolbv_struct.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ bvt boolbvt::convert_struct(const struct_exprt &expr)
4141
bvt bv;
4242
bv.resize(width);
4343

44-
std::size_t offset=0, i=0;
44+
std::size_t offset=0;
4545

46-
for(struct_typet::componentst::const_iterator
47-
it=components.begin();
48-
it!=components.end();
49-
it++)
46+
exprt::operandst::const_iterator op_it=expr.operands().begin();
47+
for(const auto & comp : components)
5048
{
51-
const typet &subtype=it->type();
52-
const exprt &op=expr.operands()[i];
49+
const typet &subtype=comp.type();
50+
const exprt &op=*op_it;
5351

5452
if(!base_type_eq(subtype, op.type(), ns))
5553
{
@@ -76,7 +74,7 @@ bvt boolbvt::convert_struct(const struct_exprt &expr)
7674
offset+=op_bv.size();
7775
}
7876

79-
i++;
77+
++op_it;
8078
}
8179

8280
assert(offset==width);

src/solvers/flattening/flatten_byte_operators.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ exprt flatten_byte_extract(
8787
// TODO this doesn't seem correct if size_bits%8!=0 as more
8888
// bits than the original expression will be returned.
8989
if(width_bytes==1)
90-
return op[0];
90+
return op.front();
9191
else // width_bytes>=2
9292
{
9393
concatenation_exprt concatenation(src.type());

src/solvers/prop/prop_conv.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ literalt prop_conv_solvert::convert_bool(const exprt &expr)
399399
if(op.size()!=1)
400400
throw "not takes one operand";
401401

402-
return !convert(op[0]);
402+
return !convert(op.front());
403403
}
404404
else if(expr.id()==ID_equal || expr.id()==ID_notequal)
405405
{

src/util/base_type.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,16 @@ bool base_type_eqt::base_type_eq_rec(
301301
if(!base_type_eq(expr1.type(), expr2.type()))
302302
return false;
303303

304-
if(expr1.operands().size()!=expr2.operands().size())
304+
const exprt::operandst &expr1_op=expr1.operands();
305+
const exprt::operandst &expr2_op=expr2.operands();
306+
if(expr1_op.size()!=expr2_op.size())
305307
return false;
306308

307-
for(unsigned i=0; i<expr1.operands().size(); i++)
308-
if(!base_type_eq(expr1.operands()[i], expr2.operands()[i]))
309+
for(exprt::operandst::const_iterator
310+
it1=expr1_op.begin(), it2=expr2_op.begin();
311+
it1!=expr1_op.end() && it2!=expr2_op.end();
312+
++it1, ++it2)
313+
if(!base_type_eq(*it1, *it2))
309314
return false;
310315

311316
if(expr1.id()==ID_constant)

src/util/expr_util.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,18 @@ exprt make_binary(const exprt &expr)
234234

235235
if(operands.size()<=2) return expr;
236236

237-
exprt previous=operands[0];
237+
exprt previous=operands.front();
238238

239-
for(std::size_t i=1; i<operands.size(); i++)
239+
for(exprt::operandst::const_iterator
240+
it=++operands.begin();
241+
it!=operands.end();
242+
++it)
240243
{
241244
exprt tmp=expr;
242245
tmp.operands().clear();
243246
tmp.operands().resize(2);
244247
tmp.op0().swap(previous);
245-
tmp.op1()=operands[i];
248+
tmp.op1()=*it;
246249
previous.swap(tmp);
247250
}
248251

src/util/std_code.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class code_blockt:public codet
6969
explicit code_blockt(const std::list<codet> &_list):codet(ID_block)
7070
{
7171
operandst &o=operands();
72-
o.reserve(_list.size());
72+
reserve_operands(_list.size());
7373
for(std::list<codet>::const_iterator
7474
it=_list.begin();
7575
it!=_list.end();
@@ -282,7 +282,7 @@ class code_assumet:public codet
282282
inline code_assumet():codet(ID_assume)
283283
{
284284
// will change to resize(1) in the future
285-
operands().reserve(1);
285+
reserve_operands(1);
286286
}
287287

288288
inline explicit code_assumet(const exprt &expr):codet(ID_assume)
@@ -321,7 +321,7 @@ class code_assertt:public codet
321321
inline code_assertt():codet(ID_assert)
322322
{
323323
// will change to resize(1) in the future
324-
operands().reserve(1);
324+
reserve_operands(1);
325325
}
326326

327327
inline explicit code_assertt(const exprt &expr):codet(ID_assert)
@@ -723,7 +723,7 @@ class code_returnt:public codet
723723
public:
724724
inline code_returnt():codet(ID_return)
725725
{
726-
operands().reserve(1);
726+
reserve_operands(1);
727727
}
728728

729729
explicit inline code_returnt(const exprt &_op):codet(ID_return)
@@ -931,7 +931,7 @@ class code_asmt:public codet
931931

932932
inline explicit code_asmt(const exprt &expr):codet(ID_asm)
933933
{
934-
operands().push_back(expr);
934+
copy_to_operands(expr);
935935
}
936936

937937
inline const irep_idt &get_flavor() const
@@ -969,7 +969,7 @@ class code_expressiont:public codet
969969

970970
inline explicit code_expressiont(const exprt &expr):codet(ID_expression)
971971
{
972-
operands().push_back(expr);
972+
copy_to_operands(expr);
973973
}
974974

975975
inline friend code_expressiont &to_code_expression(codet &code)

0 commit comments

Comments
 (0)