@@ -94,6 +94,8 @@ struct APIRecord {
94
94
RK_Global,
95
95
RK_EnumConstant,
96
96
RK_Enum,
97
+ RK_StructField,
98
+ RK_Struct,
97
99
};
98
100
99
101
private:
@@ -176,6 +178,36 @@ struct EnumRecord : APIRecord {
176
178
}
177
179
};
178
180
181
+ // / This holds information associated with struct fields.
182
+ struct StructFieldRecord : APIRecord {
183
+ StructFieldRecord (StringRef Name, StringRef USR, PresumedLoc Loc,
184
+ const AvailabilityInfo &Availability,
185
+ const DocComment &Comment, DeclarationFragments Declaration,
186
+ DeclarationFragments SubHeading)
187
+ : APIRecord(RK_StructField, Name, USR, Loc, Availability,
188
+ LinkageInfo::none (), Comment, Declaration, SubHeading) {}
189
+
190
+ static bool classof (const APIRecord *Record) {
191
+ return Record->getKind () == RK_StructField;
192
+ }
193
+ };
194
+
195
+ // / This holds information associated with structs.
196
+ struct StructRecord : APIRecord {
197
+ SmallVector<APIRecordUniquePtr<StructFieldRecord>> Fields;
198
+
199
+ StructRecord (StringRef Name, StringRef USR, PresumedLoc Loc,
200
+ const AvailabilityInfo &Availability, const DocComment &Comment,
201
+ DeclarationFragments Declaration,
202
+ DeclarationFragments SubHeading)
203
+ : APIRecord(RK_Struct, Name, USR, Loc, Availability, LinkageInfo::none(),
204
+ Comment, Declaration, SubHeading) {}
205
+
206
+ static bool classof (const APIRecord *Record) {
207
+ return Record->getKind () == RK_Struct;
208
+ }
209
+ };
210
+
179
211
// / APISet holds the set of API records collected from given inputs.
180
212
class APISet {
181
213
public:
@@ -242,6 +274,31 @@ class APISet {
242
274
DeclarationFragments Declaration,
243
275
DeclarationFragments SubHeading);
244
276
277
+ // / Create and add a struct field record into the API set.
278
+ // /
279
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
280
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
281
+ // / APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
282
+ // / to generate the USR for \c D and keep it alive in APISet.
283
+ StructFieldRecord *addStructField (StructRecord *Struct, StringRef Name,
284
+ StringRef USR, PresumedLoc Loc,
285
+ const AvailabilityInfo &Availability,
286
+ const DocComment &Comment,
287
+ DeclarationFragments Declaration,
288
+ DeclarationFragments SubHeading);
289
+
290
+ // / Create and add a struct record into the API set.
291
+ // /
292
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
293
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
294
+ // / APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
295
+ // / to generate the USR for \c D and keep it alive in APISet.
296
+ StructRecord *addStruct (StringRef Name, StringRef USR, PresumedLoc Loc,
297
+ const AvailabilityInfo &Availability,
298
+ const DocComment &Comment,
299
+ DeclarationFragments Declaration,
300
+ DeclarationFragments SubHeading);
301
+
245
302
// / A map to store the set of GlobalRecord%s with the declaration name as the
246
303
// / key.
247
304
using GlobalRecordMap =
@@ -252,6 +309,11 @@ class APISet {
252
309
using EnumRecordMap =
253
310
llvm::MapVector<StringRef, APIRecordUniquePtr<EnumRecord>>;
254
311
312
+ // / A map to store the set of StructRecord%s with the declaration name as the
313
+ // / key.
314
+ using StructRecordMap =
315
+ llvm::MapVector<StringRef, APIRecordUniquePtr<StructRecord>>;
316
+
255
317
// / Get the target triple for the ExtractAPI invocation.
256
318
const llvm::Triple &getTarget () const { return Target; }
257
319
@@ -260,6 +322,7 @@ class APISet {
260
322
261
323
const GlobalRecordMap &getGlobals () const { return Globals; }
262
324
const EnumRecordMap &getEnums () const { return Enums; }
325
+ const StructRecordMap &getStructs () const { return Structs; }
263
326
264
327
// / Generate and store the USR of declaration \p D.
265
328
// /
@@ -285,6 +348,7 @@ class APISet {
285
348
286
349
GlobalRecordMap Globals;
287
350
EnumRecordMap Enums;
351
+ StructRecordMap Structs;
288
352
};
289
353
290
354
} // namespace extractapi
0 commit comments