14#ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
15#define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
22#include "llvm/ADT/FunctionExtras.h"
31#include "llvm/ADT/StringRef.h"
38template <
typename Derived>
146 const llvm::iterator_range<
168 Derived &getDerivedExtractAPIVisitor() {
169 return *
static_cast<Derived *
>(
this);
175 for (
const auto BaseSpecifier :
Decl->bases()) {
180 if (BaseSpecifier.getType().getTypePtr()->isTemplateTypeParmType()) {
186 BaseSpecifier.getType().getTypePtr()->getAsCXXRecordDecl();
190 Bases.emplace_back(BaseClass);
195 APIRecord *determineParentRecord(
const DeclContext *
Context) {
196 SmallString<128> ParentUSR;
197 if (
Context->getDeclKind() == Decl::TranslationUnit)
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",
217 DeclFragment.insert(--DeclFragment.end(),
" { ... } ",
219 DeclFragment.insert(--DeclFragment.end(), Name,
226template <
typename Derived>
229 if (isa<ParmVarDecl>(
Decl))
246 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
250 StringRef Name =
Decl->getName();
257 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
259 Context.getDiagnostics());
267 if (
Decl->isStaticDataMember()) {
272 Context.Name = Record->getName();
277 isInSystemHeader(
Decl));
285template <
typename Derived>
288 if (
const auto *Method = dyn_cast<CXXMethodDecl>(
Decl)) {
290 if (Method->getParent()->getDescribedClassTemplate() !=
nullptr)
294 for (
const auto &
P : Context.getParents(*Method)) {
295 if (
P.template get<CXXRecordDecl>())
300 if (isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method))
305 switch (
Decl->getTemplatedKind()) {
316 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
320 StringRef Name =
Decl->getName();
327 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
329 Context.getDiagnostics());
337 if (
Decl->getTemplateSpecializationInfo())
341 getFragmentsForFunctionTemplateSpecialization(
Decl),
342 SubHeading, Signature, isInSystemHeader(
Decl));
348 Signature, isInSystemHeader(
Decl));
352template <
typename Derived>
354 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
359 StringRef Name =
Decl->getName();
361 Name = getTypedefName(
Decl);
363 llvm::raw_svector_ostream OS(QualifiedNameBuffer);
364 Decl->printQualifiedName(OS);
365 Name = QualifiedNameBuffer.str();
373 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
375 Context.getDiagnostics());
388 getDerivedExtractAPIVisitor().recordEnumConstants(
EnumRecord,
389 Decl->enumerators());
394template <
typename Derived>
397 getDerivedExtractAPIVisitor().VisitFunctionDecl(
Decl);
401template <
typename Derived>
404 getDerivedExtractAPIVisitor().VisitRecordDecl(
Decl);
408template <
typename Derived>
411 getDerivedExtractAPIVisitor().VisitCXXRecordDecl(
Decl);
415template <
typename Derived>
418 getDerivedExtractAPIVisitor().VisitCXXMethodDecl(
Decl);
422template <
typename Derived>
425 getDerivedExtractAPIVisitor().VisitClassTemplateSpecializationDecl(
Decl);
429template <
typename Derived>
433 getDerivedExtractAPIVisitor().VisitClassTemplatePartialSpecializationDecl(
438template <
typename Derived>
441 getDerivedExtractAPIVisitor().VisitVarTemplateDecl(
Decl);
445template <
typename Derived>
448 getDerivedExtractAPIVisitor().VisitVarTemplateSpecializationDecl(
Decl);
452template <
typename Derived>
456 getDerivedExtractAPIVisitor().VisitVarTemplatePartialSpecializationDecl(
Decl);
460template <
typename Derived>
463 getDerivedExtractAPIVisitor().VisitFunctionTemplateDecl(
Decl);
467template <
typename Derived>
470 getDerivedExtractAPIVisitor().VisitNamespaceDecl(
Decl);
474template <
typename Derived>
478 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
480 if (
Decl->isAnonymousNamespace())
482 StringRef Name =
Decl->getName();
489 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
491 Context.getDiagnostics());
505template <
typename Derived>
507 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
510 StringRef Name =
Decl->getName();
512 Name = getTypedefName(
Decl);
521 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
523 Context.getDiagnostics());
533 SubHeading, isInSystemHeader(
Decl));
536 getDerivedExtractAPIVisitor().recordStructFields(
StructRecord,
542template <
typename Derived>
545 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
549 StringRef Name =
Decl->getName();
555 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
557 Context.getDiagnostics());
566 else if (
Decl->isStruct())
574 if (
Decl->getDescribedClassTemplate()) {
579 Decl->getDescribedClassTemplate()));
582 SubHeading,
Template(
Decl->getDescribedClassTemplate()), Access,
583 isInSystemHeader(
Decl));
587 SubHeading, Kind, Access, isInSystemHeader(
Decl));
594template <
typename Derived>
597 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
601 if (isa<CXXConversionDecl>(
Decl))
603 if (isa<CXXConstructorDecl>(
Decl) || isa<CXXDestructorDecl>(
Decl))
611 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
613 Context.getDiagnostics());
633 }
else if (
Decl->getTemplateSpecializationInfo())
637 getFragmentsForFunctionTemplateSpecialization(
Decl),
638 SubHeading, Signature, Access, isInSystemHeader(
Decl));
639 else if (
Decl->isOverloadedOperator())
644 SubHeading, Signature, Access, isInSystemHeader(
Decl));
645 else if (
Decl->isStatic())
649 Signature, Access, isInSystemHeader(
Decl));
654 Signature, Access, isInSystemHeader(
Decl));
659template <
typename Derived>
669 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
671 Context.getDiagnostics());
687 SubHeading, Signature, Access,
688 isInSystemHeader(
Decl));
692template <
typename Derived>
702 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
704 Context.getDiagnostics());
720 SubHeading, Signature, Access,
721 isInSystemHeader(
Decl));
725template <
typename Derived>
727 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
730 StringRef Name =
Decl->getName();
736 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
738 Context.getDiagnostics());
748template <
typename Derived>
751 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
754 StringRef Name =
Decl->getName();
760 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
762 Context.getDiagnostics());
773 isInSystemHeader(
Decl));
780template <
typename Derived>
784 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
787 StringRef Name =
Decl->getName();
793 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
795 Context.getDiagnostics());
802 auto *ClassTemplatePartialSpecRecord =
807 isInSystemHeader(
Decl));
809 ClassTemplatePartialSpecRecord->
Bases = getBases(
Decl);
814template <
typename Derived>
817 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
821 StringRef Name =
Decl->getName();
828 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
830 Context.getDiagnostics());
838 Decl->getTemplatedDecl()));
859template <
typename Derived>
862 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
866 StringRef Name =
Decl->getName();
873 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
875 Context.getDiagnostics());
886 SubHeading, isInSystemHeader(
Decl));
890template <
typename Derived>
893 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
897 StringRef Name =
Decl->getName();
904 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
906 Context.getDiagnostics());
920template <
typename Derived>
923 if (isa<CXXMethodDecl>(
Decl->getTemplatedDecl()))
925 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
929 StringRef Name =
Decl->getName();
936 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
938 Context.getDiagnostics());
944 Decl->getTemplatedDecl());
954template <
typename Derived>
957 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
961 StringRef Name =
Decl->getName();
968 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
970 Context.getDiagnostics());
980 if (
const auto *SuperClassDecl =
Decl->getSuperClass()) {
981 SuperClass.
Name = SuperClassDecl->getObjCRuntimeNameAsString();
987 SubHeading, SuperClass, isInSystemHeader(
Decl));
1003template <
typename Derived>
1006 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1010 StringRef Name =
Decl->getName();
1016 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1018 Context.getDiagnostics());
1033 Decl->properties());
1040template <
typename Derived>
1044 if (isa<ObjCTypeParamDecl>(
Decl))
1050 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
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()) {
1061 if (TagTy->getDecl()->isEnum()) {
1070 StringRef Name =
Decl->getName();
1074 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1076 Context.getDiagnostics());
1086 isInSystemHeader(
Decl));
1091template <
typename Derived>
1094 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1097 StringRef Name =
Decl->getName();
1103 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1105 Context.getDiagnostics());
1116 bool IsFromExternalModule =
true;
1118 if (InterfaceDecl->
getName() == Interface.second.get()->
Name) {
1119 IsFromExternalModule =
false;
1126 Interface, isInSystemHeader(
Decl), IsFromExternalModule);
1131 Decl->properties());
1142template <
typename Derived>
1145 for (
const auto *Constant : Constants) {
1147 StringRef Name = Constant->getName();
1148 StringRef USR = API.
recordUSR(Constant);
1150 Context.getSourceManager().getPresumedLoc(Constant->getLocation());
1153 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Constant))
1155 Context.getDiagnostics());
1165 isInSystemHeader(Constant));
1171template <
typename Derived>
1174 for (
const auto *Field : Fields) {
1176 StringRef Name = Field->getName();
1179 Context.getSourceManager().getPresumedLoc(Field->getLocation());
1182 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Field))
1184 Context.getDiagnostics());
1194 isInSystemHeader(Field));
1198template <
typename Derived>
1202 if (isa<ObjCIvarDecl>(
Decl))
1205 StringRef Name =
Decl->getName();
1211 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1213 Context.getDiagnostics());
1227 Access, isInSystemHeader(
Decl));
1231template <
typename Derived>
1240 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1242 Context.getDiagnostics());
1256 if (
Decl->isStatic())
1259 SubHeading, Signature, Access,
1260 isInSystemHeader(
Decl));
1264 SubHeading, Signature, Access,
1265 isInSystemHeader(
Decl));
1271template <
typename Derived>
1275 for (
const auto *Method : Methods) {
1277 if (Method->isPropertyAccessor())
1280 StringRef Name = API.
copyString(Method->getSelector().getAsString());
1283 Context.getSourceManager().getPresumedLoc(Method->getLocation());
1286 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Method))
1288 Context.getDiagnostics());
1300 Method->isInstanceMethod(), isInSystemHeader(Method));
1304template <
typename Derived>
1308 for (
const auto *
Property : Properties) {
1309 StringRef Name =
Property->getName();
1312 Context.getSourceManager().getPresumedLoc(
Property->getLocation());
1315 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Property))
1317 Context.getDiagnostics());
1325 StringRef GetterName =
1327 StringRef SetterName =
1332 if (
Property->getPropertyAttributes() &
1340 SetterName,
Property->isOptional(),
1341 !(
Property->getPropertyAttributes() &
1347template <
typename Derived>
1350 const llvm::iterator_range<
1353 for (
const auto *Ivar : Ivars) {
1354 StringRef Name = Ivar->getName();
1357 Context.getSourceManager().getPresumedLoc(Ivar->getLocation());
1360 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Ivar))
1362 Context.getDiagnostics());
1371 Ivar->getCanonicalAccessControl();
1375 SubHeading, Access, isInSystemHeader(Ivar));
1379template <
typename Derived>
1383 for (
const auto *Protocol : Protocols)
1384 Container->Protocols.emplace_back(Protocol->getName(),
1392template <
typename Derived =
void>
1395 std::is_same_v<Derived, void>, ExtractAPIVisitor<>, Derived>> {
1404 return this->Context.getRawCommentForDeclNoCache(D);
This file defines the APIRecord-based structs and the APISet class.
Defines the clang::ASTContext interface.
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 ...
SourceManager & getSourceManager()
TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var)
Represents a C++ constructor within a class.
Represents a C++ conversion function within a class.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
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,...
Decl::Kind getDeclKind() const
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
SourceLocation getLocation() const
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
DeclContext * getDeclContext()
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Represents a member of a struct/union/class.
Represents a function declaration or definition.
@ TK_MemberSpecialization
@ TK_DependentNonTemplate
@ TK_FunctionTemplateSpecialization
@ TK_DependentFunctionTemplateSpecialization
Declaration of a template function.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Represent a C++ namespace.
ObjCCategoryDecl - Represents a category declaration.
llvm::iterator_range< specific_decl_iterator< ObjCMethodDecl > > method_range
llvm::iterator_range< specific_decl_iterator< ObjCPropertyDecl > > prop_range
Represents an ObjC class declaration.
llvm::iterator_range< protocol_iterator > protocol_range
Represents an Objective-C protocol declaration.
Represents an unpacked "presumed" location which can be presented to the user.
A (possibly-)qualified type.
Represents a struct/union/class.
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
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.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateTypeParmDecl * getDecl() const
The base class of the type hierarchy.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Base class for declarations which introduce a typedef-name.
Represents a variable declaration or definition.
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
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.
@ Property
The type of a property.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...