clang 19.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
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclCXX.h"
20#include "clang/AST/DeclObjC.h"
24#include "clang/Basic/Module.h"
31#include "llvm/ADT/SmallString.h"
32#include "llvm/ADT/StringRef.h"
33#include "llvm/Support/Casting.h"
34#include <type_traits>
35
36namespace clang {
37namespace extractapi {
38namespace impl {
39
40template <typename Derived>
42protected:
44 : Context(Context), API(API) {}
45
46public:
47 const APISet &getAPI() const { return API; }
48
50
52
54
56
58
60
62
65
68
70
73
76
78
80
82
84
86
88
90
92
94
96
98
101
104
106
107 bool
109
112
114
116
118
120
122
123 bool shouldDeclBeIncluded(const Decl *Decl) const;
124
126
127protected:
128 /// Collect API information for the enum constants and associate with the
129 /// parent enum.
131 const EnumDecl::enumerator_range Constants);
132
133 /// Collect API information for the Objective-C methods and associate with the
134 /// parent container.
136 const ObjCContainerDecl::method_range Methods);
137
139 const ObjCContainerDecl::prop_range Properties);
140
142 ObjCContainerRecord *Container,
143 const llvm::iterator_range<
145 Ivars);
146
149
152
153 StringRef getTypedefName(const TagDecl *Decl) {
154 if (const auto *TypedefDecl = Decl->getTypedefNameForAnonDecl())
155 return TypedefDecl->getName();
156
157 return {};
158 }
159
160 bool isInSystemHeader(const Decl *D) {
162 }
163
164private:
165 Derived &getDerivedExtractAPIVisitor() {
166 return *static_cast<Derived *>(this);
167 }
168
169protected:
171 // FIXME: store AccessSpecifier given by inheritance
173 for (const auto &BaseSpecifier : Decl->bases()) {
174 // skip classes not inherited as public
175 if (BaseSpecifier.getAccessSpecifier() != AccessSpecifier::AS_public)
176 continue;
177 SymbolReference BaseClass;
178 if (BaseSpecifier.getType().getTypePtr()->isTemplateTypeParmType()) {
179 BaseClass.Name = API.copyString(BaseSpecifier.getType().getAsString());
180 if (auto *TTPTD = BaseSpecifier.getType()
181 ->getAs<TemplateTypeParmType>()
182 ->getDecl()) {
184 index::generateUSRForDecl(TTPTD, USR);
185 BaseClass.USR = API.copyString(USR);
186 BaseClass.Source = API.copyString(getOwningModuleName(*TTPTD));
187 }
188 } else {
190 *BaseSpecifier.getType().getTypePtr()->getAsCXXRecordDecl());
191 }
192 Bases.emplace_back(BaseClass);
193 }
194 return Bases;
195 }
196
197 StringRef getOwningModuleName(const Decl &D) {
198 if (auto *OwningModule = D.getImportedOwningModule())
199 return OwningModule->Name;
200
201 return {};
202 }
203
205 const auto *Context = cast_if_present<Decl>(D.getDeclContext());
206
207 if (!Context || isa<TranslationUnitDecl>(Context))
208 return {};
209
211 }
212
216
218 if (Record)
219 return SymbolReference(Record);
220
221 StringRef Name;
222 if (auto *ND = dyn_cast<NamedDecl>(&D))
223 Name = ND->getName();
224
225 return API.createSymbolReference(Name, USR, getOwningModuleName(D));
226 }
227};
228
229template <typename Derived>
231 // skip function parameters.
232 if (isa<ParmVarDecl>(Decl))
233 return true;
234
235 // Skip non-global variables in records (struct/union/class) but not static
236 // members.
237 if (Decl->getDeclContext()->isRecord() && !Decl->isStaticDataMember())
238 return true;
239
240 // Skip local variables inside function or method.
242 return true;
243
244 // If this is a template but not specialization or instantiation, skip.
246 Decl->getTemplateSpecializationKind() == TSK_Undeclared)
247 return true;
248
249 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
250 return true;
251
252 // Collect symbol information.
253 StringRef Name = Decl->getName();
256 PresumedLoc Loc =
257 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
258 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
259 DocComment Comment;
260 if (auto *RawComment =
261 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
262 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
263 Context.getDiagnostics());
264
265 // Build declaration fragments and sub-heading for the variable.
268 DeclarationFragments SubHeading =
270 if (Decl->isStaticDataMember()) {
272 API.createRecord<StaticFieldRecord>(
273 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
275 SubHeading, Access, isInSystemHeader(Decl));
276 } else
277 // Add the global variable record to the API set.
278 API.createRecord<GlobalVariableRecord>(
279 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
281 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 that aren't processed here.
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();
323 PresumedLoc Loc =
324 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
325 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
326 DocComment Comment;
327 if (auto *RawComment =
328 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
329 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
330 Context.getDiagnostics());
331
332 // Build declaration fragments, sub-heading, and signature of the function.
333 DeclarationFragments SubHeading =
335 FunctionSignature Signature =
337 if (Decl->getTemplateSpecializationInfo())
339 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
343 SubHeading, Signature, isInSystemHeader(Decl));
344 else
345 // Add the function record to the API set.
346 API.createRecord<GlobalFunctionRecord>(
347 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
350 Signature, isInSystemHeader(Decl));
351 return true;
352}
353
354template <typename Derived>
356 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
357 return true;
358
359 SmallString<128> QualifiedNameBuffer;
360 // Collect symbol information.
361 StringRef Name = Decl->getName();
362 if (Name.empty())
363 Name = getTypedefName(Decl);
364 if (Name.empty()) {
365 llvm::raw_svector_ostream OS(QualifiedNameBuffer);
366 Decl->printQualifiedName(OS);
367 Name = QualifiedNameBuffer.str();
368 }
369
372 PresumedLoc Loc =
373 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
374 DocComment Comment;
375 if (auto *RawComment =
376 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
377 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
378 Context.getDiagnostics());
379
380 // Build declaration fragments and sub-heading for the enum.
383 DeclarationFragments SubHeading =
385 auto *ER = API.createRecord<EnumRecord>(
386 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
388 isInSystemHeader(Decl));
389
390 // Now collect information about the enumerators in this enum.
391 getDerivedExtractAPIVisitor().recordEnumConstants(ER, Decl->enumerators());
392
393 return true;
394}
395
396template <typename Derived>
398 const FunctionDecl *Decl) {
399 getDerivedExtractAPIVisitor().VisitFunctionDecl(Decl);
400 return true;
401}
402
403template <typename Derived>
405 const RecordDecl *Decl) {
406 getDerivedExtractAPIVisitor().VisitRecordDecl(Decl);
407 return true;
408}
409
410template <typename Derived>
412 const CXXRecordDecl *Decl) {
413 getDerivedExtractAPIVisitor().VisitCXXRecordDecl(Decl);
414 return true;
415}
416
417template <typename Derived>
419 const CXXMethodDecl *Decl) {
420 getDerivedExtractAPIVisitor().VisitCXXMethodDecl(Decl);
421 return true;
422}
423
424template <typename Derived>
427 getDerivedExtractAPIVisitor().VisitClassTemplateSpecializationDecl(Decl);
428 return true;
429}
430
431template <typename Derived>
435 getDerivedExtractAPIVisitor().VisitClassTemplatePartialSpecializationDecl(
436 Decl);
437 return true;
438}
439
440template <typename Derived>
442 const VarTemplateDecl *Decl) {
443 getDerivedExtractAPIVisitor().VisitVarTemplateDecl(Decl);
444 return true;
445}
446
447template <typename Derived>
450 getDerivedExtractAPIVisitor().VisitVarTemplateSpecializationDecl(Decl);
451 return true;
452}
453
454template <typename Derived>
458 getDerivedExtractAPIVisitor().VisitVarTemplatePartialSpecializationDecl(Decl);
459 return true;
460}
461
462template <typename Derived>
464 const FunctionTemplateDecl *Decl) {
465 getDerivedExtractAPIVisitor().VisitFunctionTemplateDecl(Decl);
466 return true;
467}
468
469template <typename Derived>
471 const NamespaceDecl *Decl) {
472 getDerivedExtractAPIVisitor().VisitNamespaceDecl(Decl);
473 return true;
474}
475
476template <typename Derived>
478 const NamespaceDecl *Decl) {
479 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
480 return true;
481 if (Decl->isAnonymousNamespace())
482 return true;
483 StringRef Name = Decl->getName();
486 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
487 PresumedLoc Loc =
488 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
489 DocComment Comment;
490 if (auto *RawComment =
491 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
492 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
493 Context.getDiagnostics());
494
495 // Build declaration fragments and sub-heading for the struct.
498 DeclarationFragments SubHeading =
500 API.createRecord<NamespaceRecord>(
501 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
503 SubHeading, isInSystemHeader(Decl));
504
505 return true;
506}
507
508template <typename Derived>
510 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
511 return true;
512
513 SmallString<128> QualifiedNameBuffer;
514 // Collect symbol information.
515 StringRef Name = Decl->getName();
516 if (Name.empty())
517 Name = getTypedefName(Decl);
518 if (Name.empty()) {
519 llvm::raw_svector_ostream OS(QualifiedNameBuffer);
520 Decl->printQualifiedName(OS);
521 Name = QualifiedNameBuffer.str();
522 }
523
526 PresumedLoc Loc =
527 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
528 DocComment Comment;
529 if (auto *RawComment =
530 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
531 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
532 Context.getDiagnostics());
533
534 // Build declaration fragments and sub-heading for the struct.
537 DeclarationFragments SubHeading =
539
540 if (Decl->isUnion())
541 API.createRecord<UnionRecord>(
542 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
544 SubHeading, isInSystemHeader(Decl));
545 else
546 API.createRecord<StructRecord>(
547 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
549 SubHeading, isInSystemHeader(Decl));
550
551 return true;
552}
553
554template <typename Derived>
556 const CXXRecordDecl *Decl) {
557 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl) ||
558 Decl->isImplicit())
559 return true;
560
561 StringRef Name = Decl->getName();
564 PresumedLoc Loc =
565 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
566 DocComment Comment;
567 if (auto *RawComment =
568 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
569 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
570 Context.getDiagnostics());
573 DeclarationFragments SubHeading =
575
577 if (Decl->isUnion())
579 else if (Decl->isStruct())
581 else
584
586 if (Decl->getDescribedClassTemplate()) {
587 // Inject template fragments before class fragments.
588 Declaration.insert(
589 Declaration.begin(),
591 Decl->getDescribedClassTemplate()));
592 Record = API.createRecord<ClassTemplateRecord>(
593 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
595 SubHeading, Template(Decl->getDescribedClassTemplate()), Access,
596 isInSystemHeader(Decl));
597 } else
598 Record = API.createRecord<CXXClassRecord>(
599 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
601 SubHeading, Kind, Access, isInSystemHeader(Decl));
602
603 Record->Bases = getBases(Decl);
604
605 return true;
606}
607
608template <typename Derived>
610 const CXXMethodDecl *Decl) {
611 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl) ||
612 Decl->isImplicit())
613 return true;
614
615 if (isa<CXXConversionDecl>(Decl))
616 return true;
617 if (isa<CXXConstructorDecl>(Decl) || isa<CXXDestructorDecl>(Decl))
618 return true;
619
622 PresumedLoc Loc =
623 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
624 DocComment Comment;
625 if (auto *RawComment =
626 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
627 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
628 Context.getDiagnostics());
629 DeclarationFragments SubHeading =
633
635 Decl->getDescribedFunctionTemplate()) {
636 API.createRecord<CXXMethodTemplateRecord>(
637 USR, Decl->getName(), createHierarchyInformationForDecl(*Decl), Loc,
643 Template(TemplateDecl), isInSystemHeader(Decl));
644 } else if (Decl->getTemplateSpecializationInfo())
646 USR, Decl->getName(), createHierarchyInformationForDecl(*Decl), Loc,
650 SubHeading, Signature, Access, isInSystemHeader(Decl));
651 else if (Decl->isOverloadedOperator())
652 API.createRecord<CXXInstanceMethodRecord>(
653 USR, Decl->getNameAsString(), createHierarchyInformationForDecl(*Decl),
656 SubHeading, Signature, Access, isInSystemHeader(Decl));
657 else if (Decl->isStatic())
658 API.createRecord<CXXStaticMethodRecord>(
659 USR, Decl->getName(), createHierarchyInformationForDecl(*Decl), Loc,
662 Signature, Access, isInSystemHeader(Decl));
663 else
664 API.createRecord<CXXInstanceMethodRecord>(
665 USR, Decl->getName(), createHierarchyInformationForDecl(*Decl), Loc,
668 Signature, Access, isInSystemHeader(Decl));
669
670 return true;
671}
672
673template <typename Derived>
675 const CXXConstructorDecl *Decl) {
676 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl) ||
677 Decl->isImplicit())
678 return true;
679
680 auto Name = Decl->getNameAsString();
683 PresumedLoc Loc =
684 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
685 DocComment Comment;
686 if (auto *RawComment =
687 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
688 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
689 Context.getDiagnostics());
690
691 // Build declaration fragments, sub-heading, and signature for the method.
694 DeclarationFragments SubHeading =
696 FunctionSignature Signature =
699
700 API.createRecord<CXXConstructorRecord>(
701 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
703 Signature, Access, isInSystemHeader(Decl));
704 return true;
705}
706
707template <typename Derived>
709 const CXXDestructorDecl *Decl) {
710 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl) ||
711 Decl->isImplicit())
712 return true;
713
714 auto Name = Decl->getNameAsString();
717 PresumedLoc Loc =
718 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
719 DocComment Comment;
720 if (auto *RawComment =
721 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
722 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
723 Context.getDiagnostics());
724
725 // Build declaration fragments, sub-heading, and signature for the method.
728 DeclarationFragments SubHeading =
730 FunctionSignature Signature =
733 API.createRecord<CXXDestructorRecord>(
734 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
736 Signature, Access, isInSystemHeader(Decl));
737 return true;
738}
739
740template <typename Derived>
742 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
743 return true;
744
745 StringRef Name = Decl->getName();
748 PresumedLoc Loc =
749 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
750 DocComment Comment;
751 if (auto *RawComment =
752 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
753 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
754 Context.getDiagnostics());
757 DeclarationFragments SubHeading =
759 API.createRecord<ConceptRecord>(
760 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
762 Template(Decl), isInSystemHeader(Decl));
763 return true;
764}
765
766template <typename Derived>
769 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
770 return true;
771
772 StringRef Name = Decl->getName();
775 PresumedLoc Loc =
776 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
777 DocComment Comment;
778 if (auto *RawComment =
779 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
780 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
781 Context.getDiagnostics());
784 Decl);
785 DeclarationFragments SubHeading =
787
788 auto *CTSR = API.createRecord<ClassTemplateSpecializationRecord>(
789 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
792 isInSystemHeader(Decl));
793
794 CTSR->Bases = getBases(Decl);
795
796 return true;
797}
798
799template <typename Derived>
803 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
804 return true;
805
806 StringRef Name = Decl->getName();
809 PresumedLoc Loc =
810 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
811 DocComment Comment;
812 if (auto *RawComment =
813 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
814 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
815 Context.getDiagnostics());
818 DeclarationFragments SubHeading =
820 auto *CTPSR = API.createRecord<ClassTemplatePartialSpecializationRecord>(
821 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
824 isInSystemHeader(Decl));
825
826 CTPSR->Bases = getBases(Decl);
827
828 return true;
829}
830
831template <typename Derived>
833 const VarTemplateDecl *Decl) {
834 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
835 return true;
836
837 // Collect symbol information.
838 StringRef Name = Decl->getName();
841 PresumedLoc Loc =
842 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
843 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
844 DocComment Comment;
845 if (auto *RawComment =
846 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
847 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
848 Context.getDiagnostics());
849
850 // Build declaration fragments and sub-heading for the variable.
854 Decl))
856 Decl->getTemplatedDecl()));
857 // Inject template fragments before var fragments.
858 DeclarationFragments SubHeading =
860
861 if (Decl->getDeclContext()->getDeclKind() == Decl::CXXRecord)
862 API.createRecord<CXXFieldTemplateRecord>(
863 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
866 Template(Decl), isInSystemHeader(Decl));
867 else
868 API.createRecord<GlobalVariableTemplateRecord>(
869 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
871 SubHeading, Template(Decl), isInSystemHeader(Decl));
872 return true;
873}
874
875template <typename Derived>
878 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
879 return true;
880
881 // Collect symbol information.
882 StringRef Name = Decl->getName();
885 PresumedLoc Loc =
886 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
887 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
888 DocComment Comment;
889 if (auto *RawComment =
890 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
891 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
892 Context.getDiagnostics());
893
894 // Build declaration fragments and sub-heading for the variable.
897 Decl);
898 DeclarationFragments SubHeading =
901 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
903 SubHeading, isInSystemHeader(Decl));
904 return true;
905}
906
907template <typename Derived>
910 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
911 return true;
912
913 // Collect symbol information.
914 StringRef Name = Decl->getName();
917 PresumedLoc Loc =
918 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
919 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
920 DocComment Comment;
921 if (auto *RawComment =
922 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
923 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
924 Context.getDiagnostics());
925
926 // Build declaration fragments and sub-heading for the variable.
929 DeclarationFragments SubHeading =
932 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
934 SubHeading, Template(Decl), isInSystemHeader(Decl));
935 return true;
936}
937
938template <typename Derived>
940 const FunctionTemplateDecl *Decl) {
941 if (isa<CXXMethodDecl>(Decl->getTemplatedDecl()))
942 return true;
943 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
944 return true;
945
946 // Collect symbol information.
947 StringRef Name = Decl->getName();
950 PresumedLoc Loc =
951 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
952 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
953 DocComment Comment;
954 if (auto *RawComment =
955 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
956 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
957 Context.getDiagnostics());
958
959 DeclarationFragments SubHeading =
961 FunctionSignature Signature =
963 Decl->getTemplatedDecl());
964 API.createRecord<GlobalFunctionTemplateRecord>(
965 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
968 SubHeading, Signature, Template(Decl), isInSystemHeader(Decl));
969
970 return true;
971}
972
973template <typename Derived>
975 const ObjCInterfaceDecl *Decl) {
976 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
977 return true;
978
979 // Collect symbol information.
980 StringRef Name = Decl->getName();
983 PresumedLoc Loc =
984 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
985 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
986 DocComment Comment;
987 if (auto *RawComment =
988 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
989 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
990 Context.getDiagnostics());
991
992 // Build declaration fragments and sub-heading for the interface.
995 DeclarationFragments SubHeading =
997
998 // Collect super class information.
999 SymbolReference SuperClass;
1000 if (const auto *SuperClassDecl = Decl->getSuperClass())
1001 SuperClass = createSymbolReferenceForDecl(*SuperClassDecl);
1002
1003 auto *InterfaceRecord = API.createRecord<ObjCInterfaceRecord>(
1004 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1006 SubHeading, SuperClass, isInSystemHeader(Decl));
1007
1008 // Record all methods (selectors). This doesn't include automatically
1009 // synthesized property methods.
1010 getDerivedExtractAPIVisitor().recordObjCMethods(InterfaceRecord,
1011 Decl->methods());
1012 getDerivedExtractAPIVisitor().recordObjCProperties(InterfaceRecord,
1013 Decl->properties());
1014 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(InterfaceRecord,
1015 Decl->ivars());
1016 getDerivedExtractAPIVisitor().recordObjCProtocols(InterfaceRecord,
1017 Decl->protocols());
1018
1019 return true;
1020}
1021
1022template <typename Derived>
1024 const ObjCProtocolDecl *Decl) {
1025 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
1026 return true;
1027
1028 // Collect symbol information.
1029 StringRef Name = Decl->getName();
1030 SmallString<128> USR;
1032 PresumedLoc Loc =
1033 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1034 DocComment Comment;
1035 if (auto *RawComment =
1036 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1037 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1038 Context.getDiagnostics());
1039
1040 // Build declaration fragments and sub-heading for the protocol.
1043 DeclarationFragments SubHeading =
1045
1046 auto *ProtoRecord = API.createRecord<ObjCProtocolRecord>(
1047 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1048 AvailabilityInfo::createFromDecl(Decl), Comment, Declaration, SubHeading,
1049 isInSystemHeader(Decl));
1050
1051 getDerivedExtractAPIVisitor().recordObjCMethods(ProtoRecord, Decl->methods());
1052 getDerivedExtractAPIVisitor().recordObjCProperties(ProtoRecord,
1053 Decl->properties());
1054 getDerivedExtractAPIVisitor().recordObjCProtocols(ProtoRecord,
1055 Decl->protocols());
1056
1057 return true;
1058}
1059
1060template <typename Derived>
1062 const TypedefNameDecl *Decl) {
1063 // Skip ObjC Type Parameter for now.
1064 if (isa<ObjCTypeParamDecl>(Decl))
1065 return true;
1066
1068 return true;
1069
1070 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
1071 return true;
1072
1073 StringRef Name = Decl->getName();
1074
1075 // If the underlying type was defined as part of the typedef modify it's
1076 // fragments directly and pretend the typedef doesn't exist.
1077 if (auto *TagDecl = Decl->getUnderlyingType()->getAsTagDecl()) {
1078 if (TagDecl->getName() == Decl->getName() &&
1080 SmallString<128> TagUSR;
1082 if (auto *Record = API.findRecordForUSR(TagUSR)) {
1083 DeclarationFragments LeadingFragments;
1084 LeadingFragments.append("typedef",
1086 nullptr);
1087 LeadingFragments.appendSpace();
1088 Record->Declaration.removeTrailingSemicolon()
1089 .insert(Record->Declaration.begin(), std::move(LeadingFragments))
1092 .appendSemicolon();
1093
1094 return true;
1095 }
1096 }
1097 }
1098
1099 PresumedLoc Loc =
1100 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1101 SmallString<128> USR;
1103 DocComment Comment;
1104 if (auto *RawComment =
1105 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1106 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1107 Context.getDiagnostics());
1108
1109 QualType Type = Decl->getUnderlyingType();
1110 SymbolReference SymRef =
1112 API);
1113
1114 API.createRecord<TypedefRecord>(
1115 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1119 isInSystemHeader(Decl));
1120
1121 return true;
1122}
1123
1124template <typename Derived>
1126 const ObjCCategoryDecl *Decl) {
1127 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
1128 return true;
1129
1130 StringRef Name = Decl->getName();
1131 SmallString<128> USR;
1133 PresumedLoc Loc =
1134 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1135 DocComment Comment;
1136 if (auto *RawComment =
1137 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1138 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1139 Context.getDiagnostics());
1140 // Build declaration fragments and sub-heading for the category.
1143 DeclarationFragments SubHeading =
1145
1146 const ObjCInterfaceDecl *InterfaceDecl = Decl->getClassInterface();
1147 SymbolReference Interface = createSymbolReferenceForDecl(*InterfaceDecl);
1148
1149 auto *CategoryRecord = API.createRecord<ObjCCategoryRecord>(
1150 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1151 AvailabilityInfo::createFromDecl(Decl), Comment, Declaration, SubHeading,
1152 Interface, isInSystemHeader(Decl));
1153
1154 getDerivedExtractAPIVisitor().recordObjCMethods(CategoryRecord,
1155 Decl->methods());
1156 getDerivedExtractAPIVisitor().recordObjCProperties(CategoryRecord,
1157 Decl->properties());
1158 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(CategoryRecord,
1159 Decl->ivars());
1160 getDerivedExtractAPIVisitor().recordObjCProtocols(CategoryRecord,
1161 Decl->protocols());
1162
1163 return true;
1164}
1165
1166/// Collect API information for the enum constants and associate with the
1167/// parent enum.
1168template <typename Derived>
1171 for (const auto *Constant : Constants) {
1172 // Collect symbol information.
1173 StringRef Name = Constant->getName();
1174 SmallString<128> USR;
1175 index::generateUSRForDecl(Constant, USR);
1176 PresumedLoc Loc =
1177 Context.getSourceManager().getPresumedLoc(Constant->getLocation());
1178 DocComment Comment;
1179 if (auto *RawComment =
1180 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Constant))
1181 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1182 Context.getDiagnostics());
1183
1184 // Build declaration fragments and sub-heading for the enum constant.
1187 DeclarationFragments SubHeading =
1189
1190 API.createRecord<EnumConstantRecord>(
1191 USR, Name, createHierarchyInformationForDecl(*Constant), Loc,
1193 SubHeading, isInSystemHeader(Constant));
1194 }
1195}
1196
1197template <typename Derived>
1199 // ObjCIvars are handled separately
1200 if (isa<ObjCIvarDecl>(Decl) || isa<ObjCAtDefsFieldDecl>(Decl))
1201 return true;
1202
1203 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
1204 return true;
1205
1206 // Collect symbol information.
1207 StringRef Name = Decl->getName();
1208 SmallString<128> USR;
1210 PresumedLoc Loc =
1211 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1212 DocComment Comment;
1213 if (auto *RawComment =
1214 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1215 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1216 Context.getDiagnostics());
1217
1218 // Build declaration fragments and sub-heading for the struct field.
1221 DeclarationFragments SubHeading =
1223
1224 if (isa<CXXRecordDecl>(Decl->getDeclContext())) {
1226
1227 API.createRecord<CXXFieldRecord>(
1228 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1230 SubHeading, Access, isInSystemHeader(Decl));
1231 } else if (auto *RD = dyn_cast<RecordDecl>(Decl->getDeclContext())) {
1232 if (RD->isUnion())
1233 API.createRecord<UnionFieldRecord>(
1234 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1236 SubHeading, isInSystemHeader(Decl));
1237 else
1238 API.createRecord<StructFieldRecord>(
1239 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1241 SubHeading, isInSystemHeader(Decl));
1242 }
1243
1244 return true;
1245}
1246
1247template <typename Derived>
1249 const CXXConversionDecl *Decl) {
1250 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl) ||
1251 Decl->isImplicit())
1252 return true;
1253
1254 auto Name = Decl->getNameAsString();
1255 SmallString<128> USR;
1257 PresumedLoc Loc =
1258 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
1259 DocComment Comment;
1260 if (auto *RawComment =
1261 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
1262 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1263 Context.getDiagnostics());
1264
1265 // Build declaration fragments, sub-heading, and signature for the method.
1268 DeclarationFragments SubHeading =
1270 FunctionSignature Signature =
1273
1274 if (Decl->isStatic())
1275 API.createRecord<CXXStaticMethodRecord>(
1276 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1278 SubHeading, Signature, Access, isInSystemHeader(Decl));
1279 else
1280 API.createRecord<CXXInstanceMethodRecord>(
1281 USR, Name, createHierarchyInformationForDecl(*Decl), Loc,
1283 SubHeading, Signature, Access, isInSystemHeader(Decl));
1284
1285 return true;
1286}
1287
1288/// Collect API information for the Objective-C methods and associate with the
1289/// parent container.
1290template <typename Derived>
1292 ObjCContainerRecord *Container,
1293 const ObjCContainerDecl::method_range Methods) {
1294 for (const auto *Method : Methods) {
1295 // Don't record selectors for properties.
1296 if (Method->isPropertyAccessor())
1297 continue;
1298
1299 auto Name = Method->getSelector().getAsString();
1300 SmallString<128> USR;
1301 index::generateUSRForDecl(Method, USR);
1302 PresumedLoc Loc =
1303 Context.getSourceManager().getPresumedLoc(Method->getLocation());
1304 DocComment Comment;
1305 if (auto *RawComment =
1306 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Method))
1307 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1308 Context.getDiagnostics());
1309
1310 // Build declaration fragments, sub-heading, and signature for the method.
1313 DeclarationFragments SubHeading =
1315 FunctionSignature Signature =
1317
1318 if (Method->isInstanceMethod())
1319 API.createRecord<ObjCInstanceMethodRecord>(
1320 USR, Name, createHierarchyInformationForDecl(*Method), Loc,
1322 SubHeading, Signature, isInSystemHeader(Method));
1323 else
1324 API.createRecord<ObjCClassMethodRecord>(
1325 USR, Name, createHierarchyInformationForDecl(*Method), Loc,
1327 SubHeading, Signature, isInSystemHeader(Method));
1328 }
1329}
1330
1331template <typename Derived>
1333 ObjCContainerRecord *Container,
1334 const ObjCContainerDecl::prop_range Properties) {
1335 for (const auto *Property : Properties) {
1336 StringRef Name = Property->getName();
1337 SmallString<128> USR;
1339 PresumedLoc Loc =
1340 Context.getSourceManager().getPresumedLoc(Property->getLocation());
1341 DocComment Comment;
1342 if (auto *RawComment =
1343 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Property))
1344 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1345 Context.getDiagnostics());
1346
1347 // Build declaration fragments and sub-heading for the property.
1350 DeclarationFragments SubHeading =
1352
1353 auto GetterName = Property->getGetterName().getAsString();
1354 auto SetterName = Property->getSetterName().getAsString();
1355
1356 // Get the attributes for property.
1357 unsigned Attributes = ObjCPropertyRecord::NoAttr;
1358 if (Property->getPropertyAttributes() &
1360 Attributes |= ObjCPropertyRecord::ReadOnly;
1361
1362 if (Property->getPropertyAttributes() & ObjCPropertyAttribute::kind_class)
1363 API.createRecord<ObjCClassPropertyRecord>(
1364 USR, Name, createHierarchyInformationForDecl(*Property), Loc,
1366 SubHeading,
1367 static_cast<ObjCPropertyRecord::AttributeKind>(Attributes),
1368 GetterName, SetterName, Property->isOptional(),
1369 isInSystemHeader(Property));
1370 else
1371 API.createRecord<ObjCInstancePropertyRecord>(
1372 USR, Name, createHierarchyInformationForDecl(*Property), Loc,
1374 SubHeading,
1375 static_cast<ObjCPropertyRecord::AttributeKind>(Attributes),
1376 GetterName, SetterName, Property->isOptional(),
1377 isInSystemHeader(Property));
1378 }
1379}
1380
1381template <typename Derived>
1383 ObjCContainerRecord *Container,
1384 const llvm::iterator_range<
1386 Ivars) {
1387 for (const auto *Ivar : Ivars) {
1388 StringRef Name = Ivar->getName();
1389 SmallString<128> USR;
1390 index::generateUSRForDecl(Ivar, USR);
1391
1392 PresumedLoc Loc =
1393 Context.getSourceManager().getPresumedLoc(Ivar->getLocation());
1394 DocComment Comment;
1395 if (auto *RawComment =
1396 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Ivar))
1397 Comment = RawComment->getFormattedLines(Context.getSourceManager(),
1398 Context.getDiagnostics());
1399
1400 // Build declaration fragments and sub-heading for the instance variable.
1403 DeclarationFragments SubHeading =
1405
1406 API.createRecord<ObjCInstanceVariableRecord>(
1407 USR, Name, createHierarchyInformationForDecl(*Ivar), Loc,
1409 SubHeading, isInSystemHeader(Ivar));
1410 }
1411}
1412
1413template <typename Derived>
1415 ObjCContainerRecord *Container,
1417 for (const auto *Protocol : Protocols)
1418 Container->Protocols.emplace_back(createSymbolReferenceForDecl(*Protocol));
1419}
1420
1421} // namespace impl
1422
1423/// The RecursiveASTVisitor to traverse symbol declarations and collect API
1424/// information.
1425template <typename Derived = void>
1427 : public impl::ExtractAPIVisitorBase<std::conditional_t<
1428 std::is_same_v<Derived, void>, ExtractAPIVisitor<>, Derived>> {
1429 using Base = impl::ExtractAPIVisitorBase<std::conditional_t<
1430 std::is_same_v<Derived, void>, ExtractAPIVisitor<>, Derived>>;
1431
1432public:
1434
1435 bool shouldDeclBeIncluded(const Decl *D) const { return true; }
1436 const RawComment *fetchRawCommentForDecl(const Decl *D) const {
1437 return this->Context.getRawCommentForDeclNoCache(D);
1438 }
1439};
1440
1441} // namespace extractapi
1442} // namespace clang
1443
1444#endif // LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
This file defines the APIRecord-based structs and the APISet class.
Defines the clang::ASTContext interface.
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.
llvm::MachO::Record Record
Definition: MachO.h:30
Defines the clang::Module class, which describes a module in the source code.
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:705
TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var)
RawComment * getRawCommentForDeclNoCache(const Decl *D) const
Return the documentation comment attached to a given declaration, without looking into cache.
Definition: ASTContext.cpp:293
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2532
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2859
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2796
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2057
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
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:2341
bool isRecord() const
Definition: DeclBase.h:2145
Decl::Kind getDeclKind() const
Definition: DeclBase.h:2058
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:598
Module * getImportedOwningModule() const
Get the imported owning module, if this decl is from an imported (non-local) module.
Definition: DeclBase.h:802
SourceLocation getLocation() const
Definition: DeclBase.h:444
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
Definition: DeclBase.h:938
DeclContext * getDeclContext()
Definition: DeclBase.h:453
Represents an enum.
Definition: Decl.h:3868
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition: Decl.h:3999
Represents a member of a struct/union/class.
Definition: Decl.h:3058
Represents a function declaration or definition.
Definition: Decl.h:1971
@ TK_MemberSpecialization
Definition: Decl.h:1983
@ TK_DependentNonTemplate
Definition: Decl.h:1992
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1987
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1990
Declaration of a template function.
Definition: DeclTemplate.h:958
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
Represent a C++ namespace.
Definition: Decl.h:547
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2323
llvm::iterator_range< specific_decl_iterator< ObjCMethodDecl > > method_range
Definition: DeclObjC.h:1012
llvm::iterator_range< specific_decl_iterator< ObjCPropertyDecl > > prop_range
Definition: DeclObjC.h:963
Represents an ObjC class declaration.
Definition: DeclObjC.h:1152
llvm::iterator_range< protocol_iterator > protocol_range
Definition: DeclObjC.h:1354
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2079
Represents an unpacked "presumed" location which can be presented to the user.
A (possibly-)qualified type.
Definition: Type.h:738
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:4169
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:3585
bool isEmbeddedInDeclarator() const
True if this tag declaration is "embedded" (i.e., defined or declared for the very first time) in the...
Definition: Decl.h:3712
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3688
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5572
The base class of the type hierarchy.
Definition: Type.h:1607
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3535
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3433
Represents a variable declaration or definition.
Definition: Decl.h:918
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:1350
SymbolReference createSymbolReference(StringRef Name, StringRef USR, StringRef Source="")
Definition: API.cpp:92
StringRef copyString(StringRef String)
Copy String into the Allocator in this APISet.
Definition: API.cpp:79
APIRecord * findRecordForUSR(StringRef USR) const
Finds the APIRecord for a given USR.
Definition: API.cpp:68
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 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 getFragmentsForFunctionTemplateSpecialization(const FunctionDecl *Decl)
static DeclarationFragments getFragmentsForRecordDecl(const RecordDecl *)
Build DeclarationFragments for a struct/union record declaration RecordDecl.
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.
DeclarationFragments & appendSpace()
Append a text Fragment of a space character.
DeclarationFragments & insert(FragmentIterator It, StringRef Spelling, FragmentKind Kind, StringRef PreciseIdentifier="", const Decl *Declaration=nullptr)
DeclarationFragments & removeTrailingSemicolon()
Removes a trailing semicolon character if present.
DeclarationFragments & appendSemicolon()
Append a text Fragment of a semicolon character.
DeclarationFragments & append(StringRef Spelling, FragmentKind Kind, StringRef PreciseIdentifier="", const Decl *Declaration=nullptr)
Append a new Fragment to the end of the Fragments.
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)
SymbolReference createHierarchyInformationForDecl(const Decl &D)
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 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)
SymbolReference createSymbolReferenceForDecl(const Decl &D)
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)
SmallVector< SymbolReference > getBases(const CXXRecordDecl *Decl)
bool VisitConceptDecl(const ConceptDecl *Decl)
bool WalkUpFromVarTemplatePartialSpecializationDecl(const VarTemplatePartialSpecializationDecl *Decl)
bool WalkUpFromVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *Decl)
bool WalkUpFromClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl *Decl)
std::vector< RawComment::CommentLine > DocComment
DocComment is a vector of RawComment::CommentLine.
Definition: API.h:158
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
The JSON file list parser is used to communicate input to InstallAPI.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
@ 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:188
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ AS_public
Definition: Specifiers.h:121
static AvailabilityInfo createFromDecl(const Decl *Decl)
The base representation of an API record. Holds common symbol information.
Definition: API.h:192
RecordKind
Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
Definition: API.h:194
SmallVector< SymbolReference > Bases
Definition: API.h:1122
This holds information associated with enum constants.
Definition: API.h:575
This holds information associated with enums.
Definition: API.h:595
This holds information associated with global functions.
Definition: API.h:397
This holds information associated with global functions.
Definition: API.h:478
This holds information associated with Objective-C categories.
Definition: API.h:1226
The base representation of an Objective-C container record.
Definition: API.h:1102
This holds information associated with Objective-C instance variables.
Definition: API.h:1002
This holds information associated with Objective-C interfaces/classes.
Definition: API.h:1259
AttributeKind
The attributes associated with an Objective-C property.
Definition: API.h:927
This holds information associated with Objective-C protocols.
Definition: API.h:1283
StringRef Source
The source project/module/product of the referred symbol.
Definition: API.h:169
This holds information associated with typedefs.
Definition: API.h:1327
SymbolReference getSymbolReferenceForType(QualType Type, APISet &API) const
Get a SymbolReference for the given type.