@@ -27,24 +27,27 @@ namespace apigen {
27
27
void API::addSymbol (llvm::StringRef symbol, APILoc loc, APILinkage linkage,
28
28
APIFlags flags, APIAccess access,
29
29
APIAvailability availability) {
30
- globals.emplace_back (symbol, loc, linkage, flags, access, GVKind::Function,
31
- availability);
30
+ auto *global = new (allocator) GlobalRecord (
31
+ symbol, loc, linkage, flags, access, GVKind::Function, availability);
32
+ globals.push_back (global);
32
33
}
33
34
34
35
ObjCInterfaceRecord *API::addObjCClass (llvm::StringRef name, APILinkage linkage,
35
36
APILoc loc, APIAccess access,
36
37
APIAvailability availability,
37
38
llvm::StringRef superClassName) {
38
- interfaces.emplace_back (name, linkage, loc, access, availability,
39
- superClassName);
40
- return &interfaces.back ();
39
+ auto *interface = new (allocator) ObjCInterfaceRecord (
40
+ name, linkage, loc, access, availability, superClassName);
41
+ interfaces.push_back (interface);
42
+ return interface;
41
43
}
42
44
43
45
void API::addObjCMethod (ObjCInterfaceRecord *cls, llvm::StringRef name,
44
46
APILoc loc, APIAccess access, bool isInstanceMethod,
45
47
bool isOptional, APIAvailability availability) {
46
- cls->methods .emplace_back (name, loc, access, isInstanceMethod, isOptional,
47
- availability);
48
+ auto method = new (allocator) ObjCMethodRecord (
49
+ name, loc, access, isInstanceMethod, isOptional, availability);
50
+ cls->methods .push_back (method);
48
51
}
49
52
50
53
static void serialize (llvm::json::OStream &OS, APIAccess access) {
@@ -120,6 +123,10 @@ static void serialize(llvm::json::OStream &OS, const ObjCMethodRecord &record) {
120
123
});
121
124
}
122
125
126
+ static bool sortAPIRecords (const APIRecord *base, const APIRecord *compare) {
127
+ return base->name < compare->name ;
128
+ }
129
+
123
130
static void serialize (llvm::json::OStream &OS,
124
131
const ObjCInterfaceRecord &record) {
125
132
OS.object ([&]() {
@@ -131,39 +138,34 @@ static void serialize(llvm::json::OStream &OS,
131
138
OS.attribute (" super" , record.superClassName );
132
139
OS.attributeArray (" instanceMethods" , [&]() {
133
140
for (auto &method : record.methods ) {
134
- if (method. isInstanceMethod )
135
- serialize (OS, method);
141
+ if (method-> isInstanceMethod )
142
+ serialize (OS, * method);
136
143
}
137
144
});
138
145
OS.attributeArray (" classMethods" , [&]() {
139
146
for (auto &method : record.methods ) {
140
- if (!method. isInstanceMethod )
141
- serialize (OS, method);
147
+ if (!method-> isInstanceMethod )
148
+ serialize (OS, * method);
142
149
}
143
150
});
144
151
});
145
152
}
146
153
147
- static bool sortAPIRecords (const APIRecord &base, const APIRecord &compare) {
148
- return base.name < compare.name ;
149
- }
150
-
151
154
void API::writeAPIJSONFile (llvm::raw_ostream &os, bool PrettyPrint) {
152
155
unsigned indentSize = PrettyPrint ? 2 : 0 ;
153
156
llvm::json::OStream JSON (os, indentSize);
154
157
155
- // FIXME: only write PublicSDKContentRoot now.
156
158
JSON.object ([&]() {
157
159
JSON.attribute (" target" , target.str ());
158
160
JSON.attributeArray (" globals" , [&]() {
159
161
llvm::sort (globals, sortAPIRecords);
160
- for (const auto & g : globals)
161
- serialize (JSON, g);
162
+ for (const auto * g : globals)
163
+ serialize (JSON, * g);
162
164
});
163
165
JSON.attributeArray (" interfaces" , [&]() {
164
166
llvm::sort (interfaces, sortAPIRecords);
165
- for (const auto & i : interfaces)
166
- serialize (JSON, i);
167
+ for (const auto * i : interfaces)
168
+ serialize (JSON, * i);
167
169
});
168
170
JSON.attribute (" version" , " 1.0" );
169
171
});
0 commit comments