clang 18.0.0git
ExtractAPIVisitor.h
Go to the documentation of this file.
1//===- ExtractAPI/ExtractAPIVisitor.h ---------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file defines the ExtractAPVisitor AST visitation interface.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
15#define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
16
17#include "clang/AST/DeclCXX.h"
22#include "llvm/ADT/FunctionExtras.h"
23
31#include "llvm/ADT/StringRef.h"
32#include <type_traits>
33
34namespace clang {
35namespace extractapi {
36namespace impl {
37
38template <typename Derived>
40protected:
42 : Context(Context), API(API) {}
43
44public:
45 const APISet &getAPI() const { return API; }
46
48
50
52
54
56
58
60
63
66
68
71
74
76
78
80
82
84
86
88
90
92
94
96
99
102
104
105 bool
107
110
112
114
116
118
120
121 bool shouldDeclBeIncluded(const Decl *Decl) const;
122
124
125protected:
126 /// Collect API information for the enum constants and associate with the
127 /// parent enum.
129 const EnumDecl::enumerator_range Constants);
130
131 /// Collect API information for the struct fields and associate with the
132 /// parent struct.
134 const RecordDecl::field_range Fields);
135
136 /// Collect API information for the Objective-C methods and associate with the
137 /// parent container.
139 const ObjCContainerDecl::method_range Methods);
140
142 const ObjCContainerDecl::prop_range Properties);
143
145 ObjCContainerRecord *Container,
146 const llvm::iterator_range<
148 Ivars);
149
152
155
156 StringRef getTypedefName(const TagDecl *Decl) {
157 if (const auto *TypedefDecl = Decl->getTypedefNameForAnonDecl())
158 return TypedefDecl->getName();
159
160 return {};
161 }
162
163 bool isInSystemHeader(const Decl *D) {
165 }
166
167private:
168 Derived &getDerivedExtractAPIVisitor() {
169 return *static_cast<Derived *>(this);
170 }
171
173 // FIXME: store AccessSpecifier given by inheritance
175 for (const auto BaseSpecifier : Decl->bases()) {
176 // skip classes not inherited as public
177 if (BaseSpecifier.getAccessSpecifier() != AccessSpecifier::AS_public)
178 continue;
179 SymbolReference BaseClass;
180 if (BaseSpecifier.getType().getTypePtr()->isTemplateTypeParmType()) {
181 BaseClass.Name = API.copyString(BaseSpecifier.getType().getAsString());
182 BaseClass.USR = API.recordUSR(
183 BaseSpecifier.getType()->getAs<TemplateTypeParmType>()->getDecl());
184 } else {
185 CXXRecordDecl *BaseClassDecl =
186 BaseSpecifier.getType().getTypePtr()->getAsCXXRecordDecl();
187 BaseClass.Name = BaseClassDecl->getName();
188 BaseClass.USR = API.recordUSR(BaseClassDecl);
189 }
190 Bases.emplace_back(BaseClass);
191 }
192 return Bases;
193 }
194
195 APIRecord *determineParentRecord(const DeclContext *Context) {
196 SmallString<128> ParentUSR;
197 if (Context->getDeclKind() == Decl::TranslationUnit)
198 return nullptr;
199
200 index::generateUSRForDecl(dyn_cast<Decl>(Context), ParentUSR);
201
202 APIRecord *Parent = API.findRecordForUSR(ParentUSR);
203 return Parent;
204 }
205};
206
207template <typename T>
208static void modifyRecords(const T &Records, const StringRef &Name) {
209 for (const auto &Record : Records) {
210 if (Name == Record.second.get()->Name) {
211 auto &DeclFragment = Record.second->Declaration;
212 DeclFragment.insert(DeclFragment.begin(), " ",
214 DeclFragment.insert(DeclFragment.begin(), "typedef",
216 nullptr);
217 DeclFragment.insert(--DeclFragment.end(), " { ... } ",
219 DeclFragment.insert(--DeclFragment.end(), Name,
221 break;
222 }
223 }
224}
225
226template <typename Derived>
228 // skip function parameters.
229 if (isa<ParmVarDecl>(Decl))
230 return true;
231
232 // Skip non-global variables in records (struct/union/class) but not static
233 // members.
234 if (Decl->getDeclContext()->isRecord() && !Decl->isStaticDataMember())
235 return true;
236
237 // Skip local variables inside function or method.
239 return true;
240
241 // If this is a template but not specialization or instantiation, skip.
243 Decl->getTemplateSpecializationKind() == TSK_Undeclared)
244 return true;
245
246 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
247 return true;
248
249 // Collect symbol information.
250 StringRef Name = Decl->getName();
251 StringRef USR = API.recordUSR(Decl);
252 PresumedLoc Loc =
253 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
254 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
255 DocComment Comment;
256 if (auto *RawComment =
257 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
258 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
259 Context.getDiagnostics());
260
261 // Build declaration fragments and sub-heading for the variable.
264 DeclarationFragments SubHeading =
266
267 if (Decl->isStaticDataMember()) {
268 SymbolReference Context;
269 // getDeclContext() should return a RecordDecl since we
270 // are currently handling a static data member.
271 auto *Record = cast<RecordDecl>(Decl->getDeclContext());
272 Context.Name = Record->getName();
273 Context.USR = API.recordUSR(Record);
275 API.addStaticField(Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment,
276 Declaration, SubHeading, Context, Access,
277 isInSystemHeader(Decl));
278 } else
279 // Add the global variable record to the API set.
280 API.addGlobalVar(Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment,
281 Declaration, SubHeading, isInSystemHeader(Decl));
282 return true;
283}
284
285template <typename Derived>
287 const FunctionDecl *Decl) {
288 if (const auto *Method = dyn_cast<CXXMethodDecl>(Decl)) {
289 // Skip member function in class templates.
290 if (Method->getParent()->getDescribedClassTemplate() != nullptr)
291 return true;
292
293 // Skip methods in records.
294 for (const auto &P : Context.getParents(*Method)) {
295 if (P.template get<CXXRecordDecl>())
296 return true;
297 }
298
299 // Skip ConstructorDecl and DestructorDecl.
300 if (isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method))
301 return true;
302 }
303
304 // Skip templated functions.
305 switch (Decl->getTemplatedKind()) {
309 break;
313 return true;
314 }
315
316 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
317 return true;
318
319 // Collect symbol information.
320 StringRef Name = Decl->getName();
321 StringRef USR = API.recordUSR(Decl);
322 PresumedLoc Loc =
323 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
324 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
325 DocComment Comment;
326 if (auto *RawComment =
327 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
328 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
329 Context.getDiagnostics());
330
331 // Build declaration fragments, sub-heading, and signature of the function.
332 DeclarationFragments SubHeading =
334 FunctionSignature Signature =
336
337 if (Decl->getTemplateSpecializationInfo())
339 Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment,
341 getFragmentsForFunctionTemplateSpecialization(Decl),
342 SubHeading, Signature, isInSystemHeader(Decl));
343 else
344 // Add the function record to the API set.
346 Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment,
348 Signature, isInSystemHeader(Decl));
349 return true;
350}
351
352template <typename Derived>
354 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
355 return true;
356
357 SmallString<128> QualifiedNameBuffer;
358 // Collect symbol information.
359 StringRef Name = Decl->getName();
360 if (Name.empty())
361 Name = getTypedefName(Decl);
362 if (Name.empty()) {
363 llvm::raw_svector_ostream OS(QualifiedNameBuffer);
364 Decl->printQualifiedName(OS);
365 Name = QualifiedNameBuffer.str();
366 }
367
368 StringRef USR = API.recordUSR(Decl);
369 PresumedLoc Loc =
370 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
371 DocComment Comment;
372 if (auto *RawComment =
373 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
374 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
375 Context.getDiagnostics());
376
377 // Build declaration fragments and sub-heading for the enum.
380 DeclarationFragments SubHeading =
382
384 API.addEnum(API.copyString(Name), USR, Loc, AvailabilitySet(Decl),
385 Comment, Declaration, SubHeading, isInSystemHeader(Decl));
386
387 // Now collect information about the enumerators in this enum.
388 getDerivedExtractAPIVisitor().recordEnumConstants(EnumRecord,
389 Decl->enumerators());
390
391 return true;
392}
393
394template <typename Derived>
396 const FunctionDecl *Decl) {
397 getDerivedExtractAPIVisitor().VisitFunctionDecl(Decl);
398 return true;
399}
400
401template <typename Derived>
403 const RecordDecl *Decl) {
404 getDerivedExtractAPIVisitor().VisitRecordDecl(Decl);
405 return true;
406}
407
408template <typename Derived>
410 const CXXRecordDecl *Decl) {
411 getDerivedExtractAPIVisitor().VisitCXXRecordDecl(Decl);
412 return true;
413}
414
415template <typename Derived>
417 const CXXMethodDecl *Decl) {
418 getDerivedExtractAPIVisitor().VisitCXXMethodDecl(Decl);
419 return true;
420}
421
422template <typename Derived>
425 getDerivedExtractAPIVisitor().VisitClassTemplateSpecializationDecl(Decl);
426 return true;
427}
428
429template <typename Derived>
433 getDerivedExtractAPIVisitor().VisitClassTemplatePartialSpecializationDecl(
434 Decl);
435 return true;
436}
437
438template <typename Derived>
440 const VarTemplateDecl *Decl) {
441 getDerivedExtractAPIVisitor().VisitVarTemplateDecl(Decl);
442 return true;
443}
444
445template <typename Derived>
448 getDerivedExtractAPIVisitor().VisitVarTemplateSpecializationDecl(Decl);
449 return true;
450}
451
452template <typename Derived>
456 getDerivedExtractAPIVisitor().VisitVarTemplatePartialSpecializationDecl(Decl);
457 return true;
458}
459
460template <typename Derived>
462 const FunctionTemplateDecl *Decl) {
463 getDerivedExtractAPIVisitor().VisitFunctionTemplateDecl(Decl);
464 return true;
465}
466
467template <typename Derived>
469 const NamespaceDecl *Decl) {
470 getDerivedExtractAPIVisitor().VisitNamespaceDecl(Decl);
471 return true;
472}
473
474template <typename Derived>
476 const NamespaceDecl *Decl) {
477
478 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
479 return true;
480 if (Decl->isAnonymousNamespace())
481 return true;
482 StringRef Name = Decl->getName();
483 StringRef USR = API.recordUSR(Decl);
484 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
485 PresumedLoc Loc =
486 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
487 DocComment Comment;
488 if (auto *RawComment =
489 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
490 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
491 Context.getDiagnostics());
492
493 // Build declaration fragments and sub-heading for the struct.
496 DeclarationFragments SubHeading =
498 APIRecord *Parent = determineParentRecord(Decl->getDeclContext());
499 API.addNamespace(Parent, Name, USR, Loc, AvailabilitySet(Decl), Linkage,
500 Comment, Declaration, SubHeading, isInSystemHeader(Decl));
501
502 return true;
503}
504
505template <typename Derived>
507 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
508 return true;
509 // Collect symbol information.
510 StringRef Name = Decl->getName();
511 if (Name.empty())
512 Name = getTypedefName(Decl);
513 if (Name.empty())
514 return true;
515
516 StringRef USR = API.recordUSR(Decl);
517 PresumedLoc Loc =
518 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
519 DocComment Comment;
520 if (auto *RawComment =
521 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
522 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
523 Context.getDiagnostics());
524
525 // Build declaration fragments and sub-heading for the struct.
528 DeclarationFragments SubHeading =
530
532 API.addStruct(Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration,
533 SubHeading, isInSystemHeader(Decl));
534
535 // Now collect information about the fields in this struct.
536 getDerivedExtractAPIVisitor().recordStructFields(StructRecord,
537 Decl->fields());
538
539 return true;
540}
541
542template <typename Derived>
544 const CXXRecordDecl *Decl) {
545 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl) ||
546 Decl->isImplicit())
547 return true;
548
549 StringRef Name = Decl->getName();
550 StringRef USR = API.recordUSR(Decl);
551 PresumedLoc Loc =
552 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
553 DocComment Comment;
554 if (auto *RawComment =
555 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
556 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
557 Context.getDiagnostics());
560 DeclarationFragments SubHeading =
562
564 if (Decl->isUnion())
566 else if (Decl->isStruct())
568 else
571
572 APIRecord *Parent = determineParentRecord(Decl->getDeclContext());
574 if (Decl->getDescribedClassTemplate()) {
575 // Inject template fragments before class fragments.
576 Declaration.insert(
577 Declaration.begin(),
579 Decl->getDescribedClassTemplate()));
581 Parent, Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration,
582 SubHeading, Template(Decl->getDescribedClassTemplate()), Access,
583 isInSystemHeader(Decl));
584 } else
586 Parent, Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration,
587 SubHeading, Kind, Access, isInSystemHeader(Decl));
588
589 CXXClassRecord->Bases = getBases(Decl);
590
591 return true;
592}
593
594template <typename Derived>
596 const CXXMethodDecl *Decl) {
597 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl) ||
598 Decl->isImplicit())
599 return true;
600
601 if (isa<CXXConversionDecl>(Decl))
602 return true;
603 if (isa<CXXConstructorDecl>(Decl) || isa<CXXDestructorDecl>(Decl))
604 return true;
605
606 StringRef USR = API.recordUSR(Decl);
607 PresumedLoc Loc =
608 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
609 DocComment Comment;
610 if (auto *RawComment =
611 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
612 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
613 Context.getDiagnostics());
614 DeclarationFragments SubHeading =
618
619 SmallString<128> ParentUSR;
620 index::generateUSRForDecl(dyn_cast<CXXRecordDecl>(Decl->getDeclContext()),
621 ParentUSR);
622 auto *Parent = API.findRecordForUSR(ParentUSR);
623 if (Decl->isTemplated()) {
624 FunctionTemplateDecl *TemplateDecl = Decl->getDescribedFunctionTemplate();
626 API.findRecordForUSR(ParentUSR), Decl->getName(), USR, Loc,
627 AvailabilitySet(Decl), Comment,
632 Template(TemplateDecl), isInSystemHeader(Decl));
633 } else if (Decl->getTemplateSpecializationInfo())
635 Parent, Decl->getName(), USR, Loc, AvailabilitySet(Decl), Comment,
637 getFragmentsForFunctionTemplateSpecialization(Decl),
638 SubHeading, Signature, Access, isInSystemHeader(Decl));
639 else if (Decl->isOverloadedOperator())
641 Parent, API.copyString(Decl->getNameAsString()), USR, Loc,
642 AvailabilitySet(Decl), Comment,
644 SubHeading, Signature, Access, isInSystemHeader(Decl));
645 else if (Decl->isStatic())
647 Parent, Decl->getName(), USR, Loc, AvailabilitySet(Decl), Comment,
649 Signature, Access, isInSystemHeader(Decl));
650 else
652 Parent, Decl->getName(), USR, Loc, AvailabilitySet(Decl), Comment,
654 Signature, Access, isInSystemHeader(Decl));
655
656 return true;
657}
658
659template <typename Derived>
661 const CXXConstructorDecl *Decl) {
662
663 StringRef Name = API.copyString(Decl->getNameAsString());
664 StringRef USR = API.recordUSR(Decl);
665 PresumedLoc Loc =
666 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
667 DocComment Comment;
668 if (auto *RawComment =
669 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
670 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
671 Context.getDiagnostics());
672
673 // Build declaration fragments, sub-heading, and signature for the method.
676 DeclarationFragments SubHeading =
678 FunctionSignature Signature =
681
682 SmallString<128> ParentUSR;
683 index::generateUSRForDecl(dyn_cast<CXXRecordDecl>(Decl->getDeclContext()),
684 ParentUSR);
685 API.addCXXInstanceMethod(API.findRecordForUSR(ParentUSR), Name, USR, Loc,
687 SubHeading, Signature, Access,
688 isInSystemHeader(Decl));
689 return true;
690}
691
692template <typename Derived>
694 const CXXDestructorDecl *Decl) {
695
696 StringRef Name = API.copyString(Decl->getNameAsString());
697 StringRef USR = API.recordUSR(Decl);
698 PresumedLoc Loc =
699 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
700 DocComment Comment;
701 if (auto *RawComment =
702 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
703 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
704 Context.getDiagnostics());
705
706 // Build declaration fragments, sub-heading, and signature for the method.
709 DeclarationFragments SubHeading =
711 FunctionSignature Signature =
714
715 SmallString<128> ParentUSR;
716 index::generateUSRForDecl(dyn_cast<CXXRecordDecl>(Decl->getDeclContext()),
717 ParentUSR);
718 API.addCXXInstanceMethod(API.findRecordForUSR(ParentUSR), Name, USR, Loc,
720 SubHeading, Signature, Access,
721 isInSystemHeader(Decl));
722 return true;
723}
724
725template <typename Derived>
727 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
728 return true;
729
730 StringRef Name = Decl->getName();
731 StringRef USR = API.recordUSR(Decl);
732 PresumedLoc Loc =
733 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
734 DocComment Comment;
735 if (auto *RawComment =
736 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
737 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
738 Context.getDiagnostics());
741 DeclarationFragments SubHeading =
743 API.addConcept(Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration,
744 SubHeading, Template(Decl), isInSystemHeader(Decl));
745 return true;
746}
747
748template <typename Derived>
751 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
752 return true;
753
754 StringRef Name = Decl->getName();
755 StringRef USR = API.recordUSR(Decl);
756 PresumedLoc Loc =
757 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
758 DocComment Comment;
759 if (auto *RawComment =
760 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
761 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
762 Context.getDiagnostics());
765 Decl);
766 DeclarationFragments SubHeading =
768
769 APIRecord *Parent = determineParentRecord(Decl->getDeclContext());
771 Parent, Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration,
773 isInSystemHeader(Decl));
774
776
777 return true;
778}
779
780template <typename Derived>
784 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
785 return true;
786
787 StringRef Name = Decl->getName();
788 StringRef USR = API.recordUSR(Decl);
789 PresumedLoc Loc =
790 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
791 DocComment Comment;
792 if (auto *RawComment =
793 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
794 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
795 Context.getDiagnostics());
798 DeclarationFragments SubHeading =
800
801 APIRecord *Parent = determineParentRecord(Decl->getDeclContext());
802 auto *ClassTemplatePartialSpecRecord =
804 Parent, Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration,
805 SubHeading, Template(Decl),
807 isInSystemHeader(Decl));
808
809 ClassTemplatePartialSpecRecord->Bases = getBases(Decl);
810
811 return true;
812}
813
814template <typename Derived>
816 const VarTemplateDecl *Decl) {
817 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
818 return true;
819
820 // Collect symbol information.
821 StringRef Name = Decl->getName();
822 StringRef USR = API.recordUSR(Decl);
823 PresumedLoc Loc =
824 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
825 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
826 DocComment Comment;
827 if (auto *RawComment =
828 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
829 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
830 Context.getDiagnostics());
831
832 // Build declaration fragments and sub-heading for the variable.
836 Decl))
838 Decl->getTemplatedDecl()));
839 // Inject template fragments before var fragments.
840 DeclarationFragments SubHeading =
842
843 SmallString<128> ParentUSR;
844 index::generateUSRForDecl(dyn_cast<CXXRecordDecl>(Decl->getDeclContext()),
845 ParentUSR);
846 if (Decl->getDeclContext()->getDeclKind() == Decl::CXXRecord)
847 API.addCXXFieldTemplate(API.findRecordForUSR(ParentUSR), Name, USR, Loc,
849 SubHeading,
851 Template(Decl), isInSystemHeader(Decl));
852 else
854 Linkage, Comment, Declaration, SubHeading,
855 Template(Decl), isInSystemHeader(Decl));
856 return true;
857}
858
859template <typename Derived>
862 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
863 return true;
864
865 // Collect symbol information.
866 StringRef Name = Decl->getName();
867 StringRef USR = API.recordUSR(Decl);
868 PresumedLoc Loc =
869 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
870 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
871 DocComment Comment;
872 if (auto *RawComment =
873 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
874 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
875 Context.getDiagnostics());
876
877 // Build declaration fragments and sub-heading for the variable.
880 Decl);
881 DeclarationFragments SubHeading =
883
885 Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment, Declaration,
886 SubHeading, isInSystemHeader(Decl));
887 return true;
888}
889
890template <typename Derived>
893 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
894 return true;
895
896 // Collect symbol information.
897 StringRef Name = Decl->getName();
898 StringRef USR = API.recordUSR(Decl);
899 PresumedLoc Loc =
900 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
901 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
902 DocComment Comment;
903 if (auto *RawComment =
904 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
905 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
906 Context.getDiagnostics());
907
908 // Build declaration fragments and sub-heading for the variable.
911 DeclarationFragments SubHeading =
913
915 Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment, Declaration,
916 SubHeading, Template(Decl), isInSystemHeader(Decl));
917 return true;
918}
919
920template <typename Derived>
922 const FunctionTemplateDecl *Decl) {
923 if (isa<CXXMethodDecl>(Decl->getTemplatedDecl()))
924 return true;
925 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
926 return true;
927
928 // Collect symbol information.
929 StringRef Name = Decl->getName();
930 StringRef USR = API.recordUSR(Decl);
931 PresumedLoc Loc =
932 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
933 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
934 DocComment Comment;
935 if (auto *RawComment =
936 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
937 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
938 Context.getDiagnostics());
939
940 DeclarationFragments SubHeading =
942 FunctionSignature Signature =
944 Decl->getTemplatedDecl());
945
947 Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment,
949 SubHeading, Signature, Template(Decl), isInSystemHeader(Decl));
950
951 return true;
952}
953
954template <typename Derived>
956 const ObjCInterfaceDecl *Decl) {
957 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
958 return true;
959
960 // Collect symbol information.
961 StringRef Name = Decl->getName();
962 StringRef USR = API.recordUSR(Decl);
963 PresumedLoc Loc =
964 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
965 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
966 DocComment Comment;
967 if (auto *RawComment =
968 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
969 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
970 Context.getDiagnostics());
971
972 // Build declaration fragments and sub-heading for the interface.
975 DeclarationFragments SubHeading =
977
978 // Collect super class information.
979 SymbolReference SuperClass;
980 if (const auto *SuperClassDecl = Decl->getSuperClass()) {
981 SuperClass.Name = SuperClassDecl->getObjCRuntimeNameAsString();
982 SuperClass.USR = API.recordUSR(SuperClassDecl);
983 }
984
986 Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment, Declaration,
987 SubHeading, SuperClass, isInSystemHeader(Decl));
988
989 // Record all methods (selectors). This doesn't include automatically
990 // synthesized property methods.
991 getDerivedExtractAPIVisitor().recordObjCMethods(ObjCInterfaceRecord,
992 Decl->methods());
993 getDerivedExtractAPIVisitor().recordObjCProperties(ObjCInterfaceRecord,
994 Decl->properties());
995 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(ObjCInterfaceRecord,
996 Decl->ivars());
997 getDerivedExtractAPIVisitor().recordObjCProtocols(ObjCInterfaceRecord,
998 Decl->protocols());
999
1000 return true;
1001}
1002
1003template <typename Derived>
1005 const ObjCProtocolDecl *Decl) {
1006 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
1007 return true;
1008
1009 // Collect symbol information.
1010 StringRef Name = Decl->getName();
1011 StringRef USR = API.recordUSR(Decl);
1012 PresumedLoc Loc =
1013 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1014 DocComment Comment;
1015 if (auto *RawComment =
1016 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1017 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1018 Context.getDiagnostics());
1019
1020 // Build declaration fragments and sub-heading for the protocol.
1023 DeclarationFragments SubHeading =
1025
1027 API.addObjCProtocol(Name, USR, Loc, AvailabilitySet(Decl), Comment,
1028 Declaration, SubHeading, isInSystemHeader(Decl));
1029
1030 getDerivedExtractAPIVisitor().recordObjCMethods(ObjCProtocolRecord,
1031 Decl->methods());
1032 getDerivedExtractAPIVisitor().recordObjCProperties(ObjCProtocolRecord,
1033 Decl->properties());
1034 getDerivedExtractAPIVisitor().recordObjCProtocols(ObjCProtocolRecord,
1035 Decl->protocols());
1036
1037 return true;
1038}
1039
1040template <typename Derived>
1042 const TypedefNameDecl *Decl) {
1043 // Skip ObjC Type Parameter for now.
1044 if (isa<ObjCTypeParamDecl>(Decl))
1045 return true;
1046
1048 return true;
1049
1050 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
1051 return true;
1052
1053 // Add the notion of typedef for tag type (struct or enum) of the same name.
1054 if (const ElaboratedType *ET =
1055 dyn_cast<ElaboratedType>(Decl->getUnderlyingType())) {
1056 if (const TagType *TagTy = dyn_cast<TagType>(ET->desugar())) {
1057 if (Decl->getName() == TagTy->getDecl()->getName()) {
1058 if (TagTy->getDecl()->isStruct()) {
1059 modifyRecords(API.getStructs(), Decl->getName());
1060 }
1061 if (TagTy->getDecl()->isEnum()) {
1062 modifyRecords(API.getEnums(), Decl->getName());
1063 }
1064 }
1065 }
1066 }
1067
1068 PresumedLoc Loc =
1069 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1070 StringRef Name = Decl->getName();
1071 StringRef USR = API.recordUSR(Decl);
1072 DocComment Comment;
1073 if (auto *RawComment =
1074 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1075 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1076 Context.getDiagnostics());
1077
1078 QualType Type = Decl->getUnderlyingType();
1079 SymbolReference SymRef =
1081 API);
1082
1083 API.addTypedef(Name, USR, Loc, AvailabilitySet(Decl), Comment,
1086 isInSystemHeader(Decl));
1087
1088 return true;
1089}
1090
1091template <typename Derived>
1093 const ObjCCategoryDecl *Decl) {
1094 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
1095 return true;
1096
1097 StringRef Name = Decl->getName();
1098 StringRef USR = API.recordUSR(Decl);
1099 PresumedLoc Loc =
1100 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1101 DocComment Comment;
1102 if (auto *RawComment =
1103 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1104 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1105 Context.getDiagnostics());
1106 // Build declaration fragments and sub-heading for the category.
1109 DeclarationFragments SubHeading =
1111
1112 const ObjCInterfaceDecl *InterfaceDecl = Decl->getClassInterface();
1113 SymbolReference Interface(InterfaceDecl->getName(),
1114 API.recordUSR(InterfaceDecl));
1115
1116 bool IsFromExternalModule = true;
1117 for (const auto &Interface : API.getObjCInterfaces()) {
1118 if (InterfaceDecl->getName() == Interface.second.get()->Name) {
1119 IsFromExternalModule = false;
1120 break;
1121 }
1122 }
1123
1125 Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration, SubHeading,
1126 Interface, isInSystemHeader(Decl), IsFromExternalModule);
1127
1128 getDerivedExtractAPIVisitor().recordObjCMethods(ObjCCategoryRecord,
1129 Decl->methods());
1130 getDerivedExtractAPIVisitor().recordObjCProperties(ObjCCategoryRecord,
1131 Decl->properties());
1132 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(ObjCCategoryRecord,
1133 Decl->ivars());
1134 getDerivedExtractAPIVisitor().recordObjCProtocols(ObjCCategoryRecord,
1135 Decl->protocols());
1136
1137 return true;
1138}
1139
1140/// Collect API information for the enum constants and associate with the
1141/// parent enum.
1142template <typename Derived>
1145 for (const auto *Constant : Constants) {
1146 // Collect symbol information.
1147 StringRef Name = Constant->getName();
1148 StringRef USR = API.recordUSR(Constant);
1149 PresumedLoc Loc =
1150 Context.getSourceManager().getPresumedLoc(Constant->getLocation());
1151 DocComment Comment;
1152 if (auto *RawComment =
1153 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Constant))
1154 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1155 Context.getDiagnostics());
1156
1157 // Build declaration fragments and sub-heading for the enum constant.
1160 DeclarationFragments SubHeading =
1162
1163 API.addEnumConstant(EnumRecord, Name, USR, Loc, AvailabilitySet(Constant),
1164 Comment, Declaration, SubHeading,
1165 isInSystemHeader(Constant));
1166 }
1167}
1168
1169/// Collect API information for the struct fields and associate with the
1170/// parent struct.
1171template <typename Derived>
1174 for (const auto *Field : Fields) {
1175 // Collect symbol information.
1176 StringRef Name = Field->getName();
1177 StringRef USR = API.recordUSR(Field);
1178 PresumedLoc Loc =
1179 Context.getSourceManager().getPresumedLoc(Field->getLocation());
1180 DocComment Comment;
1181 if (auto *RawComment =
1182 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Field))
1183 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1184 Context.getDiagnostics());
1185
1186 // Build declaration fragments and sub-heading for the struct field.
1189 DeclarationFragments SubHeading =
1191
1192 API.addStructField(StructRecord, Name, USR, Loc, AvailabilitySet(Field),
1193 Comment, Declaration, SubHeading,
1194 isInSystemHeader(Field));
1195 }
1196}
1197
1198template <typename Derived>
1200 if (Decl->getDeclContext()->getDeclKind() == Decl::Record)
1201 return true;
1202 if (isa<ObjCIvarDecl>(Decl))
1203 return true;
1204 // Collect symbol information.
1205 StringRef Name = Decl->getName();
1206 StringRef USR = API.recordUSR(Decl);
1207 PresumedLoc Loc =
1208 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1209 DocComment Comment;
1210 if (auto *RawComment =
1211 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1212 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1213 Context.getDiagnostics());
1214
1215 // Build declaration fragments and sub-heading for the struct field.
1218 DeclarationFragments SubHeading =
1221
1222 SmallString<128> ParentUSR;
1223 index::generateUSRForDecl(dyn_cast<CXXRecordDecl>(Decl->getDeclContext()),
1224 ParentUSR);
1225 API.addCXXField(API.findRecordForUSR(ParentUSR), Name, USR, Loc,
1226 AvailabilitySet(Decl), Comment, Declaration, SubHeading,
1227 Access, isInSystemHeader(Decl));
1228 return true;
1229}
1230
1231template <typename Derived>
1233 const CXXConversionDecl *Decl) {
1234 StringRef Name = API.copyString(Decl->getNameAsString());
1235 StringRef USR = API.recordUSR(Decl);
1236 PresumedLoc Loc =
1237 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1238 DocComment Comment;
1239 if (auto *RawComment =
1240 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1241 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1242 Context.getDiagnostics());
1243
1244 // Build declaration fragments, sub-heading, and signature for the method.
1247 DeclarationFragments SubHeading =
1249 FunctionSignature Signature =
1252
1253 SmallString<128> ParentUSR;
1254 index::generateUSRForDecl(dyn_cast<CXXRecordDecl>(Decl->getDeclContext()),
1255 ParentUSR);
1256 if (Decl->isStatic())
1257 API.addCXXStaticMethod(API.findRecordForUSR(ParentUSR), Name, USR, Loc,
1258 AvailabilitySet(Decl), Comment, Declaration,
1259 SubHeading, Signature, Access,
1260 isInSystemHeader(Decl));
1261 else
1262 API.addCXXInstanceMethod(API.findRecordForUSR(ParentUSR), Name, USR, Loc,
1263 AvailabilitySet(Decl), Comment, Declaration,
1264 SubHeading, Signature, Access,
1265 isInSystemHeader(Decl));
1266 return true;
1267}
1268
1269/// Collect API information for the Objective-C methods and associate with the
1270/// parent container.
1271template <typename Derived>
1273 ObjCContainerRecord *Container,
1274 const ObjCContainerDecl::method_range Methods) {
1275 for (const auto *Method : Methods) {
1276 // Don't record selectors for properties.
1277 if (Method->isPropertyAccessor())
1278 continue;
1279
1280 StringRef Name = API.copyString(Method->getSelector().getAsString());
1281 StringRef USR = API.recordUSR(Method);
1282 PresumedLoc Loc =
1283 Context.getSourceManager().getPresumedLoc(Method->getLocation());
1284 DocComment Comment;
1285 if (auto *RawComment =
1286 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Method))
1287 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1288 Context.getDiagnostics());
1289
1290 // Build declaration fragments, sub-heading, and signature for the method.
1293 DeclarationFragments SubHeading =
1295 FunctionSignature Signature =
1297
1298 API.addObjCMethod(Container, Name, USR, Loc, AvailabilitySet(Method),
1299 Comment, Declaration, SubHeading, Signature,
1300 Method->isInstanceMethod(), isInSystemHeader(Method));
1301 }
1302}
1303
1304template <typename Derived>
1306 ObjCContainerRecord *Container,
1307 const ObjCContainerDecl::prop_range Properties) {
1308 for (const auto *Property : Properties) {
1309 StringRef Name = Property->getName();
1310 StringRef USR = API.recordUSR(Property);
1311 PresumedLoc Loc =
1312 Context.getSourceManager().getPresumedLoc(Property->getLocation());
1313 DocComment Comment;
1314 if (auto *RawComment =
1315 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Property))
1316 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1317 Context.getDiagnostics());
1318
1319 // Build declaration fragments and sub-heading for the property.
1322 DeclarationFragments SubHeading =
1324
1325 StringRef GetterName =
1326 API.copyString(Property->getGetterName().getAsString());
1327 StringRef SetterName =
1328 API.copyString(Property->getSetterName().getAsString());
1329
1330 // Get the attributes for property.
1331 unsigned Attributes = ObjCPropertyRecord::NoAttr;
1332 if (Property->getPropertyAttributes() &
1334 Attributes |= ObjCPropertyRecord::ReadOnly;
1335
1336 API.addObjCProperty(
1337 Container, Name, USR, Loc, AvailabilitySet(Property), Comment,
1338 Declaration, SubHeading,
1339 static_cast<ObjCPropertyRecord::AttributeKind>(Attributes), GetterName,
1340 SetterName, Property->isOptional(),
1341 !(Property->getPropertyAttributes() &
1343 isInSystemHeader(Property));
1344 }
1345}
1346
1347template <typename Derived>
1349 ObjCContainerRecord *Container,
1350 const llvm::iterator_range<
1352 Ivars) {
1353 for (const auto *Ivar : Ivars) {
1354 StringRef Name = Ivar->getName();
1355 StringRef USR = API.recordUSR(Ivar);
1356 PresumedLoc Loc =
1357 Context.getSourceManager().getPresumedLoc(Ivar->getLocation());
1358 DocComment Comment;
1359 if (auto *RawComment =
1360 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Ivar))
1361 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1362 Context.getDiagnostics());
1363
1364 // Build declaration fragments and sub-heading for the instance variable.
1367 DeclarationFragments SubHeading =
1369
1371 Ivar->getCanonicalAccessControl();
1372
1373 API.addObjCInstanceVariable(Container, Name, USR, Loc,
1374 AvailabilitySet(Ivar), Comment, Declaration,
1375 SubHeading, Access, isInSystemHeader(Ivar));
1376 }
1377}
1378
1379template <typename Derived>
1381 ObjCContainerRecord *Container,
1383 for (const auto *Protocol : Protocols)
1384 Container->Protocols.emplace_back(Protocol->getName(),
1385 API.recordUSR(Protocol));
1386}
1387
1388} // namespace impl
1389
1390/// The RecursiveASTVisitor to traverse symbol declarations and collect API
1391/// information.
1392template <typename Derived = void>
1394 : public impl::ExtractAPIVisitorBase<std::conditional_t<
1395 std::is_same_v<Derived, void>, ExtractAPIVisitor<>, Derived>> {
1396 using Base = impl::ExtractAPIVisitorBase<std::conditional_t<
1397 std::is_same_v<Derived, void>, ExtractAPIVisitor<>, Derived>>;
1398
1399public:
1401
1402 bool shouldDeclBeIncluded(const Decl *D) const { return true; }
1403 const RawComment *fetchRawCommentForDecl(const Decl *D) const {
1404 return this->Context.getRawCommentForDeclNoCache(D);
1405 }
1406};
1407
1408} // namespace extractapi
1409} // namespace clang
1410
1411#endif // LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
This file defines the APIRecord-based structs and the APISet class.
Defines the clang::ASTContext interface.
NodeId Parent
Definition: ASTDiff.cpp:191
StringRef P
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
This file defines the Declaration Fragments related classes.
Defines an enumeration for C++ overloaded operators.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
This file defines the UnderlyingTypeResolver which is a helper type for resolving the undelrying type...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
SourceManager & getSourceManager()
Definition: ASTContext.h:691
TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var)
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2491
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2818
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2755
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2035
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
Represents a class template specialization, which refers to a class template with a given set of temp...
Declaration of a C++20 concept.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2226
bool isRecord() const
Definition: DeclBase.h:2030
Decl::Kind getDeclKind() const
Definition: DeclBase.h:1944
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:429
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:576
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
Definition: DeclBase.cpp:263
SourceLocation getLocation() const
Definition: DeclBase.h:432
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
Definition: DeclBase.h:917
DeclContext * getDeclContext()
Definition: DeclBase.h:441
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5757
Represents an enum.
Definition: Decl.h:3758
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition: Decl.h:3889
Represents a member of a struct/union/class.
Definition: Decl.h:2962
Represents a function declaration or definition.
Definition: Decl.h:1919
@ TK_MemberSpecialization
Definition: Decl.h:1931
@ TK_DependentNonTemplate
Definition: Decl.h:1940
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1935
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1938
Declaration of a template function.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274
Represent a C++ namespace.
Definition: Decl.h:544
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2312
llvm::iterator_range< specific_decl_iterator< ObjCMethodDecl > > method_range
Definition: DeclObjC.h:1007
llvm::iterator_range< specific_decl_iterator< ObjCPropertyDecl > > prop_range
Definition: DeclObjC.h:958
Represents an ObjC class declaration.
Definition: DeclObjC.h:1147
llvm::iterator_range< protocol_iterator > protocol_range
Definition: DeclObjC.h:1345
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2069
Represents an unpacked "presumed" location which can be presented to the user.
A (possibly-)qualified type.
Definition: Type.h:736
std::vector< CommentLine > getFormattedLines(const SourceManager &SourceMgr, DiagnosticsEngine &Diags) const
Returns sanitized comment text as separated lines with locations in source, suitable for further proc...
Represents a struct/union/class.
Definition: Decl.h:4036
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
Definition: Decl.h:4261
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3477
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:410
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5166
The base class of the type hierarchy.
Definition: Type.h:1597
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3429
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3327
Represents a variable declaration or definition.
Definition: Decl.h:915
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
APISet holds the set of API records collected from given inputs.
Definition: API.h:1190
NamespaceRecord * addNamespace(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeaderg)
Definition: API.cpp:48
ObjCMethodRecord * addObjCMethod(ObjCContainerRecord *Container, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsInstanceMethod, bool IsFromSystemHeader)
Create and add an Objective-C method record into the API set.
Definition: API.cpp:417
GlobalVariableTemplatePartialSpecializationRecord * addGlobalVariableTemplatePartialSpecialization(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, bool IsFromSystemHeader)
Definition: API.cpp:293
ObjCPropertyRecord * addObjCProperty(ObjCContainerRecord *Container, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, ObjCPropertyRecord::AttributeKind Attributes, StringRef GetterName, StringRef SetterName, bool IsOptional, bool IsInstanceProperty, bool IsFromSystemHeader)
Create and add an Objective-C property record into the API set.
Definition: API.cpp:439
CXXMethodTemplateRecord * addCXXMethodTemplate(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, Template Template, bool IsFromSystemHeader)
Definition: API.cpp:350
StaticFieldRecord * addStaticField(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference Context, AccessControl Access, bool IsFromSystemHeaderg)
Definition: API.cpp:177
StringRef copyString(StringRef String)
Copy String into the Allocator in this APISet.
Definition: API.cpp:529
TypedefRecord * addTypedef(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference UnderlyingType, bool IsFromSystemHeader)
Create a typedef record into the API set.
Definition: API.cpp:499
GlobalVariableRecord * addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeadin, bool IsFromSystemHeaderg)
Create and add a global variable record into the API set.
Definition: API.cpp:64
ClassTemplateRecord * addClassTemplate(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, AccessControl Access, bool IsFromSystemHeader)
Definition: API.cpp:234
ClassTemplateSpecializationRecord * addClassTemplateSpecialization(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader)
Definition: API.cpp:249
StructFieldRecord * addStructField(StructRecord *Struct, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader)
Create and add a struct field record into the API set.
Definition: API.cpp:149
const RecordMap< EnumRecord > & getEnums() const
Definition: API.h:1547
GlobalVariableTemplateSpecializationRecord * addGlobalVariableTemplateSpecialization(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader)
Definition: API.cpp:281
ObjCProtocolRecord * addObjCProtocol(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader)
Create and add an Objective-C protocol record into the API set.
Definition: API.cpp:477
ObjCInstanceVariableRecord * addObjCInstanceVariable(ObjCContainerRecord *Container, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, ObjCInstanceVariableRecord::AccessControl Access, bool IsFromSystemHeader)
Create and add an Objective-C instance variable record into the API set.
Definition: API.cpp:463
CXXMethodTemplateSpecializationRecord * addCXXMethodTemplateSpec(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader)
Definition: API.cpp:366
ObjCInterfaceRecord * addObjCInterface(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference SuperClass, bool IsFromSystemHeader)
Create and add an Objective-C interface record into the API set.
Definition: API.cpp:405
GlobalFunctionRecord * addGlobalFunction(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsFromSystemHeader)
Create and add a function record into the API set.
Definition: API.cpp:85
GlobalFunctionTemplateRecord * addGlobalFunctionTemplate(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, Template Template, bool IsFromSystemHeader)
Definition: API.cpp:97
CXXMethodRecord * addCXXInstanceMethod(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader)
Definition: API.cpp:316
GlobalVariableTemplateRecord * addGlobalVariableTemplate(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, bool IsFromSystemHeader)
Definition: API.cpp:73
CXXFieldTemplateRecord * addCXXFieldTemplate(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, Template Template, bool IsFromSystemHeader)
Definition: API.cpp:203
CXXMethodRecord * addCXXStaticMethod(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader)
Definition: API.cpp:333
CXXFieldRecord * addCXXField(APIRecord *CXXClass, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader)
Definition: API.cpp:190
GlobalFunctionTemplateSpecializationRecord * addGlobalFunctionTemplateSpecialization(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsFromSystemHeader)
Definition: API.cpp:110
ObjCCategoryRecord * addObjCCategory(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference Interface, bool IsFromSystemHeader, bool IsFromExternalModule)
Create and add an Objective-C category record into the API set.
Definition: API.cpp:383
CXXClassRecord * addCXXClass(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, APIRecord::RecordKind Kind, AccessControl Access, bool IsFromSystemHeader)
Definition: API.cpp:219
EnumConstantRecord * addEnumConstant(EnumRecord *Enum, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader)
Create and add an enum constant record into the API set.
Definition: API.cpp:122
ConceptRecord * addConcept(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, bool IsFromSystemHeader)
Definition: API.cpp:305
StringRef recordUSR(const Decl *D)
Generate and store the USR of declaration D.
Definition: API.cpp:516
const RecordMap< ObjCInterfaceRecord > & getObjCInterfaces() const
Definition: API.h:1583
StructRecord * addStruct(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader)
Create and add a struct record into the API set.
Definition: API.cpp:165
APIRecord * findRecordForUSR(StringRef USR) const
Finds the APIRecord for a given USR.
Definition: API.cpp:509
const RecordMap< StructRecord > & getStructs() const
Definition: API.h:1548
EnumRecord * addEnum(StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader)
Create and add an enum record into the API set.
Definition: API.cpp:138
ClassTemplatePartialSpecializationRecord * addClassTemplatePartialSpecialization(APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, AccessControl Access, bool IsFromSystemHeader)
Definition: API.cpp:265
A factory class to build DeclarationFragments for different kinds of Decl.
static DeclarationFragments getFragmentsForRedeclarableTemplate(const RedeclarableTemplateDecl *)
static DeclarationFragments getFragmentsForCXXClass(const CXXRecordDecl *)
static DeclarationFragments getFragmentsForEnumConstant(const EnumConstantDecl *)
Build DeclarationFragments for an enum constant declaration EnumConstantDecl.
static DeclarationFragments getFragmentsForObjCCategory(const ObjCCategoryDecl *)
Build DeclarationFragments for an Objective-C category declaration ObjCCategoryDecl.
static DeclarationFragments getFragmentsForTypedef(const TypedefNameDecl *Decl)
Build DeclarationFragments for a typedef TypedefNameDecl.
static DeclarationFragments getFragmentsForEnum(const EnumDecl *)
Build DeclarationFragments for an enum declaration EnumDecl.
static DeclarationFragments getFragmentsForConversionFunction(const CXXConversionDecl *)
static DeclarationFragments getFragmentsForClassTemplateSpecialization(const ClassTemplateSpecializationDecl *)
static DeclarationFragments getFragmentsForObjCProtocol(const ObjCProtocolDecl *)
Build DeclarationFragments for an Objective-C protocol declaration ObjCProtocolDecl.
static DeclarationFragments getFragmentsForConcept(const ConceptDecl *)
static DeclarationFragments getFragmentsForField(const FieldDecl *)
Build DeclarationFragments for a field declaration FieldDecl.
static DeclarationFragments getFragmentsForVar(const VarDecl *)
Build DeclarationFragments for a variable declaration VarDecl.
static DeclarationFragments getFragmentsForClassTemplatePartialSpecialization(const ClassTemplatePartialSpecializationDecl *)
static DeclarationFragments getFragmentsForObjCMethod(const ObjCMethodDecl *)
Build DeclarationFragments for an Objective-C method declaration ObjCMethodDecl.
static DeclarationFragments getFragmentsForFunction(const FunctionDecl *)
Build DeclarationFragments for a function declaration FunctionDecl.
static AccessControl getAccessControl(const Decl *Decl)
static DeclarationFragments getFragmentsForObjCProperty(const ObjCPropertyDecl *)
Build DeclarationFragments for an Objective-C property declaration ObjCPropertyDecl.
static DeclarationFragments getFragmentsForSpecialCXXMethod(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForCXXMethod(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForNamespace(const NamespaceDecl *Decl)
static DeclarationFragments getFragmentsForStruct(const RecordDecl *)
Build DeclarationFragments for a struct record declaration RecordDecl.
static DeclarationFragments getFragmentsForVarTemplatePartialSpecialization(const VarTemplatePartialSpecializationDecl *)
static DeclarationFragments getFragmentsForFunctionTemplate(const FunctionTemplateDecl *Decl)
static DeclarationFragments getFragmentsForVarTemplateSpecialization(const VarTemplateSpecializationDecl *)
static FunctionSignature getFunctionSignature(const FunctionT *Function)
Build FunctionSignature for a function-like declaration FunctionT like FunctionDecl,...
static DeclarationFragments getSubHeading(const NamedDecl *)
Build sub-heading fragments for a NamedDecl.
static DeclarationFragments getFragmentsForVarTemplate(const VarDecl *)
static DeclarationFragments getFragmentsForOverloadedOperator(const CXXMethodDecl *)
static DeclarationFragments getFragmentsForObjCInterface(const ObjCInterfaceDecl *)
Build DeclarationFragments for an Objective-C interface declaration ObjCInterfaceDecl.
DeclarationFragments is a vector of tagged important parts of a symbol's declaration.
The RecursiveASTVisitor to traverse symbol declarations and collect API information.
const RawComment * fetchRawCommentForDecl(const Decl *D) const
ExtractAPIVisitor(ASTContext &Context, APISet &API)
bool shouldDeclBeIncluded(const Decl *D) const
Store function signature information with DeclarationFragments of the return type and parameters.
ExtractAPIVisitorBase(ASTContext &Context, APISet &API)
bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *Decl)
bool WalkUpFromClassTemplatePartialSpecializationDecl(const ClassTemplatePartialSpecializationDecl *Decl)
bool VisitFunctionTemplateDecl(const FunctionTemplateDecl *Decl)
bool VisitFunctionDecl(const FunctionDecl *Decl)
bool VisitClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl *Decl)
bool VisitCXXMethodDecl(const CXXMethodDecl *Decl)
bool VisitVarTemplateDecl(const VarTemplateDecl *Decl)
bool WalkUpFromCXXMethodDecl(const CXXMethodDecl *Decl)
StringRef getTypedefName(const TagDecl *Decl)
void recordObjCInstanceVariables(ObjCContainerRecord *Container, const llvm::iterator_range< DeclContext::specific_decl_iterator< ObjCIvarDecl > > Ivars)
bool VisitCXXRecordDecl(const CXXRecordDecl *Decl)
void recordObjCMethods(ObjCContainerRecord *Container, const ObjCContainerDecl::method_range Methods)
Collect API information for the Objective-C methods and associate with the parent container.
void recordObjCProperties(ObjCContainerRecord *Container, const ObjCContainerDecl::prop_range Properties)
bool WalkUpFromNamespaceDecl(const NamespaceDecl *Decl)
bool WalkUpFromRecordDecl(const RecordDecl *Decl)
bool VisitCXXDestructorDecl(const CXXDestructorDecl *Decl)
bool VisitClassTemplatePartialSpecializationDecl(const ClassTemplatePartialSpecializationDecl *Decl)
bool WalkUpFromCXXRecordDecl(const CXXRecordDecl *Decl)
const RawComment * fetchRawCommentForDecl(const Decl *Decl) const
bool VisitVarTemplatePartialSpecializationDecl(const VarTemplatePartialSpecializationDecl *Decl)
bool VisitTypedefNameDecl(const TypedefNameDecl *Decl)
void recordStructFields(StructRecord *StructRecord, const RecordDecl::field_range Fields)
Collect API information for the struct fields and associate with the parent struct.
void recordEnumConstants(EnumRecord *EnumRecord, const EnumDecl::enumerator_range Constants)
Collect API information for the enum constants and associate with the parent enum.
bool VisitVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *Decl)
bool VisitObjCProtocolDecl(const ObjCProtocolDecl *Decl)
bool WalkUpFromVarTemplateDecl(const VarTemplateDecl *Decl)
bool shouldDeclBeIncluded(const Decl *Decl) const
bool VisitNamespaceDecl(const NamespaceDecl *Decl)
bool WalkUpFromFunctionTemplateDecl(const FunctionTemplateDecl *Decl)
bool VisitObjCCategoryDecl(const ObjCCategoryDecl *Decl)
bool WalkUpFromFunctionDecl(const FunctionDecl *Decl)
bool VisitCXXConstructorDecl(const CXXConstructorDecl *Decl)
void recordObjCProtocols(ObjCContainerRecord *Container, ObjCInterfaceDecl::protocol_range Protocols)
bool VisitCXXConversionDecl(const CXXConversionDecl *Decl)
bool VisitConceptDecl(const ConceptDecl *Decl)
bool WalkUpFromVarTemplatePartialSpecializationDecl(const VarTemplatePartialSpecializationDecl *Decl)
bool WalkUpFromVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *Decl)
bool WalkUpFromClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl *Decl)
static void modifyRecords(const T &Records, const StringRef &Name)
std::vector< RawComment::CommentLine > DocComment
DocComment is a vector of RawComment::CommentLine.
Definition: API.h:150
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:23
@ Property
The type of a property.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
Definition: Specifiers.h:182
@ AS_public
Definition: Specifiers.h:115
The base representation of an API record. Holds common symbol information.
Definition: API.h:156
RecordKind
Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
Definition: API.h:158
SmallVector< SymbolReference > Bases
Definition: API.h:921
This holds information associated with enums.
Definition: API.h:461
This holds information associated with Objective-C categories.
Definition: API.h:1007
The base representation of an Objective-C container record.
Definition: API.h:899
This holds information associated with Objective-C interfaces/classes.
Definition: API.h:1032
AttributeKind
The attributes associated with an Objective-C property.
Definition: API.h:702
This holds information associated with Objective-C protocols.
Definition: API.h:1057
This holds information associated with structs.
Definition: API.h:499
This represents a reference to another symbol that might come from external sources.
Definition: API.h:858
SymbolReference getSymbolReferenceForType(QualType Type, APISet &API) const
Get a SymbolReference for the given type.