-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaderFileAnalysis.h
90 lines (76 loc) · 2.01 KB
/
headerFileAnalysis.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <filesystem>
namespace fs = std::filesystem;;
class Node {
private:
uint32_t node_id;
std::string node_name;
std::vector<uint32_t> child_nodes;
public:
Node();
Node(uint32_t id, const std::string& name);
~Node();
bool set_node_name(const std::string& name);
const std::string& get_node_name();
bool set_node_id(uint32_t id);
uint32_t get_node_id();
bool add_child_node(uint32_t id);
uint32_t get_child_node_count();
std::vector<uint32_t>& get_child_nodes();
};
class Graph {
private:
uint32_t node_count;
std::map<uint32_t, Node*> node_map;
std::map<std::string, Node*> node_name_map;
// for circle check
std::set<uint32_t> visited;
std::set<uint32_t> visiting;
public:
Graph();
~Graph();
uint32_t get_node_count();
bool add_node(Node* node);
Node* get_node_by_id(uint32_t id);
Node* get_node_by_name(const std::string& name);
bool add_record(Node* node, std::string& parent_name);
bool gen_dot_file();
void check_circle();
bool check_circle_dfs(Node* node, std::vector<uint32_t>& cirlce_link);
void print_circle(std::vector<uint32_t>& circle_link);
};
static uint32_t gen_id() {
static uint32_t id = 0;
return ++id;
}
static Node* make_node(const std::string& name) {
assert(name != "");
uint32_t id = gen_id();
Node* node = new Node(id, name);
return node;
}
class WalkMan {
private:
Graph g;
fs::path base_dir;
std::vector<fs::path> source_file_paths;
std::set<std::string> headers;
std::vector<std::vector<std::string>> include_infos;
public:
WalkMan();
WalkMan(const std::string& dir);
~WalkMan();
void start();
void walk_dir();
void init_headers();
void analysis_file();
void build_graph();
bool is_source_code(fs::path path);
bool is_header_file(fs::path path);
std::vector<std::string> get_include_lines(const fs::path& path);
};