Skip to content

Commit c92033f

Browse files
author
Daniel Kroening
committed
avoid usage of partial constructor for constant_exprt
1 parent c89d376 commit c92033f

14 files changed

+38
-76
lines changed

src/goto-cc/linker_script_merge.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,11 @@ int linker_script_merget::ls_data2instructions(
565565

566566
symbol_exprt lhs(d["sym"].value, pointer_type(char_type()));
567567

568-
constant_exprt rhs;
569-
rhs.set_value(integer2binary(string2integer(id2string(symbol_value)),
570-
unsigned_int_type().get_width()));
571-
rhs.type()=unsigned_int_type();
568+
constant_exprt rhs(
569+
integer2binary(
570+
string2integer(id2string(symbol_value)),
571+
unsigned_int_type().get_width()),
572+
unsigned_int_type());
572573

573574
exprt rhs_tc(rhs);
574575
rhs_tc.make_typecast(pointer_type(char_type()));

src/solvers/flattening/boolbv_get.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,13 @@ exprt boolbvt::bv_get_rec(
255255
mp_integer int_value=binary2integer(value, false);
256256
mp_integer from=string2integer(type.get_string(ID_from));
257257

258-
constant_exprt value_expr(type);
259-
value_expr.set_value(integer2string(int_value+from));
260-
return value_expr;
258+
return constant_exprt(integer2string(int_value + from), type);
261259
}
262260
break;
263261

264262
default:
265263
case bvtypet::IS_C_ENUM:
266-
constant_exprt value_expr(type);
267-
value_expr.set_value(value);
268-
return value_expr;
264+
return constant_exprt(value, type);
269265
}
270266

271267
return nil_exprt();

