-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpp_analysis.h
114 lines (105 loc) · 2.39 KB
/
cpp_analysis.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
#include <string>
#include <map>
#include <list>
#include <memory>
using namespace std;
struct object
{
enum class e_type
{
_null,
_type,
_method,
_variant,
_enum,
_enum_value,
_comment,
};
e_type type;
int ppp = 0;// 0=public,1=private, 2=protected
unsigned line = 0;
object(e_type type = e_type::_null) :type(type) {}
virtual ~object() {}
operator bool()
{
return type != e_type::_null;
}
string to_string()
{
if (type == e_type::_type)return "class";
else if (type == e_type::_enum)return "enum";
else if (type == e_type::_enum_value)return "enum value";
else if (type == e_type::_variant)return "variant";
else if (type == e_type::_comment)return "comment";
else if (type == e_type::_method)return "function";
else return "nothing";
}
};
struct comment : public object
{
string content;
comment(const string& content) :object(e_type::_comment), content(content) {}
};
struct variant : public object
{
bool isconst = false;
bool isextern = false;
bool isstatic = false;
string reftype;// && & &*
string type;
string name;
string default_value;
variant() :object(e_type::_variant) {}
};
struct enumeration_value : public object
{
string name;
string value;
enumeration_value() :object(e_type::_enum_value) {}
};
struct enumeration : public object
{
string name;
string base;
bool isclass = false;
map<string, shared_ptr<enumeration_value>> members;
enumeration() :object(e_type::_enum) {}
};
struct method : public object
{
string return_type;
bool isconst = false;
bool isextern = false;
bool isstatic = false;
bool decl = false;
using object::object;
list<shared_ptr<variant>> argument;
method() :object(e_type::_method) {}
~method() {}
};
struct context;
typedef shared_ptr<context> context_ptr;
struct context
{
context_ptr parent;
multimap<string, shared_ptr<object>> objects;
context(context_ptr parent = nullptr) :parent(parent) {}
};
struct type : public object
{
using object::object;
string name;
bool pre_declare = false;
bool is_template = false;
string bases;
list<string> friends;
context_ptr context;
multimap<string, shared_ptr<object>> objects;
type() :object(e_type::_type), context(new ::context()) {}
};
class cpp_analysis
{
public:
static shared_ptr<context> analysis(const string& filename) throw();
};