Skip to content

Commit c306c80

Browse files
committed
Various bits of cleanup, to be broken up into sensible commits
1 parent df42736 commit c306c80

Some content is hidden

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

58 files changed

+318
-307
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))
@@ -250,17 +253,16 @@ void add_padding(struct_typet &type, const namespacet &ns)
250253
}
251254

252255
// any explicit alignment for the struct?
253-
if(type.find(ID_C_alignment).is_not_nil())
256+
const exprt &alignment =
257+
static_cast<const exprt &>(type.find(ID_C_alignment));
258+
if(alignment.is_not_nil())
254259
{
255-
const exprt &alignment=
256-
static_cast<const exprt &>(type.find(ID_C_alignment));
257260
if(alignment.id()!=ID_default)
258261
{
259-
exprt tmp=alignment;
260-
simplify(tmp, ns);
261-
mp_integer tmp_i;
262-
if(!to_integer(tmp, tmp_i) && tmp_i>max_alignment)
263-
max_alignment=tmp_i;
262+
const auto tmp_i = numeric_cast<mp_integer>(simplify_expr(alignment, ns));
263+
264+
if(tmp_i.has_value() && *tmp_i > max_alignment)
265+
max_alignment = *tmp_i;
264266
}
265267
}
266268
// 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
@@ -437,7 +437,7 @@ void cpp_typecheckt::default_assignop_value(
437437
declarator.value().add_source_location()=source_location;
438438
declarator.value().id(ID_code);
439439
declarator.value().set(ID_statement, ID_block);
440-
declarator.value().type()=code_typet();
440+
declarator.value().type() = code_typet({}, empty_typet());
441441

442442
exprt &block=declarator.value();
443443

@@ -484,13 +484,11 @@ void cpp_typecheckt::default_assignop_value(
484484
continue;
485485
}
486486

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

492-
exprt::operandst empty_operands;
493-
for(mp_integer i=0; i < size; ++i)
491+
for(mp_integer i = 0; i < *size; ++i)
494492
copy_array(source_location, mem_name, i, arg_name, block);
495493
}
496494
else
@@ -503,7 +501,7 @@ void cpp_typecheckt::default_assignop_value(
503501
ret_code.operands().push_back(exprt(ID_dereference));
504502
ret_code.op0().operands().push_back(exprt("cpp-this"));
505503
ret_code.set(ID_statement, ID_return);
506-
ret_code.type()=code_typet();
504+
ret_code.type() = code_typet({}, empty_typet());
507505
}
508506

509507
/// 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
@@ -5275,9 +5275,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname)
52755275
<< "Parser::rTypeNameOrFunctionType 2\n";
52765276
#endif
52775277

5278-
code_typet type;
5279-
5280-
if(!rCastOperatorName(type.return_type()))
5278+
typet return_type;
5279+
if(!rCastOperatorName(return_type))
52815280
return false;
52825281

52835282
#ifdef DEBUG
@@ -5287,7 +5286,7 @@ bool Parser::rTypeNameOrFunctionType(typet &tname)
52875286

52885287
if(lex.LookAhead(0)!='(')
52895288
{
5290-
tname.swap(type.return_type());
5289+
tname.swap(return_type);
52915290

52925291
if(!optPtrOperator(tname))
52935292
return false;
@@ -5300,6 +5299,7 @@ bool Parser::rTypeNameOrFunctionType(typet &tname)
53005299
<< "Parser::rTypeNameOrFunctionType 4\n";
53015300
#endif
53025301

5302+
code_typet type({}, return_type);
53035303
cpp_tokent op;
53045304
lex.get_token(op);
53055305

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
@@ -360,7 +360,7 @@ void remove_repetition(std::set<exprt> &exprs)
360360
{
361361
std::set<signed> signs1 = sign_of_expr(c, x);
362362
std::set<signed> signs2 = sign_of_expr(c, y);
363-
int s1 = signs1.size(), s2 = signs2.size();
363+
std::size_t s1 = signs1.size(), s2 = signs2.size();
364364
// it is easy to check non-equivalence;
365365
if(s1 != s2)
366366
{

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
@@ -774,15 +774,15 @@ bool goto_program2codet::set_block_end_points(
774774
cases_listt &cases,
775775
std::set<unsigned> &processed_locations)
776776
{
777-
std::map<goto_programt::const_targett, std::size_t> targets_done;
777+
std::set<goto_programt::const_targett> targets_done;
778778

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

788788
// compute the block that belongs to this case
@@ -818,8 +818,6 @@ bool goto_program2codet::set_block_end_points(
818818

819819
it->case_last=case_end;
820820
}
821-
822-
targets_done[it->case_start]=1;
823821
}
824822

825823
return false;
@@ -970,7 +968,7 @@ goto_programt::const_targett goto_program2codet::convert_goto_switch(
970968
it->case_last->location_number > max_target->location_number)
971969
max_target=it->case_last;
972970

973-
std::map<goto_programt::const_targett, unsigned> targets_done;
971+
std::map<goto_programt::const_targett, std::size_t> targets_done;
974972
loop_last_stack.push_back(std::make_pair(max_target, false));
975973

976974
// 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
@@ -171,12 +171,15 @@ void goto_convertt::finish_gotos(goto_programt &dest, const irep_idt &mode)
171171
bool stack_is_prefix=true;
172172
if(label_stack.size()>goto_stack.size())
173173
stack_is_prefix=false;
174-
for(std::size_t i=0, ilim=label_stack.size();
175-
i!=ilim && stack_is_prefix;
176-
++i)
174+
auto label_stack_it = label_stack.begin();
175+
for(const auto &g : goto_stack)
177176
{
178-
if(goto_stack[i]!=label_stack[i])
177+
if(!stack_is_prefix || label_stack_it == label_stack.end())
178+
break;
179+
else if(g != *label_stack_it)
179180
stack_is_prefix=false;
181+
182+
++label_stack_it;
180183
}
181184

182185
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)

0 commit comments

Comments
 (0)