ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
ast_method.hpp
Go to the documentation of this file.
1
5#pragma once
6
8
9#include <vector>
10#include <filesystem>
11#include <fstream>
12#include <mutex>
13#include <atomic>
14#include <tree_sitter/api.h>
15
16namespace fs = std::filesystem;
17
18struct ZSNode {
19 TSSymbol symbol;
20 std::vector<ZSNode> children;
21};
22
27 std::vector<TSSymbol> labels;
28
37 std::vector<int> lmd;
38
39 fs::path path;
40};
41
42class ASTMethod : public IMethod {
43 private:
44 static constexpr const char* SAVING_MESSAGE = "Saving results...";
45
46 fs::path base_path;
47 double similarity;
48
49 std::vector<PostOrderTree> processed;
50
51 std::ofstream output_file;
52
53 std::mutex processed_mutex;
54 std::mutex output_mutex;
55
56 std::atomic<size_t> total_matches{0};
57
58 ZSNode from_tsnode(TSNode node);
59
79 int tree_distance(const PostOrderTree& a, const PostOrderTree& b);
80
97 double similarity_score(const PostOrderTree& a, const PostOrderTree& b);
98
118 void compare_range(
119 const std::vector<PostOrderTree>& processed,
120 size_t begin, size_t end,
121 std::vector<DuplicationEntry>& local
122 );
123
124 void save_duplications(std::vector<DuplicationEntry>& file_duplication_pairs) override;
125 void flush_duplications(std::vector<DuplicationEntry>& local);
126 void header_duplications();
127 public:
133 ASTMethod(const fs::path& base_path_, double similarity_);
134
135 void on_function(const FunctionData& fd) override;
136
140 void execute() override;
141};
ASTMethod(const fs::path &base_path_, double similarity_)
Constructs preprocessor with configuration.
Definition: ast_method.cpp:89
void on_function(const FunctionData &fd) override
Definition: ast_method.cpp:142
void execute() override
Executes the preprocessing pipeline.
Definition: ast_method.cpp:163
fs::path path
Definition: ast_method.hpp:39
std::vector< int > lmd
Left-most descendant index for each node.
Definition: ast_method.hpp:37
std::vector< TSSymbol > labels
Tree-sitter grammar symbol for each node.
Definition: ast_method.hpp:27
std::vector< ZSNode > children
Definition: ast_method.hpp:20
TSSymbol symbol
Definition: ast_method.hpp:19