ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
function_loader.cpp
Go to the documentation of this file.
4
6
7#include "nlohmann/json.hpp"
9
10void FunctionLoader::read_content(Function& function) {
11 FunctionStorage storage;
12
13 fs::path source_path = storage.build_source_path(function.path());
14 function.content_ = Utils::read_file_with_vector(source_path);
15}
16
17void FunctionLoader::read_header(Function& function) {
18 FunctionStorage storage;
19
20 fs::path header_path = storage.build_header_path(function.path());
21 function.header_ = Utils::read_file_with_vector(header_path);
22}
23
24void FunctionLoader::read_info(Function& function) {
25 FunctionStorage storage;
26
27 fs::path info_path = storage.build_info_path(function.path());
28 json info = Utils::read_json(info_path);
29 function.location_.declaration = info.value(LINE_DECLARATION_JSON, INVALID_LINE);
30 function.location_.begin = info.value(START_NUMBER_LINE_JSON, INVALID_LINE);
31 function.location_.end = info.value(END_NUMBER_LINE_JSON, INVALID_LINE);
32}
33
35 if (path.empty())
36 return {};
37
38 Function function(path);
39
40 function.name_ = path.value().stem().string();
41
42 read_content(function);
43 read_header(function);
44 read_info(function);
45
46 return function;
47}
48
50 if (path.empty())
51 return {};
52
53 Function function(path);
54
55 function.name_ = path.value().stem().string();
56
57 read_info(function);
58
59 return function;
60}
Function load(const Path &path)
Loads a function from a path.
Function load_metadata(const Path &path)
Loads function metadata from a path.
fs::path build_header_path(const Path &path) const
Builds header file path.
fs::path build_source_path(const Path &path) const
Builds source file path.
fs::path build_info_path(const Path &path) const
Builds metadata file path.
Represents a function extracted from a codebase.
Definition: function.hpp:45
const Path & path() const
Gets the function path information.
Definition: function.cpp:5
Represents a logical path to a function in the codebase.
Definition: path.hpp:26
bool empty() const
Checks if path is empty.
Definition: path.cpp:11
const fs::path & value() const
Gets the underlying filesystem path.
Definition: path.cpp:7
nlohmann::json json
Provides functionality to load Function objects from external sources.
Provides access to function storage locations.
json read_json(const fs::path &string_path)
Reads and parses a JSON file, uses nlohmann json library.
Definition: utils.cpp:50
std::vector< std::string > read_file_with_vector(const fs::path &path)
Reads a file line by line into a vector of strings.
Definition: utils.cpp:26
Logical path abstraction for source code elements.
uint32_t end
Line number where function ends.
Definition: function.hpp:25
uint32_t declaration
Line number of function declaration.
Definition: function.hpp:23
uint32_t begin
Line number where function starts.
Definition: function.hpp:24
Defines utility functions used across all files.