Arkanjo 0.1
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
function.cpp
Go to the documentation of this file.
1#include "function.hpp"
2
3void Function::read_content(){
4 string source_path = path.build_source_path();
5 content = Utils::read_file_generic(source_path);
6}
7
8void Function::read_header(){
9 string header_path = path.build_header_path();
10 header = Utils::read_file_generic(header_path);
11}
12void Function::read_info(){
13 string info_path = path.build_info_path();
14 json info = Utils::read_json(info_path);
15 line_declaration = info.value(LINE_DECLARATION_JSON,-1);
16 start_number_line = info.value(START_NUMBER_LINE_JSON,-1);
17 end_number_line = info.value(END_NUMBER_LINE_JSON,-1);
18}
19
21 return end_number_line-line_declaration+1;
22}
23
25 path = _path;
26 if(path.is_empty()){
27 return;
28 }
29 read_content();
30 read_header();
31 read_info();
32}
33
35 return {line_declaration,start_number_line,end_number_line};
36}
37
38vector<string> Function::get_header(){
39 return header;
40}
41
43
44 vector<string> ret;
45 //the last line of header should merge with the first line of content
46 for(auto line : header){
47 ret.push_back(line);
48 }
49 for(int i = 0; i < int(content.size()); i++){
50 auto line = content[i];
51 if(i >= 1){
52 ret.push_back(line);
53 }else{
54 ret.back() += line;
55 }
56 }
57 return ret;
58}
59
61 string function_message = FUNCTION_PREFIX_PRINT + path.build_function_name();
62 string relative_message = RELATIVE_PATH_PRINT + path.build_relative_path();
63 string start_message = LINE_DECLARATION_PRINT + to_string(line_declaration+1);
64 string end_message = END_DECLARATION_PRINT + to_string(end_number_line+1);
65 string number_message = NUMBER_LINE_PRINT + to_string(number_of_lines());
66
67 cout << '\n';
68 cout << Utils::LIMITER_PRINT << '\n';
69 cout << Utils::format_colored_message(function_message, Utils::BRIGHT_YELLOW) << '\n';
70 cout << Utils::format_colored_message(relative_message, Utils::GREEN) << '\n';
71 cout << Utils::format_colored_message(start_message, Utils::WHITE) << '\n';
72 cout << Utils::format_colored_message(end_message, Utils::WHITE) << '\n';
73 cout << Utils::format_colored_message(number_message, Utils::WHITE) << '\n';
74 cout << Utils::LIMITER_PRINT << '\n';
75 cout << '\n';
76}
vector< string > build_all_content()
Builds combined content of header and source.
Definition function.cpp:42
array< int, 3 > get_scope_function_in_file()
Gets the function's line number scope.
Definition function.cpp:34
void print_basic_info()
Prints formatted function information to console.
Definition function.cpp:60
vector< string > get_header()
Gets the function's header content.
Definition function.cpp:38
Function(Path _path)
Constructs a Function object.
Definition function.cpp:24
int number_of_lines()
Calculates the total number of lines in the function.
Definition function.cpp:20
Path manipulation class for tool-specific directory structure.
Definition path.hpp:27
string build_source_path()
Builds source file path.
Definition path.cpp:68
string build_info_path()
Builds metadata file path.
Definition path.cpp:76
string build_relative_path()
Builds relative path portion.
Definition path.cpp:112
string build_header_path()
Builds header file path.
Definition path.cpp:72
bool is_empty()
Checks if path is empty.
Definition path.cpp:33
string build_function_name()
Extracts function name from path.
Definition path.cpp:121
return ret
Definition sum.c:3
Function abstraction for temporary codebase.
nlohmann::json json
Definition function.hpp:25
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition json.hpp:25317
json read_json(string string_path)
Reads and parses a JSON file, uses nlohmann json library.
Definition utils.cpp:60
@ BRIGHT_YELLOW
Bright yellow color.
Definition utils.hpp:113
@ WHITE
White color.
Definition utils.hpp:112
@ GREEN
Green color.
Definition utils.hpp:106
string format_colored_message(string message, COLOR color)
Formats a message with ANSI color codes.
Definition utils.cpp:84
vector< string > read_file_generic(string string_path)
Reads a file line by line into a vector of strings.
Definition utils.cpp:19
const string LIMITER_PRINT
Constant string used as a visual delimiter/separator in prints.
Definition utils.hpp:33