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();
619template <
typename Derived>
622 bool Ret = Base::TraverseCXXRecordDecl(
Decl);
627 API.removeRecord(USR);
633template <
typename Derived>
640 StringRef Name =
Decl->getName();
661 if (
Decl->getDescribedClassTemplate()) {
665 Decl->getDescribedClassTemplate()));
669 SubHeading,
Template(
Decl->getDescribedClassTemplate()), Access,
685template <
typename Derived>
712 Decl->getDescribedFunctionTemplate()) {
721 }
else if (
Decl->getTemplateSpecializationInfo())
726 getFragmentsForFunctionTemplateSpecialization(
Decl),
728 else if (
Decl->isOverloadedOperator())
734 else if (
Decl->isStatic())
750template <
typename Derived>
757 auto Name =
Decl->getNameAsString();
784template <
typename Derived>
791 auto Name =
Decl->getNameAsString();
817template <
typename Derived>
822 StringRef Name =
Decl->getName();
843template <
typename Derived>
849 StringRef Name =
Decl->getName();
876template <
typename Derived>
883 StringRef Name =
Decl->getName();
909template <
typename Derived>
916 StringRef Name =
Decl->getName();
934 Decl->getTemplatedDecl()));
953template <
typename Derived>
960 StringRef Name =
Decl->getName();
985template <
typename Derived>
992 StringRef Name =
Decl->getName();
1016template <
typename Derived>
1025 auto Name =
Decl->getNameAsString();
1041 Decl->getTemplatedDecl());
1051template <
typename Derived>
1058 StringRef Name =
Decl->getName();
1078 if (
const auto *SuperClassDecl =
Decl->getSuperClass())
1088 getDerivedExtractAPIVisitor().recordObjCMethods(InterfaceRecord,
1090 getDerivedExtractAPIVisitor().recordObjCProperties(InterfaceRecord,
1091 Decl->properties());
1092 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(InterfaceRecord,
1094 getDerivedExtractAPIVisitor().recordObjCProtocols(InterfaceRecord,
1100template <
typename Derived>
1107 StringRef Name =
Decl->getName();
1129 getDerivedExtractAPIVisitor().recordObjCMethods(ProtoRecord,
Decl->methods());
1130 getDerivedExtractAPIVisitor().recordObjCProperties(ProtoRecord,
1131 Decl->properties());
1132 getDerivedExtractAPIVisitor().recordObjCProtocols(ProtoRecord,
1138template <
typename Derived>
1151 StringRef Name =
Decl->getName();
1156 if (TagName == Name)
1161 if (TagName.starts_with(
'_')) {
1162 StringRef StrippedName = TagName.ltrim(
'_');
1164 if (StrippedName == Name)
1173 if (
auto *
TagDecl =
Decl->getUnderlyingType()->getAsTagDecl()) {
1178 if (
auto *
Record =
API.findRecordForUSR(TagUSR)) {
1180 LeadingFragments.
append(
"typedef",
1183 Record->Declaration.removeTrailingSemicolon()
1184 .prepend(std::move(LeadingFragments))
1224template <
typename Derived>
1230 StringRef Name =
Decl->getName();
1254 getDerivedExtractAPIVisitor().recordObjCMethods(CategoryRecord,
1256 getDerivedExtractAPIVisitor().recordObjCProperties(CategoryRecord,
1257 Decl->properties());
1258 getDerivedExtractAPIVisitor().recordObjCInstanceVariables(CategoryRecord,
1260 getDerivedExtractAPIVisitor().recordObjCProtocols(CategoryRecord,
1268template <
typename Derived>
1271 for (
const auto *Constant : Constants) {
1273 StringRef Name = Constant->getName();
1277 Context.getSourceManager().getPresumedLoc(Constant->getLocation());
1296template <
typename Derived>
1306 StringRef Name =
Decl->getName();
1351template <
typename Derived>
1358 auto Name =
Decl->getNameAsString();
1378 if (
Decl->isStatic())
1394template <
typename Derived>
1398 for (
const auto *
Method : Methods) {
1400 if (
Method->isPropertyAccessor())
1403 auto Name =
Method->getSelector().getAsString();
1407 Context.getSourceManager().getPresumedLoc(
Method->getLocation());
1422 if (
Method->isInstanceMethod())
1435template <
typename Derived>
1439 for (
const auto *
Property : Properties) {
1440 StringRef Name =
Property->getName();
1457 auto GetterName =
Property->getGetterName().getAsString();
1458 auto SetterName =
Property->getSetterName().getAsString();
1462 if (
Property->getPropertyAttributes() &
1472 GetterName, SetterName,
Property->isOptional(),
1480 GetterName, SetterName,
Property->isOptional(),
1485template <
typename Derived>
1488 const llvm::iterator_range<
1491 for (
const auto *Ivar : Ivars) {
1492 StringRef Name = Ivar->getName();
1497 Context.getSourceManager().getPresumedLoc(Ivar->getLocation());
1517template <
typename Derived>
1521 for (
const auto *Protocol : Protocols)
1529template <
typename Derived =
void>
1532 std::is_same_v<Derived, void>, ExtractAPIVisitor<>, Derived>> {
1541 if (
const auto *Comment = this->
Context.getRawCommentForDeclNoCache(D))
1544 if (
const auto *
Declarator = dyn_cast<DeclaratorDecl>(D)) {
1545 const auto *TagTypeDecl =
Declarator->getType()->getAsTagDecl();
1546 if (TagTypeDecl && TagTypeDecl->isEmbeddedInDeclarator() &&
1547 TagTypeDecl->isCompleteDefinition())
1548 return this->
Context.getRawCommentForDeclNoCache(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.
static AvailabilityInfo createFromDecl(const Decl *Decl)