Skip to content

Commit fb8ccf7

Browse files
committed
Various bits of cleanup, to be broken up into sensible commits
1 parent 3e14fe5 commit fb8ccf7

Some content is hidden

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

57 files changed

+299
-269
lines changed

src/ansi-c/expr2c.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -2218,9 +2218,8 @@ std::string expr2ct::convert_array(
22182218
break;
22192219

22202220
assert(it->is_constant());
2221-
mp_integer i;
2222-
to_integer(*it, i);
2223-
unsigned int ch=integer2unsigned(i);
2221+
const auto i = numeric_cast<mp_integer>(*it);
2222+
const unsigned int ch = numeric_cast_v<unsigned>(*i);
22242223

22252224
if(last_was_hex)
22262225
{

src/ansi-c/padding.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ mp_integer alignment(const typet &type, const namespacet &ns)
3535
const exprt &given_alignment=
3636
static_cast<const exprt &>(type.find(ID_C_alignment));
3737

38-
mp_integer a_int;
38+
mp_integer a_int = 0;
3939

4040
// we trust it blindly, no matter how nonsensical
41-
if(given_alignment.is_nil() ||
42-
to_integer(given_alignment, a_int))
43-
a_int=0;
41+
if(given_alignment.is_not_nil())
42+
{
43+
const auto a = numeric_cast<mp_integer>(given_alignment);
44+
if(a.has_value())
45+
a_int = *a;
46+
}
4447

4548
// alignment but no packing
4649
if(a_int>0 && !type.get_bool(ID_C_packed))
@@ -386,17 +389,16 @@ static void add_padding_gcc(struct_typet &type, const namespacet &ns)
386389
}
387390

388391
// any explicit alignment for the struct?
389-
if(type.find(ID_C_alignment).is_not_nil())
392+
const exprt &alignment =
393+
static_cast<const exprt &>(type.find(ID_C_alignment));
394+
if(alignment.is_not_nil())
390395
{
391-
const exprt &alignment=
392-
static_cast<const exprt &>(type.find(ID_C_alignment));
393396
if(alignment.id()!=ID_default)
394397
{
395-
exprt tmp=alignment;
396-
simplify(tmp, ns);
397-
mp_integer tmp_i;
398-
if(!to_integer(tmp, tmp_i) && tmp_i>max_alignment)
399-
max_alignment=tmp_i;
398+
const auto tmp_i = numeric_cast<mp_integer>(simplify_expr(alignment, ns));
399+
400+
if(tmp_i.has_value() && *tmp_i > max_alignment)
401+
max_alignment = *tmp_i;
400402
}
401403
}
402404
// Is the struct packed, without any alignment specification?

src/ansi-c/type2name.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,19 @@ static std::string type2name(
178178
}
179179
else if(type.id()==ID_array)
180180
{
181-
const array_typet &t=to_array_type(type);
182-
mp_integer size;
183-
if(t.size().id()==ID_symbol)
184-
result += "ARR" + id2string(to_symbol_expr(t.size()).get_identifier());
185-
else if(to_integer(t.size(), size))
186-
result+="ARR?";
181+
const exprt &size = to_array_type(type).size();
182+
183+
if(size.id()==ID_symbol)
184+
result += "ARR" + id2string(to_symbol_expr(size).get_identifier());
187185
else
188-
result+="ARR"+integer2string(size);
186+
{
187+
const auto size_int = numeric_cast<mp_integer>(size);
188+
189+
if(!size_int.has_value())
190+
result += "ARR?";
191+
else
192+
result += "ARR" + integer2string(*size_int);
193+
}
189194
}
190195
else if(type.id()==ID_symbol ||
191196
type.id()==ID_c_enum_tag ||

src/cpp/cpp_token_buffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <ansi-c/ansi_c_y.tab.h>
1717
#include <ansi-c/ansi_c_parser.h>
1818

19-
int cpp_token_buffert::LookAhead(unsigned offset)
19+
int cpp_token_buffert::LookAhead(std::size_t offset)
2020
{
2121
assert(current_pos<=token_vector.size());
2222

@@ -56,7 +56,7 @@ int cpp_token_buffert::get_token()
5656
return kind;
5757
}
5858

59-
int cpp_token_buffert::LookAhead(unsigned offset, cpp_tokent &token)
59+
int cpp_token_buffert::LookAhead(std::size_t offset, cpp_tokent &token)
6060
{
6161
assert(current_pos<=token_vector.size());
6262

src/cpp/cpp_token_buffer.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class cpp_token_buffert
2525
{
2626
}
2727

28-
typedef unsigned int post;
28+
typedef std::size_t post;
2929

30-
int LookAhead(unsigned offset);
30+
int LookAhead(std::size_t offset);
3131
int get_token(cpp_tokent &token);
3232
int get_token();
33-
int LookAhead(unsigned offset, cpp_tokent &token);
33+
int LookAhead(std::size_t offset, cpp_tokent &token);
3434

3535
post Save();
3636
void Restore(post pos);

src/cpp/cpp_typecheck_code.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ void cpp_typecheckt::typecheck_code(codet &code)
2525

2626
if(statement==ID_try_catch)
2727
{
28-
code.type()=code_typet();
28+
code.type() = code_typet({}, empty_typet());
2929
typecheck_try_catch(code);
3030
}
3131
else if(statement==ID_member_initializer)
3232
{
33-
code.type()=code_typet();
33+
code.type() = code_typet({}, empty_typet());
3434
typecheck_member_initializer(code);
3535
}
3636
else if(statement==ID_msc_if_exists ||

src/cpp/cpp_typecheck_constructor.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ void cpp_typecheckt::default_assignop_value(
435435
declarator.value().add_source_location()=source_location;
436436
declarator.value().id(ID_code);
437437
declarator.value().set(ID_statement, ID_block);
438-
declarator.value().type()=code_typet();
438+
declarator.value().type() = code_typet({}, empty_typet());
439439

440440
exprt &block=declarator.value();
441441

@@ -482,13 +482,11 @@ void cpp_typecheckt::default_assignop_value(
482482
continue;
483483
}
484484

485-
mp_integer size;
486-
bool to_int=to_integer(size_expr, size);
487-
CHECK_RETURN(!to_int);
488-
CHECK_RETURN(size>=0);
485+
const auto size = numeric_cast<mp_integer>(size_expr);
486+
CHECK_RETURN(!size.has_value());
487+
CHECK_RETURN(*size >= 0);
489488

490-
exprt::operandst empty_operands;
491-
for(mp_integer i=0; i < size; ++i)
489+
for(mp_integer i = 0; i < *size; ++i)
492490
copy_array(source_location, mem_name, i, arg_name, block);
493491
}
494492
else
@@ -501,7 +499,7 @@ void cpp_typecheckt::default_assignop_value(
501499
ret_code.operands().push_back(exprt(ID_dereference));
502500
ret_code.op0().operands().push_back(exprt("cpp-this"));
503501
ret_code.set(ID_statement, ID_return);
504-
ret_code.type()=code_typet();
502+
ret_code.type() = code_typet({}, empty_typet());
505503
}
506504

507505
/// Check a constructor initialization-list. An initializer has to be a data

src/cpp/parse.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -5514,9 +5514,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname)
55145514
<< "Parser::rTypeNameOrFunctionType 2\n";
55155515
#endif
55165516

5517-
code_typet type;
5518-
5519-
if(!rCastOperatorName(type.return_type()))
5517+
typet return_type;
5518+
if(!rCastOperatorName(return_type))
55205519
return false;
55215520

55225521
#ifdef DEBUG
@@ -5526,7 +5525,7 @@ bool Parser::rTypeNameOrFunctionType(typet &tname)
55265525

55275526
if(lex.LookAhead(0)!='(')
55285527
{
5529-
tname.swap(type.return_type());
5528+
tname.swap(return_type);
55305529

55315530
if(!optPtrOperator(tname))
55325531
return false;
@@ -5539,6 +5538,7 @@ bool Parser::rTypeNameOrFunctionType(typet &tname)
55395538
<< "Parser::rTypeNameOrFunctionType 4\n";
55405539
#endif
55415540

5541+
code_typet type({}, return_type);
55425542
cpp_tokent op;
55435543
lex.get_token(op);
55445544

src/goto-cc/linker_script_merge.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ int linker_script_merget::ls_data2instructions(
415415

416416

417417
// Array symbol_exprt
418-
std::size_t array_size=integer2size_t(string2integer(d["size"].value));
418+
mp_integer array_size = string2integer(d["size"].value);
419419
if(array_size > MAX_FLATTENED_ARRAY_SIZE)
420420
{
421421
warning() << "Object section '" << d["section"].value << "' of size "
@@ -434,7 +434,7 @@ int linker_script_merget::ls_data2instructions(
434434
array_loc.set_file(linker_script);
435435
std::ostringstream array_comment;
436436
array_comment << "Object section '" << d["section"].value << "' of size "
437-
<< integer2unsigned(array_size) << " bytes";
437+
<< array_size << " bytes";
438438
array_loc.set_comment(array_comment.str());
439439
array_expr.add_source_location()=array_loc;
440440

src/goto-instrument/cover_basic_blocks.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
6161
// update lines belonging to block
6262
const irep_idt &line = it->source_location.get_line();
6363
if(!line.empty())
64-
block_info.lines.insert(unsafe_string2unsigned(id2string(line)));
64+
block_info.lines.insert(unsafe_string2size_t(id2string(line)));
6565

6666
// set representative program location to instrument
6767
if(
@@ -155,7 +155,7 @@ void cover_basic_blockst::update_covered_lines(block_infot &block_info)
155155

156156
const auto &cover_set = block_info.lines;
157157
INVARIANT(!cover_set.empty(), "covered lines set must not be empty");
158-
std::vector<unsigned> line_list(cover_set.begin(), cover_set.end());
158+
std::vector<std::size_t> line_list(cover_set.begin(), cover_set.end());
159159

160160
std::string covered_lines = format_number_range(line_list);
161161
block_info.source_location.set_basic_block_covered_lines(covered_lines);

src/goto-instrument/cover_instrument_mcdc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ void remove_repetition(std::set<exprt> &exprs)
361361
{
362362
std::set<signed> signs1 = sign_of_expr(c, x);
363363
std::set<signed> signs2 = sign_of_expr(c, y);
364-
int s1 = signs1.size(), s2 = signs2.size();
364+
std::size_t s1 = signs1.size(), s2 = signs2.size();
365365
// it is easy to check non-equivalence;
366366
if(s1 != s2)
367367
{

src/goto-instrument/document_properties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class document_propertiest
7373

7474
void document_propertiest::strip_space(std::list<linet> &lines)
7575
{
76-
unsigned strip=50;
76+
std::size_t strip=50;
7777

7878
for(std::list<linet>::const_iterator it=lines.begin();
7979
it!=lines.end(); it++)

src/goto-instrument/function.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ code_function_callt function_to_call(
3434
typet p=pointer_type(char_type());
3535
p.subtype().set(ID_C_constant, true);
3636

37-
code_typet function_type;
38-
function_type.return_type()=empty_typet();
39-
function_type.parameters().push_back(
40-
code_typet::parametert(p));
37+
const code_typet function_type({code_typet::parametert(p)}, empty_typet());
4138

4239
symbolt new_symbol;
4340
new_symbol.name=id;

src/goto-instrument/goto_program2code.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -775,15 +775,15 @@ bool goto_program2codet::set_block_end_points(
775775
cases_listt &cases,
776776
std::set<unsigned> &processed_locations)
777777
{
778-
std::map<goto_programt::const_targett, std::size_t> targets_done;
778+
std::set<goto_programt::const_targett> targets_done;
779779

780780
for(cases_listt::iterator it=cases.begin();
781781
it!=cases.end();
782782
++it)
783783
{
784784
// some branch targets may be shared by multiple branch instructions,
785785
// as in case 1: case 2: code; we build a nested code_switch_caset
786-
if(targets_done.find(it->case_start)!=targets_done.end())
786+
if(!targets_done.insert(it->case_start).second)
787787
continue;
788788

789789
// compute the block that belongs to this case
@@ -819,8 +819,6 @@ bool goto_program2codet::set_block_end_points(
819819

820820
it->case_last=case_end;
821821
}
822-
823-
targets_done[it->case_start]=1;
824822
}
825823

826824
return false;
@@ -971,7 +969,7 @@ goto_programt::const_targett goto_program2codet::convert_goto_switch(
971969
it->case_last->location_number > max_target->location_number)
972970
max_target=it->case_last;
973971

974-
std::map<goto_programt::const_targett, unsigned> targets_done;
972+
std::map<goto_programt::const_targett, std::size_t> targets_done;
975973
loop_last_stack.push_back(std::make_pair(max_target, false));
976974

977975
// iterate over all <branch conditions, branch instruction, branch target>

src/goto-instrument/wmm/data_dp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void data_dpt::dp_merge()
120120
if(data.size()<2)
121121
return;
122122

123-
unsigned initial_size=data.size();
123+
std::size_t initial_size=data.size();
124124

125125
unsigned from=0;
126126
unsigned to=0;

src/goto-instrument/wmm/goto2graph.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ unsigned instrumentert::goto2graph_cfg(
115115
<< visitor.max_thread << messaget::eom;
116116

117117
/* SCCs which could host critical cycles */
118-
unsigned interesting_sccs=0;
119-
for(unsigned i=0; i<num_sccs; i++)
118+
std::size_t interesting_sccs=0;
119+
for(std::size_t i=0; i<num_sccs; i++)
120120
if(egraph_SCCs[i].size()>3)
121121
interesting_sccs++;
122122

src/goto-instrument/wmm/goto2graph.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class instrumentert
289289

290290
/* critical cycles per SCC */
291291
std::vector<std::set<event_grapht::critical_cyclet> > set_of_cycles_per_SCC;
292-
unsigned num_sccs;
292+
std::size_t num_sccs;
293293

294294
/* map from function to begin and end of the corresponding part of the
295295
graph */

src/goto-instrument/wmm/weak_memory.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ void weak_memory(
161161
{
162162
instrumenter.collect_cycles_by_SCCs(model);
163163
message.status()<<"cycles collected: "<<messaget::eom;
164-
unsigned interesting_scc = 0;
165-
unsigned total_cycles = 0;
166-
for(unsigned i=0; i<instrumenter.num_sccs; i++)
164+
std::size_t interesting_scc = 0;
165+
std::size_t total_cycles = 0;
166+
for(std::size_t i=0; i<instrumenter.num_sccs; i++)
167167
if(instrumenter.egraph_SCCs[i].size()>=4)
168168
{
169169
message.status()<<"SCC #"<<i<<": "

src/goto-programs/goto_convert.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,15 @@ void goto_convertt::finish_gotos(goto_programt &dest, const irep_idt &mode)
149149
bool stack_is_prefix=true;
150150
if(label_stack.size()>goto_stack.size())
151151
stack_is_prefix=false;
152-
for(std::size_t i=0, ilim=label_stack.size();
153-
i!=ilim && stack_is_prefix;
154-
++i)
152+
auto label_stack_it = label_stack.begin();
153+
for(const auto &g : goto_stack)
155154
{
156-
if(goto_stack[i]!=label_stack[i])
155+
if(!stack_is_prefix || label_stack_it == label_stack.end())
156+
break;
157+
else if(g != *label_stack_it)
157158
stack_is_prefix=false;
159+
160+
++label_stack_it;
158161
}
159162

160163
if(!stack_is_prefix)

src/goto-programs/goto_trace.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ void trace_value(
214214
<< "\n";
215215
}
216216

217-
void show_state_header(
217+
static void show_state_header(
218218
std::ostream &out,
219219
const goto_trace_stept &state,
220220
const source_locationt &source_location,
221-
unsigned step_nr)
221+
std::size_t step_nr)
222222
{
223223
out << "\n";
224224

@@ -249,7 +249,7 @@ void show_goto_trace(
249249
const namespacet &ns,
250250
const goto_tracet &goto_trace)
251251
{
252-
unsigned prev_step_nr=0;
252+
std::size_t prev_step_nr=0;
253253
bool first_step=true;
254254

255255
for(const auto &step : goto_trace.steps)

src/goto-programs/remove_function_pointers.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ remove_function_pointerst::remove_function_pointerst(
106106

107107
// build type map
108108
forall_goto_functions(f_it, goto_functions)
109-
type_map[f_it->first]=f_it->second.type;
109+
type_map.emplace(f_it->first, f_it->second.type);
110110
}
111111

112112
bool remove_function_pointerst::arg_is_type_compatible(

0 commit comments

Comments
 (0)