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
7
#include <
arkanjo/methods/method.hpp
>
8
9
#include <vector>
10
#include <filesystem>
11
#include <fstream>
12
#include <mutex>
13
#include <atomic>
14
#include <tree_sitter/api.h>
15
16
namespace
fs = std::filesystem;
17
18
struct
ZSNode
{
19
TSSymbol
symbol
;
20
std::vector<ZSNode>
children
;
21
};
22
23
struct
PostOrderTree
{
27
std::vector<TSSymbol>
labels
;
28
37
std::vector<int>
lmd
;
38
39
fs::path
path
;
40
};
41
42
class
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
Definition:
ast_method.hpp:42
ASTMethod::ASTMethod
ASTMethod(const fs::path &base_path_, double similarity_)
Constructs preprocessor with configuration.
Definition:
ast_method.cpp:89
ASTMethod::on_function
void on_function(const FunctionData &fd) override
Definition:
ast_method.cpp:142
ASTMethod::execute
void execute() override
Executes the preprocessing pipeline.
Definition:
ast_method.cpp:163
FunctionData
Definition:
function_data.hpp:8
IMethod
Definition:
method.hpp:13
method.hpp
PostOrderTree
Definition:
ast_method.hpp:23
PostOrderTree::path
fs::path path
Definition:
ast_method.hpp:39
PostOrderTree::lmd
std::vector< int > lmd
Left-most descendant index for each node.
Definition:
ast_method.hpp:37
PostOrderTree::labels
std::vector< TSSymbol > labels
Tree-sitter grammar symbol for each node.
Definition:
ast_method.hpp:27
ZSNode
Definition:
ast_method.hpp:18
ZSNode::children
std::vector< ZSNode > children
Definition:
ast_method.hpp:20
ZSNode::symbol
TSSymbol symbol
Definition:
ast_method.hpp:19
include
arkanjo
methods
ast
ast_method.hpp
Generated by
1.9.4