Arkanjo 0.1
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(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(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(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(string file_path, string 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 }
52 else if(is_java_extension(extension)){
53 FunctionBreakerJava function_breaker_java(file_path, folder_path);
54 }else{
55 assert(false && "NOT ALLOWED FILE PASSED");
56 }
57}
58
59void FunctionBreaker::function_breaker(string folder_path){
60 for(const auto &dirEntry: std::filesystem::recursive_directory_iterator(folder_path)){
61 string file_path = dirEntry.path().string();
62 file_breaker(file_path,folder_path);
63 }
64}
65
67 function_breaker(folder_path);
68}
C/C++ function parser and extractor.
Java function parser and extractor.
FunctionBreaker(string folder_path)
Constructs function breaker and processes directory.
Main function extraction interface.
string extract_extension(string file_path)
Extracts file extension from path.