-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.cpp
77 lines (60 loc) · 2.2 KB
/
class.cpp
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
#include "class.hpp"
class ClassDumpInfo {
public:
std::vector<ConstructorData> &c;
std::vector<MethodData> &m;
ClassDumpInfo(
std::vector<ConstructorData> &constructors,
std::vector<MethodData> &methods
) : c(constructors), m(methods) {}
};
CXChildVisitResult class_dump_visitor(CXCursor cursor, CXCursor parent, CXClientData client_data) {
ClassDumpInfo *i = (ClassDumpInfo *)client_data;
if (clang_getCursorKind(cursor) == CXCursor_Constructor) {
CXType c = clang_getCursorType(cursor);
ConstructorData cdata;
for (size_t i = 0; i < clang_getNumArgTypes(c); ++i)
cdata.push_back(clang_getArgType(c, i));
i->c.push_back(cdata);
} else if (clang_getCursorKind(cursor) == CXCursor_CXXMethod) {
CXType m = clang_getCursorType(cursor);
MethodData mdata(cursor);
for (size_t i = 0; i < clang_getNumArgTypes(m); ++i)
mdata.args.push_back(clang_getArgType(m, i));
i->m.push_back(mdata);
}
return CXChildVisit_Continue;
}
ClassData::ClassData(CXCursor class_cursor) {
ClassDumpInfo i(constructors, methods);
clang_visitChildren(class_cursor, class_dump_visitor, (CXClientData)&i);
}
void ClassData::debug_print(std::ostream &out) const {
out << "Number of constrs: " << constructors.size() << std::endl;
for (auto &c : constructors) {
for (auto &a : c){
CXString tmp = clang_getTypeSpelling(a);
out << clang_getCString(tmp) << " ";
clang_disposeString(tmp);
}
out << std::endl;
}
out << "Number of methods: " << methods.size() << std::endl;
for (auto &m : methods) {
CXString tmp = clang_getCursorSpelling(m.name);
out << clang_getCString(tmp) << ": ";
clang_disposeString(tmp);
for (auto &a : m.args){
tmp = clang_getTypeSpelling(a);
out << clang_getCString(tmp) << " ";
clang_disposeString(tmp);
}
out << std::endl;
}
}
const std::vector<ConstructorData> &ClassData::constr_vec() const {
return constructors;
}
const std::vector<MethodData> &ClassData::method_vec() const {
return methods;
}