Skip to content

Commit 95ee0f6

Browse files
author
Daniel Kroening
committed
remove exprt::negate, sum, mul, subtract (deprecated since 2011)
1 parent 80060ea commit 95ee0f6

File tree

3 files changed

+125
-232
lines changed

3 files changed

+125
-232
lines changed

src/util/expr.cpp

+6-217
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ Author: Daniel Kroening, [email protected]
99
/// \file
1010
/// Expression Representation
1111

12+
#include "arith_tools.h"
1213
#include "expr.h"
13-
#include <cassert>
14-
#include <stack>
15-
#include "string2int.h"
16-
#include "mp_arith.h"
14+
#include "expr_iterator.h"
1715
#include "fixedbv.h"
1816
#include "ieee_float.h"
1917
#include "invariant.h"
20-
#include "expr_iterator.h"
18+
#include "mp_arith.h"
2119
#include "rational.h"
2220
#include "rational_tools.h"
23-
#include "arith_tools.h"
2421
#include "std_expr.h"
22+
#include "string2int.h"
23+
24+
#include <stack>
2525

2626
void exprt::move_to_operands(exprt &expr)
2727
{
@@ -160,72 +160,6 @@ void exprt::make_false()
160160
set(ID_value, ID_false);
161161
}
162162

163-
void exprt::negate()
164-
{
165-
const irep_idt &type_id=type().id();
166-
167-
if(type_id==ID_bool)
168-
make_not();
169-
else
170-
{
171-
if(is_constant())
172-
{
173-
const irep_idt &value=get(ID_value);
174-
175-
if(type_id==ID_integer)
176-
{
177-
set(ID_value, integer2string(-string2integer(id2string(value))));
178-
}
179-
else if(type_id==ID_unsignedbv)
180-
{
181-
mp_integer int_value=binary2integer(id2string(value), false);
182-
typet _type=type();
183-
*this=from_integer(-int_value, _type);
184-
}
185-
else if(type_id==ID_signedbv)
186-
{
187-
mp_integer int_value=binary2integer(id2string(value), true);
188-
typet _type=type();
189-
*this=from_integer(-int_value, _type);
190-
}
191-
else if(type_id==ID_fixedbv)
192-
{
193-
fixedbvt fixedbv_value=fixedbvt(to_constant_expr(*this));
194-
fixedbv_value.negate();
195-
*this=fixedbv_value.to_expr();
196-
}
197-
else if(type_id==ID_floatbv)
198-
{
199-
ieee_floatt ieee_float_value=ieee_floatt(to_constant_expr(*this));
200-
ieee_float_value.negate();
201-
*this=ieee_float_value.to_expr();
202-
}
203-
else
204-
{
205-
make_nil();
206-
UNREACHABLE;
207-
}
208-
}
209-
else
210-
{
211-
if(id()==ID_unary_minus)
212-
{
213-
exprt tmp;
214-
DATA_INVARIANT(operands().size()==1,
215-
"Unary minus must have one operand");
216-
tmp.swap(op0());
217-
swap(tmp);
218-
}
219-
else
220-
{
221-
exprt tmp(ID_unary_minus, type());
222-
tmp.move_to_operands(*this);
223-
swap(tmp);
224-
}
225-
}
226-
}
227-
}
228-
229163
bool exprt::is_boolean() const
230164
{
231165
return type().id()==ID_bool;
@@ -316,151 +250,6 @@ bool exprt::is_one() const
316250
return false;
317251
}
318252

