Skip to content

Commit 6e0e0fa

Browse files
authored
Merge pull request #6854 from diffblue/goto_instruction_codet
introduce goto_instruction_codet
2 parents f9684b4 + 0de72ad commit 6e0e0fa

File tree

2 files changed

+103
-88
lines changed

2 files changed

+103
-88
lines changed

src/goto-programs/goto_instruction_code.h

+74-64
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,30 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/std_code_base.h>
1414
#include <util/std_expr.h>
1515

16-
/// A \ref codet representing an assignment in the program.
16+
using goto_instruction_codet = codet;
17+
18+
/// A \ref goto_instruction_codet representing an assignment in the program.
1719
/// For example, if an expression `e1` is represented as an \ref exprt `expr1`
1820
/// and an expression `e2` is represented as an \ref exprt `expr2`, the
1921
/// assignment `e1 = e2;` can be represented as `code_assignt(expr1, expr2)`.
20-
class code_assignt : public codet
22+
class code_assignt : public goto_instruction_codet
2123
{
2224
public:
23-
code_assignt() : codet(ID_assign)
25+
code_assignt() : goto_instruction_codet(ID_assign)
2426
{
2527
operands().resize(2);
2628
}
2729

2830
code_assignt(exprt lhs, exprt rhs)
29-
: codet(ID_assign, {std::move(lhs), std::move(rhs)})
31+
: goto_instruction_codet(ID_assign, {std::move(lhs), std::move(rhs)})
3032
{
3133
}
3234

3335
code_assignt(exprt lhs, exprt rhs, source_locationt loc)
34-
: codet(ID_assign, {std::move(lhs), std::move(rhs)}, std::move(loc))
36+
: goto_instruction_codet(
37+
ID_assign,
38+
{std::move(lhs), std::move(rhs)},
39+
std::move(loc))
3540
{
3641
}
3742

@@ -56,15 +61,15 @@ class code_assignt : public codet
5661
}
5762

5863
static void check(
59-
const codet &code,
64+
const goto_instruction_codet &code,
6065
const validation_modet vm = validation_modet::INVARIANT)
6166
{
6267
DATA_CHECK(
6368
vm, code.operands().size() == 2, "assignment must have two operands");
6469
}
6570

6671
static void validate(
67-
const codet &code,
72+
const goto_instruction_codet &code,
6873
const namespacet &,
6974
const validation_modet vm = validation_modet::INVARIANT)
7075
{
@@ -77,7 +82,7 @@ class code_assignt : public codet
7782
}
7883

7984
static void validate_full(
80-
const codet &code,
85+
const goto_instruction_codet &code,
8186
const namespacet &ns,
8287
const validation_modet vm = validation_modet::INVARIANT)
8388
{
@@ -90,10 +95,10 @@ class code_assignt : public codet
9095
}
9196

9297
protected:
93-
using codet::op0;
94-
using codet::op1;
95-
using codet::op2;
96-
using codet::op3;
98+
using goto_instruction_codet::op0;
99+
using goto_instruction_codet::op1;
100+
using goto_instruction_codet::op2;
101+
using goto_instruction_codet::op3;
97102
};
98103

99104
template <>
@@ -107,26 +112,27 @@ inline void validate_expr(const code_assignt &x)
107112
code_assignt::check(x);
108113
}
109114

110-
inline const code_assignt &to_code_assign(const codet &code)
115+
inline const code_assignt &to_code_assign(const goto_instruction_codet &code)
111116
{
112117
PRECONDITION(code.get_statement() == ID_assign);
113118
code_assignt::check(code);
114119
return static_cast<const code_assignt &>(code);
115120
}
116121

117-
inline code_assignt &to_code_assign(codet &code)
122+
inline code_assignt &to_code_assign(goto_instruction_codet &code)
118123
{
119124
PRECONDITION(code.get_statement() == ID_assign);
120125
code_assignt::check(code);
121126
return static_cast<code_assignt &>(code);
122127
}
123128

