Skip to content

Commit b3d5041

Browse files
Define initialize_ssa_identifier
This is to construct ssa_exprt. This is a specialized version of build_ssa_identifier_rec which does not have to worry about l0, l1, l2 and can avoid manipulating 2 streams, so is much simpler.
1 parent 21c98d3 commit b3d5041

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/util/ssa_expr.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,41 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/arith_tools.h>
1515

16+
/// If \p expr is:
17+
/// - a symbol_exprt "s" add "s" to the stream \p os
18+
/// - a member_exprt, apply recursively and add "..component_name"
19+
/// - an index_exprt where the index is a constant, apply recursively on the
20+
/// array and add "[[index]]"
21+
/// \return the stream \p os
22+
static std::ostream &
23+
initialize_ssa_identifier(std::ostream &os, const exprt &expr)
24+
{
25+
if(auto member = expr_try_dynamic_cast<member_exprt>(expr))
26+
{
27+
return initialize_ssa_identifier(os, member->struct_op())
28+
<< ".." << member->get_component_name();
29+
}
30+
if(auto index = expr_try_dynamic_cast<index_exprt>(expr))
31+
{
32+
const auto idx =
33+
numeric_cast_v<mp_integer>(to_constant_expr(index->index()));
34+
return initialize_ssa_identifier(os, index->array()) << "[[" << idx << "]]";
35+
}
36+
if(auto symbol = expr_try_dynamic_cast<symbol_exprt>(expr))
37+
return os << symbol->get_identifier();
38+
39+
UNREACHABLE;
40+
}
41+
1642
ssa_exprt::ssa_exprt(const exprt &expr) : symbol_exprt(expr.type())
1743
{
1844
set(ID_C_SSA_symbol, true);
1945
add(ID_expression, expr);
20-
update_identifier();
46+
std::ostringstream os;
47+
initialize_ssa_identifier(os, expr);
48+
const std::string id = os.str();
49+
set_identifier(id);
50+
set(ID_L1_object_identifier, id);
2151
}
2252

2353
void ssa_exprt::set_expression(const exprt &expr)

0 commit comments

Comments
 (0)