|
13 | 13 |
|
14 | 14 | bvt boolbvt::convert_let(const let_exprt &expr)
|
15 | 15 | {
|
16 |
| - const bvt value_bv=convert_bv(expr.value()); |
| 16 | + DATA_INVARIANT( |
| 17 | + expr.value().type() == expr.symbol().type(), |
| 18 | + "let value must have the type of the let symbol"); |
| 19 | + DATA_INVARIANT( |
| 20 | + expr.type() == expr.where().type(), |
| 21 | + "let must have the type of the 'where' operand"); |
17 | 22 |
|
18 |
| - // We expect the identifiers of the bound symbols to be unique, |
19 |
| - // and thus, these can go straight into the symbol to literal map. |
20 |
| - // This property also allows us to cache any subexpressions. |
21 |
| - const irep_idt &id=expr.symbol().get_identifier(); |
| 23 | + const bvt value_bv = convert_bv(expr.value()); |
| 24 | + |
| 25 | + bool is_boolean = expr.value().type().id() == ID_bool; |
| 26 | + const auto &old_identifier = expr.symbol().get_identifier(); |
| 27 | + |
| 28 | + // produce a new identifier |
| 29 | + const irep_idt new_identifier = |
| 30 | + "boolbvt::scope::" + std::to_string(scope_counter) + |
| 31 | + "::" + id2string(old_identifier); |
| 32 | + |
| 33 | + scope_counter++; |
22 | 34 |
|
23 | 35 | // the symbol shall be visible during the recursive call
|
24 |
| - // to convert_bv |
25 |
| - map.set_literals(id, expr.symbol().type(), value_bv); |
26 |
| - bvt result_bv=convert_bv(expr.where()); |
| 36 | + // to convert_bv for 'where' |
| 37 | + if(is_boolean) |
| 38 | + { |
| 39 | + DATA_INVARIANT(value_bv.size() == 1, "boolean values have one bit"); |
| 40 | + symbols[new_identifier] = value_bv[0]; |
| 41 | + } |
| 42 | + else |
| 43 | + map.set_literals(new_identifier, expr.symbol().type(), value_bv); |
| 44 | + |
| 45 | + // rename bound symbol in 'where' |
| 46 | + exprt where_renamed = expr.where(); |
| 47 | + |
| 48 | + where_renamed.visit_post([old_identifier, new_identifier](exprt &expr) { |
| 49 | + if(expr.id() == ID_symbol) |
| 50 | + { |
| 51 | + auto &symbol_expr = to_symbol_expr(expr); |
| 52 | + if(symbol_expr.get_identifier() == old_identifier) |
| 53 | + symbol_expr.set_identifier(new_identifier); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + // recursive call |
| 58 | + bvt result_bv = convert_bv(where_renamed); |
27 | 59 |
|
28 |
| - // now remove, no longer needed |
29 |
| - map.erase_literals(id, expr.symbol().type()); |
| 60 | + // the mapping can now be deleted |
| 61 | + if(is_boolean) |
| 62 | + symbols.erase(new_identifier); |
| 63 | + else |
| 64 | + map.erase_literals(new_identifier, expr.symbol().type()); |
30 | 65 |
|
31 | 66 | return result_bv;
|
32 | 67 | }
|
0 commit comments