124-
/// A \ref codet representing the removal of a local variable going out of
125-
/// scope.
126-
class code_deadt : public codet
129+
/// A \ref goto_instruction_codet representing the removal of
130+
/// a local variable going out of scope.
131+
class code_deadt : public goto_instruction_codet
127132
{
128133
public:
129-
explicit code_deadt(symbol_exprt symbol) : codet(ID_dead, {std::move(symbol)})
134+
explicit code_deadt(symbol_exprt symbol)
135+
: goto_instruction_codet(ID_dead, {std::move(symbol)})
130136
{
131137
}
132138

@@ -146,7 +152,7 @@ class code_deadt : public codet
146152
}
147153

148154
static void check(
149-
const codet &code,
155+
const goto_instruction_codet &code,
150156
const validation_modet vm = validation_modet::INVARIANT)
151157
{
152158
DATA_CHECK(
@@ -160,10 +166,10 @@ class code_deadt : public codet
160166
}
161167

162168
protected:
163-
using codet::op0;
164-
using codet::op1;
165-
using codet::op2;
166-
using codet::op3;
169+
using goto_instruction_codet::op0;
170+
using goto_instruction_codet::op1;
171+
using goto_instruction_codet::op2;
172+
using goto_instruction_codet::op3;
167173
};
168174

169175
template <>
@@ -177,28 +183,29 @@ inline void validate_expr(const code_deadt &x)
177183
code_deadt::check(x);
178184
}
179185

180-
inline const code_deadt &to_code_dead(const codet &code)
186+
inline const code_deadt &to_code_dead(const goto_instruction_codet &code)
181187
{
182188
PRECONDITION(code.get_statement() == ID_dead);
183189
code_deadt::check(code);
184190
return static_cast<const code_deadt &>(code);
185191
}
186192

187-
inline code_deadt &to_code_dead(codet &code)
193+
inline code_deadt &to_code_dead(goto_instruction_codet &code)
188194
{
189195
PRECONDITION(code.get_statement() == ID_dead);
190196
code_deadt::check(code);
191197
return static_cast<code_deadt &>(code);
192198
}
193199

194-
/// A `codet` representing the declaration of a local variable.
200+
/// A `goto_instruction_codet` representing the declaration of a local variable.
195201
/// For example, if a variable (symbol) `x` is represented as a
196202
/// \ref symbol_exprt `sym`, then the declaration of this variable can be
197203
/// represented as `code_declt(sym)`.
198-
class code_declt : public codet
204+
class code_declt : public goto_instruction_codet
199205
{
200206
public:
201-
explicit code_declt(symbol_exprt symbol) : codet(ID_decl, {std::move(symbol)})
207+
explicit code_declt(symbol_exprt symbol)
208+
: goto_instruction_codet(ID_decl, {std::move(symbol)})
202209
{
203210
}
204211

@@ -218,7 +225,7 @@ class code_declt : public codet
218225
}
219226

