Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
big_clone_formater.cpp
Go to the documentation of this file.
2
3string BigCloneFormater::format_relative_path(string relative_path) {
4 for (auto& c : relative_path) {
5 if (c == '/') {
6 c = ',';
7 }
8 }
9 return relative_path;
10}
11
12string BigCloneFormater::build_path_formated_string(Path path) {
13 string relative_path = path.build_relative_path();
14 relative_path = format_relative_path(relative_path);
15
16 Function function(path);
17 function.load();
18 auto [line_declaration, start_line, end_line] = function.get_scope_function_in_file();
19
20 string ret;
21 ret += relative_path;
22 ret += ',' + to_string(line_declaration);
23 ret += ',' + to_string(start_line);
24 ret += ',' + to_string(end_line);
25
26 return ret;
27}
28auto BigCloneFormater::process_similar_path_pair(Path path1, Path path2, double similarity) {
29 auto string_path1 = build_path_formated_string(path1);
30 auto string_path2 = build_path_formated_string(path2);
31
32 string comparation_string = string_path1 + ',' + string_path2 + ',';
33 cout << comparation_string;
34 cout << fixed << setprecision(2) << similarity << '\n';
35}
36
37BigCloneFormater::BigCloneFormater(Similarity_Table* _similarity_table) {
38 similarity_table = _similarity_table;
39}
40
41bool BigCloneFormater::validate([[maybe_unused]] const ParsedOptions& options) {
42 return true;
43}
44
45bool BigCloneFormater::run([[maybe_unused]] const ParsedOptions& options) {
46 auto similar_paths = similarity_table->get_all_path_pairs_and_similarity_sorted_by_similarity();
47 for (auto [similarity, path1, path2] : similar_paths) {
48 process_similar_path_pair(path1, path2, similarity);
49 }
50
51 return true;
52}
BigCloneEval format conversion interface.
bool run(const ParsedOptions &options) override
Handles BigCloneEval formatting command.
bool validate(const ParsedOptions &options) override
Validate the arguments already analyzed.
Represents a code function with its content and metadata.
Definition function.hpp:30
Path manipulation class for tool-specific directory structure.
Definition path.hpp:27
std::string build_relative_path() const
Builds relative path portion.
Definition path.cpp:101
Represents a similarity graph between functions (paths).
std::vector< std::tuple< double, Path, Path > > get_all_path_pairs_and_similarity_sorted_by_similarity()
Gets all similar path pairs with scores, sorted.