Repository navigation
Expand file tree
/
Copy pathRecord.cpp
More file actions
112 lines (89 loc) · 2.94 KB
/
Copy pathRecord.cpp
File metadata and controls
112 lines (89 loc) · 2.94 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
104
105
106
107
108
109
110
111
112
#include "IR.h"
#include <string>
namespace metagen {
StructDecl::StructDecl(CXCursor cursor) {
framework = getFrameworkName(cursor);
CXString cxname = clang_getCursorSpelling(cursor);
name = transformStructName(clang_getCString(cxname));
clang_disposeString(cxname);
size = clang_Type_getSizeOf(clang_getCursorType(cursor));
clang_visitChildren(
cursor,
[](CXCursor cursor, CXCursor, CXClientData clientData) {
if (!isAvailable(cursor)) {
return CXChildVisit_Continue;
}
auto decl = (StructDecl *)clientData;
CXCursorKind kind = clang_getCursorKind(cursor);
switch (kind) {
case CXCursor_FieldDecl: {
StructFieldDecl field;
field.name = clang_getCString(clang_getCursorSpelling(cursor));
auto type = clang_getCursorType(cursor);
field.type = TypeSpec(type);
field.type.isNullable = true;
field.offset = clang_Cursor_getOffsetOfField(cursor) / 8;
decl->fields.emplace_back(field);
break;
}
default:
break;
}
return CXChildVisit_Continue;
},
this);
}
UnionDecl::UnionDecl(CXCursor cursor) {
framework = getFrameworkName(cursor);
CXString cxname = clang_getCursorSpelling(cursor);
name = transformStructName(clang_getCString(cxname));
clang_disposeString(cxname);
size = clang_Type_getSizeOf(clang_getCursorType(cursor));
clang_visitChildren(
cursor,
[](CXCursor cursor, CXCursor, CXClientData clientData) {
if (!isAvailable(cursor)) {
return CXChildVisit_Continue;
}
auto decl = (UnionDecl *)clientData;
CXCursorKind kind = clang_getCursorKind(cursor);
switch (kind) {
case CXCursor_FieldDecl: {
UnionFieldDecl field;
field.name = clang_getCString(clang_getCursorSpelling(cursor));
auto type = clang_getCursorType(cursor);
field.type = TypeSpec(type);
field.type.isNullable = true;
decl->fields.emplace_back(field);
break;
}
default:
break;
}
return CXChildVisit_Continue;
},
this);
}
void MetadataFactory::processRecordRefs() {
while (!referencedRecords.empty()) {
std::unordered_set<std::string> refs = referencedRecords;
referencedRecords.clear();
for (const std::string &name : refs) {
if (unions.contains(name) || structs.contains(name)) {
continue;
}
if (skippedStructs.contains(name)) {
StructDecl decl = skippedStructs[name];
structs[decl.name] = decl;
postProcessStruct(structs[decl.name]);
} else if (skippedUnions.contains(name)) {
UnionDecl decl = skippedUnions[name];
unions[decl.name] = decl;
postProcessUnion(unions[decl.name]);
} else {
std::cerr << "ERROR: Unknown record " << name << std::endl;
}
}
}
}
} // namespace metagen