319-
bool exprt::sum(const exprt &expr)
320-
{
321-
if(!is_constant() || !expr.is_constant())
322-
return true;
323-
if(type()!=expr.type())
324-
return true;
325-
326-
const irep_idt &type_id=type().id();
327-
328-
if(type_id==ID_integer || type_id==ID_natural)
329-
{
330-
set(ID_value, integer2string(
331-
string2integer(get_string(ID_value))+
332-
string2integer(expr.get_string(ID_value))));
333-
return false;
334-
}
335-
else if(type_id==ID_rational)
336-
{
337-
rationalt a, b;
338-
if(!to_rational(*this, a) && !to_rational(expr, b))
339-
{
340-
exprt a_plus_b=from_rational(a+b);
341-
set(ID_value, a_plus_b.get_string(ID_value));
342-
return false;
343-
}
344-
}
345-
else if(type_id==ID_unsignedbv || type_id==ID_signedbv)
346-
{
347-
set(ID_value, integer2binary(
348-
binary2integer(get_string(ID_value), false)+
349-
binary2integer(expr.get_string(ID_value), false),
350-
unsafe_string2unsigned(type().get_string(ID_width))));
351-
return false;
352-
}
353-
else if(type_id==ID_fixedbv)
354-
{
355-
set(ID_value, integer2binary(
356-
binary2integer(get_string(ID_value), false)+
357-
binary2integer(expr.get_string(ID_value), false),
358-
unsafe_string2unsigned(type().get_string(ID_width))));
359-
return false;
360-
}
361-
else if(type_id==ID_floatbv)
362-
{
363-
ieee_floatt f(to_constant_expr(*this));
364-
f+=ieee_floatt(to_constant_expr(expr));
365-
*this=f.to_expr();
366-
return false;
367-
}
368-
369-
return true;
370-
}
371-
372-
bool exprt::mul(const exprt &expr)
373-
{
374-
if(!is_constant() || !expr.is_constant())
375-
return true;
376-
if(type()!=expr.type())
377-
return true;
378-
379-
const irep_idt &type_id=type().id();
380-
381-
if(type_id==ID_integer || type_id==ID_natural)
382-
{
383-
set(ID_value, integer2string(
384-
string2integer(get_string(ID_value))*
385-
string2integer(expr.get_string(ID_value))));
386-
return false;
387-
}
388-
else if(type_id==ID_rational)
389-
{
390-
rationalt a, b;
391-
if(!to_rational(*this, a) && !to_rational(expr, b))
392-
{
393-
exprt a_mul_b=from_rational(a*b);
394-
set(ID_value, a_mul_b.get_string(ID_value));
395-
return false;
396-
}
397-
}
398-
else if(type_id==ID_unsignedbv || type_id==ID_signedbv)
399-
{
400-
// the following works for signed and unsigned integers
401-
set(ID_value, integer2binary(
402-
binary2integer(get_string(ID_value), false)*
403-
binary2integer(expr.get_string(ID_value), false),
404-
unsafe_string2unsigned(type().get_string(ID_width))));
405-
return false;
406-
}
407-
else if(type_id==ID_fixedbv)
408-
{
409-
fixedbvt f(to_constant_expr(*this));
410-
f*=fixedbvt(to_constant_expr(expr));
411-
*this=f.to_expr();
412-
return false;
413-
}
414-
else if(type_id==ID_floatbv)
415-
{
416-
ieee_floatt f(to_constant_expr(*this));
417-
f*=ieee_floatt(to_constant_expr(expr));
418-
*this=f.to_expr();
419-
return false;
420-
}
421-
422-
return true;
423-
}
424-
425-
bool exprt::subtract(const exprt &expr)
426-
{
427-
if(!is_constant() || !expr.is_constant())
428-
return true;
429-
430-
if(type()!=expr.type())
431-
return true;
432-
433-
const irep_idt &type_id=type().id();
434-
435-
if(type_id==ID_integer || type_id==ID_natural)
436-
{
437-
set(ID_value, integer2string(
438-
string2integer(get_string(ID_value))-
439-
string2integer(expr.get_string(ID_value))));
440-
return false;
441-
}
442-
else if(type_id==ID_rational)
443-
{
444-
rationalt a, b;
445-
if(!to_rational(*this, a) && !to_rational(expr, b))
446-
{
447-
exprt a_minus_b=from_rational(a-b);
448-
set(ID_value, a_minus_b.get_string(ID_value));
449-
return false;
450-
}
451-
}
452-
else if(type_id==ID_unsignedbv || type_id==ID_signedbv)
453-
{
454-
set(ID_value, integer2binary(
455-
binary2integer(get_string(ID_value), false)-
456-
binary2integer(expr.get_string(ID_value), false),
457-
unsafe_string2unsigned(type().get_string(ID_width))));
458-
return false;
459-
}
460-
461-
return true;
462-
}
463-
464253
const source_locationt &exprt::find_source_location() const
465254
{
466255
const source_locationt &l=source_location();

src/util/expr.h

-5
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ class exprt:public irept
123123
void make_true();
124124
void make_false();
125125
void make_bool(bool value);
126-
void negate();
127-
128-
bool sum(const exprt &expr);
129-
bool mul(const exprt &expr);
130-
bool subtract(const exprt &expr);
131126

132127
bool is_constant() const;
133128
bool is_true() const;

0 commit comments

Comments
 (0)