Skip to content

Commit b01f1f6

Browse files
author
Daniel Kroening
authored
Merge pull request #3017 from diffblue/exprt-operands
nullary and ternary expressions
2 parents e1f5644 + dfb1c95 commit b01f1f6

File tree

6 files changed

+133
-68
lines changed

6 files changed

+133
-68
lines changed

src/ansi-c/ansi_c_declaration.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <cassert>
1616

17+
#include <util/std_expr.h>
1718
#include <util/symbol.h>
1819

19-
class ansi_c_declaratort:public exprt
20+
class ansi_c_declaratort : public nullary_exprt
2021
{
2122
public:
22-
ansi_c_declaratort():exprt(ID_declarator)
23+
ansi_c_declaratort() : nullary_exprt(ID_declarator)
2324
{
2425
}
2526

src/solvers/smt2/smt2_conv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ class smt2_convt:public prop_convt
241241
std::string floatbv_suffix(const exprt &) const;
242242
std::set<irep_idt> bvfp_set; // already converted
243243

244-
class smt2_symbolt:public exprt
244+
class smt2_symbolt : public nullary_exprt
245245
{
246246
public:
247-
smt2_symbolt(const irep_idt &_identifier, const typet &_type):
248-
exprt(ID_smt2_symbol, _type)
247+
smt2_symbolt(const irep_idt &_identifier, const typet &_type)
248+
: nullary_exprt(ID_smt2_symbol, _type)
249249
{ set(ID_identifier, _identifier); }
250250

251251
const irep_idt &get_identifier() const

src/util/byte_operators.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,25 @@ inline byte_extract_big_endian_exprt
122122

123123
/*! \brief TO_BE_DOCUMENTED
124124
*/
125-
class byte_update_exprt:public exprt
125+
class byte_update_exprt : public ternary_exprt
126126
{
127127
public:
128-
explicit byte_update_exprt(irep_idt _id):exprt(_id)
128+
explicit byte_update_exprt(irep_idt _id) : ternary_exprt(_id)
129129
{
130-
operands().resize(3);
131130
}
132131

133-
byte_update_exprt(irep_idt _id, const typet &_type):
134-
exprt(_id, _type)
132+
byte_update_exprt(irep_idt _id, const typet &_type)
133+
: ternary_exprt(_id, _type)
135134
{
136-
operands().resize(3);
137135
}
138136

139137
byte_update_exprt(
140138
irep_idt _id,
141-
const exprt &_op, const exprt &_offset, const exprt &_value):
142-
exprt(_id, _op.type())
139+
const exprt &_op,
140+
const exprt &_offset,
141+
const exprt &_value)
142+
: ternary_exprt(_id, _op, _offset, _value, _op.type())
143143
{
144-
copy_to_operands(_op, _offset, _value);
145144
}
146145

147146
exprt &op() { return op0(); }

src/util/std_expr.h

Lines changed: 113 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,82 @@ Author: Daniel Kroening, [email protected]
1818
#include "mathematical_types.h"
1919
#include "std_types.h"
2020

21+
/// An expression without operands
22+
class nullary_exprt : public exprt
23+
{
24+
public:
25+
// constructors
26+
DEPRECATED("use nullary_exprt(id, type) instead")
27+
explicit nullary_exprt(const irep_idt &_id) : exprt(_id)
28+
{
29+
}
30+
31+
nullary_exprt(const irep_idt &_id, const typet &_type) : exprt(_id, _type)
32+
{
33+
}
34+
35+
/// remove all operand methods
36+
operandst &operands() = delete;
37+
const operandst &operands() const = delete;
38+
39+
const exprt &op0() const = delete;
40+
exprt &op0() = delete;
41+
const exprt &op1() const = delete;
42+
exprt &op1() = delete;
43+
const exprt &op2() const = delete;
44+
exprt &op2() = delete;
45+
const exprt &op3() const = delete;
46+
exprt &op3() = delete;
47+
48+
void move_to_operands(exprt &) = delete;
49+
void move_to_operands(exprt &, exprt &) = delete;
50+
void move_to_operands(exprt &, exprt &, exprt &) = delete;
51+
52+
void copy_to_operands(const exprt &expr) = delete;
53+
void copy_to_operands(const exprt &, const exprt &) = delete;
54+
void copy_to_operands(const exprt &, const exprt &, const exprt &) = delete;
55+
};
56+
57+
/// An expression with three operands
58+
class ternary_exprt : public exprt
59+
{
60+
public:
61+
// constructors
62+
DEPRECATED("use ternary_exprt(id, op0, op1, op2, type) instead")
63+
explicit ternary_exprt(const irep_idt &_id) : exprt(_id)
64+
{
65+
operands().resize(3);
66+
}
67+
68+
DEPRECATED("use ternary_exprt(id, op0, op1, op2, type) instead")
69+
explicit ternary_exprt(const irep_idt &_id, const typet &_type)
70+
: exprt(_id, _type)
71+
{
72+
operands().resize(3);
73+
}
74+
75+
ternary_exprt(
76+
const irep_idt &_id,
77+
const exprt &_op0,
78+
const exprt &_op1,
79+
const exprt &_op2,
80+
const typet &_type)
81+
: exprt(_id, _type)
82+
{
83+
copy_to_operands(_op0, _op1, _op2);
84+
}
85+
86+
const exprt &op3() const = delete;
87+
exprt &op3() = delete;
88+
};
89+
2190
/// Transition system, consisting of state invariant, initial state predicate,
2291
/// and transition predicate.
23-
class transt:public exprt
92+
class transt : public ternary_exprt
2493
{
2594
public:
26-
transt()
95+
transt() : ternary_exprt(ID_trans)
2796
{
28-
id(ID_trans);
29-
operands().resize(3);
3097
}
3198

3299
exprt &invar() { return op0(); }
@@ -72,31 +139,30 @@ inline void validate_expr(const transt &value)
72139

73140

74141
/// Expression to hold a symbol (variable)
75-
class symbol_exprt:public exprt
142+
class symbol_exprt : public nullary_exprt
76143
{
77144
public:
78145
DEPRECATED("use symbol_exprt(identifier, type) instead")
79-
symbol_exprt():exprt(ID_symbol)
146+
symbol_exprt() : nullary_exprt(ID_symbol)
80147
{
81148
}
82149

83150
/// \param identifier: Name of symbol
84151
DEPRECATED("use symbol_exprt(identifier, type) instead")
85-
explicit symbol_exprt(const irep_idt &identifier):exprt(ID_symbol)
152+
explicit symbol_exprt(const irep_idt &identifier) : nullary_exprt(ID_symbol)
86153
{
87154
set_identifier(identifier);
88155
}
89156

90157
/// \param type: Type of symbol
91-
explicit symbol_exprt(const typet &type):exprt(ID_symbol, type)
158+
explicit symbol_exprt(const typet &type) : nullary_exprt(ID_symbol, type)
92159
{
93160
}
94161

95162
/// \param identifier: Name of symbol
96163
/// \param type: Type of symbol
97-
symbol_exprt(
98-
const irep_idt &identifier,
99-
const typet &type):exprt(ID_symbol, type)
164+
symbol_exprt(const irep_idt &identifier, const typet &type)
165+
: nullary_exprt(ID_symbol, type)
100166
{
101167
set_identifier(identifier);
102168
}
@@ -137,7 +203,7 @@ class decorated_symbol_exprt:public symbol_exprt
137203
}
138204

139205
/// \param identifier: Name of symbol
140-
/// \param : type Type of symbol
206+
/// \param type: Type of symbol
141207
decorated_symbol_exprt(
142208
const irep_idt &identifier,
143209
const typet &type):symbol_exprt(identifier, type)
@@ -207,14 +273,13 @@ inline void validate_expr(const symbol_exprt &value)
207273

208274

209275
/// \brief Expression to hold a nondeterministic choice
210-
class nondet_symbol_exprt:public exprt
276+
class nondet_symbol_exprt : public nullary_exprt
211277
{
212278
public:
213279
/// \param identifier: Name of symbol
214-
/// \param : type Type of symbol
215-
nondet_symbol_exprt(
216-
const irep_idt &identifier,
217-
const typet &type):exprt(ID_nondet_symbol, type)
280+
/// \param type: Type of symbol
281+
nondet_symbol_exprt(const irep_idt &identifier, const typet &type)
282+
: nullary_exprt(ID_nondet_symbol, type)
218283
{
219284
set_identifier(identifier);
220285
}
@@ -310,6 +375,13 @@ class unary_exprt:public exprt
310375
{
311376
return op0();
312377
}
378+
379+
const exprt &op1() const = delete;
380+
exprt &op1() = delete;
381+
const exprt &op2() const = delete;
382+
exprt &op2() = delete;
383+
const exprt &op3() const = delete;
384+
exprt &op3() = delete;
313385
};
314386

315387
/// \brief Cast an exprt to a \ref unary_exprt
@@ -666,8 +738,10 @@ class binary_exprt:public exprt
666738
copy_to_operands(_lhs, _rhs);
667739
}
668740

669-
protected:
670-
using exprt::op2; // hide
741+
const exprt &op2() const = delete;
742+
exprt &op2() = delete;
743+
const exprt &op3() const = delete;
744+
exprt &op3() = delete;
671745
};
672746

673747
/// \brief Cast an exprt to a \ref binary_exprt
@@ -3186,29 +3260,22 @@ inline void validate_expr(const dereference_exprt &value)
31863260

31873261

31883262
/// \brief The trinary if-then-else operator
3189-
class if_exprt:public exprt
3263+
class if_exprt : public ternary_exprt
31903264
{
31913265
public:
3192-
if_exprt(const exprt &cond, const exprt &t, const exprt &f):
3193-
exprt(ID_if, t.type())
3266+
if_exprt(const exprt &cond, const exprt &t, const exprt &f)
3267+
: ternary_exprt(ID_if, cond, t, f, t.type())
31943268
{
3195-
copy_to_operands(cond, t, f);
31963269
}
31973270

3198-
if_exprt(
3199-
const exprt &cond,
3200-
const exprt &t,
3201-
const exprt &f,
3202-
const typet &type):
3203-
exprt(ID_if, type)
3271+
if_exprt(const exprt &cond, const exprt &t, const exprt &f, const typet &type)
3272+
: ternary_exprt(ID_if, cond, t, f, type)
32043273
{
3205-
copy_to_operands(cond, t, f);
32063274
}
32073275

32083276
DEPRECATED("use if_exprt(cond, t, f) instead")
3209-
if_exprt():exprt(ID_if)
3277+
if_exprt() : ternary_exprt(ID_if)
32103278
{
3211-
operands().resize(3);
32123279
}
32133280

32143281
exprt &cond()
@@ -3473,29 +3540,25 @@ inline void validate_expr(const member_designatort &value)
34733540

34743541

34753542
/// \brief Operator to update elements in structs and arrays
3476-
class update_exprt:public exprt
3543+
class update_exprt : public ternary_exprt
34773544
{
34783545
public:
34793546
update_exprt(
34803547
const exprt &_old,
34813548
const exprt &_designator,
3482-
const exprt &_new_value):
3483-
exprt(ID_update, _old.type())
3549+
const exprt &_new_value)
3550+
: ternary_exprt(ID_update, _old, _designator, _new_value, _old.type())
34843551
{
3485-
copy_to_operands(_old, _designator, _new_value);
34863552
}
34873553

34883554
DEPRECATED("use update_exprt(old, where, new_value) instead")
3489-
explicit update_exprt(const typet &_type):
3490-
exprt(ID_update, _type)
3555+
explicit update_exprt(const typet &_type) : ternary_exprt(ID_update, _type)
34913556
{
3492-
operands().resize(3);
34933557
}
34943558

34953559
DEPRECATED("use update_exprt(old, where, new_value) instead")
3496-
update_exprt():exprt(ID_update)
3560+
update_exprt() : ternary_exprt(ID_update)
34973561
{
3498-
operands().resize(3);
34993562
op1().id(ID_designator);
35003563
}
35013564

@@ -4132,15 +4195,15 @@ inline ieee_float_op_exprt &to_ieee_float_op_expr(exprt &expr)
41324195

41334196

41344197
/// \brief An expression denoting a type
4135-
class type_exprt:public exprt
4198+
class type_exprt : public nullary_exprt
41364199
{
41374200
public:
41384201
DEPRECATED("use type_exprt(type) instead")
4139-
type_exprt():exprt(ID_type)
4202+
type_exprt() : nullary_exprt(ID_type)
41404203
{
41414204
}
41424205

4143-
explicit type_exprt(const typet &type):exprt(ID_type, type)
4206+
explicit type_exprt(const typet &type) : nullary_exprt(ID_type, type)
41444207
{
41454208
}
41464209
};
@@ -4223,10 +4286,11 @@ class false_exprt:public constant_exprt
42234286
};
42244287

42254288
/// \brief The NIL expression
4226-
class nil_exprt:public exprt
4289+
class nil_exprt : public nullary_exprt
42274290
{
42284291
public:
4229-
nil_exprt():exprt(static_cast<const exprt &>(get_nil_irep()))
4292+
nil_exprt()
4293+
: nullary_exprt(static_cast<const nullary_exprt &>(get_nil_irep()))
42304294
{
42314295
}
42324296
};
@@ -4393,11 +4457,11 @@ template<> inline bool can_cast_expr<concatenation_exprt>(const exprt &base)
43934457

43944458

43954459
/// \brief An expression denoting infinity
4396-
class infinity_exprt:public exprt
4460+
class infinity_exprt : public nullary_exprt
43974461
{
43984462
public:
4399-
explicit infinity_exprt(const typet &_type):
4400-
exprt(ID_infinity, _type)
4463+
explicit infinity_exprt(const typet &_type)
4464+
: nullary_exprt(ID_infinity, _type)
44014465
{
44024466
}
44034467
};

src/util/string_constant.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ Author: Daniel Kroening, [email protected]
1212
#include "c_types.h"
1313
#include "std_expr.h"
1414

15-
string_constantt::string_constantt():
16-
exprt(ID_string_constant)
15+
string_constantt::string_constantt() : nullary_exprt(ID_string_constant)
1716
{
1817
set_value(irep_idt());
1918
}
2019

21-
string_constantt::string_constantt(const irep_idt &_value):
22-
exprt(ID_string_constant)
20+
string_constantt::string_constantt(const irep_idt &_value)
21+
: nullary_exprt(ID_string_constant)
2322
{
2423
set_value(_value);
2524
}

src/util/string_constant.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ Author: Daniel Kroening, [email protected]
1212
#include "std_expr.h"
1313
#include "expr.h"
1414

15-
class string_constantt:public exprt
15+
class string_constantt : public nullary_exprt
1616
{
1717
public:
18+
DEPRECATED("use string_constantt(value) instead")
1819
string_constantt();
20+
1921
explicit string_constantt(const irep_idt &value);
2022

2123
void set_value(const irep_idt &value);

0 commit comments

Comments
 (0)