220227
static void check(
221-
const codet &code,
228+
const goto_instruction_codet &code,
222229
const validation_modet vm = validation_modet::INVARIANT)
223230
{
224231
DATA_CHECK(
@@ -242,30 +249,30 @@ inline void validate_expr(const code_declt &x)
242249
code_declt::check(x);
243250
}
244251

245-
inline const code_declt &to_code_decl(const codet &code)
252+
inline const code_declt &to_code_decl(const goto_instruction_codet &code)
246253
{
247254
PRECONDITION(code.get_statement() == ID_decl);
248255
code_declt::check(code);
249256
return static_cast<const code_declt &>(code);
250257
}
251258

252-
inline code_declt &to_code_decl(codet &code)
259+
inline code_declt &to_code_decl(goto_instruction_codet &code)
253260
{
254261
PRECONDITION(code.get_statement() == ID_decl);
255262
code_declt::check(code);
256263
return static_cast<code_declt &>(code);
257264
}
258265

259-
/// \ref codet representation of a function call statement.
266+
/// \ref goto_instruction_codet representation of a function call statement.
260267
/// The function call statement has three operands.
261268
/// The first is the expression that is used to store the return value.
262269
/// The second is the function called.
263270
/// The third is a vector of argument values.
264-
class code_function_callt : public codet
271+
class code_function_callt : public goto_instruction_codet
265272
{
266273
public:
267274
explicit code_function_callt(exprt _function)
268-
: codet(
275+
: goto_instruction_codet(
269276
ID_function_call,
270277
{nil_exprt(), std::move(_function), exprt(ID_arguments)})
271278
{
@@ -274,7 +281,7 @@ class code_function_callt : public codet
274281
typedef exprt::operandst argumentst;
275282

276283
code_function_callt(exprt _lhs, exprt _function, argumentst _arguments)
277-
: codet(
284+
: goto_instruction_codet(
278285
ID_function_call,
279286
{std::move(_lhs), std::move(_function), exprt(ID_arguments)})
280287
{
@@ -318,7 +325,7 @@ class code_function_callt : public codet
318325
}
319326

320327
static void check(
321-
const codet &code,
328+
const goto_instruction_codet &code,
322329
const validation_modet vm = validation_modet::INVARIANT)
323330
{
324331
DATA_CHECK(
@@ -330,7 +337,7 @@ class code_function_callt : public codet
330337
}
331338

332339
static void validate(
333-
const codet &code,
340+
const goto_instruction_codet &code,
334341
const namespacet &,
335342
const validation_modet vm = validation_modet::INVARIANT)
336343
{
@@ -344,7 +351,7 @@ class code_function_callt : public codet
344351
}
345352

346353
static void validate_full(
347-
const codet &code,
354+
const goto_instruction_codet &code,
348355
const namespacet &ns,
349356
const validation_modet vm = validation_modet::INVARIANT)
350357
{
@@ -357,10 +364,10 @@ class code_function_callt : public codet
357364
}
358365

359366
protected:
360-
using codet::op0;
361-
using codet::op1;
362-
using codet::op2;
363-
using codet::op3;
367+
using goto_instruction_codet::op0;
368+
using goto_instruction_codet::op1;
369+
using goto_instruction_codet::op2;
370+
using goto_instruction_codet::op3;
364371
};
365372

366373
template <>
@@ -374,29 +381,30 @@ inline void validate_expr(const code_function_callt &x)
374381
code_function_callt::check(x);
375382
}
376383

377-
inline const code_function_callt &to_code_function_call(const codet &code)
384+
inline const code_function_callt &
385+
to_code_function_call(const goto_instruction_codet &code)
378386
{
379387
PRECONDITION(code.get_statement() == ID_function_call);
380388
code_function_callt::check(code);
381389
return static_cast<const code_function_callt &>(code);
382390
}
383391

384-
inline code_function_callt &to_code_function_call(codet &code)
392+
inline code_function_callt &to_code_function_call(goto_instruction_codet &code)
385393
{
386394
PRECONDITION(code.get_statement() == ID_function_call);
387395
code_function_callt::check(code);
388396
return static_cast<code_function_callt &>(code);
389397
}
390398

391-
/// A `codet` representing the declaration that an input of a particular
392-
/// description has a value which corresponds to the value of a given expression
393-
/// (or expressions).
399+
/// A `goto_instruction_codet` representing the declaration that an input of
400+
/// a particular description has a value which corresponds to the value of a
401+
/// given expression (or expressions).
394402
/// When working with the C front end, calls to the `__CPROVER_input` intrinsic
395403
/// can be added to the input code in order add instructions of this type to the
396404
/// goto program.
397405
/// The first argument is expected to be a C string denoting the input
398406
/// identifier. The second argument is the expression for the input value.
399-
class code_inputt : public codet
407+
class code_inputt : public goto_instruction_codet
400408
{
401409
public:
402410
/// This constructor is for support of calls to `__CPROVER_input` in user
@@ -420,7 +428,7 @@ class code_inputt : public codet
420428
optionalt<source_locationt> location = {});
421429

422430
static void check(
423-
const codet &code,
431+
const goto_instruction_codet &code,
424432
const validation_modet vm = validation_modet::INVARIANT);
425433
};
426434

@@ -435,15 +443,15 @@ inline void validate_expr(const code_inputt &input)
435443
code_inputt::check(input);
436444
}
437445

438-
/// A `codet` representing the declaration that an output of a particular
439-
/// description has a value which corresponds to the value of a given expression
440-
/// (or expressions).
446+
/// A `goto_instruction_codet` representing the declaration that an output of
447+
/// a particular description has a value which corresponds to the value of a
448+
/// given expression (or expressions).
441449
/// When working with the C front end, calls to the `__CPROVER_output` intrinsic
442450
/// can be added to the input code in order add instructions of this type to the
443451
/// goto program.
444452
/// The first argument is expected to be a C string denoting the output
445453
/// identifier. The second argument is the expression for the output value.
446-
class code_outputt : public codet
454+
class code_outputt : public goto_instruction_codet
447455
{
448456
public:
449457
/// This constructor is for support of calls to `__CPROVER_output` in user
@@ -466,7 +474,7 @@ class code_outputt : public codet
466474
optionalt<source_locationt> location = {});
467475

468476
static void check(
469-
const codet &code,
477+
const goto_instruction_codet &code,
470478
const validation_modet vm = validation_modet::INVARIANT);
471479
};
472480

@@ -481,11 +489,13 @@ inline void validate_expr(const code_outputt &output)
481489
code_outputt::check(output);
482490
}
483491

