-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new function to inline calls in a goto_program
- Loading branch information
Remi Delmas
committed
Feb 20, 2023
1 parent
ce1ce13
commit 3275a34
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*******************************************************************\ | ||
Module: Inline calls in program unit tests | ||
Author: Remi Delmas | ||
\*******************************************************************/ | ||
|
||
#include <testing-utils/get_goto_model_from_c.h> | ||
#include <testing-utils/use_catch.h> | ||
#include <goto-programs/goto_inline.h> | ||
#include <util/message.h> | ||
|
||
TEST_CASE("Goto program inline", "[core][goto-programs][goto_program_inline]") | ||
{ | ||
const std::string code = R"( | ||
int x = 0; | ||
void f() { x = 1;} | ||
void g() { f(); } | ||
void main() { g(); } | ||
)"; | ||
|
||
goto_modelt goto_model = get_goto_model_from_c(code); | ||
|
||
auto &g = goto_model.goto_functions.function_map.at("g"); | ||
|
||
null_message_handlert message_handler; | ||
goto_program_inline( | ||
goto_model.goto_functions, | ||
g.body, | ||
namespacet(goto_model.symbol_table), | ||
message_handler); | ||
|
||
static int assign_count = 0; | ||
for_each_instruction_if( | ||
g, | ||
[&](goto_programt::const_targett it) { | ||
return it->is_function_call() || it->is_assign(); | ||
}, | ||
[&](goto_programt::const_targett it) { | ||
if(it->is_function_call()) | ||
{ | ||
FAIL(); | ||
} | ||
|
||
if(it->is_assign()) | ||
{ | ||
REQUIRE(assign_count == 0); | ||
assign_count++; | ||
const auto &lhs = it->assign_lhs(); | ||
REQUIRE(to_symbol_expr(lhs).get_identifier() == "x"); | ||
} | ||
}); | ||
REQUIRE(assign_count == 1); | ||
} |