19
19
#define LLVM_CLANG_EXTRACTAPI_API_H
20
20
21
21
#include " clang/AST/Decl.h"
22
+ #include " clang/AST/DeclObjC.h"
22
23
#include " clang/AST/RawCommentList.h"
23
24
#include " clang/Basic/SourceLocation.h"
24
25
#include " clang/ExtractAPI/AvailabilityInfo.h"
@@ -77,6 +78,10 @@ struct APIRecord {
77
78
RK_Enum,
78
79
RK_StructField,
79
80
RK_Struct,
81
+ RK_ObjCProperty,
82
+ RK_ObjCIvar,
83
+ RK_ObjCMethod,
84
+ RK_ObjCInterface,
80
85
};
81
86
82
87
private:
@@ -201,6 +206,154 @@ struct StructRecord : APIRecord {
201
206
virtual void anchor ();
202
207
};
203
208
209
+ // / This holds information associated with Objective-C properties.
210
+ struct ObjCPropertyRecord : APIRecord {
211
+ // / The attributes associated with an Objective-C property.
212
+ enum AttributeKind : unsigned {
213
+ NoAttr = 0 ,
214
+ ReadOnly = 1 ,
215
+ Class = 1 << 1 ,
216
+ Dynamic = 1 << 2 ,
217
+ };
218
+
219
+ AttributeKind Attributes;
220
+ StringRef GetterName;
221
+ StringRef SetterName;
222
+ bool IsOptional;
223
+
224
+ ObjCPropertyRecord (StringRef Name, StringRef USR, PresumedLoc Loc,
225
+ const AvailabilityInfo &Availability,
226
+ const DocComment &Comment,
227
+ DeclarationFragments Declaration,
228
+ DeclarationFragments SubHeading, AttributeKind Attributes,
229
+ StringRef GetterName, StringRef SetterName,
230
+ bool IsOptional)
231
+ : APIRecord(RK_ObjCProperty, Name, USR, Loc, Availability,
232
+ LinkageInfo::none (), Comment, Declaration, SubHeading),
233
+ Attributes(Attributes), GetterName(GetterName), SetterName(SetterName),
234
+ IsOptional(IsOptional) {}
235
+
236
+ bool isReadOnly () const { return Attributes & ReadOnly; }
237
+ bool isDynamic () const { return Attributes & Dynamic; }
238
+ bool isClassProperty () const { return Attributes & Class; }
239
+
240
+ static bool classof (const APIRecord *Record) {
241
+ return Record->getKind () == RK_ObjCProperty;
242
+ }
243
+
244
+ private:
245
+ virtual void anchor ();
246
+ };
247
+
248
+ // / This holds information associated with Objective-C instance variables.
249
+ struct ObjCInstanceVariableRecord : APIRecord {
250
+ using AccessControl = ObjCIvarDecl::AccessControl;
251
+ AccessControl Access;
252
+
253
+ ObjCInstanceVariableRecord (StringRef Name, StringRef USR, PresumedLoc Loc,
254
+ const AvailabilityInfo &Availability,
255
+ const DocComment &Comment,
256
+ DeclarationFragments Declaration,
257
+ DeclarationFragments SubHeading,
258
+ AccessControl Access)
259
+ : APIRecord(RK_ObjCIvar, Name, USR, Loc, Availability,
260
+ LinkageInfo::none (), Comment, Declaration, SubHeading),
261
+ Access(Access) {}
262
+
263
+ static bool classof (const APIRecord *Record) {
264
+ return Record->getKind () == RK_ObjCIvar;
265
+ }
266
+
267
+ private:
268
+ virtual void anchor ();
269
+ };
270
+
271
+ // / This holds information associated with Objective-C methods.
272
+ struct ObjCMethodRecord : APIRecord {
273
+ FunctionSignature Signature;
274
+ bool IsInstanceMethod;
275
+
276
+ ObjCMethodRecord (StringRef Name, StringRef USR, PresumedLoc Loc,
277
+ const AvailabilityInfo &Availability,
278
+ const DocComment &Comment, DeclarationFragments Declaration,
279
+ DeclarationFragments SubHeading, FunctionSignature Signature,
280
+ bool IsInstanceMethod)
281
+ : APIRecord(RK_ObjCMethod, Name, USR, Loc, Availability,
282
+ LinkageInfo::none (), Comment, Declaration, SubHeading),
283
+ Signature(Signature), IsInstanceMethod(IsInstanceMethod) {}
284
+
285
+ static bool classof (const APIRecord *Record) {
286
+ return Record->getKind () == RK_ObjCMethod;
287
+ }
288
+
289
+ private:
290
+ virtual void anchor ();
291
+ };
292
+
293
+ // / This represents a reference to another symbol that might come from external
294
+ // / sources.
295
+ struct SymbolReference {
296
+ StringRef Name;
297
+ StringRef USR;
298
+
299
+ // / The source project/module/product of the referred symbol.
300
+ StringRef Source;
301
+
302
+ SymbolReference () = default ;
303
+ SymbolReference (StringRef Name, StringRef USR = " " , StringRef Source = " " )
304
+ : Name(Name), USR(USR), Source(Source) {}
305
+ SymbolReference (const APIRecord &Record)
306
+ : Name(Record.Name), USR(Record.USR) {}
307
+
308
+ // / Determine if this SymbolReference is empty.
309
+ // /
310
+ // / \returns true if and only if all \c Name, \c USR, and \c Source is empty.
311
+ bool empty () const { return Name.empty () && USR.empty () && Source.empty (); }
312
+ };
313
+
314
+ // / The base representation of an Objective-C container record. Holds common
315
+ // / information associated with Objective-C containers.
316
+ struct ObjCContainerRecord : APIRecord {
317
+ SmallVector<std::unique_ptr<ObjCMethodRecord>> Methods;
318
+ SmallVector<std::unique_ptr<ObjCPropertyRecord>> Properties;
319
+ SmallVector<std::unique_ptr<ObjCInstanceVariableRecord>> Ivars;
320
+ SmallVector<SymbolReference> Protocols;
321
+
322
+ ObjCContainerRecord () = delete ;
323
+
324
+ ObjCContainerRecord (RecordKind Kind, StringRef Name, StringRef USR,
325
+ PresumedLoc Loc, const AvailabilityInfo &Availability,
326
+ LinkageInfo Linkage, const DocComment &Comment,
327
+ DeclarationFragments Declaration,
328
+ DeclarationFragments SubHeading)
329
+ : APIRecord(Kind, Name, USR, Loc, Availability, Linkage, Comment,
330
+ Declaration, SubHeading) {}
331
+
332
+ virtual ~ObjCContainerRecord () = 0 ;
333
+ };
334
+
335
+ // / This holds information associated with Objective-C interfaces/classes.
336
+ struct ObjCInterfaceRecord : ObjCContainerRecord {
337
+ SymbolReference SuperClass;
338
+
339
+ ObjCInterfaceRecord (StringRef Name, StringRef USR, PresumedLoc Loc,
340
+ const AvailabilityInfo &Availability, LinkageInfo Linkage,
341
+ const DocComment &Comment,
342
+ DeclarationFragments Declaration,
343
+ DeclarationFragments SubHeading,
344
+ SymbolReference SuperClass)
345
+ : ObjCContainerRecord(RK_ObjCInterface, Name, USR, Loc, Availability,
346
+ Linkage, Comment, Declaration, SubHeading),
347
+ SuperClass (SuperClass) {}
348
+
349
+ static bool classof (const APIRecord *Record) {
350
+ return Record->getKind () == RK_ObjCInterface;
351
+ }
352
+
353
+ private:
354
+ virtual void anchor ();
355
+ };
356
+
204
357
// / APISet holds the set of API records collected from given inputs.
205
358
class APISet {
206
359
public:
@@ -292,6 +445,58 @@ class APISet {
292
445
DeclarationFragments Declaration,
293
446
DeclarationFragments SubHeading);
294
447
448
+ // / Create and add an Objective-C interface record into the API set.
449
+ // /
450
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
451
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
452
+ // / APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
453
+ // / to generate the USR for \c D and keep it alive in APISet.
454
+ ObjCInterfaceRecord *
455
+ addObjCInterface (StringRef Name, StringRef USR, PresumedLoc Loc,
456
+ const AvailabilityInfo &Availability, LinkageInfo Linkage,
457
+ const DocComment &Comment, DeclarationFragments Declaration,
458
+ DeclarationFragments SubHeading, SymbolReference SuperClass);
459
+
460
+ // / Create and add an Objective-C method record into the API set.
461
+ // /
462
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
463
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
464
+ // / APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
465
+ // / to generate the USR for \c D and keep it alive in APISet.
466
+ ObjCMethodRecord *
467
+ addObjCMethod (ObjCContainerRecord *Container, StringRef Name, StringRef USR,
468
+ PresumedLoc Loc, const AvailabilityInfo &Availability,
469
+ const DocComment &Comment, DeclarationFragments Declaration,
470
+ DeclarationFragments SubHeading, FunctionSignature Signature,
471
+ bool IsInstanceMethod);
472
+
473
+ // / Create and add an Objective-C property record into the API set.
474
+ // /
475
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
476
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
477
+ // / APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
478
+ // / to generate the USR for \c D and keep it alive in APISet.
479
+ ObjCPropertyRecord *
480
+ addObjCProperty (ObjCContainerRecord *Container, StringRef Name, StringRef USR,
481
+ PresumedLoc Loc, const AvailabilityInfo &Availability,
482
+ const DocComment &Comment, DeclarationFragments Declaration,
483
+ DeclarationFragments SubHeading,
484
+ ObjCPropertyRecord::AttributeKind Attributes,
485
+ StringRef GetterName, StringRef SetterName, bool IsOptional);
486
+
487
+ // / Create and add an Objective-C instance variable record into the API set.
488
+ // /
489
+ // / Note: the caller is responsible for keeping the StringRef \p Name and
490
+ // / \p USR alive. APISet::copyString provides a way to copy strings into
491
+ // / APISet itself, and APISet::recordUSR(const Decl *D) is a helper method
492
+ // / to generate the USR for \c D and keep it alive in APISet.
493
+ ObjCInstanceVariableRecord *addObjCInstanceVariable (
494
+ ObjCContainerRecord *Container, StringRef Name, StringRef USR,
495
+ PresumedLoc Loc, const AvailabilityInfo &Availability,
496
+ const DocComment &Comment, DeclarationFragments Declaration,
497
+ DeclarationFragments SubHeading,
498
+ ObjCInstanceVariableRecord::AccessControl Access);
499
+
295
500
// / A map to store the set of GlobalRecord%s with the declaration name as the
296
501
// / key.
297
502
using GlobalRecordMap =
@@ -306,6 +511,11 @@ class APISet {
306
511
using StructRecordMap =
307
512
llvm::MapVector<StringRef, std::unique_ptr<StructRecord>>;
308
513
514
+ // / A map to store the set of ObjCInterfaceRecord%s with the declaration name
515
+ // / as the key.
516
+ using ObjCInterfaceRecordMap =
517
+ llvm::MapVector<StringRef, std::unique_ptr<ObjCInterfaceRecord>>;
518
+
309
519
// / Get the target triple for the ExtractAPI invocation.
310
520
const llvm::Triple &getTarget () const { return Target; }
311
521
@@ -315,6 +525,9 @@ class APISet {
315
525
const GlobalRecordMap &getGlobals () const { return Globals; }
316
526
const EnumRecordMap &getEnums () const { return Enums; }
317
527
const StructRecordMap &getStructs () const { return Structs; }
528
+ const ObjCInterfaceRecordMap &getObjCInterfaces () const {
529
+ return ObjCInterfaces;
530
+ }
318
531
319
532
// / Generate and store the USR of declaration \p D.
320
533
// /
@@ -343,6 +556,7 @@ class APISet {
343
556
GlobalRecordMap Globals;
344
557
EnumRecordMap Enums;
345
558
StructRecordMap Structs;
559
+ ObjCInterfaceRecordMap ObjCInterfaces;
346
560
};
347
561
348
562
} // namespace extractapi
0 commit comments