src/solvers/flattening/bv_pointers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,7 @@ exprt bv_pointerst::bv_get_rec(
633633
// we treat these like bit-vector constants, but with
634634
// some additional annotation
635635

636-
constant_exprt result(type);
637-
result.set_value(value);
636+
constant_exprt result(value, type);
638637

639638
pointer_logict::pointert pointer;
640639
pointer.object=integer2size_t(binary2integer(value_addr, false));

src/solvers/flattening/pointer_logic.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,24 @@ exprt pointer_logict::pointer_expr(
8080
{
8181
if(pointer.offset==0)
8282
{
83-
constant_exprt result(type);
84-
result.set_value(ID_NULL);
83+
null_pointer_exprt result(type);
8584
return result;
8685
}
8786
else
8887
{
89-
constant_exprt null(type);
90-
null.set_value(ID_NULL);
88+
null_pointer_exprt null(type);
9189
return plus_exprt(null,
9290
from_integer(pointer.offset, pointer_diff_type()));
9391
}
9492
}
9593
else if(pointer.object==invalid_object) // INVALID?
9694
{
97-
constant_exprt result(type);
98-
result.set_value("INVALID");
99-
return result;
95+
return constant_exprt("INVALID", type);
10096
}
10197

10298
if(pointer.object>=objects.size())
10399
{
104-
constant_exprt result(type);
105-
result.set_value("INVALID-"+std::to_string(pointer.object));
106-
return result;
100+
return constant_exprt("INVALID-" + std::to_string(pointer.object), type);
107101
}
108102

109103
const exprt &object_expr=objects[pointer.object];

src/solvers/smt2/smt2_conv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
23002300

23012301
if(src_type.id()==ID_bool)
23022302
{
2303-
constant_exprt val(dest_type);
2303+
constant_exprt val(irep_idt(), dest_type);
23042304

23052305
ieee_floatt a(to_floatbv_type(dest_type));
23062306

src/util/arith_tools.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ constant_exprt from_integer(
113113

114114
if(type_id==ID_integer)
115115
{
116-
constant_exprt result(type);
117-
result.set_value(integer2string(int_value));
118-
return result;
116+
return constant_exprt(integer2string(int_value), type);
119117
}
120118
else if(type_id==ID_natural)
121119
{
@@ -125,45 +123,34 @@ constant_exprt from_integer(
125123
r.make_nil();
126124
return r;
127125
}
128-
constant_exprt result(type);
129-
result.set_value(integer2string(int_value));
130-
return result;
126+
127+
return constant_exprt(integer2string(int_value), type);
131128
}
132129
else if(type_id==ID_unsignedbv)
133130
{
134131
std::size_t width=to_unsignedbv_type(type).get_width();
135-
constant_exprt result(type);
136-
result.set_value(integer2binary(int_value, width));
137-
return result;
132+
return constant_exprt(integer2binary(int_value, width), type);
138133
}
139134
else if(type_id==ID_bv)
140135
{
141136
std::size_t width=to_bv_type(type).get_width();
142-
constant_exprt result(type);
143-
result.set_value(integer2binary(int_value, width));
144-
return result;
137+
return constant_exprt(integer2binary(int_value, width), type);
145138
}
146139
else if(type_id==ID_signedbv)
147140
{
148141
std::size_t width=to_signedbv_type(type).get_width();
149-
constant_exprt result(type);
150-
result.set_value(integer2binary(int_value, width));
151-
return result;
142+
return constant_exprt(integer2binary(int_value, width), type);
152143
}
153144
else if(type_id==ID_c_enum)
154145
{
155146
const std::size_t width =
156147
to_c_enum_type(type).subtype().get_size_t(ID_width);
157-
constant_exprt result(type);
158-
result.set_value(integer2binary(int_value, width));
159-
return result;
148+
return constant_exprt(integer2binary(int_value, width), type);
160149
}
161150
else if(type_id==ID_c_bool)
162151
{
163152
std::size_t width=to_c_bool_type(type).get_width();
164-
constant_exprt result(type);
165-
result.set_value(integer2binary(int_value, width));
166-
return result;
153+
return constant_exprt(integer2binary(int_value, width), type);
167154
}
168155
else if(type_id==ID_bool)
169156
{
@@ -180,9 +167,7 @@ constant_exprt from_integer(
180167
else if(type_id==ID_c_bit_field)
181168
{
182169
std::size_t width=to_c_bit_field_type(type).get_width();
183-
constant_exprt result(type);
184-
result.set_value(integer2binary(int_value, width));
185-
return result;
170+
return constant_exprt(integer2binary(int_value, width), type);
186171
}
187172
else if(type_id==ID_fixedbv)
188173
{

src/util/bv_arithmetic.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ mp_integer bv_arithmetict::pack() const
8585

8686
exprt bv_arithmetict::to_expr() const
8787
{
88-
constant_exprt result(spec.to_type());
89-
result.set_value(integer2binary(value, spec.width));
90-
return result;
88+
return constant_exprt(integer2binary(value, spec.width), spec.to_type());
9189
}
9290

9391
bv_arithmetict &bv_arithmetict::operator/=(const bv_arithmetict &other)

src/util/fixedbv.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ constant_exprt fixedbvt::to_expr() const
4545
fixedbv_typet type;
4646
type.set_width(spec.width);
4747
type.set_integer_bits(spec.integer_bits);
48-
constant_exprt expr(type);
4948
assert(spec.width!=0);
50-
expr.set_value(integer2binary(v, spec.width));
51-
return expr;
49+
return constant_exprt(integer2binary(v, spec.width), type);
5250
}
5351

5452
void fixedbvt::round(const fixedbv_spect &dest_spec)

src/util/ieee_float.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,7 @@ void ieee_floatt::divide_and_round(
696696

697697
constant_exprt ieee_floatt::to_expr() const
698698
{
699-
constant_exprt result(spec.to_type());
700-
result.set_value(integer2binary(pack(), spec.width()));
701-
return result;
699+
return constant_exprt(integer2binary(pack(), spec.width()), spec.to_type());
702700
}
703701

704702
ieee_floatt &ieee_floatt::operator/=(const ieee_floatt &other)

src/util/json_expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ json_objectt json(
276276
}
277277
else if(type.id()==ID_c_enum_tag)
278278
{
279-
constant_exprt tmp;
280-
tmp.type()=ns.follow_tag(to_c_enum_tag_type(type));
281-
tmp.set_value(to_constant_expr(expr).get_value());
279+
constant_exprt tmp(
280+
to_constant_expr(expr).get_value(),
281+
ns.follow_tag(to_c_enum_tag_type(type)));
282282
return json(tmp, ns, mode);
283283
}
284284
else if(type.id()==ID_bv)

src/util/rational_tools.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,5 @@ constant_exprt from_rational(const rationalt &a)
8383
std::string d=integer2string(a.get_numerator());
8484
if(a.get_denominator()!=1)
8585
d+="/"+integer2string(a.get_denominator());
86-
constant_exprt result;
87-
result.type()=rational_typet();
88-
result.set_value(d);
89-
return result;
86+
return constant_exprt(d, rational_typet());
9087
}

src/util/simplify_expr_int.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
743743

744744
assert(a_str.size()==b_str.size());
745745

746-
constant_exprt new_op(expr.type());
747746
std::string new_value;
748747
new_value.resize(width);
749748

@@ -765,7 +764,7 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
765764
else
766765
break;
767766

768-
new_op.set_value(new_value);
767+
constant_exprt new_op(new_value, expr.type());
769768

770769
// erase first operand
771770
expr.operands().erase(expr.operands().begin());
@@ -829,8 +828,7 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
829828
}
830829
else if(expr.id()==ID_bitxor)
831830
{
832-
constant_exprt new_op(expr.type());
833-
new_op.set_value(integer2binary(0, width));
831+
constant_exprt new_op(integer2binary(0, width), expr.type());
834832
expr.swap(new_op);
835833
return false;
836834
}

src/util/std_expr.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4149,19 +4149,17 @@ template<> inline bool can_cast_expr<constant_exprt>(const exprt &base)
41494149
class true_exprt:public constant_exprt
41504150
{
41514151
public:
4152-
true_exprt():constant_exprt(bool_typet())
4152+
true_exprt() : constant_exprt(ID_true, bool_typet())
41534153
{
4154-
set_value(ID_true);
41554154
}
41564155
};
41574156

41584157
/// \brief The Boolean constant false
41594158
class false_exprt:public constant_exprt
41604159
{
41614160
public:
4162-
false_exprt():constant_exprt(bool_typet())
4161+
false_exprt() : constant_exprt(ID_false, bool_typet())
41634162
{
4164-
set_value(ID_false);
41654163
}
41664164
};
41674165

@@ -4178,9 +4176,9 @@ class nil_exprt:public exprt
41784176
class null_pointer_exprt:public constant_exprt
41794177
{
41804178
public:
4181-
explicit null_pointer_exprt(const pointer_typet &type):constant_exprt(type)
4179+
explicit null_pointer_exprt(const pointer_typet &type)
4180+
: constant_exprt(ID_NULL, type)
41824181
{
4183-
set_value(ID_NULL);
41844182
}
41854183
};
41864184

src/util/xml_expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ xmlt xml(
199199
}
200200
else if(type.id()==ID_c_enum_tag)
201201
{
202-
constant_exprt tmp;
203-
tmp.type()=ns.follow_tag(to_c_enum_tag_type(type));
204-
tmp.set_value(to_constant_expr(expr).get_value());
202+
constant_exprt tmp(
203+
to_constant_expr(expr).get_value(),
204+
ns.follow_tag(to_c_enum_tag_type(type)));
205205
return xml(tmp, ns);
206206
}
207207
else if(type.id()==ID_bv)

0 commit comments

Comments
 (0)