484-
/// \ref codet representation of a "return from a function" statement.
485-
class code_returnt : public codet
492+
/// \ref goto_instruction_codet representation of a "return from a
493+
/// function" statement.
494+
class code_returnt : public goto_instruction_codet
486495
{
487496
public:
488-
explicit code_returnt(exprt _op) : codet(ID_return, {std::move(_op)})
497+
explicit code_returnt(exprt _op)
498+
: goto_instruction_codet(ID_return, {std::move(_op)})
489499
{
490500
}
491501

@@ -500,17 +510,17 @@ class code_returnt : public codet
500510
}
501511

502512
static void check(
503-
const codet &code,
513+
const goto_instruction_codet &code,
504514
const validation_modet vm = validation_modet::INVARIANT)
505515
{
506516
DATA_CHECK(vm, code.operands().size() == 1, "return must have one operand");
507517
}
508518

509519
protected:
510-
using codet::op0;
511-
using codet::op1;
512-
using codet::op2;
513-
using codet::op3;
520+
using goto_instruction_codet::op0;
521+
using goto_instruction_codet::op1;
522+
using goto_instruction_codet::op2;
523+
using goto_instruction_codet::op3;
514524
};
515525

516526
template <>
@@ -524,14 +534,14 @@ inline void validate_expr(const code_returnt &x)
524534
code_returnt::check(x);
525535
}
526536

527-
inline const code_returnt &to_code_return(const codet &code)
537+
inline const code_returnt &to_code_return(const goto_instruction_codet &code)
528538
{
529539
PRECONDITION(code.get_statement() == ID_return);
530540
code_returnt::check(code);
531541
return static_cast<const code_returnt &>(code);
532542
}
533543

534-
inline code_returnt &to_code_return(codet &code)
544+
inline code_returnt &to_code_return(goto_instruction_codet &code)
535545
{
536546
PRECONDITION(code.get_statement() == ID_return);
537547
code_returnt::check(code);

0 commit comments

Comments
 (0)