@@ -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 ();
@@ -1131,12 +1139,9 @@ smt2_parsert::function_signature_definition()
1131
1139
throw error (" expected symbol in parameter" );
1132
1140
1133
1141
irep_idt id = smt2_tokenizer.get_buffer ();
1134
- parameters.push_back (id);
1135
1142
domain.push_back (sort ());
1136
1143
1137
- auto &entry=id_map[id];
1138
- entry.type = domain.back ();
1139
- entry.definition =nil_exprt ();
1144
+ parameters.push_back (add_fresh_id (id, exprt (ID_nil, domain.back ())));
1140
1145
1141
1146
if (next_token () != smt2_tokenizert::CLOSE)
1142
1147
throw error (" expected ')' at end of parameter" );
@@ -1196,12 +1201,8 @@ void smt2_parsert::command(const std::string &c)
1196
1201
irep_idt id = smt2_tokenizer.get_buffer ();
1197
1202
auto type = sort ();
1198
1203
1199
- if (id_map. find (id)!=id_map. end () )
1204
+ if (add_fresh_id (id, exprt (ID_nil, type)) != id )
1200
1205
throw error () << " identifier `" << id << " ' defined twice" ;
1201
-
1202
- auto &entry = id_map[id];
1203
- entry.type = type;
1204
- entry.definition = nil_exprt ();
1205
1206
}
1206
1207
else if (c==" declare-fun" )
1207
1208
{
@@ -1211,12 +1212,8 @@ void smt2_parsert::command(const std::string &c)
1211
1212
irep_idt id = smt2_tokenizer.get_buffer ();
1212
1213
auto type = function_signature_declaration ();
1213
1214
1214
- if (id_map. find (id)!=id_map. end () )
1215
+ if (add_fresh_id (id, exprt (ID_nil, type)) != id )
1215
1216
throw error () << " identifier `" << id << " ' defined twice" ;
1216
-
1217
- auto &entry = id_map[id];
1218
- entry.type = type;
1219
- entry.definition = nil_exprt ();
1220
1217
}
1221
1218
else if (c == " define-const" )
1222
1219
{
@@ -1225,9 +1222,6 @@ void smt2_parsert::command(const std::string &c)
1225
1222
1226
1223
const irep_idt id = smt2_tokenizer.get_buffer ();
1227
1224
1228
- if (id_map.find (id) != id_map.end ())
1229
- throw error () << " identifier `" << id << " ' defined twice" ;
1230
-
1231
1225
const auto type = sort ();
1232
1226
const auto value = expression ();
1233
1227
@@ -1240,23 +1234,25 @@ void smt2_parsert::command(const std::string &c)
1240
1234
}
1241
1235
1242
1236
// create the entry
1243
- auto &entry = id_map[id];
1244
- entry.type = type;
1245
- entry.definition = value;
1237
+ if (add_fresh_id (id, value) != id)
1238
+ throw error () << " identifier `" << id << " ' defined twice" ;
1246
1239
}
1247
1240
else if (c==" define-fun" )
1248
1241
{
1249
1242
if (next_token () != smt2_tokenizert::SYMBOL)
1250
1243
throw error (" expected a symbol after define-fun" );
1251
1244
1252
- const irep_idt id = smt2_tokenizer.get_buffer ();
1245
+ // save the renaming map
1246
+ renaming_mapt old_renaming_map = renaming_map;
1253
1247
1254
- if (id_map.find (id)!=id_map.end ())
1255
- throw error () << " identifier `" << id << " ' defined twice" ;
1248
+ const irep_idt id = smt2_tokenizer.get_buffer ();
1256
1249
1257
1250
const auto signature = function_signature_definition ();
1258
1251
const auto body = expression ();
1259
1252
1253
+ // restore renamings
1254
+ std::swap (renaming_map, old_renaming_map);
1255
+
1260
1256
// check type of body
1261
1257
if (signature.type .id () == ID_mathematical_function)
1262
1258
{
@@ -1276,10 +1272,11 @@ void smt2_parsert::command(const std::string &c)
1276
1272
}
1277
1273
1278
1274
// create the entry
1279
- auto &entry = id_map[id];
1280
- entry.type = signature.type ;
1281
- entry.parameters = signature.parameters ;
1282
- entry.definition = body;
1275
+ if (add_fresh_id (id, body) != id)
1276
+ throw error () << " identifier `" << id << " ' defined twice" ;
1277
+
1278
+ id_map.at (id).type = signature.type ;
1279
+ id_map.at (id).parameters = signature.parameters ;
1283
1280
}
1284
1281
else if (c==" exit" )
1285
1282
{
0 commit comments