Skip to content

Commit a77377e

Browse files
committed
remove_vector: modify expressions only when necessary
1 parent 8ae5cca commit a77377e

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/goto-programs/remove_vector.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,80 @@ Date: September 2014
1212

1313
#include "remove_vector.h"
1414

15+
/*******************************************************************\
16+
17+
Function: have_to_remove_vector
18+
19+
Inputs:
20+
21+
Outputs:
22+
23+
Purpose:
24+
25+
\*******************************************************************/
26+
27+
static bool have_to_remove_vector(const typet &type);
28+
29+
static bool have_to_remove_vector(const exprt &expr)
30+
{
31+
if(expr.type().id()==ID_vector)
32+
{
33+
if(expr.id()==ID_plus || expr.id()==ID_minus ||
34+
expr.id()==ID_mult || expr.id()==ID_div ||
35+
expr.id()==ID_mod || expr.id()==ID_bitxor ||
36+
expr.id()==ID_bitand || expr.id()==ID_bitor)
37+
return true;
38+
else if(expr.id()==ID_unary_minus || expr.id()==ID_bitnot)
39+
return true;
40+
else if(expr.id()==ID_vector)
41+
return true;
42+
}
43+
44+
if(have_to_remove_vector(expr.type()))
45+
return true;
46+
47+
forall_operands(it, expr)
48+
if(have_to_remove_vector(*it))
49+
return true;
50+
51+
return false;
52+
}
53+
54+
/*******************************************************************\
55+
56+
Function: have_to_remove_vector
57+
58+
Inputs:
59+
60+
Outputs:
61+
62+
Purpose:
63+
64+
\*******************************************************************/
65+
66+
static bool have_to_remove_vector(const typet &type)
67+
{
68+
if(type.id()==ID_struct || type.id()==ID_union)
69+
{
70+
const struct_union_typet &struct_union_type=
71+
to_struct_union_type(type);
72+
73+
for(struct_union_typet::componentst::const_iterator
74+
it=struct_union_type.components().begin();
75+
it!=struct_union_type.components().end();
76+
it++)
77+
if(have_to_remove_vector(it->type()))
78+
return true;
79+
}
80+
else if(type.id()==ID_pointer ||
81+
type.id()==ID_complex ||
82+
type.id()==ID_array)
83+
return have_to_remove_vector(type.subtype());
84+
else if(type.id()==ID_vector)
85+
return true;
86+
87+
return false;
88+
}
1589

1690
/*******************************************************************\
1791
@@ -29,6 +103,9 @@ static void remove_vector(typet &);
29103

30104
static void remove_vector(exprt &expr)
31105
{
106+
if(!have_to_remove_vector(expr))
107+
return;
108+
32109
Forall_operands(it, expr)
33110
remove_vector(*it);
34111

@@ -111,6 +188,9 @@ Purpose: removes vector data type
111188

112189
static void remove_vector(typet &type)
113190
{
191+
if(!have_to_remove_vector(type))
192+
return;
193+
114194
if(type.id()==ID_struct || type.id()==ID_union)
115195
{
116196
struct_union_typet &struct_union_type=

0 commit comments

Comments
 (0)