From a88a57e2ece0f31fe6f83723eab340f0a91801a5 Mon Sep 17 00:00:00 2001 From: Erki Date: Sun, 7 Mar 2021 18:37:13 +0200 Subject: [PATCH] Function call tests --- op-finder-lib/src/OperationFinder.cpp | 2 +- op-finder-tests/CMakeLists.txt | 3 +- op-finder-tests/function_calls.cpp | 55 +++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 op-finder-tests/function_calls.cpp diff --git a/op-finder-lib/src/OperationFinder.cpp b/op-finder-lib/src/OperationFinder.cpp index 3fcc54a..8c03c1c 100644 --- a/op-finder-lib/src/OperationFinder.cpp +++ b/op-finder-lib/src/OperationFinder.cpp @@ -87,7 +87,7 @@ void OperationFinder::processFunctionCall(const clang::CallExpr* call, const Sou llvm::outs() << "\n\tFunction call: func name: " << func_name << "\n\tResult eval type: "; - const std::string res_type = ResolveTypeName(func->getType()); + const std::string res_type = ResolveTypeName(func->getReturnType()); auto func_call = std::make_unique(); func_call->function_name = func_name; diff --git a/op-finder-tests/CMakeLists.txt b/op-finder-tests/CMakeLists.txt index 20442fa..a786acb 100644 --- a/op-finder-tests/CMakeLists.txt +++ b/op-finder-tests/CMakeLists.txt @@ -18,7 +18,8 @@ add_executable(op-finder-tests main.cpp fixtures/RunOnCodeFixture.cpp basic_operations.cpp - branches.cpp) + branches.cpp + function_calls.cpp) target_link_libraries(op-finder-tests PUBLIC diff --git a/op-finder-tests/function_calls.cpp b/op-finder-tests/function_calls.cpp new file mode 100644 index 0000000..6034b78 --- /dev/null +++ b/op-finder-tests/function_calls.cpp @@ -0,0 +1,55 @@ +// +// Created by erki on 07.03.21. +// + +#include + +#include "fixtures/RunOnCodeFixture.hpp" + +TEST_CASE("Find function call.", "[functions]") +{ + RunOnCodeFixture fixture; + + const std::string code = "int b(); int main() { b(); }"; + const auto& operations = fixture(code); + + REQUIRE(operations.size() == 1); + + const OperationLog& log = operations.front(); + + REQUIRE(log.entry_type == OperationLog::FunctionCall::TYPE_NAME); + + const OperationLog::FunctionCall* call = (OperationLog::FunctionCall*)log.entry.get(); + + REQUIRE(call->function_name == "b"); + REQUIRE(call->call_result_type == "int"); +} + +TEST_CASE("Find stacked function calls.", "[functions]") +{ + RunOnCodeFixture fixture; + + const std::string code = "int a(int); int b(); int main() { a(b()); }"; + const auto& operations = fixture(code); + + REQUIRE(operations.size() == 2); + + const OperationLog& log = operations.front(); + + REQUIRE(log.entry_type == OperationLog::FunctionCall::TYPE_NAME); + + const OperationLog::FunctionCall* call = (OperationLog::FunctionCall*)log.entry.get(); + + REQUIRE(call->function_name == "a"); + REQUIRE(call->call_result_type == "int"); + + + const OperationLog& log_two = operations.back(); + + REQUIRE(log_two.entry_type == OperationLog::FunctionCall::TYPE_NAME); + + const OperationLog::FunctionCall* call_two = (OperationLog::FunctionCall*)log_two.entry.get(); + + REQUIRE(call_two->function_name == "b"); + REQUIRE(call_two->call_result_type == "int"); +}