Repository navigation
Expand file tree
/
Copy pathProtocol.cpp
More file actions
103 lines (84 loc) · 2.64 KB
/
Copy pathProtocol.cpp
File metadata and controls
103 lines (84 loc) · 2.64 KB
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
#include "IR.h"
namespace metagen {
ProtocolDecl::ProtocolDecl(CXCursor cursor) {
framework = getFrameworkName(cursor);
CXString cxname = clang_getCursorSpelling(cursor);
name = clang_getCString(cxname);
clang_disposeString(cxname);
clang_visitChildren(
cursor,
[](CXCursor cursor, CXCursor, CXClientData clientData) {
if (!isAvailable(cursor)) {
return CXChildVisit_Continue;
}
auto protocol = (ProtocolDecl *)clientData;
CXCursorKind kind = clang_getCursorKind(cursor);
switch (kind) {
case CXCursor_ObjCProtocolRef: {
CXString name = clang_getCursorSpelling(cursor);
std::string nameStr = clang_getCString(name);
protocol->protocolNames.emplace_back(nameStr);
clang_disposeString(name);
break;
}
case CXCursor_ObjCPropertyDecl:
case CXCursor_ObjCClassMethodDecl:
case CXCursor_ObjCInstanceMethodDecl: {
auto member = MemberDecl(cursor);
member.parentProtocolName = protocol->name;
protocol->members.emplace_back(member);
break;
}
default:
break;
}
return CXChildVisit_Continue;
},
this);
}
MemberDecl *ProtocolDecl::getMemberNamed(std::string &name) {
for (auto &member : members) {
if (member.name == name) {
return &member;
}
}
return nullptr;
}
void MetadataFactory::processProtocolRefs() {
while (!referencedProtocols.empty()) {
std::unordered_set<std::string> refs = referencedProtocols;
referencedProtocols.clear();
for (const std::string &name : refs) {
if (protocols.contains(name)) {
continue;
}
if (skippedProtocols.contains(name)) {
ProtocolDecl decl = skippedProtocols[name];
protocols[name] = decl;
postProcessProtocol(protocols[name]);
} else {
std::cerr << "ERROR: Unknown protocol " << name << std::endl;
}
}
}
}
void ProtocolDecl::postProcessMembers() {
for (MemberDecl &member : members) {
for (ClassDecl *cls : implementerRefs) {
convertMethodToPropertyIfNeeded(member, cls->getMemberNamed(member.name),
false);
}
for (ProtocolDecl *protocol : protocolRefs) {
convertMethodToPropertyIfNeeded(
member, protocol->getMemberNamed(member.name), true);
}
for (ProtocolDecl *protocol : derivedProtocolRefs) {
convertMethodToPropertyIfNeeded(
member, protocol->getMemberNamed(member.name), false);
}
if (member.tsIgnore && !tsIgnore) {
tsIgnore = true;
}
}
}
} // namespace metagen