@@ -118,22 +118,33 @@ exprt::operandst smt2_parsert::operands()
118
118
return result;
119
119
}
120
120
121
- irep_idt smt2_parsert::get_fresh_id (const irep_idt &id)
121
+ irep_idt smt2_parsert::add_fresh_id (const irep_idt &id, const exprt &expr )
122
122
{
123
- if (id_map[id].type .is_nil ())
123
+ if (id_map
124
+ .emplace (
125
+ std::piecewise_construct,
126
+ std::forward_as_tuple (id),
127
+ std::forward_as_tuple (expr))
128
+ .second )
129
+ {
124
130
return id; // id not yet used
131
+ }
125
132
126
133
auto &count=renaming_counters[id];
127
134
irep_idt new_id;
128
135
do
129
136
{
130
137
new_id=id2string (id)+' #' +std::to_string (count);
131
138
count++;
132
- }
133
- while (id_map.find (new_id)!=id_map.end ());
139
+ } while (!id_map
140
+ .emplace (
141
+ std::piecewise_construct,
142
+ std::forward_as_tuple (new_id),
143
+ std::forward_as_tuple (expr))
144
+ .second );
134
145
135
146
// record renaming
136
- renaming_map[id]= new_id;
147
+ renaming_map[id] = new_id;
137
148
138
149
return new_id;
139
150
}
@@ -184,10 +195,7 @@ exprt smt2_parsert::let_expression()
184
195
for (auto &b : bindings)
185
196
{
186
197
// get a fresh id for it
187
- b.first =get_fresh_id (b.first );
188
- auto &entry=id_map[b.first ];
189
- entry.type =b.second .type ();
190
- entry.definition =b.second ;
198
+ b.first = add_fresh_id (b.first , b.second );
191
199
}
192
200
193
201
exprt expr=expression ();
@@ -246,9 +254,9 @@ exprt smt2_parsert::quantifier_expression(irep_idt id)
246
254
// go forwards, add to id_map
247
255
for (const auto &b : bindings)
248
256
{
249
- auto &entry=id_map[b. get_identifier ()];
250
- entry. type = b.type ();
251
- entry. definition = nil_exprt ( );
257
+ const irep_idt id =
258
+ add_fresh_id (b. get_identifier (), exprt (ID_nil, b.type ()) );
259
+ CHECK_RETURN (id == b. get_identifier () );
252
260
}
253
261
254
262
exprt expr=expression ();
@@ -1134,9 +1142,8 @@ smt2_parsert::function_signature_definition()
1134
1142
parameters.push_back (id);
1135
1143
domain.push_back (sort ());
1136
1144
1137
- auto &entry=id_map[id];
1138
- entry.type = domain.back ();
1139
- entry.definition =nil_exprt ();
1145
+ if (add_fresh_id (id, exprt (ID_nil, domain.back ())) != id)
1146
+ CHECK_RETURN (false );
1140
1147
1141
1148
if (next_token () != smt2_tokenizert::CLOSE)
1142
1149
throw error (" expected ')' at end of parameter" );
@@ -1196,12 +1203,8 @@ void smt2_parsert::command(const std::string &c)
1196
1203
irep_idt id = smt2_tokenizer.get_buffer ();
1197
1204
auto type = sort ();
1198
1205
1199
- if (id_map. find (id)!=id_map. end () )
1206
+ if (add_fresh_id (id, exprt (ID_nil, type)) != id )
1200
1207
throw error () << " identifier `" << id << " ' defined twice" ;
1201
-
1202
- auto &entry = id_map[id];
1203
- entry.type = type;
1204
- entry.definition = nil_exprt ();
1205
1208
}
1206
1209
else if (c==" declare-fun" )
1207
1210
{
@@ -1211,12 +1214,8 @@ void smt2_parsert::command(const std::string &c)
1211
1214
irep_idt id = smt2_tokenizer.get_buffer ();
1212
1215
auto type = function_signature_declaration ();
1213
1216
1214
- if (id_map. find (id)!=id_map. end () )
1217
+ if (add_fresh_id (id, exprt (ID_nil, type)) != id )
1215
1218
throw error () << " identifier `" << id << " ' defined twice" ;
1216
-
1217
- auto &entry = id_map[id];
1218
- entry.type = type;
1219
- entry.definition = nil_exprt ();
1220
1219
}
1221
1220
else if (c == " define-const" )
1222
1221
{
@@ -1225,9 +1224,6 @@ void smt2_parsert::command(const std::string &c)
1225
1224
1226
1225
const irep_idt id = smt2_tokenizer.get_buffer ();
1227
1226
1228
- if (id_map.find (id) != id_map.end ())
1229
- throw error () << " identifier `" << id << " ' defined twice" ;
1230
-
1231
1227
const auto type = sort ();
1232
1228
const auto value = expression ();
1233
1229
@@ -1240,9 +1236,8 @@ void smt2_parsert::command(const std::string &c)
1240
1236
}
1241
1237
1242
1238
// create the entry
1243
- auto &entry = id_map[id];
1244
- entry.type = type;
1245
- entry.definition = value;
1239
+ if (add_fresh_id (id, value) != id)
1240
+ throw error () << " identifier `" << id << " ' defined twice" ;
1246
1241
}
1247
1242
else if (c==" define-fun" )
1248
1243
{
@@ -1251,9 +1246,6 @@ void smt2_parsert::command(const std::string &c)
1251
1246
1252
1247
const irep_idt id = smt2_tokenizer.get_buffer ();
1253
1248
1254
- if (id_map.find (id)!=id_map.end ())
1255
- throw error () << " identifier `" << id << " ' defined twice" ;
1256
-
1257
1249
const auto signature = function_signature_definition ();
1258
1250
const auto body = expression ();
1259
1251
@@ -1276,10 +1268,10 @@ void smt2_parsert::command(const std::string &c)
1276
1268
}
1277
1269
1278
1270
// create the entry
1279
- auto &entry = id_map[id];
1280
- entry. type = signature. type ;
1281
- entry. parameters = signature. parameters ;
1282
- entry. definition = body ;
1271
+ if ( add_fresh_id (id, body) != id)
1272
+ throw error () << " identifier ` " << id << " ' defined twice " ;
1273
+
1274
+ id_map. at (id). parameters = signature. parameters ;
1283
1275
}
1284
1276
else if (c==" exit" )
1285
1277
{
0 commit comments