Skip to content

Commit 797f69c

Browse files
author
Daniel Kroening
committed
added instructiont::apply(f)
1 parent 5f2b883 commit 797f69c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/goto-programs/goto_program.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,48 @@ void goto_programt::instructiont::transform(
992992
}
993993
}
994994

995+
void goto_programt::instructiont::apply(
996+
std::function<void(const exprt &)> f) const
997+
{
998+
switch(type)
999+
{
1000+
case OTHER:
1001+
if(get_other().get_statement() == ID_expression)
1002+
f(to_code_expression(get_other()).expression());
1003+
break;
1004+
1005+
case RETURN:
1006+
f(get_return().return_value());
1007+
break;
1008+
1009+
case ASSIGN:
1010+
f(get_assign().lhs());
1011+
f(get_assign().rhs());
1012+
break;
1013+
1014+
case DECL:
1015+
f(get_decl().symbol());
1016+
break;
1017+
1018+
case DEAD:
1019+
f(get_dead().symbol());
1020+
break;
1021+
1022+
case FUNCTION_CALL:
1023+
{
1024+
const auto &call = get_function_call();
1025+
f(new_call.lhs());
1026+
for(auto &a : call.arguments())
1027+
f(a);
1028+
}
1029+
break;
1030+
1031+
default:
1032+
if(has_condition())
1033+
f(get_condition());
1034+
}
1035+
}
1036+
9951037
bool goto_programt::equals(const goto_programt &other) const
9961038
{
9971039
if(instructions.size() != other.instructions.size())

src/goto-programs/goto_program.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ class goto_programt
559559
/// Apply given transformer to all expressions; no return value
560560
/// means no change needed.
561561
void transform(std::function<optionalt<exprt>(exprt)>);
562+
563+
/// Apply given function to all expressions
564+
void apply(std::function<void(const exprt &)>) const;
562565
};
563566

564567
// Never try to change this to vector-we mutate the list while iterating

0 commit comments

Comments
 (0)