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);
200 if (
Decl->isStruct())
208 return OwningModule->Name;
231 if (
auto *ND = dyn_cast<NamedDecl>(&D))
232 Name = ND->getName();
244 if (!NewRecordContext)
249 if (
auto *
Record = llvm::dyn_cast_if_present<TagRecord>(
251 if (
Record->IsEmbeddedInVarDeclarator) {
253 auto *NewRecord = cast<APIRecord>(NewRecordContext);
254 if (NewRecord->Comment.empty())
255 NewRecord->Comment =
Record->Comment;
261template <
typename Derived>
264 if (isa<ParmVarDecl>(
Decl))
281 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
285 StringRef Name =
Decl->getName();
293 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
295 Context.getDiagnostics());
302 if (
Decl->isStaticDataMember()) {
305 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
307 SubHeading, Access, isInSystemHeader(
Decl));
311 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
313 SubHeading, isInSystemHeader(
Decl));
317 maybeMergeWithAnonymousTag(*
Decl, NewRecord);
323template <
typename Derived>
326 if (
const auto *Method = dyn_cast<CXXMethodDecl>(
Decl)) {
328 if (Method->getParent()->getDescribedClassTemplate() !=
nullptr)
332 for (
const auto &
P : Context.getParents(*Method)) {
333 if (
P.template get<CXXRecordDecl>())
338 if (isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method))
343 switch (
Decl->getTemplatedKind()) {
354 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
358 StringRef Name =
Decl->getName();
366 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
368 Context.getDiagnostics());
375 if (
Decl->getTemplateSpecializationInfo())
377 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
381 SubHeading, Signature, isInSystemHeader(
Decl));
385 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
388 Signature, isInSystemHeader(
Decl));
392template <
typename Derived>
394 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
399 StringRef Name =
Decl->getName();
401 Name = getTypedefName(
Decl);
403 llvm::raw_svector_ostream OS(QualifiedNameBuffer);
404 Decl->printQualifiedName(OS);
405 Name = QualifiedNameBuffer;
414 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
416 Context.getDiagnostics());
424 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
426 isInSystemHeader(
Decl), isEmbeddedInVarDeclarator(*
Decl));
429 getDerivedExtractAPIVisitor().recordEnumConstants(ER,
Decl->enumerators());
434template <
typename Derived>
437 getDerivedExtractAPIVisitor().VisitFunctionDecl(
Decl);
441template <
typename Derived>
444 getDerivedExtractAPIVisitor().VisitRecordDecl(
Decl);
448template <
typename Derived>
451 getDerivedExtractAPIVisitor().VisitCXXRecordDecl(
Decl);
455template <
typename Derived>
458 getDerivedExtractAPIVisitor().VisitCXXMethodDecl(
Decl);
462template <
typename Derived>
465 getDerivedExtractAPIVisitor().VisitClassTemplateSpecializationDecl(
Decl);
469template <
typename Derived>
473 getDerivedExtractAPIVisitor().VisitClassTemplatePartialSpecializationDecl(
478template <
typename Derived>
481 getDerivedExtractAPIVisitor().VisitVarTemplateDecl(
Decl);
485template <
typename Derived>
488 getDerivedExtractAPIVisitor().VisitVarTemplateSpecializationDecl(
Decl);
492template <
typename Derived>
496 getDerivedExtractAPIVisitor().VisitVarTemplatePartialSpecializationDecl(
Decl);
500template <
typename Derived>
503 getDerivedExtractAPIVisitor().VisitFunctionTemplateDecl(
Decl);
507template <
typename Derived>
510 getDerivedExtractAPIVisitor().VisitNamespaceDecl(
Decl);
514template <
typename Derived>
517 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
519 if (
Decl->isAnonymousNamespace())
521 StringRef Name =
Decl->getName();
529 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
531 Context.getDiagnostics());
539 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
541 SubHeading, isInSystemHeader(
Decl));
546template <
typename Derived>
548 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
552 StringRef Name =
Decl->getName();
554 Name = getTypedefName(
Decl);
562 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
564 Context.getDiagnostics());
574 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
576 SubHeading, isInSystemHeader(
Decl), isEmbeddedInVarDeclarator(*
Decl));
579 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
581 SubHeading, isInSystemHeader(
Decl), isEmbeddedInVarDeclarator(*
Decl));
586template <
typename Derived>
589 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
593 StringRef Name =
Decl->getName();
595 Name = getTypedefName(
Decl);
603 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
605 Context.getDiagnostics());
614 if (
Decl->getDescribedClassTemplate()) {
618 Decl->getDescribedClassTemplate()));
620 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
622 SubHeading,
Template(
Decl->getDescribedClassTemplate()), Access,
623 isInSystemHeader(
Decl));
626 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
629 isInSystemHeader(
Decl), isEmbeddedInVarDeclarator(*
Decl));
638template <
typename Derived>
641 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
645 if (isa<CXXConversionDecl>(
Decl))
647 if (isa<CXXConstructorDecl>(
Decl) || isa<CXXDestructorDecl>(
Decl))
656 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
658 Context.getDiagnostics());
665 Decl->getDescribedFunctionTemplate()) {
667 USR,
Decl->getName(), createHierarchyInformationForDecl(*
Decl),
Loc,
674 }
else if (
Decl->getTemplateSpecializationInfo())
676 USR,
Decl->getName(), createHierarchyInformationForDecl(*
Decl),
Loc,
680 SubHeading, Signature, Access, isInSystemHeader(
Decl));
681 else if (
Decl->isOverloadedOperator())
683 USR,
Decl->getNameAsString(), createHierarchyInformationForDecl(*
Decl),
686 SubHeading, Signature, Access, isInSystemHeader(
Decl));
687 else if (
Decl->isStatic())
689 USR,
Decl->getName(), createHierarchyInformationForDecl(*
Decl),
Loc,
692 Signature, Access, isInSystemHeader(
Decl));
695 USR,
Decl->getName(), createHierarchyInformationForDecl(*
Decl),
Loc,
698 Signature, Access, isInSystemHeader(
Decl));
703template <
typename Derived>
706 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
710 auto Name =
Decl->getNameAsString();
717 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
719 Context.getDiagnostics());
731 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
733 Signature, Access, isInSystemHeader(
Decl));
737template <
typename Derived>
740 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
744 auto Name =
Decl->getNameAsString();
751 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
753 Context.getDiagnostics());
764 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
766 Signature, Access, isInSystemHeader(
Decl));
770template <
typename Derived>
772 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
775 StringRef Name =
Decl->getName();
782 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
784 Context.getDiagnostics());
790 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
796template <
typename Derived>
799 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
802 StringRef Name =
Decl->getName();
809 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
811 Context.getDiagnostics());
819 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
822 isInSystemHeader(
Decl));
829template <
typename Derived>
833 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
836 StringRef Name =
Decl->getName();
843 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
845 Context.getDiagnostics());
851 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
854 isInSystemHeader(
Decl));
857 CTPSR->Bases = getBases(
Decl);
862template <
typename Derived>
865 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
869 StringRef Name =
Decl->getName();
877 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
879 Context.getDiagnostics());
887 Decl->getTemplatedDecl()));
894 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
900 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
906template <
typename Derived>
909 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
913 StringRef Name =
Decl->getName();
921 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
923 Context.getDiagnostics());
932 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
934 SubHeading, isInSystemHeader(
Decl));
938template <
typename Derived>
941 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
945 StringRef Name =
Decl->getName();
953 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
955 Context.getDiagnostics());
963 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
969template <
typename Derived>
972 if (isa<CXXMethodDecl>(
Decl->getTemplatedDecl()))
974 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
978 StringRef Name =
Decl->getName();
986 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
988 Context.getDiagnostics());
994 Decl->getTemplatedDecl());
996 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1004template <
typename Derived>
1007 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1011 StringRef Name =
Decl->getName();
1019 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1021 Context.getDiagnostics());
1031 if (
const auto *SuperClassDecl =
Decl->getSuperClass())
1032 SuperClass = createSymbolReferenceForDecl(*SuperClassDecl);
1035 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1037 SubHeading, SuperClass, isInSystemHeader(
Decl));
1041 getDerivedExtractAPIVisitor().recordObjCMethods(InterfaceRecord,
1043 getDerivedExtractAPIVisitor().recordObjCProperties(InterfaceRecord,
1044 Decl->properties());
1045 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(InterfaceRecord,
1047 getDerivedExtractAPIVisitor().recordObjCProtocols(InterfaceRecord,
1053template <
typename Derived>
1056 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1060 StringRef Name =
Decl->getName();
1067 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1069 Context.getDiagnostics());
1078 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1080 isInSystemHeader(
Decl));
1082 getDerivedExtractAPIVisitor().recordObjCMethods(ProtoRecord,
Decl->methods());
1083 getDerivedExtractAPIVisitor().recordObjCProperties(ProtoRecord,
1084 Decl->properties());
1085 getDerivedExtractAPIVisitor().recordObjCProtocols(ProtoRecord,
1091template <
typename Derived>
1095 if (isa<ObjCTypeParamDecl>(
Decl))
1101 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1104 StringRef Name =
Decl->getName();
1108 if (
auto *
TagDecl =
Decl->getUnderlyingType()->getAsTagDecl()) {
1113 if (
auto *
Record = API.findRecordForUSR(TagUSR)) {
1115 LeadingFragments.
append(
"typedef",
1119 .
prepend(std::move(LeadingFragments))
1135 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1137 Context.getDiagnostics());
1145 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1149 isInSystemHeader(
Decl));
1154template <
typename Derived>
1157 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1160 StringRef Name =
Decl->getName();
1167 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1169 Context.getDiagnostics());
1180 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1184 getDerivedExtractAPIVisitor().recordObjCMethods(CategoryRecord,
1186 getDerivedExtractAPIVisitor().recordObjCProperties(CategoryRecord,
1187 Decl->properties());
1188 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(CategoryRecord,
1190 getDerivedExtractAPIVisitor().recordObjCProtocols(CategoryRecord,
1198template <
typename Derived>
1201 for (
const auto *Constant : Constants) {
1203 StringRef Name = Constant->getName();
1207 Context.getSourceManager().getPresumedLoc(Constant->getLocation());
1210 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Constant))
1212 Context.getDiagnostics());
1221 USR, Name, createHierarchyInformationForDecl(*Constant),
Loc,
1223 SubHeading, isInSystemHeader(Constant));
1227template <
typename Derived>
1230 if (isa<ObjCIvarDecl>(
Decl) || isa<ObjCAtDefsFieldDecl>(
Decl))
1233 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl))
1237 StringRef Name =
Decl->getName();
1244 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1246 Context.getDiagnostics());
1259 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1261 SubHeading, Access, isInSystemHeader(
Decl));
1265 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1267 SubHeading, isInSystemHeader(
Decl));
1270 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1272 SubHeading, isInSystemHeader(
Decl));
1277 maybeMergeWithAnonymousTag(*
Decl, NewRecord);
1282template <
typename Derived>
1285 if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(
Decl) ||
1289 auto Name =
Decl->getNameAsString();
1296 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Decl))
1298 Context.getDiagnostics());
1309 if (
Decl->isStatic())
1311 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1313 SubHeading, Signature, Access, isInSystemHeader(
Decl));
1316 USR, Name, createHierarchyInformationForDecl(*
Decl),
Loc,
1318 SubHeading, Signature, Access, isInSystemHeader(
Decl));
1325template <
typename Derived>
1329 for (
const auto *Method : Methods) {
1331 if (Method->isPropertyAccessor())
1334 auto Name = Method->getSelector().getAsString();
1338 Context.getSourceManager().getPresumedLoc(Method->getLocation());
1341 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Method))
1343 Context.getDiagnostics());
1353 if (Method->isInstanceMethod())
1355 USR, Name, createHierarchyInformationForDecl(*Method),
Loc,
1357 SubHeading, Signature, isInSystemHeader(Method));
1360 USR, Name, createHierarchyInformationForDecl(*Method),
Loc,
1362 SubHeading, Signature, isInSystemHeader(Method));
1366template <
typename Derived>
1370 for (
const auto *
Property : Properties) {
1371 StringRef Name =
Property->getName();
1375 Context.getSourceManager().getPresumedLoc(
Property->getLocation());
1378 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(
Property))
1380 Context.getDiagnostics());
1388 auto GetterName =
Property->getGetterName().getAsString();
1389 auto SetterName =
Property->getSetterName().getAsString();
1393 if (
Property->getPropertyAttributes() &
1399 USR, Name, createHierarchyInformationForDecl(*
Property),
Loc,
1403 GetterName, SetterName,
Property->isOptional(),
1407 USR, Name, createHierarchyInformationForDecl(*
Property),
Loc,
1411 GetterName, SetterName,
Property->isOptional(),
1416template <
typename Derived>
1419 const llvm::iterator_range<
1422 for (
const auto *Ivar : Ivars) {
1423 StringRef Name = Ivar->getName();
1428 Context.getSourceManager().getPresumedLoc(Ivar->getLocation());
1431 getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Ivar))
1433 Context.getDiagnostics());
1442 USR, Name, createHierarchyInformationForDecl(*Ivar),
Loc,
1444 SubHeading, isInSystemHeader(Ivar));
1448template <
typename Derived>
1452 for (
const auto *Protocol : Protocols)
1453 Container->Protocols.emplace_back(createSymbolReferenceForDecl(*Protocol));
1460template <
typename Derived =
void>
1463 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)