Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
function_breaker.cpp
Go to the documentation of this file.
1/*
2This file intends to create a script to read a directory with
3code in c and extract every function/struct of every .c file as a new file
4
5Example of expected behaviour:
6There is a file example.c with functions a and b, will be create two new
7files: example/a.c and example/b.c
8
9TODO: Doesn't work correct if the file has an incorrect bracket sequence,
10even if the bracket sequence is in a commentary
11*/
12
13#include "function_breaker.hpp"
14
15bool FunctionBreaker::is_c_extension(const std::string& extension) {
16 for (auto c_extension : C_EXTENSIONS) {
17 if (extension == c_extension) {
18 return true;
19 }
20 }
21 return false;
22}
23
24bool FunctionBreaker::is_java_extension(const std::string& extension) {
25 for (auto java_extension : JAVA_EXTENSIONS) {
26 if (extension == java_extension) {
27 return true;
28 }
29 }
30 return false;
31}
32
33bool FunctionBreaker::is_allowed_extension(const std::string& extension) {
34 for (auto allowed_extension : ALLOWED_EXTENSIONS) {
35 if (extension == allowed_extension) {
36 return true;
37 }
38 }
39 return false;
40}
41
42void FunctionBreaker::file_breaker(const fs::path& file_path, const fs::path& folder_path) {
43 string extension = extract_extension(file_path);
44
45 if (!is_allowed_extension(extension)) {
46 return;
47 }
48
49 if (is_c_extension(extension)) {
50 FunctionBreakerC function_breaker_c(file_path, folder_path);
51 } else if (is_java_extension(extension)) {
52 FunctionBreakerJava function_breaker_java(file_path, folder_path);
53 } else {
54 assert(false && "NOT ALLOWED FILE PASSED");
55 }
56}
57
58void FunctionBreaker::function_breaker(const fs::path& folder_path) {
59 for (const auto& dirEntry : fs::recursive_directory_iterator(folder_path)) {
60 file_breaker(dirEntry.path(), folder_path);
61 }
62}
63
64FunctionBreaker::FunctionBreaker(const fs::path& folder_path) {
65 function_breaker(folder_path);
66}
C/C++ function parser and extractor.
Java function parser and extractor.
FunctionBreaker(const fs::path &folder_path)
Constructs function breaker and processes directory.
Main function extraction interface.
string extract_extension(const fs::path &file_path)
Extracts file extension from path.