14#ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
15#define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
31#include "llvm/ADT/SmallString.h"
32#include "llvm/ADT/StringRef.h"
33#include "llvm/Support/Casting.h"
40template <
typename Derived>
143 const llvm::iterator_range<
165 Derived &getDerivedExtractAPIVisitor() {
166 return *
static_cast<Derived *
>(
this);
173 for (
const auto &BaseSpecifier :
Decl->bases()) {
178 if (BaseSpecifier.getType().getTypePtr()->isTemplateTypeParmType()) {
180 if (
auto *TTPTD = BaseSpecifier.getType()
190 *BaseSpecifier.getType().getTypePtr()->getAsCXXRecordDecl());
192 Bases.emplace_back(BaseClass);
199 return OwningModule->Name;
222 if (
auto *ND = dyn_cast<NamedDecl>(&D))
223 Name = ND->getName();
235 if (!NewRecordContext)
240 if (
auto *
Record = llvm::dyn_cast_if_present<TagRecord>(
242 if (
Record->IsEmbeddedInVarDeclarator) {
244 auto *NewRecord = cast<APIRecord>(NewRecordContext);
245 if (NewRecord->Comment.empty())
246 NewRecord->Comment =
Record->Comment;
252template <
typename Derived>
255 if (isa<ParmVarDecl>(
Decl))
272 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
276 StringRef Name =
Decl->getName();
284 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
286 Context.getDiagnostics());
293 if (
Decl->isStaticDataMember()) {
296 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
298 SubHeading, Access, isInSystemHeader(
Decl));
302 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
304 SubHeading, isInSystemHeader(
Decl));
308 maybeMergeWithAnonymousTag(*
Decl, NewRecord);
314template <
typename Derived>
317 if (
const auto *Method = dyn_cast<CXXMethodDecl>(
Decl)) {
319 if (Method->getParent()->getDescribedClassTemplate() !=
nullptr)
323 for (
const auto &
P : Context.getParents(*Method)) {
324 if (
P.template get<CXXRecordDecl>())
329 if (isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method))
334 switch (
Decl->getTemplatedKind()) {
345 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
349 StringRef Name =
Decl->getName();
357 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
359 Context.getDiagnostics());
366 if (
Decl->getTemplateSpecializationInfo())
368 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
372 SubHeading, Signature, isInSystemHeader(
Decl));
376 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
379 Signature, isInSystemHeader(
Decl));
383template <
typename Derived>
385 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
390 StringRef Name =
Decl->getName();
392 Name = getTypedefName(
Decl);
394 llvm::raw_svector_ostream OS(QualifiedNameBuffer);
395 Decl->printQualifiedName(OS);
396 Name = QualifiedNameBuffer;
405 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
407 Context.getDiagnostics());
415 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
417 isInSystemHeader(
Decl), isEmbeddedInVarDeclarator(*
Decl));
420 getDerivedExtractAPIVisitor().recordEnumConstants(ER,
Decl->enumerators());
425template <
typename Derived>
428 getDerivedExtractAPIVisitor().VisitFunctionDecl(
Decl);
432template <
typename Derived>
435 getDerivedExtractAPIVisitor().VisitRecordDecl(
Decl);
439template <
typename Derived>
442 getDerivedExtractAPIVisitor().VisitCXXRecordDecl(
Decl);
446template <
typename Derived>
449 getDerivedExtractAPIVisitor().VisitCXXMethodDecl(
Decl);
453template <
typename Derived>
456 getDerivedExtractAPIVisitor().VisitClassTemplateSpecializationDecl(
Decl);
460template <
typename Derived>
464 getDerivedExtractAPIVisitor().VisitClassTemplatePartialSpecializationDecl(
469template <
typename Derived>
472 getDerivedExtractAPIVisitor().VisitVarTemplateDecl(
Decl);
476template <
typename Derived>
479 getDerivedExtractAPIVisitor().VisitVarTemplateSpecializationDecl(
Decl);
483template <
typename Derived>
487 getDerivedExtractAPIVisitor().VisitVarTemplatePartialSpecializationDecl(
Decl);
491template <
typename Derived>
494 getDerivedExtractAPIVisitor().VisitFunctionTemplateDecl(
Decl);
498template <
typename Derived>
501 getDerivedExtractAPIVisitor().VisitNamespaceDecl(
Decl);
505template <
typename Derived>
508 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
510 if (
Decl->isAnonymousNamespace())
512 StringRef Name =
Decl->getName();
520 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
522 Context.getDiagnostics());
530 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
532 SubHeading, isInSystemHeader(
Decl));
537template <
typename Derived>
539 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
543 StringRef Name =
Decl->getName();
545 Name = getTypedefName(
Decl);
553 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
555 Context.getDiagnostics());
565 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
567 SubHeading, isInSystemHeader(
Decl), isEmbeddedInVarDeclarator(*
Decl));
570 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
572 SubHeading, isInSystemHeader(
Decl), isEmbeddedInVarDeclarator(*
Decl));
577template <
typename Derived>
580 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
584 StringRef Name =
Decl->getName();
586 Name = getTypedefName(
Decl);
594 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
596 Context.getDiagnostics());
605 else if (
Decl->isStruct())
612 if (
Decl->getDescribedClassTemplate()) {
616 Decl->getDescribedClassTemplate()));
618 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
620 SubHeading,
Template(
Decl->getDescribedClassTemplate()), Access,
621 isInSystemHeader(
Decl));
624 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
626 SubHeading, Kind, Access, isInSystemHeader(
Decl),
627 isEmbeddedInVarDeclarator(*
Decl));
634template <
typename Derived>
637 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
641 if (isa<CXXConversionDecl>(
Decl))
643 if (isa<CXXConstructorDecl>(
Decl) || isa<CXXDestructorDecl>(
Decl))
652 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
654 Context.getDiagnostics());
661 Decl->getDescribedFunctionTemplate()) {
663 USR,
Decl->getName(), createHierarchyInformationForDecl(*
Decl), Loc,
670 }
else if (
Decl->getTemplateSpecializationInfo())
672 USR,
Decl->getName(), createHierarchyInformationForDecl(*
Decl), Loc,
676 SubHeading, Signature, Access, isInSystemHeader(
Decl));
677 else if (
Decl->isOverloadedOperator())
679 USR,
Decl->getNameAsString(), createHierarchyInformationForDecl(*
Decl),
682 SubHeading, Signature, Access, isInSystemHeader(
Decl));
683 else if (
Decl->isStatic())
685 USR,
Decl->getName(), createHierarchyInformationForDecl(*
Decl), Loc,
688 Signature, Access, isInSystemHeader(
Decl));
691 USR,
Decl->getName(), createHierarchyInformationForDecl(*
Decl), Loc,
694 Signature, Access, isInSystemHeader(
Decl));
699template <
typename Derived>
702 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
706 auto Name =
Decl->getNameAsString();
713 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
715 Context.getDiagnostics());
727 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
729 Signature, Access, isInSystemHeader(
Decl));
733template <
typename Derived>
736 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
740 auto Name =
Decl->getNameAsString();
747 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
749 Context.getDiagnostics());
760 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
762 Signature, Access, isInSystemHeader(
Decl));
766template <
typename Derived>
768 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
771 StringRef Name =
Decl->getName();
778 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
780 Context.getDiagnostics());
786 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
792template <
typename Derived>
795 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
798 StringRef Name =
Decl->getName();
805 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
807 Context.getDiagnostics());
815 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
818 isInSystemHeader(
Decl));
825template <
typename Derived>
829 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
832 StringRef Name =
Decl->getName();
839 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
841 Context.getDiagnostics());
847 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
850 isInSystemHeader(
Decl));
857template <
typename Derived>
860 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
864 StringRef Name =
Decl->getName();
872 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
874 Context.getDiagnostics());
882 Decl->getTemplatedDecl()));
889 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
895 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
901template <
typename Derived>
904 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
908 StringRef Name =
Decl->getName();
916 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
918 Context.getDiagnostics());
927 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
929 SubHeading, isInSystemHeader(
Decl));
933template <
typename Derived>
936 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
940 StringRef Name =
Decl->getName();
948 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
950 Context.getDiagnostics());
958 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
964template <
typename Derived>
967 if (isa<CXXMethodDecl>(
Decl->getTemplatedDecl()))
969 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
973 StringRef Name =
Decl->getName();
981 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
983 Context.getDiagnostics());
989 Decl->getTemplatedDecl());
991 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
999template <
typename Derived>
1002 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1006 StringRef Name =
Decl->getName();
1014 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1016 Context.getDiagnostics());
1026 if (
const auto *SuperClassDecl =
Decl->getSuperClass())
1027 SuperClass = createSymbolReferenceForDecl(*SuperClassDecl);
1030 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1032 SubHeading, SuperClass, isInSystemHeader(
Decl));
1036 getDerivedExtractAPIVisitor().recordObjCMethods(InterfaceRecord,
1038 getDerivedExtractAPIVisitor().recordObjCProperties(InterfaceRecord,
1039 Decl->properties());
1040 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(InterfaceRecord,
1042 getDerivedExtractAPIVisitor().recordObjCProtocols(InterfaceRecord,
1048template <
typename Derived>
1051 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1055 StringRef Name =
Decl->getName();
1062 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1064 Context.getDiagnostics());
1073 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1075 isInSystemHeader(
Decl));
1077 getDerivedExtractAPIVisitor().recordObjCMethods(ProtoRecord,
Decl->methods());
1078 getDerivedExtractAPIVisitor().recordObjCProperties(ProtoRecord,
1079 Decl->properties());
1080 getDerivedExtractAPIVisitor().recordObjCProtocols(ProtoRecord,
1086template <
typename Derived>
1090 if (isa<ObjCTypeParamDecl>(
Decl))
1096 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1099 StringRef Name =
Decl->getName();
1103 if (
auto *
TagDecl =
Decl->getUnderlyingType()->getAsTagDecl()) {
1108 if (
auto *
Record = API.findRecordForUSR(TagUSR)) {
1110 LeadingFragments.
append(
"typedef",
1114 .
prepend(std::move(LeadingFragments))
1130 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1132 Context.getDiagnostics());
1140 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1144 isInSystemHeader(
Decl));
1149template <
typename Derived>
1152 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1155 StringRef Name =
Decl->getName();
1162 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1164 Context.getDiagnostics());
1175 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1179 getDerivedExtractAPIVisitor().recordObjCMethods(CategoryRecord,
1181 getDerivedExtractAPIVisitor().recordObjCProperties(CategoryRecord,
1182 Decl->properties());
1183 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(CategoryRecord,
1185 getDerivedExtractAPIVisitor().recordObjCProtocols(CategoryRecord,
1193template <
typename Derived>
1196 for (
const auto *Constant : Constants) {
1198 StringRef Name = Constant->getName();
1202 Context.getSourceManager().getPresumedLoc(Constant->getLocation());
1205 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Constant))
1207 Context.getDiagnostics());
1216 USR, Name, createHierarchyInformationForDecl(*Constant), Loc,
1218 SubHeading, isInSystemHeader(Constant));
1222template <
typename Derived>
1225 if (isa<ObjCIvarDecl>(
Decl) || isa<ObjCAtDefsFieldDecl>(
Decl))
1228 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1232 StringRef Name =
Decl->getName();
1239 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1241 Context.getDiagnostics());
1254 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1256 SubHeading, Access, isInSystemHeader(
Decl));
1260 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1262 SubHeading, isInSystemHeader(
Decl));
1265 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1267 SubHeading, isInSystemHeader(
Decl));
1272 maybeMergeWithAnonymousTag(*
Decl, NewRecord);
1277template <
typename Derived>
1280 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
1284 auto Name =
Decl->getNameAsString();
1291 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1293 Context.getDiagnostics());
1304 if (
Decl->isStatic())
1306 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1308 SubHeading, Signature, Access, isInSystemHeader(
Decl));
1311 USR, Name, createHierarchyInformationForDecl(*
Decl), Loc,
1313 SubHeading, Signature, Access, isInSystemHeader(
Decl));
1320template <
typename Derived>
1324 for (
const auto *Method : Methods) {
1326 if (Method->isPropertyAccessor())
1329 auto Name = Method->getSelector().getAsString();
1333 Context.getSourceManager().getPresumedLoc(Method->getLocation());
1336 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Method))
1338 Context.getDiagnostics());
1348 if (Method->isInstanceMethod())
1350 USR, Name, createHierarchyInformationForDecl(*Method), Loc,
1352 SubHeading, Signature, isInSystemHeader(Method));
1355 USR, Name, createHierarchyInformationForDecl(*Method), Loc,
1357 SubHeading, Signature, isInSystemHeader(Method));
1361template <
typename Derived>
1365 for (
const auto *
Property : Properties) {
1366 StringRef Name =
Property->getName();
1370 Context.getSourceManager().getPresumedLoc(
Property->getLocation());
1373 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Property))
1375 Context.getDiagnostics());
1383 auto GetterName =
Property->getGetterName().getAsString();
1384 auto SetterName =
Property->getSetterName().getAsString();
1388 if (
Property->getPropertyAttributes() &
1394 USR, Name, createHierarchyInformationForDecl(*
Property), Loc,
1398 GetterName, SetterName,
Property->isOptional(),
1402 USR, Name, createHierarchyInformationForDecl(*
Property), Loc,
1406 GetterName, SetterName,
Property->isOptional(),
1411template <
typename Derived>
1414 const llvm::iterator_range<
1417 for (
const auto *Ivar : Ivars) {
1418 StringRef Name = Ivar->getName();
1423 Context.getSourceManager().getPresumedLoc(Ivar->getLocation());
1426 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Ivar))
1428 Context.getDiagnostics());
1437 USR, Name, createHierarchyInformationForDecl(*Ivar), Loc,
1439 SubHeading, isInSystemHeader(Ivar));
1443template <
typename Derived>
1447 for (
const auto *Protocol : Protocols)
1448 Container->Protocols.emplace_back(createSymbolReferenceForDecl(*Protocol));
1455template <
typename Derived =
void>
1458 std::is_same_v<Derived, void>, ExtractAPIVisitor<>, Derived>> {
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.
llvm::MachO::Record Record
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 ...
SourceManager & getSourceManager()
TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var)
RawComment * getRawCommentForDeclNoCache(const Decl *D) const
Return the documentation comment attached to a given declaration, without looking into cache.
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.
Module * getImportedOwningModule() const
Get the imported owning module, if this decl is from an imported (non-local) module.
SourceLocation getLocation() const
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
DeclContext * getDeclContext()
Represents a ValueDecl that came out of a declarator.
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.
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.
bool isEmbeddedInDeclarator() const
True if this tag declaration is "embedded" (i.e., defined or declared for the very first time) in the...
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateTypeParmDecl * getDecl() const
The base class of the type hierarchy.
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
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.
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.
@ Property
The type of a property.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
static AvailabilityInfo createFromDecl(const Decl *Decl)