@@ -81,8 +81,10 @@ class external_value_set_exprt:public exprt
81
81
// The default-initalised version of EVS doesn't represent anything sane;
82
82
// the caller should set label() before using an instance constructed
83
83
// this way.
84
- operands ().resize (1 );
85
- operands ()[0 ]=constant_exprt ();
84
+ operands ().resize (2 );
85
+ op0 ()=constant_exprt ();
86
+ // / No need to initialise op1(). op1().operands() will hold the vector of
87
+ // / access path entries.
86
88
}
87
89
88
90
external_value_set_exprt (
@@ -92,15 +94,17 @@ class external_value_set_exprt:public exprt
92
94
bool is_initializer):
93
95
exprt (ID_external_value_set, type)
94
96
{
95
- operands ().resize (1 );
96
- operands ()[0 ]=_label;
97
- set (" #lva_mode" , std::to_string (static_cast <int >(mode)));
98
- set (" is_initializer" , std::to_string (is_initializer ? 1 : 0 ));
97
+ operands ().resize (2 );
98
+ op0 ()=_label;
99
+ // / No need to initialise op1(). op1().operands() will hold the vector of
100
+ // / access path entries.
101
+ set (ID_lvsa_mode, std::to_string (static_cast <int >(mode)));
102
+ set (ID_is_initializer, std::to_string (is_initializer ? 1 : 0 ));
99
103
}
100
104
101
105
local_value_set_analysis_modet analysis_mode () const
102
106
{
103
- return (local_value_set_analysis_modet)get_int (" #lva_mode " );
107
+ return (local_value_set_analysis_modet)get_int (ID_lvsa_mode );
104
108
}
105
109
106
110
// / At the beginning of a function, the value set for EVS("A.b") is
@@ -112,38 +116,32 @@ class external_value_set_exprt:public exprt
112
116
// / from a different A.b.
113
117
bool is_initializer () const
114
118
{
115
- return get_bool (" is_initializer " );
119
+ return get_bool (ID_is_initializer );
116
120
}
117
121
118
122
constant_exprt &label () { return to_constant_expr (op0 ()); }
119
123
const constant_exprt &label () const { return to_constant_expr (op0 ()); }
120
124
121
- size_t access_path_size () const { return operands ().size ()-1 ; }
122
- access_path_entry_exprt &access_path_entry (size_t index)
123
- {
124
- return to_access_path_entry (operands ()[index +1 ]);
125
- }
126
- const access_path_entry_exprt &access_path_entry (size_t index) const
127
- {
128
- return to_access_path_entry (operands ()[index +1 ]);
129
- }
130
- const access_path_entry_exprt &access_path_back () const
125
+ typedef std::vector<access_path_entry_exprt> access_path_entriest;
126
+
127
+ access_path_entriest &access_path_entries ()
131
128
{
132
- assert (access_path_size ()!=0 );
133
- return to_access_path_entry (operands ().back ());
129
+ return reinterpret_cast <access_path_entriest &>(op1 ().operands ());
134
130
}
135
- void access_path_push_back (const access_path_entry_exprt &newentry)
131
+
132
+ const access_path_entriest &access_path_entries () const
136
133
{
137
- copy_to_operands (newentry );
134
+ return reinterpret_cast < const access_path_entriest &>( op1 (). operands () );
138
135
}
136
+
139
137
std::string get_access_path_label () const
140
138
{
141
139
if (analysis_mode ()==LOCAL_VALUE_SET_ANALYSIS_SINGLE_EXTERNAL_SET)
142
140
return " external_objects" ;
143
141
std::ostringstream ret;
144
142
ret << id2string (label ().get_value ());
145
- for (size_t i= 0 ; i!= access_path_size (); ++i )
146
- ret << id2string (access_path_entry (i) .label ());
143
+ for (const access_path_entry_exprt &entry : access_path_entries () )
144
+ ret << id2string (entry .label ());
147
145
return ret.str ();
148
146
}
149
147
@@ -162,26 +160,27 @@ class external_value_set_exprt:public exprt
162
160
{
163
161
if (analysis_mode ()==LOCAL_VALUE_SET_ANALYSIS_SINGLE_EXTERNAL_SET)
164
162
return " external_objects" +type_to_basename (declared_on_type);
165
- assert (access_path_size ()!= 0 );
163
+ assert (! access_path_entries (). empty () );
166
164
std::ostringstream ret;
167
165
ret << id2string (label ().get_value ());
168
- for (size_t i=0 ; i!=access_path_size ()-1 ; ++i)
169
- ret << id2string (access_path_entry (i).label ());
166
+ for (
167
+ auto it=access_path_entries ().begin ();
168
+ it!=std::prev (access_path_entries ().end ());
169
+ ++it)
170
+ {
171
+ ret << id2string (it->label ());
172
+ }
170
173
return ret.str ();
171
174
}
172
175
bool access_path_loops () const
173
176
{
174
- if (access_path_size ()<2 )
177
+ if (access_path_entries (). size ()<2 )
175
178
return false ;
176
- return access_path_entry ( access_path_size ()- 2 ) .is_loop ();
179
+ return access_path_entries ()[ access_path_entries (). size ()- 2 ] .is_loop ();
177
180
}
178
181
void create_access_path_loop ()
179
182
{
180
- copy_to_operands (access_path_entry_exprt::get_loop_tag ());
181
- }
182
- void replace_access_path_back (const access_path_entry_exprt &newtail)
183
- {
184
- operands ()[operands ().size ()-1 ]=newtail;
183
+ access_path_entries ().push_back (access_path_entry_exprt::get_loop_tag ());
185
184
}
186
185
187
186
void extend_access_path (const access_path_entry_exprt &newentry)
@@ -194,29 +193,29 @@ class external_value_set_exprt:public exprt
194
193
// In this case entries created at different
195
194
// locations are not distinguished:
196
195
toadd.drop_loc ();
197
- if (access_path_size ()== 0 )
198
- access_path_push_back (toadd);
196
+ if (access_path_entries (). empty () )
197
+ access_path_entries (). push_back (toadd);
199
198
else
200
- replace_access_path_back (toadd) ;
199
+ access_path_entries (). back ()=toadd ;
201
200
}
202
201
else
203
202
{
204
203
if (access_path_loops ())
205
204
{
206
205
// Replace the existing tail field with this one.
207
- replace_access_path_back (newentry) ;
206
+ access_path_entries (). back ()=newentry ;
208
207
}
209
208
else
210
209
{
211
- for (size_t i= 0 ; i!= access_path_size (); ++i )
210
+ for (const auto &entry : access_path_entries () )
212
211
{
213
- if (access_path_entry (i) .label ()==newentry.label ())
212
+ if (entry .label ()==newentry.label ())
214
213
{
215
214
create_access_path_loop ();
216
215
break ;
217
216
}
218
217
}
219
- access_path_push_back (newentry);
218
+ access_path_entries (). push_back (newentry);
220
219
}
221
220
}
222
221
}
@@ -228,7 +227,7 @@ class external_value_set_exprt:public exprt
228
227
else
229
228
{
230
229
external_value_set_exprt copy=*this ;
231
- copy.set (" is_initializer " , ID_0);
230
+ copy.set (ID_is_initializer , ID_0);
232
231
return copy;
233
232
}
234
233
}
0 commit comments