14#ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
15#define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
32#include "llvm/ADT/SmallString.h"
33#include "llvm/ADT/StringRef.h"
34#include "llvm/Support/Casting.h"
41template <
typename Derived>
148 const llvm::iterator_range<
170 Derived &getDerivedExtractAPIVisitor() {
171 return *
static_cast<Derived *
>(
this);
176 if (!
Decl->isCompleteDefinition()) {
182 for (
const auto &BaseSpecifier :
Decl->bases()) {
186 if (
auto *BaseDecl = BaseSpecifier.getType()->getAsTagDecl()) {
190 BaseClass.
Name =
API.copyString(BaseSpecifier.getType().getAsString(
193 if (BaseSpecifier.getType().getTypePtr()->isTemplateTypeParmType()) {
194 if (
auto *TTPTD = BaseSpecifier.getType()
195 ->getAs<TemplateTypeParmType>()
199 BaseClass.USR =
API.copyString(USR);
203 Bases.emplace_back(BaseClass);
212 if (
Decl->isStruct())
220 return OwningModule->getTopLevelModule()->Name;
243 if (
auto *ND = dyn_cast<NamedDecl>(&D))
244 Name = ND->getName();
256 if (!NewRecordContext)
261 Tag = AT->getElementType()->getAsTagDecl();
266 if (
auto *
Record = llvm::dyn_cast_if_present<TagRecord>(
267 API.findRecordForUSR(TagUSR))) {
268 if (
Record->IsEmbeddedInVarDeclarator) {
276template <
typename Derived>
300 StringRef Name =
Decl->getName();
317 if (
Decl->isStaticDataMember()) {
338template <
typename Derived>
341 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(
Decl)) {
343 if (
Method->getParent()->getDescribedClassTemplate() !=
nullptr)
348 if (P.template get<CXXRecordDecl>())
358 switch (
Decl->getTemplatedKind()) {
373 auto Name =
Decl->getNameAsString();
390 if (
Decl->getTemplateSpecializationInfo())
407template <
typename Derived>
431 if (
Decl->hasNameForLinkage()) {
432 StringRef Name =
Decl->getName();
444 ParentContainer = {};
448 getDerivedExtractAPIVisitor().recordEnumConstants(ParentContainer,
449 Decl->enumerators());
454template <
typename Derived>
457 getDerivedExtractAPIVisitor().VisitFunctionDecl(
Decl);
461template <
typename Derived>
464 getDerivedExtractAPIVisitor().VisitRecordDecl(
Decl);
468template <
typename Derived>
471 getDerivedExtractAPIVisitor().VisitCXXRecordDecl(
Decl);
475template <
typename Derived>
478 getDerivedExtractAPIVisitor().VisitCXXMethodDecl(
Decl);
482template <
typename Derived>
485 getDerivedExtractAPIVisitor().VisitClassTemplateSpecializationDecl(
Decl);
489template <
typename Derived>
493 getDerivedExtractAPIVisitor().VisitClassTemplatePartialSpecializationDecl(
498template <
typename Derived>
501 getDerivedExtractAPIVisitor().VisitVarTemplateDecl(
Decl);
505template <
typename Derived>
508 getDerivedExtractAPIVisitor().VisitVarTemplateSpecializationDecl(
Decl);
512template <
typename Derived>
516 getDerivedExtractAPIVisitor().VisitVarTemplatePartialSpecializationDecl(
Decl);
520template <
typename Derived>
523 getDerivedExtractAPIVisitor().VisitFunctionTemplateDecl(
Decl);
527template <
typename Derived>
530 getDerivedExtractAPIVisitor().VisitNamespaceDecl(
Decl);
534template <
typename Derived>
539 if (
Decl->isAnonymousNamespace())
541 StringRef Name =
Decl->getName();
566template <
typename Derived>
568 bool Ret = Base::TraverseRecordDecl(
Decl);
573 API.removeRecord(USR);
579template <
typename Derived>
585 StringRef Name =
Decl->getName();
623template <
typename Derived>
626 bool Ret = Base::TraverseCXXRecordDecl(
Decl);
631 API.removeRecord(USR);
637template <
typename Derived>
644 StringRef Name =
Decl->getName();
665 if (
Decl->getDescribedClassTemplate()) {
669 Decl->getDescribedClassTemplate()));
673 SubHeading,
Template(
Decl->getDescribedClassTemplate()), Access,
689template <
typename Derived>
716 Decl->getDescribedFunctionTemplate()) {
725 }
else if (
Decl->getTemplateSpecializationInfo())
730 getFragmentsForFunctionTemplateSpecialization(
Decl),
732 else if (
Decl->isOverloadedOperator())
738 else if (
Decl->isStatic())
754template <
typename Derived>
761 auto Name =
Decl->getNameAsString();
788template <
typename Derived>
795 auto Name =
Decl->getNameAsString();
821template <
typename Derived>
826 StringRef Name =
Decl->getName();
847template <
typename Derived>
853 StringRef Name =
Decl->getName();
880template <
typename Derived>
887 StringRef Name =
Decl->getName();
913template <
typename Derived>
920 StringRef Name =
Decl->getName();
938 Decl->getTemplatedDecl()));
957template <
typename Derived>
964 StringRef Name =
Decl->getName();
989template <
typename Derived>
996 StringRef Name =
Decl->getName();
1020template <
typename Derived>
1029 auto Name =
Decl->getNameAsString();
1045 Decl->getTemplatedDecl());
1055template <
typename Derived>
1062 StringRef Name =
Decl->getName();
1082 if (
const auto *SuperClassDecl =
Decl->getSuperClass())
1092 getDerivedExtractAPIVisitor().recordObjCMethods(InterfaceRecord,
1094 getDerivedExtractAPIVisitor().recordObjCProperties(InterfaceRecord,
1095 Decl->properties());
1096 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(InterfaceRecord,
1098 getDerivedExtractAPIVisitor().recordObjCProtocols(InterfaceRecord,
1104template <
typename Derived>
1111 StringRef Name =
Decl->getName();
1133 getDerivedExtractAPIVisitor().recordObjCMethods(ProtoRecord,
Decl->methods());
1134 getDerivedExtractAPIVisitor().recordObjCProperties(ProtoRecord,
1135 Decl->properties());
1136 getDerivedExtractAPIVisitor().recordObjCProtocols(ProtoRecord,
1142template <
typename Derived>
1155 StringRef Name =
Decl->getName();
1160 if (TagName == Name)
1165 if (TagName.starts_with(
'_')) {
1166 StringRef StrippedName = TagName.ltrim(
'_');
1168 if (StrippedName == Name)
1177 if (
auto *
TagDecl =
Decl->getUnderlyingType()->getAsTagDecl()) {
1182 if (
auto *
Record =
API.findRecordForUSR(TagUSR)) {
1184 LeadingFragments.
append(
"typedef",
1187 Record->Declaration.removeTrailingSemicolon()
1188 .prepend(std::move(LeadingFragments))
1228template <
typename Derived>
1234 StringRef Name =
Decl->getName();
1258 getDerivedExtractAPIVisitor().recordObjCMethods(CategoryRecord,
1260 getDerivedExtractAPIVisitor().recordObjCProperties(CategoryRecord,
1261 Decl->properties());
1262 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(CategoryRecord,
1264 getDerivedExtractAPIVisitor().recordObjCProtocols(CategoryRecord,
1272template <
typename Derived>
1275 for (
const auto *
Constant : Constants) {
1277 StringRef Name =
Constant->getName();
1300template <
typename Derived>
1310 StringRef Name =
Decl->getName();
1355template <
typename Derived>
1362 auto Name =
Decl->getNameAsString();
1382 if (
Decl->isStatic())
1398template <
typename Derived>
1402 for (
const auto *
Method : Methods) {
1404 if (
Method->isPropertyAccessor())
1407 auto Name =
Method->getSelector().getAsString();
1411 Context.getSourceManager().getPresumedLoc(
Method->getLocation());
1426 if (
Method->isInstanceMethod())
1439template <
typename Derived>
1443 for (
const auto *
Property : Properties) {
1444 StringRef Name =
Property->getName();
1461 auto GetterName =
Property->getGetterName().getAsString();
1462 auto SetterName =
Property->getSetterName().getAsString();
1466 if (
Property->getPropertyAttributes() &
1476 GetterName, SetterName,
Property->isOptional(),
1484 GetterName, SetterName,
Property->isOptional(),
1489template <
typename Derived>
1492 const llvm::iterator_range<
1495 for (
const auto *Ivar : Ivars) {
1496 StringRef Name = Ivar->getName();
1501 Context.getSourceManager().getPresumedLoc(Ivar->getLocation());
1521template <
typename Derived>
1525 for (
const auto *Protocol : Protocols)
1533template <
typename Derived =
void>
1536 std::is_same_v<Derived, void>, ExtractAPIVisitor<>, Derived>> {
1545 if (
const auto *Comment = this->
Context.getRawCommentNoCache(D))
1548 if (
const auto *
Declarator = dyn_cast<DeclaratorDecl>(D)) {
1549 const auto *TagTypeDecl =
Declarator->getType()->getAsTagDecl();
1550 if (TagTypeDecl && TagTypeDecl->isEmbeddedInDeclarator() &&
1551 TagTypeDecl->isCompleteDefinition())
1552 return this->
Context.getRawCommentNoCache(TagTypeDecl);
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.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
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 ...
TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var)
const clang::PrintingPolicy & getPrintingPolicy() const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
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.
Information about one declarator, including the parsed type information and the identifier.
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...
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.
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
The base class of all kinds of template declarations (e.g., class, function, etc.).
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.
bool isa(CodeGen::Address addr)
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.
@ Template
We are parsing a template declaration.
@ 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.
Storage of availability attributes for a declaration.
void mergeWith(AvailabilityInfo Other)
Augments the existing information with additional constraints provided by Other.
static AvailabilityInfo createFromDecl(const Decl *Decl)