This commit is contained in:
parent
021a270e08
commit
a88a57e2ec
@ -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: ";
|
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<OperationLog::FunctionCall>();
|
auto func_call = std::make_unique<OperationLog::FunctionCall>();
|
||||||
func_call->function_name = func_name;
|
func_call->function_name = func_name;
|
||||||
|
|||||||
@ -18,7 +18,8 @@ add_executable(op-finder-tests
|
|||||||
main.cpp
|
main.cpp
|
||||||
fixtures/RunOnCodeFixture.cpp
|
fixtures/RunOnCodeFixture.cpp
|
||||||
basic_operations.cpp
|
basic_operations.cpp
|
||||||
branches.cpp)
|
branches.cpp
|
||||||
|
function_calls.cpp)
|
||||||
|
|
||||||
target_link_libraries(op-finder-tests
|
target_link_libraries(op-finder-tests
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
|||||||
55
op-finder-tests/function_calls.cpp
Normal file
55
op-finder-tests/function_calls.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
//
|
||||||
|
// Created by erki on 07.03.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
#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");
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user