22
22
#include " clang/AST/DeclObjC.h"
23
23
#include " clang/AST/RawCommentList.h"
24
24
#include " clang/Basic/SourceLocation.h"
25
+ #include " clang/Basic/Specifiers.h"
25
26
#include " clang/ExtractAPI/AvailabilityInfo.h"
26
27
#include " clang/ExtractAPI/DeclarationFragments.h"
27
28
#include " llvm/ADT/MapVector.h"
@@ -64,6 +65,14 @@ struct APIRecord {
64
65
RK_Enum,
65
66
RK_StructField,
66
67
RK_Struct,
68
+ RK_Union,
69
+ RK_StaticField,
70
+ RK_CXXField,
71
+ RK_CXXClass,
72
+ RK_CXXStaticMethod,
73
+ RK_CXXInstanceMethod,
74
+ RK_CXXConstructorMethod,
75
+ RK_CXXDestructorMethod,
67
76
RK_ObjCInstanceProperty,
68
77
RK_ObjCClassProperty,
69
78
RK_ObjCIvar,
@@ -266,6 +275,132 @@ struct StructRecord : APIRecord {
266
275
virtual void anchor ();
267
276
};
268
277
278
+ struct CXXFieldRecord : APIRecord {
279
+ AccessControl Access;
280
+
281
+ CXXFieldRecord (StringRef USR, StringRef Name, PresumedLoc Loc,
282
+ AvailabilitySet Availabilities, const DocComment &Comment,
283
+ DeclarationFragments Declaration,
284
+ DeclarationFragments SubHeading, AccessControl Access,
285
+ bool IsFromSystemHeader)
286
+ : APIRecord(RK_CXXField, USR, Name, Loc, std::move(Availabilities),
287
+ LinkageInfo::none (), Comment, Declaration, SubHeading,
288
+ IsFromSystemHeader),
289
+ Access(Access) {}
290
+
291
+ CXXFieldRecord (RecordKind Kind, StringRef USR, StringRef Name,
292
+ PresumedLoc Loc, AvailabilitySet Availabilities,
293
+ const DocComment &Comment, DeclarationFragments Declaration,
294
+ DeclarationFragments SubHeading, AccessControl Access,
295
+ bool IsFromSystemHeader)
296
+ : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities),
297
+ LinkageInfo::none(), Comment, Declaration, SubHeading,
298
+ IsFromSystemHeader),
299
+ Access(Access) {}
300
+
301
+ static bool classof (const APIRecord *Record) {
302
+ return Record->getKind () == RK_CXXField;
303
+ }
304
+
305
+ private:
306
+ virtual void anchor ();
307
+ };
308
+
309
+ struct CXXMethodRecord : APIRecord {
310
+ FunctionSignature Signature;
311
+ AccessControl Access;
312
+
313
+ CXXMethodRecord () = delete ;
314
+
315
+ CXXMethodRecord (RecordKind Kind, StringRef USR, StringRef Name,
316
+ PresumedLoc Loc, AvailabilitySet Availabilities,
317
+ const DocComment &Comment, DeclarationFragments Declaration,
318
+ DeclarationFragments SubHeading, FunctionSignature Signature,
319
+ AccessControl Access, bool IsFromSystemHeader)
320
+ : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities),
321
+ LinkageInfo::none (), Comment, Declaration, SubHeading,
322
+ IsFromSystemHeader),
323
+ Signature(Signature), Access(Access) {}
324
+
325
+ virtual ~CXXMethodRecord () = 0 ;
326
+ };
327
+
328
+ struct CXXConstructorRecord : CXXMethodRecord {
329
+ CXXConstructorRecord (StringRef USR, StringRef Name, PresumedLoc Loc,
330
+ AvailabilitySet Availabilities,
331
+ const DocComment &Comment,
332
+ DeclarationFragments Declaration,
333
+ DeclarationFragments SubHeading,
334
+ FunctionSignature Signature, AccessControl Access,
335
+ bool IsFromSystemHeader)
336
+ : CXXMethodRecord(RK_CXXConstructorMethod, USR, Name, Loc,
337
+ std::move (Availabilities), Comment, Declaration,
338
+ SubHeading, Signature, Access, IsFromSystemHeader) {}
339
+ static bool classof (const APIRecord *Record) {
340
+ return Record->getKind () == RK_CXXConstructorMethod;
341
+ }
342
+
343
+ private:
344
+ virtual void anchor ();
345
+ };
346
+
347
+ struct CXXDestructorRecord : CXXMethodRecord {
348
+ CXXDestructorRecord (StringRef USR, StringRef Name, PresumedLoc Loc,
349
+ AvailabilitySet Availabilities, const DocComment &Comment,
350
+ DeclarationFragments Declaration,
351
+ DeclarationFragments SubHeading,
352
+ FunctionSignature Signature, AccessControl Access,
353
+ bool IsFromSystemHeader)
354
+ : CXXMethodRecord(RK_CXXDestructorMethod, USR, Name, Loc,
355
+ std::move (Availabilities), Comment, Declaration,
356
+ SubHeading, Signature, Access, IsFromSystemHeader) {}
357
+ static bool classof (const APIRecord *Record) {
358
+ return Record->getKind () == RK_CXXDestructorMethod;
359
+ }
360
+
361
+ private:
362
+ virtual void anchor ();
363
+ };
364
+
365
+ struct CXXStaticMethodRecord : CXXMethodRecord {
366
+ CXXStaticMethodRecord (StringRef USR, StringRef Name, PresumedLoc Loc,
367
+ AvailabilitySet Availabilities,
368
+ const DocComment &Comment,
369
+ DeclarationFragments Declaration,
370
+ DeclarationFragments SubHeading,
371
+ FunctionSignature Signature, AccessControl Access,
372
+ bool IsFromSystemHeader)
373
+ : CXXMethodRecord(RK_CXXStaticMethod, USR, Name, Loc,
374
+ std::move (Availabilities), Comment, Declaration,
375
+ SubHeading, Signature, Access, IsFromSystemHeader) {}
376
+ static bool classof (const APIRecord *Record) {
377
+ return Record->getKind () == RK_CXXStaticMethod;
378
+ }
379
+
380
+ private:
381
+ virtual void anchor ();
382
+ };
383
+
384
+ struct CXXInstanceMethodRecord : CXXMethodRecord {
385
+ CXXInstanceMethodRecord (StringRef USR, StringRef Name, PresumedLoc Loc,
386
+ AvailabilitySet Availabilities,
387
+ const DocComment &Comment,
388
+ DeclarationFragments Declaration,
389
+ DeclarationFragments SubHeading,
390
+ FunctionSignature Signature, AccessControl Access,
391
+ bool IsFromSystemHeader)
392
+ : CXXMethodRecord(RK_CXXInstanceMethod, USR, Name, Loc,
393
+ std::move (Availabilities), Comment, Declaration,
394
+ SubHeading, Signature, Access, IsFromSystemHeader) {}
395
+
396
+ static bool classof (const APIRecord *Record) {
397
+ return Record->getKind () == RK_CXXInstanceMethod;
398
+ }
399
+
400
+ private:
401
+ virtual void anchor ();
402
+ };
403
+
269
404
// / This holds information associated with Objective-C properties.
270
405
struct ObjCPropertyRecord : APIRecord {
271
406
// / The attributes associated with an Objective-C property.
@@ -444,6 +579,24 @@ struct SymbolReference {
444
579
bool empty () const { return Name.empty () && USR.empty () && Source.empty (); }
445
580
};
446
581
582
+ struct StaticFieldRecord : CXXFieldRecord {
583
+ SymbolReference Context;
584
+
585
+ StaticFieldRecord (StringRef USR, StringRef Name, PresumedLoc Loc,
586
+ AvailabilitySet Availabilities, LinkageInfo Linkage,
587
+ const DocComment &Comment, DeclarationFragments Declaration,
588
+ DeclarationFragments SubHeading, SymbolReference Context,
589
+ AccessControl Access, bool IsFromSystemHeader)
590
+ : CXXFieldRecord(RK_StaticField, USR, Name, Loc,
591
+ std::move (Availabilities), Comment, Declaration,
592
+ SubHeading, Access, IsFromSystemHeader),
593
+ Context(Context) {}
594
+
595
+ static bool classof (const APIRecord *Record) {
596
+ return Record->getKind () == RK_StaticField;
597
+ }
598
+ };
599
+
447
600
// / The base representation of an Objective-C container record. Holds common
448
601
// / information associated with Objective-C containers.
449
602
struct ObjCContainerRecord : APIRecord {
@@ -465,6 +618,28 @@ struct ObjCContainerRecord : APIRecord {
465
618
virtual ~ObjCContainerRecord () = 0 ;
466
619
};
467
620
621
+ struct CXXClassRecord : APIRecord {
622
+ SmallVector<std::unique_ptr<CXXFieldRecord>> Fields;
623
+ SmallVector<std::unique_ptr<CXXMethodRecord>> Methods;
624
+ SmallVector<SymbolReference> Bases;
625
+
626
+ CXXClassRecord (StringRef USR, StringRef Name, PresumedLoc Loc,
627
+ AvailabilitySet Availabilities, const DocComment &Comment,
628
+ DeclarationFragments Declaration,
629
+ DeclarationFragments SubHeading, RecordKind Kind,
630
+ bool IsFromSystemHeader)
631
+ : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities),
632
+ LinkageInfo::none (), Comment, Declaration, SubHeading,
633
+ IsFromSystemHeader) {}
634
+
635
+ static bool classof (const APIRecord *Record) {
636
+ return (Record->getKind () == RK_CXXClass);
637
+ }
638
+
639
+ private:
640
+ virtual void anchor ();
641
+ };
642
+
468
643
// / This holds information associated with Objective-C categories.
469
644
struct ObjCCategoryRecord : ObjCContainerRecord {
470
645
SymbolReference Interface;
@@ -591,6 +766,12 @@ struct has_function_signature<ObjCInstanceMethodRecord>
591
766
: public std::true_type {};
592
767
template <>
593
768
struct has_function_signature <ObjCClassMethodRecord> : public std::true_type {};
769
+ template <>
770
+ struct has_function_signature <CXXMethodRecord> : public std::true_type {};
771
+
772
+ template <typename RecordTy> struct has_access : public std ::false_type {};
773
+ template <> struct has_access <CXXMethodRecord> : public std::true_type {};
774
+ template <> struct has_access <CXXFieldRecord> : public std::true_type {};
594
775
595
776
// / APISet holds the set of API records collected from given inputs.
596
777
class APISet {
@@ -668,6 +849,41 @@ class APISet {
668
849
DeclarationFragments SubHeading,
669
850
bool IsFromSystemHeader);
670
851
852
+ StaticFieldRecord *
853
+ addStaticField (StringRef Name, StringRef USR, PresumedLoc Loc,
854
+ AvailabilitySet Availabilities, LinkageInfo Linkage,
855
+ const DocComment &Comment, DeclarationFragments Declaration,
856
+ DeclarationFragments SubHeading, SymbolReference Context,
857
+ AccessControl Access, bool IsFromSystemHeaderg);
858
+
859
+ CXXFieldRecord *addCXXField (CXXClassRecord *CXXClass, StringRef Name,
860
+ StringRef USR, PresumedLoc Loc,
861
+ AvailabilitySet Availabilities,
862
+ const DocComment &Comment,
863
+ DeclarationFragments Declaration,
864
+ DeclarationFragments SubHeading,
865
+ AccessControl Access, bool IsFromSystemHeader);
866
+
867
+ CXXClassRecord *
868
+ addCXXClass (StringRef Name, StringRef USR, PresumedLoc Loc,
869
+ AvailabilitySet Availability, const DocComment &Comment,
870
+ DeclarationFragments Declaration, DeclarationFragments SubHeading,
871
+ APIRecord::RecordKind Kind, bool IsFromSystemHeader);
872
+
873
+ CXXMethodRecord *
874
+ addCXXMethod (CXXClassRecord *CXXClassRecord, StringRef Name, StringRef USR,
875
+ PresumedLoc Loc, AvailabilitySet Availability,
876
+ const DocComment &Comment, DeclarationFragments Declaration,
877
+ DeclarationFragments SubHeading, FunctionSignature Signature,
878
+ bool IsStatic, AccessControl Access, bool IsFromSystemHeader);
879
+
880
+ CXXMethodRecord *addCXXSpecialMethod (
881
+ CXXClassRecord *CXXClassRecord, StringRef Name, StringRef USR,
882
+ PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment,
883
+ DeclarationFragments Declaration, DeclarationFragments SubHeading,
884
+ FunctionSignature Signature, bool IsConstructor, AccessControl Access,
885
+ bool IsFromSystemHeader);
886
+
671
887
// / Create and add an Objective-C category record into the API set.
672
888
// /
673
889
// / Note: the caller is responsible for keeping the StringRef \p Name and
@@ -790,8 +1006,12 @@ class APISet {
790
1006
const RecordMap<GlobalVariableRecord> &getGlobalVariables () const {
791
1007
return GlobalVariables;
792
1008
}
1009
+ const RecordMap<StaticFieldRecord> &getStaticFields () const {
1010
+ return StaticFields;
1011
+ }
793
1012
const RecordMap<EnumRecord> &getEnums () const { return Enums; }
794
1013
const RecordMap<StructRecord> &getStructs () const { return Structs; }
1014
+ const RecordMap<CXXClassRecord> &getCXXClasses () const { return CXXClasses; }
795
1015
const RecordMap<ObjCCategoryRecord> &getObjCCategories () const {
796
1016
return ObjCCategories;
797
1017
}
@@ -845,8 +1065,10 @@ class APISet {
845
1065
llvm::DenseMap<StringRef, APIRecord *> USRBasedLookupTable;
846
1066
RecordMap<GlobalFunctionRecord> GlobalFunctions;
847
1067
RecordMap<GlobalVariableRecord> GlobalVariables;
1068
+ RecordMap<StaticFieldRecord> StaticFields;
848
1069
RecordMap<EnumRecord> Enums;
849
1070
RecordMap<StructRecord> Structs;
1071
+ RecordMap<CXXClassRecord> CXXClasses;
850
1072
RecordMap<ObjCCategoryRecord> ObjCCategories;
851
1073
RecordMap<ObjCInterfaceRecord> ObjCInterfaces;
852
1074
RecordMap<ObjCProtocolRecord> ObjCProtocols;
0 commit comments