ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
function_printer.cpp
Go to the documentation of this file.
3
5
8 auto location = function.scope_location();
9
10 std::string function_message = FUNCTION_PREFIX_PRINT + function.name();
11 fs::path relative_path = params.path / fs::path{function.path().relative_path()};
12 std::string relative_message = RELATIVE_PATH_PRINT + relative_path.string();
13 std::string start_message = LINE_DECLARATION_PRINT + std::to_string(location.declaration + 1) +
14 "-" + std::to_string(location.end + 1);
15 std::string number_message = NUMBER_LINE_PRINT + std::to_string(location.size());
16
17 std::cout << YELLOW(function_message) << '\n';
18 std::cout << GREEN(relative_message) << '\n';
19 std::cout << WHITE(start_message) << '\n';
20 std::cout << WHITE(number_message) << '\n';
21}
22
23void FunctionPrinter::print_code(const Function& function, bool no_numbers) {
24 auto lines = function.build_all_content();
25
26 int line_number = function.scope_location().declaration + 1;
27
28 for (const auto& line : lines) {
29 if (!no_numbers) {
30 std::ostringstream oss;
31 oss << std::setw(4) << line_number++;
32
33 std::cout << CYAN(oss.str()) << " | " << line << '\n';
34 } else {
35 std::cout << line << '\n';
36 }
37 }
38}
39
41 const auto& path = function.path();
42
43 return path.relative_path().string() + BETWEEN_RELATIVE_AND_FUNCTION_NAME + function.name();
44}
static void print_basic_info(const Function &function)
Prints formatted function information to console.
static void print_code(const Function &function, bool no_numbers=false)
Prints the function source code.
static std::string format_path_message_in_pair(const Function &function)
Formats path for display.
Represents a function extracted from a codebase.
Definition: function.hpp:45
const Path & path() const
Gets the function path information.
Definition: function.cpp:5
std::vector< std::string > build_all_content() const
Builds combined content of header and source.
Definition: function.cpp:25
const std::string & name() const
Gets the function name.
Definition: function.cpp:9
const FunctionLocation & scope_location() const
Gets the function location inside the source file.
Definition: function.cpp:17
fs::path relative_path() const
Gets the directory portion of the path.
Definition: path.cpp:15
static PreprocessRunParams read_current_run_params()
read preprocessing parameters runs
Provides utilities for printing function information and source code.
@ WHITE
White color.
Definition: utils.hpp:120
@ GREEN
Green color.
Definition: utils.hpp:114
@ YELLOW
Yellow color.
Definition: utils.hpp:115
@ CYAN
Cyan color.
Definition: utils.hpp:118
uint32_t declaration
Line number of function declaration.
Definition: function.hpp:23