Skip to content

Commit e2204fc

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#1032 from tautschnig/empty-cleanup
Use empty() instead of size()==0, size()<1
2 parents a71dfb5 + 9d991b4 commit e2204fc

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

+61
-64
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,7 @@ exprt c_typecheck_baset::do_special_functions(
25662566
// http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
25672567

25682568
// adjust return type of function to match pointer subtype
2569-
if(expr.arguments().size()<1)
2569+
if(expr.arguments().empty())
25702570
{
25712571
err_location(f_op);
25722572
error() << "__sync_* primitives take as least one argument" << eom;

src/ansi-c/expr2c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ std::string expr2ct::convert_code_switch(
25882588
const codet &src,
25892589
unsigned indent)
25902590
{
2591-
if(src.operands().size()<1)
2591+
if(src.operands().empty())
25922592
{
25932593
unsigned precedence;
25942594
return convert_norep(src, precedence);

src/clobber/clobber_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ bool clobber_parse_optionst::get_goto_program(
192192
const optionst &options,
193193
goto_functionst &goto_functions)
194194
{
195-
if(cmdline.args.size()==0)
195+
if(cmdline.args.empty())
196196
{
197197
error() << "Please provide a program to verify" << eom;
198198
return true;

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
466466
{
467467
is_virtual=true;
468468
const code_typet &code_type=to_code_type(comp.type());
469-
assert(code_type.parameters().size()>0);
469+
assert(!code_type.parameters().empty());
470470
const typet &pointer_type=code_type.parameters()[0].type();
471471
assert(pointer_type.id()==ID_pointer);
472472
virtual_bases.insert(pointer_type.subtype().get(ID_identifier));

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,13 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member(
574574
expr.type().subtype().id()==ID_code)
575575
{
576576
code_typet code1=to_code_type(expr.type().subtype());
577-
assert(code1.parameters().size()>0);
577+
assert(!code1.parameters().empty());
578578
code_typet::parametert this1=code1.parameters()[0];
579579
assert(this1.get(ID_C_base_name)==ID_this);
580580
code1.parameters().erase(code1.parameters().begin());
581581

582582
code_typet code2=to_code_type(type.subtype());
583-
assert(code2.parameters().size()>0);
583+
assert(!code2.parameters().empty());
584584
code_typet::parametert this2=code2.parameters()[0];
585585
assert(this2.get(ID_C_base_name)==ID_this);
586586
code2.parameters().erase(code2.parameters().begin());

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
14311431
// http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
14321432

14331433
// adjust return type of function to match pointer subtype
1434-
if(fargs.operands.size()<1)
1434+
if(fargs.operands.empty())
14351435
{
14361436
error().source_location=source_location;
14371437
error() << "__sync_* primitives take as least one argument"

src/goto-cc/compile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ bool compilet::doit()
102102
return true;
103103
}
104104

105-
if(mode==LINK_LIBRARY && source_files.size()>0)
105+
if(mode==LINK_LIBRARY && !source_files.empty())
106106
{
107107
error() << "cannot link source files" << eom;
108108
return true;
109109
}
110110

111-
if(mode==PREPROCESS_ONLY && object_files.size()>0)
111+
if(mode==PREPROCESS_ONLY && !object_files.empty())
112112
{
113113
error() << "cannot preprocess object files" << eom;
114114
return true;
@@ -117,7 +117,7 @@ bool compilet::doit()
117117
const unsigned warnings_before=
118118
get_message_handler().get_message_count(messaget::M_WARNING);
119119

120-
if(source_files.size()>0)
120+
if(!source_files.empty())
121121
if(compile())
122122
return true;
123123

@@ -346,7 +346,7 @@ bool compilet::link()
346346
convert_symbols(compiled_functions);
347347

348348
// parse object files
349-
while(object_files.size()>0)
349+
while(!object_files.empty())
350350
{
351351
std::string file_name=object_files.front();
352352
object_files.pop_front();

src/goto-cc/xml_binaries/xml_goto_function.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ void convert(const xmlt &xml, goto_functionst::goto_functiont &function)
3333
{
3434
function.body.clear();
3535
convert(xml, function.body);
36-
function.body_available = function.body.instructions.size()>0;
3736
// don't forget to fix the functions type via the symbol table!
3837
}

src/goto-cc/xml_binaries/xml_goto_function_hashing.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ void xml_goto_function_convertt::convert(
3838
xml_goto_program_convertt gpconverter(ireps_container);
3939
function.body.clear();
4040
gpconverter.convert(xml, function.body);
41-
function.body_available = function.body.instructions.size()>0;
4241
// don't forget to fix the functions type via the symbol table!
4342
}

src/goto-cc/xml_binaries/xml_symbol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void convert(const symbolt &sym, xmlt &root)
5454
flags.new_element("base_name").data=id2string(sym.base_name);
5555
flags.new_element("module").data=id2string(sym.module);
5656

57-
if(sym.pretty_name.size()>0)
57+
if(!sym.pretty_name.empty())
5858
flags.new_element("pretty_name").data=id2string(sym.pretty_name);
5959

6060
xmlt &xmlloc = xmlsym.new_element("location");

src/goto-instrument/accelerate/acceleration_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ bool acceleration_utilst::do_arrays(
573573
<< " array assignments\n";
574574
#endif
575575

576-
if(array_assignments.size()==0)
576+
if(array_assignments.empty())
577577
{
578578
// The loop doesn't write to any arrays. We're done!
579579
return true;

src/goto-instrument/accelerate/trace_automaton.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ void automatont::reverse(goto_programt::targett epsilon)
366366
transitions.push_back(transitionst());
367367
}
368368

369-
if(accept_states.size()==0)
369+
if(accept_states.empty())
370370
{
371371
num_states=0;
372372
return;

src/goto-instrument/rw_set.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ class rw_set_with_trackt:public _rw_set_loct
266266

267267
void track_deref(const entryt &entry, bool read)
268268
{
269-
if(dereferencing && dereferenced.size()==0)
269+
if(dereferencing && dereferenced.empty())
270270
{
271271
dereferenced.insert(dereferenced.begin(), entry);
272272
if(read)
273273
set_reads.insert(entry.object);
274274
}
275-
else if(dereferencing && dereferenced.size()>0)
275+
else if(dereferencing && !dereferenced.empty())
276276
dereferenced_from.insert(
277277
std::make_pair(entry.object, dereferenced.front().object));
278278
}

src/goto-instrument/wmm/cycle_collection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,21 +521,21 @@ bool event_grapht::graph_explorert::backtrack(
521521

522522
std::stack<event_idt> tmp;
523523

524-
while(marked_stack.size()>0 && marked_stack.top()!=vertex)
524+
while(!marked_stack.empty() && marked_stack.top()!=vertex)
525525
{
526526
tmp.push(marked_stack.top());
527527
mark[marked_stack.top()]=false;
528528
marked_stack.pop();
529529
}
530530

531-
if(marked_stack.size()>0)
531+
if(!marked_stack.empty())
532532
{
533533
assert(marked_stack.top()==vertex);
534534
mark[vertex]=true;
535535
}
536536
else
537537
{
538-
while(tmp.size()>0)
538+
while(!tmp.empty())
539539
{
540540
marked_stack.push(tmp.top());
541541
mark[tmp.top()]=true;

src/goto-instrument/wmm/event_graph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void event_grapht::print_rec_graph(std::ofstream &file, event_idt node_id,
5555

5656
void event_grapht::print_graph()
5757
{
58-
assert(po_order.size()>0);
58+
assert(!po_order.empty());
5959
std::set<event_idt> visited;
6060
event_idt root=po_order.front();
6161
std::ofstream file;
@@ -113,7 +113,7 @@ event_idt event_grapht::copy_segment(event_idt begin, event_idt end)
113113
/* collects the nodes of the subgraph */
114114
explore_copy_segment(covered, begin, end);
115115

116-
if(covered.size()==0)
116+
if(covered.empty())
117117
return end;
118118

119119
// for(std::set<event_idt>::const_iterator it=covered.begin();

src/goto-instrument/wmm/event_graph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class event_grapht
178178
{
179179
critical_cyclet reduced(egraph, id);
180180
this->hide_internals(reduced);
181-
assert(reduced.size()>0);
181+
assert(!reduced.empty());
182182
return print_name(reduced, model);
183183
}
184184
else

src/goto-instrument/wmm/weak_memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void weak_memory(
189189
<<" cycles found"<<messaget::eom;
190190

191191
/* if no cycle, no need to instrument */
192-
if(instrumenter.set_of_cycles.size() == 0)
192+
if(instrumenter.set_of_cycles.empty())
193193
{
194194
message.status()<<"program safe -- no need to instrument"<<messaget::eom;
195195
return;

src/goto-programs/builtin_functions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void goto_convertt::do_scanf(
233233

234234
if(f_id==CPROVER_PREFIX "scanf")
235235
{
236-
if(arguments.size()<1)
236+
if(arguments.empty())
237237
{
238238
error().source_location=function.find_source_location();
239239
error() << "scanf takes at least one argument" << eom;
@@ -1328,7 +1328,7 @@ void goto_convertt::do_function_call_symbol(
13281328
}
13291329
else if(identifier==CPROVER_PREFIX "fence")
13301330
{
1331-
if(arguments.size()<1)
1331+
if(arguments.empty())
13321332
{
13331333
error().source_location=function.find_source_location();
13341334
error() << "`" << identifier

src/goto-programs/interpreter_evaluate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void interpretert::evaluate(
144144
}
145145
else if(expr.id()==ID_or)
146146
{
147-
if(expr.operands().size()<1)
147+
if(expr.operands().empty())
148148
throw id2string(expr.id())+" expects at least one operand";
149149

150150
bool result=false;
@@ -188,7 +188,7 @@ void interpretert::evaluate(
188188
}
189189
else if(expr.id()==ID_and)
190190
{
191-
if(expr.operands().size()<1)
191+
if(expr.operands().empty())
192192
throw id2string(expr.id())+" expects at least one operand";
193193

194194
bool result=true;

src/goto-programs/remove_unused_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void remove_unused_functions(
3333

3434
messaget message(message_handler);
3535

36-
if(unused_functions.size()>0)
36+
if(!unused_functions.empty())
3737
{
3838
message.statistics()
3939
<< "Dropping " << unused_functions.size() << " of " <<

src/goto-programs/show_goto_functions_json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ json_objectt show_goto_functions_jsont::convert(
7676
instruction_entry["instruction"]=
7777
json_stringt(instruction_builder.str());
7878

79-
if(instruction.code.operands().size()>0)
79+
if(!instruction.code.operands().empty())
8080
{
8181
json_arrayt operand_array;
8282
for(const exprt &operand : instruction.code.operands())

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
17721772
}
17731773
else if(statement=="putfield")
17741774
{
1775-
assert(op.size()==2 && results.size()==0);
1775+
assert(op.size()==2 && results.empty());
17761776
code_blockt block;
17771777
save_stack_entries(
17781778
"stack_field",
@@ -1948,7 +1948,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
19481948
else if(statement=="tableswitch" ||
19491949
statement=="lookupswitch")
19501950
{
1951-
assert(op.size()==1 && results.size()==0);
1951+
assert(op.size()==1 && results.empty());
19521952

19531953
// we turn into switch-case
19541954
code_switcht code_switch;
@@ -2298,7 +2298,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
22982298
code_labelt newlabel(label(std::to_string(address)), code_blockt());
22992299
root_block.move_to_operands(newlabel);
23002300
root.branch.push_back(block_tree_nodet::get_leaf());
2301-
assert((root.branch_addresses.size()==0 ||
2301+
assert((root.branch_addresses.empty() ||
23022302
root.branch_addresses.back()<address) &&
23032303
"Block addresses should be unique and increasing");
23042304
root.branch_addresses.push_back(address);

src/java_bytecode/java_bytecode_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
507507
do
508508
{
509509
any_new_methods=false;
510-
while(method_worklist2.size()!=0)
510+
while(!method_worklist2.empty())
511511
{
512512
std::swap(method_worklist1, method_worklist2);
513513
for(const auto &mname : method_worklist1)

src/memory-models/mmcc_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int mmcc_parse_optionst::doit()
4848

4949
return convert(in, cmdline.args[0]);
5050
}
51-
else if(cmdline.args.size()==0)
51+
else if(cmdline.args.empty())
5252
{
5353
return convert(std::cin, "stdin");
5454
}

src/musketeer/cycles_visitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void cycles_visitort::com_constraint(
347347

348348
std::list<event_idt>::const_iterator e_it=C_j.begin();
349349
std::list<event_idt>::const_iterator next_it=e_it;
350-
assert(C_j.size()>0);
350+
assert(!C_j.empty());
351351
++next_it;
352352
for(; next_it!=C_j.end() && e_it!=C_j.end(); ++e_it, ++next_it)
353353
{

src/musketeer/fencer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void fence_weak_memory(
111111
<< " cycles found" << messaget::eom;
112112

113113
/* if no cycle, no need to instrument */
114-
if(instrumenter.set_of_cycles.size() == 0)
114+
if(instrumenter.set_of_cycles.empty())
115115
{
116116
message.result()
117117
<< "program safe -- no need to place additional fences"

src/musketeer/graph_visitor.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void const_graph_visitort::graph_explore(
3535
edges.insert(fence_inserter.add_edge(edget(*it, *next_it)));
3636
}
3737
}
38-
else if(egraph.po_out(next).size()==0)
38+
else if(egraph.po_out(next).empty())
3939
{
4040
/* this path is not connecting a to b => return */
4141
}
@@ -76,7 +76,7 @@ void const_graph_visitort::const_graph_explore(
7676
fence_inserter.add_edge(edget(*it, *next_it));
7777
}
7878
}
79-
else if(egraph.po_out(next).size()==0)
79+
else if(egraph.po_out(next).empty())
8080
{
8181
/* this path is not connecting a to b => return */
8282
}
@@ -106,7 +106,7 @@ void const_graph_visitort::graph_explore_BC(
106106
bool porw)
107107
{
108108
/* TODO: restricts to C_1 U ... U C_n for perf improvement */
109-
assert(old_path.size()>0);
109+
assert(!old_path.empty());
110110

111111
fence_inserter.instrumenter.message.debug() << "(BC) explore "
112112
<< old_path.front()
@@ -129,7 +129,7 @@ void const_graph_visitort::graph_explore_BC(
129129
break;
130130
}
131131

132-
if(egraph.po_out(next).size()==0 || no_other_pos)
132+
if(egraph.po_out(next).empty() || no_other_pos)
133133
{
134134
/* inserts all the pos collected from old_path in edges */
135135
std::list<event_idt>::const_iterator it=old_path.begin();
@@ -184,7 +184,7 @@ void const_graph_visitort::const_graph_explore_BC(
184184
break;
185185
}
186186

187-
if(egraph.po_out(next).size()==0 || no_other_pos)
187+
if(egraph.po_out(next).empty() || no_other_pos)
188188
{
189189
/* inserts all the pos collected from old_path in edges */
190190
std::list<event_idt>::const_iterator it=old_path.begin();
@@ -244,7 +244,7 @@ void const_graph_visitort::graph_explore_AC(
244244
break;
245245
}
246246

247-
if(egraph.po_in(next).size()==0 || no_other_pos)
247+
if(egraph.po_in(next).empty() || no_other_pos)
248248
{
249249
/* inserts all the pos collected from old_path in edges */
250250
std::list<event_idt>::const_iterator it=old_path.begin();
@@ -300,7 +300,7 @@ void const_graph_visitort::const_graph_explore_AC(
300300
}
301301

302302
/* if beginning of the thread */
303-
if(egraph.po_in(next).size()==0 || no_other_pos)
303+
if(egraph.po_in(next).empty() || no_other_pos)
304304
{
305305
/* inserts all the pos collected from old_path in edges */
306306
std::list<event_idt>::const_iterator it=old_path.begin();

0 commit comments

Comments
 (0)