@@ -27,24 +27,27 @@ namespace apigen {
2727void API::addSymbol (llvm::StringRef symbol, APILoc loc, APILinkage linkage,
2828 APIFlags flags, APIAccess access,
2929 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);
3233}
3334
3435ObjCInterfaceRecord *API::addObjCClass (llvm::StringRef name, APILinkage linkage,
3536 APILoc loc, APIAccess access,
3637 APIAvailability availability,
3738 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;
4143}
4244
4345void API::addObjCMethod (ObjCInterfaceRecord *cls, llvm::StringRef name,
4446 APILoc loc, APIAccess access, bool isInstanceMethod,
4547 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);
4851}
4952
5053static void serialize (llvm::json::OStream &OS, APIAccess access) {
@@ -120,6 +123,10 @@ static void serialize(llvm::json::OStream &OS, const ObjCMethodRecord &record) {
120123 });
121124}
122125
126+ static bool sortAPIRecords (const APIRecord *base, const APIRecord *compare) {
127+ return base->name < compare->name ;
128+ }
129+
123130static void serialize (llvm::json::OStream &OS,
124131 const ObjCInterfaceRecord &record) {
125132 OS.object ([&]() {
@@ -131,39 +138,34 @@ static void serialize(llvm::json::OStream &OS,
131138 OS.attribute (" super" , record.superClassName );
132139 OS.attributeArray (" instanceMethods" , [&]() {
133140 for (auto &method : record.methods ) {
134- if (method. isInstanceMethod )
135- serialize (OS, method);
141+ if (method-> isInstanceMethod )
142+ serialize (OS, * method);
136143 }
137144 });
138145 OS.attributeArray (" classMethods" , [&]() {
139146 for (auto &method : record.methods ) {
140- if (!method. isInstanceMethod )
141- serialize (OS, method);
147+ if (!method-> isInstanceMethod )
148+ serialize (OS, * method);
142149 }
143150 });
144151 });
145152}
146153
147- static bool sortAPIRecords (const APIRecord &base, const APIRecord &compare) {
148- return base.name < compare.name ;
149- }
150-
151154void API::writeAPIJSONFile (llvm::raw_ostream &os, bool PrettyPrint) {
152155 unsigned indentSize = PrettyPrint ? 2 : 0 ;
153156 llvm::json::OStream JSON (os, indentSize);
154157
155- // FIXME: only write PublicSDKContentRoot now.
156158 JSON.object ([&]() {
157159 JSON.attribute (" target" , target.str ());
158160 JSON.attributeArray (" globals" , [&]() {
159161 llvm::sort (globals, sortAPIRecords);
160- for (const auto & g : globals)
161- serialize (JSON, g);
162+ for (const auto * g : globals)
163+ serialize (JSON, * g);
162164 });
163165 JSON.attributeArray (" interfaces" , [&]() {
164166 llvm::sort (interfaces, sortAPIRecords);
165- for (const auto & i : interfaces)
166- serialize (JSON, i);
167+ for (const auto * i : interfaces)
168+ serialize (JSON, * i);
167169 });
168170 JSON.attribute (" version" , " 1.0" );
169171 });
0 commit comments